mask2cidr error with integer value - argument of type 'int' is not iterable
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
cloud-init |
Fix Released
|
Medium
|
Andreas Karis | ||
cloud-init (Ubuntu) |
Fix Released
|
Medium
|
Unassigned | ||
Xenial |
Fix Released
|
Medium
|
Unassigned | ||
Yakkety |
Fix Released
|
Medium
|
Unassigned | ||
Zesty |
Fix Released
|
Medium
|
Unassigned |
Bug Description
=== Begin SRU Template ===
[Impact]
On Openstack instances, when rendering sysconfig output, cloud-init
would stacktrace due to a TypeError.
This affects runtime only when rendering sysconfig networking, which
is what is used on CentOS and RedHat systems.
[Test Case]
The basic idea below is:
a.) launch an instance with proposed version of cloud-init.
b.) inside instance, get cloud-init's network rendering tool from trunk
c.) run the rendering tool against a config that failed before.
d.) check rendered netplan config to verify it has the correct format.
The failed output would have 'addresses' with a format like:
172.
The expected output would be 'cidr' format:
172.19.1.34/24
## launch an instance.
$ release=xenial
$ ref=$release-
$ lxc-proposed-
$ lxc launch $ref $name
$ lxc exec $name
## get render tool
% wget https:/
## write the network_data.json
% cat > simple-ipv6.yaml <<EOF
version: 1
config:
- type: physical
name: eth0
subnets:
- type: static
address: "2000:192:168::5"
netmask: 64
routes:
- netmask: 0
gateway: "2000:192:168::1"
network: "::"
EOF
## run the converter
% ./net-convert.py --network-
--kind=yaml --output-kind=eni --directory=out.d
## check the output
% cat out.d/etc/
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet6 static
address 2000:192:168::5
netmask 64
post-up route add -A inet6 default gw 2000:192:168::1 || true
pre-down route del -A inet6 default gw 2000:192:168::1 || true
## show the cloud-init versions
% dpkg-query --show cloud-init
...
[Regression Potential]
The fix here was just to make a common networking method accept
a string input as intended rather than only an integer.
The common code changes could shake out other failures in the networking
path.
[Other Info]
Upstream commit at
https:/
lxc-proposed-
https:/
It publishes an image to lxd with proposed enabled and cloud-init upgraded.
=== End SRU Template ===
mask2cidr error with integer value - argument of type 'int' is not iterable
~~~
def mask2cidr(mask):
if ':' in str(mask):
return ipv6mask2cidr(mask)
elif '.' in mask:
return ipv4mask2cidr(mask)
else:
return mask
~~~
is not type safe. It tries to take into account that this can be a prefix (so it does not contain ':' not '.' and then return mask. The problem is that if mask is an integer, then this returns:
~~~
Traceback (most recent call last):
File "/usr/lib/
ret = functor(name, args)
File "/usr/lib/
init.
File "/usr/lib/
return self.distro.
File "/usr/lib/
dev_names = self._write_
File "/usr/lib/
ns = parse_net_
File "/usr/lib/
nsi.
File "/usr/lib/
handler(self, command)
File "/usr/lib/
return func(self, command, *args, **kwargs)
File "/usr/lib/
subnet[
File "/usr/lib/
elif '.' in mask:
~~~
Made a modification to the code to troubleshoot this:
~~~
# convert subnet ipv6 netmask to cidr as needed
subnets = command.
print subnets
if subnets:
for subnet in subnets:
if subnet['type'] == 'static':
~~~
This error can be hit on RHEL when running the following 2x (don't know why 2x):
rm -Rf /var/lib/
On the second run, this will be returned:
~~~
Traceback (most recent call last):
File "/usr/lib/
ret = functor(name, args)
File "/usr/lib/
init.
File "/usr/lib/
return self.distro.
File "/usr/lib/
dev_names = self._write_
File "/usr/lib/
ns = parse_net_
File "/usr/lib/
nsi.
File "/usr/lib/
handler(self, command)
File "/usr/lib/
return func(self, command, *args, **kwargs)
File "/usr/lib/
subnet[
File "/usr/lib/
elif '.' in mask:
TypeError: argument of type 'int' is not iterable
-------
[{u'routes': [{u'netmask': u'0.0.0.0', u'network': u'0.0.0.0', u'gateway': u'192.168.0.1'}], u'netmask': u'255.255.255.0', u'type': 'static', 'ipv4': True, 'address': u'192.168.0.11'}, {u'routes': [{u'netmask': 0, u'network': u'::', u'gateway': u'2000:
~~~
not the `u'netmask': 64` integer
This can be fixed by changing the code to:
~~~
def mask2cidr(mask):
if ':' in str(mask):
return ipv6mask2cidr(mask)
elif '.' in str(mask):
return ipv4mask2cidr(mask)
else:
return mask
~~~
Related branches
- Chad Smith: Needs Fixing
- Server Team CI bot: Approve (continuous-integration)
- cloud-init Commiters: Pending requested
-
Diff: 16 lines (+2/-2)1 file modifiedcloudinit/net/network_state.py (+2/-2)
Changed in cloud-init: | |
assignee: | nobody → Andreas Karis (akaris) |
Changed in cloud-init: | |
status: | New → Confirmed |
importance: | Undecided → Medium |
Changed in cloud-init: | |
status: | Confirmed → Fix Committed |
Changed in cloud-init (Ubuntu): | |
status: | New → Fix Released |
importance: | Undecided → Medium |
Changed in cloud-init (Ubuntu Xenial): | |
status: | New → Confirmed |
Changed in cloud-init (Ubuntu Yakkety): | |
status: | New → Confirmed |
Changed in cloud-init (Ubuntu Zesty): | |
status: | New → Confirmed |
Changed in cloud-init (Ubuntu Xenial): | |
importance: | Undecided → Medium |
Changed in cloud-init (Ubuntu Yakkety): | |
importance: | Undecided → Medium |
Changed in cloud-init (Ubuntu Zesty): | |
importance: | Undecided → Medium |
description: | updated |
description: | updated |
With the above modification of 'print subnets', I ran this twice:
[root@rhel2 ~]# vi /usr/lib/ python2. 7/site- packages/ cloudinit/ net/network_ state.py cloud/data/ * ; cloud-init --force init +++++++ +++++++ +++++++ +++Net device info+++ +++++++ +++++++ +++++++ +++++++ ---+--- ---+--- ------- ----+-- ------- ------+ ------- +------ ------- ------+ ---+--- ---+--- ------- ----+-- ------- ------+ ------- +------ ------- ------+ ---+--- ---+--- ------- ----+-- ------- ------+ ------- +------ ------- ------+ +++++++ +++++++ +++++++ Route IPv4 info+++ +++++++ +++++++ +++++++ +++++ -+----- ------- -+----- ------- +------ ------- --+---- ------- +------ -+ -+----- ------- -+----- ------- +------ ------- --+---- ------- +------ -+ -+----- ------- -+----- ------- +------ ------- --+---- ------- +------ -+ 192:168: :1'}], u'netmask': u'ffff: ffff:ffff: ffff::' , 'address': u'2000:192:168::5', u'type': 'static', 'ipv6': True}] 172:20: :1'}], u'netmask': u'ffff: ffff:ffff: ffff::' , 'address': u'2000:172:20::4', u'type': 'static', 'ipv6': True}]
[root@rhel2 ~]# rm -Rf /var/lib/
Cloud-init v. 0.7.9 running 'init' at Fri, 21 Apr 2017 20:59:09 +0000. Up 101437.95 seconds.
ci-info: +++++++
ci-info: +------
ci-info: | Device | Up | Address | Mask | Scope | Hw-Address |
ci-info: +------
ci-info: | eth0:0: | True | 192.168.0.11 | 255.255.255.0 | . | fa:16:3e:cc:06:c3 |
ci-info: | eth1: | True | . | . | . | fa:16:3e:8a:1f:f4 |
ci-info: | eth1: | True | . | . | d | fa:16:3e:8a:1f:f4 |
ci-info: | eth2: | True | . | . | . | fa:16:3e:78:c2:39 |
ci-info: | eth2: | True | . | . | d | fa:16:3e:78:c2:39 |
ci-info: | eth0: | True | . | . | . | fa:16:3e:cc:06:c3 |
ci-info: | eth0: | True | . | . | d | fa:16:3e:cc:06:c3 |
ci-info: | eth3: | True | . | . | . | fa:16:3e:3b:76:55 |
ci-info: | eth3: | True | . | . | d | fa:16:3e:3b:76:55 |
ci-info: | lo: | True | 127.0.0.1 | 255.0.0.0 | . | . |
ci-info: | lo: | True | . | . | d | . |
ci-info: | eth2:0: | True | 10.0.0.106 | 255.255.255.0 | . | fa:16:3e:78:c2:39 |
ci-info: +------
ci-info: +++++++
ci-info: +------
ci-info: | Route | Destination | Gateway | Genmask | Interface | Flags |
ci-info: +------
ci-info: | 0 | 0.0.0.0 | 10.0.0.250 | 0.0.0.0 | eth2 | UG |
ci-info: | 1 | 10.0.0.0 | 0.0.0.0 | 255.255.255.0 | eth2 | U |
ci-info: | 2 | 192.168.0.0 | 0.0.0.0 | 255.255.255.0 | eth0 | U |
ci-info: +------
[{u'routes': [{u'netmask': u'0.0.0.0', u'network': u'0.0.0.0', u'gateway': u'192.168.0.1'}], u'netmask': u'255.255.255.0', u'type': 'static', 'ipv4': True, 'address': u'192.168.0.11'}, {u'routes': [{u'netmask': u'::', u'network': u'::', u'gateway': u'2000:
[{u'routes': [{u'netmask': u'::', u'network': u'::', u'gateway': u'2000:
[{u'routes': [{u'netmask': u'0.0.0.0', u'network': u'0.0.0.0', u'gateway': u'10.0.0.250'}], u'netmask': u'255.255.255.0', u'type': 'static', 'ipv4': True, 'address': u'10.0.0.106'}, {u'rout...