summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2016-07-27 18:15:06 +0000
committerGerrit Code Review <review@openstack.org>2016-07-27 18:15:06 +0000
commitf19044ff807df284103d04d2c63cabbba988fe30 (patch)
treef9fb481c079aea5e8f54e006ac7c251500c3b41b
parent67c34607f29ba39bb0709bd31f31e784fa5d1af6 (diff)
parent9d4f497827351745483363b696376c457d0c2281 (diff)
downloadneutron-f19044ff807df284103d04d2c63cabbba988fe30.tar.gz
Merge "DVR: Ensure that only one fg device can exist at a time in fip ns" into stable/liberty
-rw-r--r--neutron/agent/l3/dvr_fip_ns.py14
-rw-r--r--neutron/tests/functional/agent/test_l3_agent.py64
2 files changed, 76 insertions, 2 deletions
diff --git a/neutron/agent/l3/dvr_fip_ns.py b/neutron/agent/l3/dvr_fip_ns.py
index 441005c89d..6557cc267b 100644
--- a/neutron/agent/l3/dvr_fip_ns.py
+++ b/neutron/agent/l3/dvr_fip_ns.py
@@ -108,6 +108,18 @@ class FipNamespace(namespaces.Namespace):
prefix=FIP_EXT_DEV_PREFIX,
mtu=ex_gw_port.get('mtu'))
+ # Remove stale fg devices
+ ip_wrapper = ip_lib.IPWrapper(namespace=ns_name)
+ devices = ip_wrapper.get_devices()
+ for device in devices:
+ name = device.name
+ if name.startswith(FIP_EXT_DEV_PREFIX) and name != interface_name:
+ ext_net_bridge = self.agent_conf.external_network_bridge
+ self.driver.unplug(name,
+ bridge=ext_net_bridge,
+ namespace=ns_name,
+ prefix=FIP_EXT_DEV_PREFIX)
+
ip_cidrs = common_utils.fixed_ip_cidrs(ex_gw_port['fixed_ips'])
self.driver.init_l3(interface_name, ip_cidrs, namespace=ns_name,
clean_connections=True)
@@ -115,8 +127,6 @@ class FipNamespace(namespaces.Namespace):
self.update_gateway_port(ex_gw_port)
cmd = ['sysctl', '-w', 'net.ipv4.conf.%s.proxy_arp=1' % interface_name]
- # TODO(Carl) mlavelle's work has self.ip_wrapper
- ip_wrapper = ip_lib.IPWrapper(namespace=ns_name)
ip_wrapper.netns.execute(cmd, check_exit_code=False)
def create(self):
diff --git a/neutron/tests/functional/agent/test_l3_agent.py b/neutron/tests/functional/agent/test_l3_agent.py
index fbf56385e5..f5b9185e86 100644
--- a/neutron/tests/functional/agent/test_l3_agent.py
+++ b/neutron/tests/functional/agent/test_l3_agent.py
@@ -32,6 +32,7 @@ import webob.exc
from neutron.agent.common import config as agent_config
from neutron.agent.common import ovs_lib
from neutron.agent.l3 import agent as neutron_l3_agent
+from neutron.agent.l3 import dvr_fip_ns
from neutron.agent.l3 import dvr_snat_ns
from neutron.agent.l3 import namespace_manager
from neutron.agent.l3 import namespaces
@@ -1135,6 +1136,69 @@ class TestDvrRouter(L3AgentTestFramework):
self._assert_dvr_floating_ips(router)
self._assert_snat_namespace_does_not_exist(router)
+ def test_dvr_router_fips_stale_gw_port(self):
+ self.agent.conf.agent_mode = 'dvr'
+
+ # Create the router with external net
+ dvr_router_kwargs = {'ip_address': '19.4.4.3',
+ 'subnet_cidr': '19.4.4.0/24',
+ 'gateway_ip': '19.4.4.1',
+ 'gateway_mac': 'ca:fe:de:ab:cd:ef'}
+ router_info = self.generate_dvr_router_info(**dvr_router_kwargs)
+ external_gw_port = router_info['gw_port']
+ ext_net_id = router_info['_floatingips'][0]['floating_network_id']
+ self.mock_plugin_api.get_external_network_id.return_value(ext_net_id)
+
+ # Create the fip namespace up front
+ stale_fip_ns = dvr_fip_ns.FipNamespace(ext_net_id,
+ self.agent.conf,
+ self.agent.driver,
+ self.agent.use_ipv6)
+ stale_fip_ns.create()
+
+ # Add a stale fg port to the namespace
+ fixed_ip = external_gw_port['fixed_ips'][0]
+ float_subnet = external_gw_port['subnets'][0]
+ fip_gw_port_ip = str(netaddr.IPAddress(fixed_ip['ip_address']) + 10)
+ prefixlen = netaddr.IPNetwork(float_subnet['cidr']).prefixlen
+ stale_agent_gw_port = {
+ 'subnets': [{'cidr': float_subnet['cidr'],
+ 'gateway_ip': float_subnet['gateway_ip'],
+ 'id': fixed_ip['subnet_id']}],
+ 'network_id': external_gw_port['network_id'],
+ 'device_owner': l3_constants.DEVICE_OWNER_AGENT_GW,
+ 'mac_address': 'fa:16:3e:80:8f:89',
+ 'binding:host_id': self.agent.conf.host,
+ 'fixed_ips': [{'subnet_id': fixed_ip['subnet_id'],
+ 'ip_address': fip_gw_port_ip,
+ 'prefixlen': prefixlen}],
+ 'id': _uuid(),
+ 'device_id': _uuid()}
+ stale_fip_ns.create_gateway_port(stale_agent_gw_port)
+
+ stale_dev_exists = self.device_exists_with_ips_and_mac(
+ stale_agent_gw_port,
+ stale_fip_ns.get_ext_device_name,
+ stale_fip_ns.get_name())
+ self.assertTrue(stale_dev_exists)
+
+ # Create the router, this shouldn't allow the duplicate port to stay
+ router = self.manage_router(self.agent, router_info)
+
+ # Assert the device no longer exists
+ stale_dev_exists = self.device_exists_with_ips_and_mac(
+ stale_agent_gw_port,
+ stale_fip_ns.get_ext_device_name,
+ stale_fip_ns.get_name())
+ self.assertFalse(stale_dev_exists)
+
+ # Validate things are looking good and clean up
+ self._validate_fips_for_external_network(
+ router, router.fip_ns.get_name())
+ ext_gateway_port = router_info['gw_port']
+ self._delete_router(self.agent, router.router_id)
+ self._assert_fip_namespace_deleted(ext_gateway_port)
+
def test_dvr_update_floatingip_statuses(self):
self.agent.conf.agent_mode = 'dvr'
self._test_update_floatingip_statuses(self.generate_dvr_router_info())