Change agents to use get_devices_with_ip()
Instead of instantiating an IPDevice object just to get the list of IPs, call get_devices_with_ip() instead since that's what it's doing anyways. Trivialfix Change-Id: I5055d24a40d45f3f3b13b05249d353ea67acf4d5
This commit is contained in:
parent
418bed5409
commit
b083d39a83
@ -277,9 +277,9 @@ class DvrEdgeRouter(dvr_local_router.DvrLocalRouter):
|
||||
return set()
|
||||
interface_name = self.get_snat_external_device_interface_name(
|
||||
ex_gw_port)
|
||||
device = ip_lib.IPDevice(
|
||||
interface_name, namespace=self.snat_namespace.name)
|
||||
return set([addr['cidr'] for addr in device.addr.list()])
|
||||
return set([addr['cidr'] for addr in ip_lib.get_devices_with_ip(
|
||||
self.snat_namespace.name,
|
||||
name=interface_name)])
|
||||
|
||||
def get_router_cidrs(self, device):
|
||||
"""Over-ride the get_router_cidrs function to return the list.
|
||||
|
@ -401,10 +401,8 @@ class HaRouter(router.RouterInfo):
|
||||
pm.disable(sig=str(int(signal.SIGKILL)))
|
||||
|
||||
def update_initial_state(self, callback):
|
||||
ha_device = ip_lib.IPDevice(
|
||||
self.get_ha_device_name(),
|
||||
self.ha_namespace)
|
||||
addresses = ha_device.addr.list()
|
||||
addresses = ip_lib.get_devices_with_ip(self.ha_namespace,
|
||||
name=self.get_ha_device_name())
|
||||
cidrs = (address['cidr'] for address in addresses)
|
||||
ha_cidr = self._get_primary_vip()
|
||||
state = 'master' if ha_cidr in cidrs else 'backup'
|
||||
|
@ -1066,9 +1066,6 @@ class Dnsmasq(DhcpLocalProcess):
|
||||
return options
|
||||
|
||||
def _make_subnet_interface_ip_map(self):
|
||||
ip_dev = ip_lib.IPDevice(self.interface_name,
|
||||
namespace=self.network.namespace)
|
||||
|
||||
subnet_lookup = dict(
|
||||
(netaddr.IPNetwork(subnet.cidr), subnet.id)
|
||||
for subnet in self.network.subnets
|
||||
@ -1076,7 +1073,8 @@ class Dnsmasq(DhcpLocalProcess):
|
||||
|
||||
retval = {}
|
||||
|
||||
for addr in ip_dev.addr.list():
|
||||
for addr in ip_lib.get_devices_with_ip(self.network.namespace,
|
||||
name=self.interface_name):
|
||||
ip_net = netaddr.IPNetwork(addr['cidr'])
|
||||
|
||||
if ip_net in subnet_lookup:
|
||||
|
@ -26,6 +26,7 @@ import six
|
||||
from neutron.agent.common import ovs_lib
|
||||
from neutron.agent.linux import ip_lib
|
||||
from neutron.common import constants as n_const
|
||||
from neutron.common import utils
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
@ -224,10 +225,11 @@ class LinuxInterfaceDriver(object):
|
||||
break
|
||||
|
||||
def get_ipv6_llas(self, device_name, namespace):
|
||||
device = ip_lib.IPDevice(device_name,
|
||||
namespace=namespace)
|
||||
|
||||
return device.addr.list(scope='link', ip_version=6)
|
||||
kwargs = {'family': utils.get_socket_address_family(
|
||||
constants.IP_VERSION_6),
|
||||
'scope': 'link'}
|
||||
return ip_lib.get_devices_with_ip(namespace, name=device_name,
|
||||
**kwargs)
|
||||
|
||||
def check_bridge_exists(self, bridge):
|
||||
if not ip_lib.device_exists(bridge):
|
||||
|
@ -2502,10 +2502,9 @@ class TestDnsmasq(TestBase):
|
||||
self._test_read_leases_file_leases(None, True)
|
||||
|
||||
def test_make_subnet_interface_ip_map(self):
|
||||
with mock.patch('neutron.agent.linux.ip_lib.IPDevice') as ip_dev:
|
||||
ip_dev.return_value.addr.list.return_value = [
|
||||
{'cidr': '192.168.0.1/24'}
|
||||
]
|
||||
with mock.patch('neutron.agent.linux.ip_lib.'
|
||||
'get_devices_with_ip') as list_mock:
|
||||
list_mock.return_value = [{'cidr': '192.168.0.1/24'}]
|
||||
|
||||
dm = self._get_dnsmasq(FakeDualNetwork())
|
||||
|
||||
@ -2705,9 +2704,9 @@ class TestDnsmasq(TestBase):
|
||||
for key, value in config_opts.items():
|
||||
self.conf.set_override(key, value)
|
||||
dm = self._get_dnsmasq(network_class())
|
||||
with mock.patch('neutron.agent.linux.ip_lib.IPDevice') as ipdev_mock:
|
||||
list_addr = ipdev_mock.return_value.addr.list
|
||||
list_addr.return_value = [{'cidr': alloc.ip_address + '/24'}
|
||||
with mock.patch('neutron.agent.linux.ip_lib.'
|
||||
'get_devices_with_ip') as list_mock:
|
||||
list_mock.return_value = [{'cidr': alloc.ip_address + '/24'}
|
||||
for alloc in FakeDhcpPort().fixed_ips]
|
||||
options, idx_map = dm._generate_opts_per_subnet()
|
||||
|
||||
|
@ -21,6 +21,7 @@ from oslo_utils import excutils
|
||||
from neutron.agent.common import ovs_lib
|
||||
from neutron.agent.linux import interface
|
||||
from neutron.agent.linux import ip_lib
|
||||
from neutron.common import utils
|
||||
from neutron.conf.agent import common as config
|
||||
from neutron.tests import base
|
||||
|
||||
@ -66,6 +67,9 @@ class TestBase(base.BaseTestCase):
|
||||
self.ip = self.ip_p.start()
|
||||
self.device_exists_p = mock.patch.object(ip_lib, 'device_exists')
|
||||
self.device_exists = self.device_exists_p.start()
|
||||
self.get_devices_with_ip_p = mock.patch.object(ip_lib,
|
||||
'get_devices_with_ip')
|
||||
self.get_devices_with_ip = self.get_devices_with_ip_p.start()
|
||||
|
||||
|
||||
class TestABCDriver(TestBase):
|
||||
@ -352,17 +356,18 @@ class TestABCDriver(TestBase):
|
||||
addresses = [dict(scope='link',
|
||||
dynamic=False,
|
||||
cidr='fe80:cafe::/64')]
|
||||
self.ip_dev().addr.list = mock.Mock(return_value=addresses)
|
||||
self.get_devices_with_ip.return_value = addresses
|
||||
device_name = self.ip_dev().name
|
||||
bc = BaseChild(self.conf)
|
||||
|
||||
llas = bc.get_ipv6_llas(device_name, ns)
|
||||
|
||||
self.assertEqual(addresses, llas)
|
||||
self.ip_dev.assert_has_calls(
|
||||
[mock.call(device_name, namespace=ns),
|
||||
mock.call().addr.list(
|
||||
scope='link', ip_version=constants.IP_VERSION_6)])
|
||||
kwargs = {'family': utils.get_socket_address_family(
|
||||
constants.IP_VERSION_6),
|
||||
'scope': 'link'}
|
||||
self.get_devices_with_ip.assert_called_with(
|
||||
ns, name=device_name, **kwargs)
|
||||
|
||||
def test_set_mtu_logs_once(self):
|
||||
bc = BaseChild(self.conf)
|
||||
|
Loading…
Reference in New Issue
Block a user