netinfo.py displays corrupted inet/inet6 addr on Linux

Bug #1285185 reported by Oleg Strikov
4
This bug affects 1 person
Affects Status Importance Assigned to Milestone
cloud-init
Fix Released
Medium
Unassigned

Bug Description

>>> import cloudinit.netinfo
>>> print(cloudinit.netinfo.debug_info())
ci-info: ++++++++++++++++++++++++++++Net device info++++++++++++++++++++++++++++
ci-info: +--------+------+-----------------+---------------+-------------------+
ci-info: | Device | Up | Address | Mask | Hw-Address |
ci-info: +--------+------+-----------------+---------------+-------------------+
ci-info: | lo | True | addr:127.0.0.1 | 255.0.0.0 | . |
ci-info: | eth0 | True | addr:10.0.128.5 | 255.255.255.0 | fa:16:3e:2d:1a:c7 |
ci-info: +--------+------+-----------------+---------------+-------------------+
ci-info: +++++++++++++++++++++++++++++++Route info+++++++++++++++++++++++++++++++
ci-info: +-------+-------------+------------+---------------+-----------+-------+
ci-info: | Route | Destination | Gateway | Genmask | Interface | Flags |
ci-info: +-------+-------------+------------+---------------+-----------+-------+
ci-info: | 0 | 0.0.0.0 | 10.0.128.6 | 0.0.0.0 | eth0 | UG |
ci-info: | 1 | 10.0.128.0 | 0.0.0.0 | 255.255.255.0 | eth0 | U |
ci-info: +-------+-------------+------------+---------------+-----------+-------+

'addr:127.0.0.1' and 'addr:10.0.128.5' are obviously incorrect values.
Correct ones are '127.0.0.1' and '10.0.128.5' respectively.

This issue was introduced together with basic FreeBSD support in this commit:
http://bazaar.launchpad.net/~cloud-init-dev/cloud-init/trunk/revision/920

This code (http://bazaar.launchpad.net/~cloud-init-dev/cloud-init/trunk/view/head:/cloudinit/netinfo.py#L63)
parses the following string 'inet addr:10.0.128.5 Bcast:10.0.128.255 Mask:255.255.255.0'
It handles both 'inet' token (required for FreeBSD) and 'addr:' token but 'inet' shows up first and gets handled by setting
devs[curdev]['inet'] = toks[i + 1] where toks[i + 1] == 'addr:10.0.128.5 '
'addr:' is not handled because we don't allow to overwrite data in devs[x][y].

I was able to fix this issue by allowing the script to overwrite data in devs[x][y].
It still handles 'inet' and sets incorrect devs[x][y] value but it's overwrited by correct 'addr:' handler on the next step.
My change is here: http://bazaar.launchpad.net/~strikov/cloud-init/netinfo-inet-addr-fix/revision/956

(!) We need to make sure that this code works correctly on FreeBSD (!)

Is there any good reason (e.g. we don't want to add one more dependency to solve such a simple task) to avoid using https://pypi.python.org/pypi/netifaces or some other library?

Related branches

Revision history for this message
Scott Moser (smoser) wrote :

Oleg,
  Thanks for the bug and diagnosis.
  I don't have a really good reason (https://bugs.launchpad.net/cloud-init/+bug/925145 shows that there are issues with what we have).
  That said, at this point in this cycle, I'd just like to grab a fix and not add the dependency.

Revision history for this message
Scott Moser (smoser) wrote :

fix-committed in trunk at 956.

The fix is more specific to this error, as I was afraid of other fallout for overwriting existing keys.

Changed in cloud-init:
importance: Undecided → Medium
status: New → Fix Committed
Scott Moser (smoser)
Changed in cloud-init:
status: Fix Committed → Fix Released
Revision history for this message
James Falcon (falcojr) wrote :
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.