Replace netaddr dependency with stdlib ipaddress
netaddr is quite a big library, and all we need is covered by the built-in ipaddress module (available in python 3). Also add a safeguard for invalid 'ip route' output. Change-Id: I9d76a8d1c1b6b1585e301a9c63b37fab3b98746f
This commit is contained in:
parent
9f6c2aa05b
commit
4354bc04f9
@ -13,6 +13,7 @@
|
||||
# limitations under the License.
|
||||
|
||||
import collections
|
||||
import ipaddress
|
||||
import os
|
||||
import random
|
||||
import select
|
||||
@ -23,7 +24,6 @@ from wsgiref import simple_server
|
||||
|
||||
from ironic_lib import exception as lib_exc
|
||||
from ironic_lib import mdns
|
||||
import netaddr
|
||||
from oslo_concurrency import processutils
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log
|
||||
@ -238,14 +238,22 @@ class IronicPythonAgent(base.ExecuteCommandMixin):
|
||||
|
||||
try:
|
||||
source = out.strip().split('\n')[0].split('src')[1].split()[0]
|
||||
if netaddr.IPAddress(source).is_link_local():
|
||||
LOG.info('Ignoring link-local source to %(dest)s: %(rec)s',
|
||||
{'dest': dest, 'rec': out})
|
||||
return
|
||||
return source
|
||||
except IndexError:
|
||||
LOG.warning('No route to host %(dest)s, route record: %(rec)s',
|
||||
{'dest': dest, 'rec': out})
|
||||
return
|
||||
|
||||
try:
|
||||
if ipaddress.ip_address(source).is_link_local:
|
||||
LOG.info('Ignoring link-local source to %(dest)s: %(rec)s',
|
||||
{'dest': dest, 'rec': out})
|
||||
return
|
||||
except ValueError as exc:
|
||||
LOG.warning('Invalid IP address %(addr)s returned as a route '
|
||||
'to host %(dest)s: %(err)s',
|
||||
{'dest': dest, 'addr': source, 'err': exc})
|
||||
|
||||
return source
|
||||
|
||||
def set_agent_advertise_addr(self):
|
||||
"""Set advertised IP address for the agent, if not already set.
|
||||
|
@ -15,6 +15,7 @@
|
||||
import abc
|
||||
import binascii
|
||||
import functools
|
||||
import ipaddress
|
||||
import json
|
||||
from multiprocessing.pool import ThreadPool
|
||||
import os
|
||||
@ -24,7 +25,6 @@ import time
|
||||
|
||||
from ironic_lib import disk_utils
|
||||
from ironic_lib import utils as il_utils
|
||||
import netaddr
|
||||
from oslo_concurrency import processutils
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log
|
||||
@ -1320,9 +1320,9 @@ class GenericHardwareManager(HardwareManager):
|
||||
out = out.strip()
|
||||
|
||||
try:
|
||||
netaddr.IPAddress(out)
|
||||
except netaddr.AddrFormatError:
|
||||
LOG.warning('Invalid IP address: %s', out)
|
||||
ipaddress.ip_address(out)
|
||||
except ValueError as exc:
|
||||
LOG.warning('Invalid IP address %s: %s', out, exc)
|
||||
continue
|
||||
|
||||
# In case we get 0.0.0.0 on a valid channel, we need to keep
|
||||
@ -1397,9 +1397,9 @@ class GenericHardwareManager(HardwareManager):
|
||||
continue
|
||||
|
||||
try:
|
||||
return str(netaddr.IPNetwork(address).ip)
|
||||
except netaddr.AddrFormatError:
|
||||
LOG.warning('Invalid IP address: %s', address)
|
||||
return str(ipaddress.ip_interface(address).ip)
|
||||
except ValueError as exc:
|
||||
LOG.warning('Invalid IP address %s: %s', address, exc)
|
||||
continue
|
||||
except (processutils.ProcessExecutionError, OSError) as e:
|
||||
# Not error, because it's normal in virtual environment
|
||||
|
@ -37,7 +37,6 @@ mock==2.0.0
|
||||
monotonic==1.4
|
||||
mox3==0.25.0
|
||||
msgpack==0.5.6
|
||||
netaddr==0.7.18
|
||||
netifaces==0.10.4
|
||||
openstackdocstheme==1.20.0
|
||||
os-client-config==1.29.0
|
||||
|
@ -3,7 +3,6 @@
|
||||
# process, which may cause wedges in the gate later.
|
||||
pbr!=2.1.0,>=2.0.0 # Apache-2.0
|
||||
eventlet!=0.18.3,!=0.20.1,>=0.18.2 # MIT
|
||||
netaddr>=0.7.18 # BSD
|
||||
netifaces>=0.10.4 # MIT
|
||||
oslo.config>=5.2.0 # Apache-2.0
|
||||
oslo.concurrency>=3.26.0 # Apache-2.0
|
||||
|
Loading…
Reference in New Issue
Block a user