Browse Source

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
(cherry picked from commit a8f9174ca6)
changes/50/706750/1
Mohammed Naser 3 weeks ago
parent
commit
c5e2a0084f
2 changed files with 7 additions and 6 deletions
  1. +7
    -5
      manila/share/drivers/service_instance.py
  2. +0
    -1
      manila/tests/share/drivers/test_service_instance.py

+ 7
- 5
manila/share/drivers/service_instance.py View File

@@ -973,14 +973,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)
@@ -988,6 +987,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)

+ 0
- 1
manila/tests/share/drivers/test_service_instance.py View File

@@ -2148,7 +2148,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…
Cancel
Save