Merge ~akaris/cloud-init:bug1684349 into cloud-init:master

Proposed by Andreas Karis
Status: Merged
Merged at revision: 16a7302f6acb69adb0aee75eaf12392fa3688853
Proposed branch: ~akaris/cloud-init:bug1684349
Merge into: cloud-init:master
Diff against target: 16 lines (+2/-2)
1 file modified
cloudinit/net/network_state.py (+2/-2)
Reviewer Review Type Date Requested Status
Chad Smith Needs Fixing
Server Team CI bot continuous-integration Approve
cloud-init Commiters Pending
Review via email: mp+322992@code.launchpad.net

Commit message

Fix mask2cidr error with integer value

mask2cidr error with integer value - argument of type 'int' is not iterable. Method mask2cidr is not type safe. It tries to take into account that this can be a prefix (so it does not contain ':' nor '.') and then simly return mask without action. The problem is that if mask is an integer, then this throws an error, so this patch casts mask to type string in the if/elif.

LP: #1684349

To post a comment you must log in.
Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Lars Kellogg-Stedman (larsks) wrote :

If code is actually calling this with an integer argument, this looks like a fine temporary fix.

I say "temporary" because I'm a little confused by the return value of this function, too, which looks like it may be an int (when it calls ipv4mask2cidr) or a string (when it calls ipv6mask2cidr) or whatever "mask" happens to me if either of the previous conditionals fail. I will try to ping smoser about it tomorrow.

Revision history for this message
Dimitri John Ledkov (xnox) wrote :

It is called with whatever the config source provided.

It may be called with cidr, it could be an ipv6 netmask, or an ipv4 netmask.

Always return cidr.

I guess it would be better named any2cidr()

Revision history for this message
Chad Smith (chad.smith) wrote :

Generally, if we are changing functionality, I'd love to see a unit test exercising this functionality so we don't have to test it with integration tests.

It appears that this changeset will only pass this type problem down into ipv4mask2cidr and ipv6mask2cidr which will fall over with the same traceback as they attempt the same string search in mask(which is still an int).

Scott mentioned in IRC today that he's working a branch cleaning up network_state so I'm wondering if we just wait on the cleanup there to see if it addresses this issue.

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

I've marked this 'merged'
the change was present at
 https://code.launchpad.net/~xnox/cloud-init/+git/cloud-init/+merge/324010

i have a lot of further improvements to that general area, fixing Andreas's issues with the type safety of that function. Theres more to do, but you can see at https://code.launchpad.net/~smoser/cloud-init/+git/cloud-init/+merge/324274

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/cloudinit/net/network_state.py b/cloudinit/net/network_state.py
index db3c357..9e9c05a 100644
--- a/cloudinit/net/network_state.py
+++ b/cloudinit/net/network_state.py
@@ -734,9 +734,9 @@ def ipv6mask2cidr(mask):
734734
735735
736def mask2cidr(mask):736def mask2cidr(mask):
737 if ':' in mask:737 if ':' in str(mask):
738 return ipv6mask2cidr(mask)738 return ipv6mask2cidr(mask)
739 elif '.' in mask:739 elif '.' in str(mask):
740 return ipv4mask2cidr(mask)740 return ipv4mask2cidr(mask)
741 else:741 else:
742 return mask742 return mask

Subscribers

People subscribed via source and target branches