Merge "Drop dependency on netifaces"
This commit is contained in:
@@ -19,12 +19,13 @@ import functools
|
||||
import inspect
|
||||
import itertools
|
||||
import math
|
||||
import socket
|
||||
import traceback
|
||||
|
||||
import netifaces
|
||||
from oslo_log import log
|
||||
from oslo_serialization import jsonutils
|
||||
from oslo_utils import excutils
|
||||
import psutil
|
||||
|
||||
from nova.accelerator import cyborg
|
||||
from nova import block_device
|
||||
@@ -1071,22 +1072,20 @@ def get_machine_ips():
|
||||
:returns: list of Strings of ip addresses
|
||||
"""
|
||||
addresses = []
|
||||
for interface in netifaces.interfaces():
|
||||
try:
|
||||
iface_data = netifaces.ifaddresses(interface)
|
||||
for family in iface_data:
|
||||
if family not in (netifaces.AF_INET, netifaces.AF_INET6):
|
||||
continue
|
||||
for address in iface_data[family]:
|
||||
addr = address['addr']
|
||||
for interface, ifaddresses in psutil.net_if_addrs().items():
|
||||
for ifaddress in ifaddresses:
|
||||
if ifaddress.family not in (socket.AF_INET, socket.AF_INET6):
|
||||
continue
|
||||
|
||||
addr = ifaddress.address
|
||||
|
||||
# If we have an ipv6 address remove the
|
||||
# %ether_interface at the end
|
||||
if ifaddress.family == socket.AF_INET6:
|
||||
addr = addr.split('%')[0]
|
||||
|
||||
addresses.append(addr)
|
||||
|
||||
# If we have an ipv6 address remove the
|
||||
# %ether_interface at the end
|
||||
if family == netifaces.AF_INET6:
|
||||
addr = addr.split('%')[0]
|
||||
addresses.append(addr)
|
||||
except ValueError:
|
||||
pass
|
||||
return addresses
|
||||
|
||||
|
||||
|
||||
5
nova/tests/fixtures/nova.py
vendored
5
nova/tests/fixtures/nova.py
vendored
@@ -32,6 +32,7 @@ import warnings
|
||||
import eventlet
|
||||
import fixtures
|
||||
import futurist
|
||||
from openstack.cloud import _utils
|
||||
from openstack import service_description
|
||||
from oslo_concurrency import lockutils
|
||||
from oslo_config import cfg
|
||||
@@ -1662,6 +1663,8 @@ class OpenStackSDKFixture(fixtures.Fixture):
|
||||
self.useFixture(fixtures.MockPatchObject(
|
||||
service_description.ServiceDescription, '_make_proxy',
|
||||
fake_make_proxy))
|
||||
self.useFixture(fixtures.MockPatchObject(
|
||||
_utils, 'localhost_supports_ipv6', return_value=False))
|
||||
|
||||
|
||||
class HostNameWeigher(weights.BaseHostWeigher):
|
||||
@@ -1716,7 +1719,7 @@ class HostNameWeigherFixture(fixtures.Fixture):
|
||||
class GenericPoisonFixture(fixtures.Fixture):
|
||||
POISON_THESE = (
|
||||
(
|
||||
'netifaces.interfaces',
|
||||
'psutil.net_if_addrs',
|
||||
'tests should not be inspecting real interfaces on the test node',
|
||||
),
|
||||
(
|
||||
|
||||
@@ -1155,18 +1155,6 @@ class ComputeUtilsTestCase(test.NoDBTestCase):
|
||||
self.assertRaises(test.TestingException,
|
||||
self._test_event_reporter_graceful_exit, error)
|
||||
|
||||
@mock.patch('netifaces.interfaces')
|
||||
def test_get_machine_ips_value_error(self, mock_interfaces):
|
||||
# Tests that the utility method does not explode if netifaces raises
|
||||
# a ValueError.
|
||||
iface = mock.sentinel
|
||||
mock_interfaces.return_value = [iface]
|
||||
with mock.patch('netifaces.ifaddresses',
|
||||
side_effect=ValueError) as mock_ifaddresses:
|
||||
addresses = compute_utils.get_machine_ips()
|
||||
self.assertEqual([], addresses)
|
||||
mock_ifaddresses.assert_called_once_with(iface)
|
||||
|
||||
@mock.patch('nova.compute.utils.notify_about_instance_action')
|
||||
@mock.patch('nova.compute.utils.notify_about_instance_usage')
|
||||
@mock.patch('nova.objects.Instance.destroy')
|
||||
|
||||
@@ -18,7 +18,6 @@ Paste>=2.0.2 # MIT
|
||||
PrettyTable>=0.7.1 # BSD
|
||||
alembic>=1.5.0 # MIT
|
||||
netaddr>=0.7.18 # BSD
|
||||
netifaces>=0.10.4 # MIT
|
||||
paramiko>=2.7.1 # LGPLv2.1+
|
||||
iso8601>=0.1.11 # MIT
|
||||
jsonschema>=4.0.0 # MIT
|
||||
|
||||
Reference in New Issue
Block a user