ansible-collections / ansible.utils

A collection of ansible utilities for the content creator.
GNU General Public License v3.0
75 stars 78 forks source link

fix: netaddr is_private method deprecation #338

Closed rizlas closed 8 months ago

rizlas commented 8 months ago
SUMMARY

Fix: #331

Netaddr has removed is_private method. This PR aims to fix it using is_global method instead that support both IPv4 and IPv6.

First argument of _private_query is IPNetwork that's why .ip (v.ip) attribute is used. Otherwise is_global function is not available (see below for more infos).

Backward compatibility is maintained till netaddr 0.10.0. Not before.

Netaddr changelog: https://netaddr.readthedocs.io/en/latest/changes.html#release-1-0-0

ISSUE TYPE
COMPONENT NAME

ipaddr_utils.py

ADDITIONAL INFORMATION

Install netaddr > 1.0.0 and use ansible.utils.ipaddr('private') to reproduce.

Object attributes of IPNetwork.ip (only notable):

'ipv4', 'ipv6', 'is_global', 'is_hostmask', 'is_ipv4_compat', 'is_ipv4_mapped', 'is_ipv4_private_use', 'is_ipv6_unique_local', 'is_link_local', 'is_loopback', 'is_multicast', 'is_netmask', 'is_reserved', 'is_unicast'

Object attributes of IPAddress class (only notable):

'ipv4', 'ipv6', 'is_global', 'is_hostmask', 'is_ipv4_compat', 'is_ipv4_mapped', 'is_ipv4_private_use', 'is_ipv6_unique_local', 'is_link_local', 'is_loopback', 'is_multicast', 'is_netmask', 'is_reserved', 'is_unicast'

softwarefactory-project-zuul[bot] commented 8 months ago

Build succeeded. https://ansible.softwarefactory-project.io/zuul/buildset/60f51c6451114da9ae7911da8942ba13

:heavy_check_mark: ansible-galaxy-importer SUCCESS in 4m 41s :heavy_check_mark: build-ansible-collection SUCCESS in 8m 20s

RPDiep commented 8 months ago

LGTM; this would fix our problems as well. Need a review from a reviewer though.

sean-m-sullivan commented 8 months ago

LGTM; this would fix our problems as well. Need a review from a reviewer though.

rizlas commented 8 months ago

Hi, test is failing due to a wrong expected result:

https://github.com/ansible-collections/ansible.utils/blob/main/tests/integration/targets/utils_ipaddr_filter/vars/main.yaml#L29

ipaddr_result3:
  - 192.24.2.1
  - 2001:db8:32c:faad::/64

The IPv6 is reserved for documentation purposes and is not globally reachable and cannot be assigned by an isp (https://www.iana.org/assignments/iana-ipv6-special-registry/iana-ipv6-special-registry.xhtml). Therefore we can deduce that is not "public".

The range is also present in netaddr ip class https://github.com/netaddr/netaddr/blob/master/netaddr/ip/__init__.py#L2067.

Finally, please do note that is_global method is available since netaddr 0.10.0.

About PR I don't know how the value - "42540766412265424405338506004571095040/64" is "parsed", without @ashwini-mhatre and @Ruchip16 support I can't do any further adjustment.

Thank you

farwarx commented 8 months ago

Hi, anynews on the PR? It's a blocking issue for many ansible colletion like Zabbix for example. Regards ;)

ashwini-mhatre commented 8 months ago

@rizlas could you please add changelog

rizlas commented 8 months ago

Yeah, on it! Thank you

softwarefactory-project-zuul[bot] commented 8 months ago

Build succeeded. https://ansible.softwarefactory-project.io/zuul/buildset/95c22d287240439b923ae7ed7947826d

:heavy_check_mark: ansible-galaxy-importer SUCCESS in 7m 31s :heavy_check_mark: build-ansible-collection SUCCESS in 8m 26s

rizlas commented 8 months ago

Should I also change this to netaddr>=0.10.1?

Edit: I changed netaddr minimum version. I'll just revert if you don't like it 😅

softwarefactory-project-zuul[bot] commented 8 months ago

Build succeeded. https://ansible.softwarefactory-project.io/zuul/buildset/9937106841244835ab51b34f6909b8bc

:heavy_check_mark: ansible-galaxy-importer SUCCESS in 4m 36s :heavy_check_mark: build-ansible-collection SUCCESS in 8m 23s