Unplug external device when delete snat namespace

[1] allow us to identify the stale snat namespace and delete the
namespace when the gateway is cleared as the agent restarts. But Method
SnatNamespace.delete unplugs 'sg-XXX' devices only, leads to stale
port remaining in ovs bridge.

This patch identify the stale external device and unplug it.

[1] https://review.openstack.org/#/c/326729/

Change-Id: I27fff32aeeecdc599a578637f390dc1d73f0171b
Closes-Bug: #1649092
This commit is contained in:
Quan Tian 2016-12-11 02:14:44 +08:00
parent 24b5a3b73e
commit fd3eebbec4
2 changed files with 30 additions and 0 deletions

View File

@ -47,6 +47,12 @@ class SnatNamespace(namespaces.Namespace):
LOG.debug('Unplugging DVR device %s', d.name)
self.driver.unplug(d.name, namespace=self.name,
prefix=SNAT_INT_DEV_PREFIX)
elif d.name.startswith(namespaces.EXTERNAL_DEV_PREFIX):
self.driver.unplug(
d.name,
bridge=self.agent_conf.external_network_bridge,
namespace=self.name,
prefix=namespaces.EXTERNAL_DEV_PREFIX)
# TODO(mrsmith): delete ext-gw-port
LOG.debug('DVR: destroy snat ns: %s', self.name)

View File

@ -1937,6 +1937,30 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
ns.delete()
self.mock_ip.netns.delete.assert_called_once_with("qrouter-bar")
def test_destroy_snat_namespace(self):
namespace = 'snat-bar'
self.mock_ip.get_namespaces.return_value = [namespace]
self.mock_ip.get_devices.return_value = [
l3_test_common.FakeDev('qg-aaaa'),
l3_test_common.FakeDev('sg-aaaa')]
agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
ns = dvr_snat_ns.SnatNamespace(
'bar', self.conf, agent.driver, agent.use_ipv6)
ns.create()
ns.delete()
calls = [mock.call('qg-aaaa',
bridge=agent.conf.external_network_bridge,
namespace=namespace,
prefix=l3_agent.EXTERNAL_DEV_PREFIX),
mock.call('sg-aaaa',
namespace=namespace,
prefix=dvr_snat_ns.SNAT_INT_DEV_PREFIX)]
self.mock_driver.unplug.assert_has_calls(calls, any_order=True)
def _configure_metadata_proxy(self, enableflag=True):
if not enableflag:
self.conf.set_override('enable_metadata_proxy', False)