-
Notifications
You must be signed in to change notification settings - Fork 177
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IPNetwork: Allow partial addresses (again) #377
Conversation
e35fe2f
to
32e86e5
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## master #377 +/- ##
==========================================
+ Coverage 85.72% 86.11% +0.38%
==========================================
Files 47 47
Lines 4379 4392 +13
Branches 737 740 +3
==========================================
+ Hits 3754 3782 +28
+ Misses 449 434 -15
Partials 176 176 ☔ View full report in Codecov by Sentry. |
32e86e5
to
4794351
Compare
The comment suggests expand_partial_ipv4_address, but this requires parsing IPNetwork (by splitting host and bitmask) and then expand the first bit and combine these two again for parsing. It'd make better sense to implement that conversion within IPNetwork, to avoid redundant split -> join -> split. |
Thank you for the contribution @kajinamit. Can you advocate for the need for the old behavior? It was removed intentionally and I'm hesitant to consider giving it first-class support without a good reason for it. |
Maybe put differently – is this form produced by some commonly used software or is it otherwise common (and so is the need to handle it)? Any links to relevant materials (including but not limited to RFCs) will be appreciated. |
Hi - it's related to Openstack Neutron. While we can fix our code to deal with the change in most places, the API behavior would previously allow '10/8' for a cidr [0], but with versions > 1.0.0 of netaddr this isn't possible. While I hope no one was using that notation we can't be sure. [0] https://bugs.launchpad.net/neutron/+bug/2054203/comments/4 |
@jstasiak Because netaddr was used at user input validation, it's quite hard to guarantee that no one has been relying on its previous behavior, and we likely need to retain the previous "wider" acceptance. |
Thank you both for the explanation. Some followup questions below.
Can you clarify what does "supported" mean here? Is it explicitly allowed with well-defined behavior or has it been working only as an unintended consequence of netaddr's (old) behavior? What is
Is the fact that addresses like
Is this actually a commonly used format and people are likely to be affected? I'm not opposed to bringing this kind of behavior back, behind a feature flag, in principle – I'm trying to gauge if this is worth it. |
Thank you for taking your time !
Probably the word "accepted" would explain my intention better.
Yes I noticed that during looking into the changes and I found it very odd. However that's how OpenStack parsed user inputs for very long time.
This may not be very common (even I wasn't aware of it ...), but this behavior has been kept for several years and we can't tell no one is affected, either.
I understand. [1] https://docs.openstack.org/api-ref/network/v2/index.html#create-subnet |
Ok, I thought about it and let's bring this behavior back. Changes to make to this PR:
|
4794351
to
a9a4d54
Compare
a93a441
to
ac60cb9
Compare
I've updated the change to address these. I'm not very sure about the 2nd point, which may make it a bit tricky to adapt to this upgrade (we have to make the logic change when we bump netaddr), but I'd not strongly object to it. |
a210284
to
fcbfb49
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I did some research and it seems there is in fact no standard for this shorthand notation, but I can confirm that is has been common to use it in network engineer circles for the last 20 years at least. It is also accepted e.g. by iproute2 so you can do things like ìp route show 10/8
. Finally it is mentioned in some similar library docs like https://metacpan.org/pod/Net::IP#Object-Creation
fcbfb49
to
e6f567c
Compare
This introduces the new expand argument to IPNetwork class, so that users can retain the previous behavior of netaddr < 1.0.0 optionally. >>> import netaddr >>> netaddr.IPNetwork('10/8') Traceback (most recent call last): File "/home/tkajinam/git/python/netaddr/netaddr/strategy/ipv4.py", line 126, in str_to_int packed = _inet_pton(AF_INET, addr) ^^^^^^^^^^^^^^^^^^^^^^^^^ OSError: illegal IP address string passed to inet_pton ... During handling of the above exception, another exception occurred: Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/tkajinam/git/python/netaddr/netaddr/ip/__init__.py", line 1035, in __init__ raise AddrFormatError('invalid IPNetwork %s' % (addr,)) netaddr.core.AddrFormatError: invalid IPNetwork 10/8 >>> netaddr.IPNetwork('10/8', partial=True) IPNetwork('10.0.0.0/8')
e6f567c
to
959e045
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thx
@@ -961,11 +964,15 @@ class IPNetwork(BaseIP, IPListMixin): | |||
.. versionchanged:: 1.1.0 | |||
Removed partial IPv4 address support accidentally left when making 1.0.0 release. | |||
Use :func:`expand_partial_ipv4_address` if you need this behavior. | |||
|
|||
.. versionchanged:: NEXT_NETADDR_VERSION |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this is supposed to be an actual number, otherwise lgtm.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a placeholder used in the project, it's good
Thank you |
The flag has been introduced in [1]. I think it improves things a little for the flag's name to be more verbose and to require passing it via keyword arguments (otherwise it's just True or False which is gonna be quite opaque to the reader). [1] d2f5d05 ("IPNetwork: Allow partial addresses (again) (#377)")
I allowed myself to change the new parameter to keyword-only |
This introduces the new expand argument to IPNetwork class, so that users can retain the previous behavior of netaddr < 1.0.0 optionally.