clear_outdated_routes: reduce neutron calls
This patch refactors the code which clears routes into another function which already gets all of the subnets to avoid hitting the Neutron API twice, and allowing us to eventually refactor all of this code into the linux interface management API. Change-Id: I6e1debce1ac379d15190db82299bdd92c9ff7734
This commit is contained in:
parent
e8adbf3cd4
commit
a8f9174ca6
|
@ -966,14 +966,13 @@ class NeutronNetworkHelper(BaseNetworkhelper):
|
|||
'manila-admin-share')
|
||||
interface_name = self.vif_driver.get_device_name(port)
|
||||
device = ip_lib.IPDevice(interface_name)
|
||||
for fixed_ip in port['fixed_ips']:
|
||||
subnet = self.neutron_api.get_subnet(fixed_ip['subnet_id'])
|
||||
device.route.clear_outdated_routes(subnet['cidr'])
|
||||
self._plug_interface_in_host(interface_name, device, port)
|
||||
self._plug_interface_in_host(interface_name, device, port,
|
||||
clear_outdated_routes=True)
|
||||
|
||||
@utils.synchronized("service_instance_plug_interface_in_host",
|
||||
external=True)
|
||||
def _plug_interface_in_host(self, interface_name, device, port):
|
||||
def _plug_interface_in_host(self, interface_name, device, port,
|
||||
clear_outdated_routes=False):
|
||||
|
||||
LOG.debug("Plug interface into host - interface_name: %s, "
|
||||
"device: %s, port: %s", interface_name, device, port)
|
||||
|
@ -981,6 +980,9 @@ class NeutronNetworkHelper(BaseNetworkhelper):
|
|||
ip_cidrs = []
|
||||
for fixed_ip in port['fixed_ips']:
|
||||
subnet = self.neutron_api.get_subnet(fixed_ip['subnet_id'])
|
||||
if clear_outdated_routes:
|
||||
device.route.clear_outdated_routes(subnet['cidr'])
|
||||
|
||||
net = netaddr.IPNetwork(subnet['cidr'])
|
||||
ip_cidr = '%s/%s' % (fixed_ip['ip_address'], net.prefixlen)
|
||||
ip_cidrs.append(ip_cidr)
|
||||
|
|
|
@ -2123,7 +2123,6 @@ class NeutronNetworkHelperTestCase(test.TestCase):
|
|||
fake_admin_port['mac_address'])])
|
||||
instance.neutron_api.get_subnet.assert_has_calls([
|
||||
mock.call(fake_subnet_service['id']),
|
||||
mock.call(fake_subnet_admin['id']),
|
||||
mock.call(fake_subnet_admin['id'])])
|
||||
instance.vif_driver.init_l3.assert_has_calls([
|
||||
mock.call(interface_name_service,
|
||||
|
|
Loading…
Reference in New Issue