From a8f9174ca6a9ca7d7f5ca8a369c0d1b9c9be4714 Mon Sep 17 00:00:00 2001 From: Mohammed Naser Date: Thu, 30 Jan 2020 16:39:20 +0100 Subject: [PATCH] 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 --- manila/share/drivers/service_instance.py | 12 +++++++----- manila/tests/share/drivers/test_service_instance.py | 1 - 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/manila/share/drivers/service_instance.py b/manila/share/drivers/service_instance.py index 545606078f..c99a59ad6d 100644 --- a/manila/share/drivers/service_instance.py +++ b/manila/share/drivers/service_instance.py @@ -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) diff --git a/manila/tests/share/drivers/test_service_instance.py b/manila/tests/share/drivers/test_service_instance.py index 90c0a7826d..94bbcaf46a 100644 --- a/manila/tests/share/drivers/test_service_instance.py +++ b/manila/tests/share/drivers/test_service_instance.py @@ -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,