From 968e3d348d57d60016e9b17615234b83fb7bc20c Mon Sep 17 00:00:00 2001 From: Michael Johnson Date: Tue, 2 Aug 2022 21:52:40 +0000 Subject: [PATCH] Remove netaddr module requirement This patch removes the 'netaddr' module from the Designate requirements list. It replaces the use of netaddr in Designate with the python standard library 'ipaddress' module. Change-Id: I2fb1549e1d6cbccf58c03810c7d74c8c378682d5 --- contrib/fixleadingzeros.py | 5 +++-- designate/backend/impl_pdns4.py | 4 ++-- designate/schema/format.py | 9 ++++----- .../remove-netaddr-requirement-ab9b9c2d15aa8e1c.yaml | 5 +++++ requirements.txt | 1 - 5 files changed, 14 insertions(+), 10 deletions(-) create mode 100644 releasenotes/notes/remove-netaddr-requirement-ab9b9c2d15aa8e1c.yaml diff --git a/contrib/fixleadingzeros.py b/contrib/fixleadingzeros.py index cdf49f1d3..3659a29a7 100755 --- a/contrib/fixleadingzeros.py +++ b/contrib/fixleadingzeros.py @@ -15,6 +15,7 @@ # License for the specific language governing permissions and limitations # under the License. import argparse +import ipaddress import logging import sys @@ -22,7 +23,6 @@ import dns.exception from dns.ipv4 import inet_aton from keystoneauth1.identity import generic from keystoneauth1 import session as keystone_session -import netaddr from designateclient import shell from designateclient.v2 import client @@ -72,8 +72,9 @@ def fix_bad_recordsets(bad_recordsets): for rs in bad_recordsets: new_records = [] for ip in bad_recordsets[rs]['records']: + ip = '.'.join(f'{int(i)}' for i in ip.split('.')) new_records.append( - str(netaddr.IPAddress(ip, flags=netaddr.ZEROFILL).ipv4()) + str(ipaddress.IPv4Address(ip)) ) bad_recordsets[rs]['records'] = new_records return bad_recordsets diff --git a/designate/backend/impl_pdns4.py b/designate/backend/impl_pdns4.py index a7e8cf6e5..30172233b 100644 --- a/designate/backend/impl_pdns4.py +++ b/designate/backend/impl_pdns4.py @@ -11,10 +11,10 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. +import ipaddress import os.path import urllib -import netaddr from oslo_config import cfg from oslo_log import log as logging import requests @@ -83,7 +83,7 @@ class PDNS4Backend(base.Backend): masters = [] for master in self.masters: host = master.host - if netaddr.IPAddress(host).version == 6: + if ipaddress.ip_address(host).version == 6: host = '[%s]' % host masters.append('%s:%d' % (host, master.port)) diff --git a/designate/schema/format.py b/designate/schema/format.py index bbed2017d..72f968c48 100644 --- a/designate/schema/format.py +++ b/designate/schema/format.py @@ -13,10 +13,10 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. +import ipaddress import re import jsonschema -import netaddr # NOTE(kiall): All of the below regular expressions are terminated with @@ -59,9 +59,7 @@ def is_ipv4(instance): return True try: - address = netaddr.IPAddress(instance, version=4) - # netaddr happly accepts, and expands "127.0" into "127.0.0.0" - if str(address) != instance: + if ipaddress.ip_address(instance).version != 4: return False except Exception: return False @@ -79,7 +77,8 @@ def is_ipv6(instance): return True try: - netaddr.IPAddress(instance, version=6) + if ipaddress.ip_address(instance).version != 6: + return False except Exception: return False diff --git a/releasenotes/notes/remove-netaddr-requirement-ab9b9c2d15aa8e1c.yaml b/releasenotes/notes/remove-netaddr-requirement-ab9b9c2d15aa8e1c.yaml new file mode 100644 index 000000000..fb810839f --- /dev/null +++ b/releasenotes/notes/remove-netaddr-requirement-ab9b9c2d15aa8e1c.yaml @@ -0,0 +1,5 @@ +--- +other: + - | + The netaddr python module has been removed as a Designate requirement. It + has been replaced with the python standard library 'ipaddress' module. diff --git a/requirements.txt b/requirements.txt index 6fa0ddf91..ac138eb25 100644 --- a/requirements.txt +++ b/requirements.txt @@ -12,7 +12,6 @@ Jinja2>=2.10 # BSD License (3 clause) jsonschema>=3.2.0 # MIT keystoneauth1>=3.4.0 # Apache-2.0 keystonemiddleware>=4.17.0 # Apache-2.0 -netaddr>=0.7.18 # BSD oslo.config>=6.8.0 # Apache-2.0 oslo.concurrency>=4.2.0 # Apache-2.0 oslo.messaging>=12.4.0 # Apache-2.0