Refactor route clearing to linux interface
The code for clearing routes currently lives inside the
service_instance module but it belongs better inside the linux
interface ones.
This patch refactors it into there, which can allow for a true
noop driver as all network operations would happen inside that
section.
Change-Id: I9fa29e9e5ed7dd2c620b56efab559f4cec25aced
(cherry picked from commit e7858ad084
)
This commit is contained in:
parent
c5e2a0084f
commit
ccc781d084
|
@ -65,7 +65,7 @@ class LinuxInterfaceDriver(object):
|
||||||
self.conf = CONF
|
self.conf = CONF
|
||||||
|
|
||||||
@device_name_synchronized
|
@device_name_synchronized
|
||||||
def init_l3(self, device_name, ip_cidrs, namespace=None):
|
def init_l3(self, device_name, ip_cidrs, namespace=None, clear_cidrs=[]):
|
||||||
"""Set the L3 settings for the interface using data from the port.
|
"""Set the L3 settings for the interface using data from the port.
|
||||||
|
|
||||||
ip_cidrs: list of 'X.X.X.X/YY' strings
|
ip_cidrs: list of 'X.X.X.X/YY' strings
|
||||||
|
@ -73,6 +73,9 @@ class LinuxInterfaceDriver(object):
|
||||||
device = ip_lib.IPDevice(device_name,
|
device = ip_lib.IPDevice(device_name,
|
||||||
namespace=namespace)
|
namespace=namespace)
|
||||||
|
|
||||||
|
for cidr in clear_cidrs:
|
||||||
|
device.route.clear_outdated_routes(cidr)
|
||||||
|
|
||||||
previous = {}
|
previous = {}
|
||||||
for address in device.addr.list(scope='global', filters=['permanent']):
|
for address in device.addr.list(scope='global', filters=['permanent']):
|
||||||
previous[address['cidr']] = address['ip_version']
|
previous[address['cidr']] = address['ip_version']
|
||||||
|
|
|
@ -984,17 +984,19 @@ class NeutronNetworkHelper(BaseNetworkhelper):
|
||||||
LOG.debug("Plug interface into host - interface_name: %s, "
|
LOG.debug("Plug interface into host - interface_name: %s, "
|
||||||
"device: %s, port: %s", interface_name, device, port)
|
"device: %s, port: %s", interface_name, device, port)
|
||||||
self.vif_driver.plug(interface_name, port['id'], port['mac_address'])
|
self.vif_driver.plug(interface_name, port['id'], port['mac_address'])
|
||||||
|
cidrs_to_clear = []
|
||||||
ip_cidrs = []
|
ip_cidrs = []
|
||||||
for fixed_ip in port['fixed_ips']:
|
for fixed_ip in port['fixed_ips']:
|
||||||
subnet = self.neutron_api.get_subnet(fixed_ip['subnet_id'])
|
subnet = self.neutron_api.get_subnet(fixed_ip['subnet_id'])
|
||||||
if clear_outdated_routes:
|
if clear_outdated_routes:
|
||||||
device.route.clear_outdated_routes(subnet['cidr'])
|
cidrs_to_clear.append(subnet['cidr'])
|
||||||
|
|
||||||
net = netaddr.IPNetwork(subnet['cidr'])
|
net = netaddr.IPNetwork(subnet['cidr'])
|
||||||
ip_cidr = '%s/%s' % (fixed_ip['ip_address'], net.prefixlen)
|
ip_cidr = '%s/%s' % (fixed_ip['ip_address'], net.prefixlen)
|
||||||
ip_cidrs.append(ip_cidr)
|
ip_cidrs.append(ip_cidr)
|
||||||
|
|
||||||
self.vif_driver.init_l3(interface_name, ip_cidrs)
|
self.vif_driver.init_l3(interface_name, ip_cidrs,
|
||||||
|
clear_cidrs=cidrs_to_clear)
|
||||||
|
|
||||||
@utils.synchronized("service_instance_get_service_port", external=True)
|
@utils.synchronized("service_instance_get_service_port", external=True)
|
||||||
def _get_service_port(self, network_id, subnet_id, device_id):
|
def _get_service_port(self, network_id, subnet_id, device_id):
|
||||||
|
|
|
@ -98,9 +98,11 @@ class TestABCDriver(TestBase):
|
||||||
self.mock_object(bc, '_remove_outdated_interfaces')
|
self.mock_object(bc, '_remove_outdated_interfaces')
|
||||||
|
|
||||||
ns = '12345678-1234-5678-90ab-ba0987654321'
|
ns = '12345678-1234-5678-90ab-ba0987654321'
|
||||||
bc.init_l3('tap0', ['192.168.1.2/24'], namespace=ns)
|
bc.init_l3('tap0', ['192.168.1.2/24'], namespace=ns,
|
||||||
|
clear_cidrs=['192.168.0.0/16'])
|
||||||
self.ip_dev.assert_has_calls(
|
self.ip_dev.assert_has_calls(
|
||||||
[mock.call('tap0', namespace=ns),
|
[mock.call('tap0', namespace=ns),
|
||||||
|
mock.call().route.clear_outdated_routes('192.168.0.0/16'),
|
||||||
mock.call().addr.list(scope='global', filters=['permanent']),
|
mock.call().addr.list(scope='global', filters=['permanent']),
|
||||||
mock.call().addr.add(4, '192.168.1.2/24', '192.168.1.255'),
|
mock.call().addr.add(4, '192.168.1.2/24', '192.168.1.255'),
|
||||||
mock.call().addr.delete(4, '172.16.77.240/24'),
|
mock.call().addr.delete(4, '172.16.77.240/24'),
|
||||||
|
|
|
@ -2151,8 +2151,10 @@ class NeutronNetworkHelperTestCase(test.TestCase):
|
||||||
mock.call(fake_subnet_admin['id'])])
|
mock.call(fake_subnet_admin['id'])])
|
||||||
instance.vif_driver.init_l3.assert_has_calls([
|
instance.vif_driver.init_l3.assert_has_calls([
|
||||||
mock.call(interface_name_service,
|
mock.call(interface_name_service,
|
||||||
['10.254.0.2/%s' % fake_division_mask]),
|
['10.254.0.2/%s' % fake_division_mask],
|
||||||
mock.call(interface_name_admin, ['10.0.0.4/24'])])
|
clear_cidrs=[]),
|
||||||
|
mock.call(interface_name_admin, ['10.0.0.4/24'],
|
||||||
|
clear_cidrs=[fake_subnet_admin['cidr']])])
|
||||||
service_instance.ip_lib.IPDevice.assert_has_calls([
|
service_instance.ip_lib.IPDevice.assert_has_calls([
|
||||||
mock.call(interface_name_service),
|
mock.call(interface_name_service),
|
||||||
mock.call(interface_name_admin)])
|
mock.call(interface_name_admin)])
|
||||||
|
|
Loading…
Reference in New Issue