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