Revert "DVR: Clear SNAT namespace when agent restarts after router move"
This reverts commit 9dc70ed77e
.
Change-Id: I85a8051d56c535a4de4c70b3624eb7ccefa9e656
Closes-Bug: #1590041
This commit is contained in:
parent
9dc70ed77e
commit
e4b82f7e64
|
@ -29,12 +29,7 @@ class DvrEdgeRouter(dvr_local_router.DvrLocalRouter):
|
||||||
|
|
||||||
def __init__(self, agent, host, *args, **kwargs):
|
def __init__(self, agent, host, *args, **kwargs):
|
||||||
super(DvrEdgeRouter, self).__init__(agent, host, *args, **kwargs)
|
super(DvrEdgeRouter, self).__init__(agent, host, *args, **kwargs)
|
||||||
# NOTE: Initialize the snat_namespace object here.
|
self.snat_namespace = None
|
||||||
# The namespace can be created later, just to align with the
|
|
||||||
# parent init.
|
|
||||||
self.snat_namespace = dvr_snat_ns.SnatNamespace(
|
|
||||||
self.router_id, self.agent_conf,
|
|
||||||
self.driver, self.use_ipv6)
|
|
||||||
self.snat_iptables_manager = None
|
self.snat_iptables_manager = None
|
||||||
|
|
||||||
def external_gateway_added(self, ex_gw_port, interface_name):
|
def external_gateway_added(self, ex_gw_port, interface_name):
|
||||||
|
@ -158,11 +153,10 @@ class DvrEdgeRouter(dvr_local_router.DvrLocalRouter):
|
||||||
# TODO(mlavalle): in the near future, this method should contain the
|
# TODO(mlavalle): in the near future, this method should contain the
|
||||||
# code in the L3 agent that creates a gateway for a dvr. The first step
|
# code in the L3 agent that creates a gateway for a dvr. The first step
|
||||||
# is to move the creation of the snat namespace here
|
# is to move the creation of the snat namespace here
|
||||||
if not self.snat_namespace:
|
self.snat_namespace = dvr_snat_ns.SnatNamespace(self.router['id'],
|
||||||
self.snat_namespace = dvr_snat_ns.SnatNamespace(self.router['id'],
|
self.agent_conf,
|
||||||
self.agent_conf,
|
self.driver,
|
||||||
self.driver,
|
self.use_ipv6)
|
||||||
self.use_ipv6)
|
|
||||||
self.snat_namespace.create()
|
self.snat_namespace.create()
|
||||||
return self.snat_namespace
|
return self.snat_namespace
|
||||||
|
|
||||||
|
|
|
@ -35,13 +35,12 @@ class SnatNamespace(namespaces.Namespace):
|
||||||
|
|
||||||
def delete(self):
|
def delete(self):
|
||||||
ns_ip = ip_lib.IPWrapper(namespace=self.name)
|
ns_ip = ip_lib.IPWrapper(namespace=self.name)
|
||||||
if ns_ip.netns.exists(self.name):
|
for d in ns_ip.get_devices(exclude_loopback=True):
|
||||||
for d in ns_ip.get_devices(exclude_loopback=True):
|
if d.name.startswith(SNAT_INT_DEV_PREFIX):
|
||||||
if d.name.startswith(SNAT_INT_DEV_PREFIX):
|
LOG.debug('Unplugging DVR device %s', d.name)
|
||||||
LOG.debug('Unplugging DVR device %s', d.name)
|
self.driver.unplug(d.name, namespace=self.name,
|
||||||
self.driver.unplug(d.name, namespace=self.name,
|
prefix=SNAT_INT_DEV_PREFIX)
|
||||||
prefix=SNAT_INT_DEV_PREFIX)
|
|
||||||
|
|
||||||
# TODO(mrsmith): delete ext-gw-port
|
# TODO(mrsmith): delete ext-gw-port
|
||||||
LOG.debug('DVR: destroy snat ns: %s', self.name)
|
LOG.debug('DVR: destroy snat ns: %s', self.name)
|
||||||
super(SnatNamespace, self).delete()
|
super(SnatNamespace, self).delete()
|
||||||
|
|
|
@ -611,95 +611,6 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
|
||||||
def test_external_gateway_updated_dual_stack(self):
|
def test_external_gateway_updated_dual_stack(self):
|
||||||
self._test_external_gateway_updated(dual_stack=True)
|
self._test_external_gateway_updated(dual_stack=True)
|
||||||
|
|
||||||
def test_dvr_edge_router_init_for_snat_namespace_object(self):
|
|
||||||
router = l3_test_common.prepare_router_data(num_internal_ports=2)
|
|
||||||
ri = dvr_router.DvrEdgeRouter(mock.Mock(),
|
|
||||||
HOSTNAME,
|
|
||||||
router['id'],
|
|
||||||
router,
|
|
||||||
**self.ri_kwargs)
|
|
||||||
# Makesure that ri.snat_namespace object is created when the
|
|
||||||
# router is initialized
|
|
||||||
self.assertIsNotNone(ri.snat_namespace)
|
|
||||||
|
|
||||||
@mock.patch.object(dvr_snat_ns.SnatNamespace, 'delete')
|
|
||||||
def test_ext_gw_updated_calling_snat_ns_delete_if_gw_port_host_none(
|
|
||||||
self, mock_snat_ns):
|
|
||||||
"""Function to check the impact of snat_namespace object.
|
|
||||||
|
|
||||||
This function specifically checks the impact of the snat
|
|
||||||
namespace object value on external_gateway_removed for deleting
|
|
||||||
snat_namespace when the gw_port_host mismatches or none.
|
|
||||||
"""
|
|
||||||
router = l3_test_common.prepare_router_data(num_internal_ports=2)
|
|
||||||
ri = dvr_router.DvrEdgeRouter(mock.Mock(),
|
|
||||||
HOSTNAME,
|
|
||||||
router['id'],
|
|
||||||
router,
|
|
||||||
**self.ri_kwargs)
|
|
||||||
ri._create_snat_namespace()
|
|
||||||
interface_name, ex_gw_port = l3_test_common.prepare_ext_gw_test(self,
|
|
||||||
ri)
|
|
||||||
router['gw_port_host'] = ''
|
|
||||||
ri.external_gateway_updated(ex_gw_port, interface_name)
|
|
||||||
if router['gw_port_host'] != ri.host:
|
|
||||||
if ri.snat_namespace:
|
|
||||||
self.assertEqual(1, mock_snat_ns.call_count)
|
|
||||||
|
|
||||||
@mock.patch.object(dvr_snat_ns.SnatNamespace, 'delete')
|
|
||||||
def test_ext_gw_updated_not_calling_snat_ns_delete_if_gw_port_host_none(
|
|
||||||
self, mock_snat_ns):
|
|
||||||
"""Function to check the impact of snat_namespace object.
|
|
||||||
|
|
||||||
This function specifically checks the impact of the snat
|
|
||||||
namespace object value on external_gateway_removed for deleting
|
|
||||||
snat_namespace when gw_port_host mismatches and when the
|
|
||||||
self.snat_namespace is None.
|
|
||||||
"""
|
|
||||||
router = l3_test_common.prepare_router_data(num_internal_ports=2)
|
|
||||||
ri = dvr_router.DvrEdgeRouter(mock.Mock(),
|
|
||||||
HOSTNAME,
|
|
||||||
router['id'],
|
|
||||||
router,
|
|
||||||
**self.ri_kwargs)
|
|
||||||
ri._create_snat_namespace()
|
|
||||||
interface_name, ex_gw_port = l3_test_common.prepare_ext_gw_test(self,
|
|
||||||
ri)
|
|
||||||
router['gw_port_host'] = ''
|
|
||||||
# Initialize the snat_namespace object to the None here to emulate
|
|
||||||
# an agent restart.
|
|
||||||
ri.snat_namespace = None
|
|
||||||
ri.external_gateway_updated(ex_gw_port, interface_name)
|
|
||||||
if router['gw_port_host'] != ri.host:
|
|
||||||
if ri.snat_namespace is None:
|
|
||||||
self.assertFalse(mock_snat_ns.called)
|
|
||||||
|
|
||||||
@mock.patch.object(namespaces.Namespace, 'delete')
|
|
||||||
def test_snat_ns_delete_not_called_when_snat_namespace_does_not_exist(
|
|
||||||
self, mock_ns_del):
|
|
||||||
"""Function to check the impact of snat_namespace object.
|
|
||||||
|
|
||||||
This function specifically checks the impact of the snat
|
|
||||||
namespace object initialization without the actual creation
|
|
||||||
of snat_namespace. When deletes are issued to the snat
|
|
||||||
namespace based on the snat namespace object existence, it
|
|
||||||
should be checking for the valid namespace existence before
|
|
||||||
it tries to delete.
|
|
||||||
"""
|
|
||||||
router = l3_test_common.prepare_router_data(num_internal_ports=2)
|
|
||||||
ri = dvr_router.DvrEdgeRouter(mock.Mock(),
|
|
||||||
HOSTNAME,
|
|
||||||
router['id'],
|
|
||||||
router,
|
|
||||||
**self.ri_kwargs)
|
|
||||||
# Make sure we set a return value to emulate the non existence
|
|
||||||
# of the namespace.
|
|
||||||
self.mock_ip.netns.exists.return_value = False
|
|
||||||
self.assertTrue(ri.snat_namespace)
|
|
||||||
if ri.snat_namespace:
|
|
||||||
ri.snat_namespace.delete()
|
|
||||||
self.assertFalse(mock_ns_del.called)
|
|
||||||
|
|
||||||
def _test_ext_gw_updated_dvr_edge_router(self, host_match,
|
def _test_ext_gw_updated_dvr_edge_router(self, host_match,
|
||||||
snat_hosted_before=True):
|
snat_hosted_before=True):
|
||||||
"""
|
"""
|
||||||
|
@ -719,7 +630,7 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
|
||||||
ri._create_snat_namespace()
|
ri._create_snat_namespace()
|
||||||
snat_ns_name = ri.snat_namespace.name
|
snat_ns_name = ri.snat_namespace.name
|
||||||
else:
|
else:
|
||||||
self.assertIsNotNone(ri.snat_namespace)
|
self.assertIsNone(ri.snat_namespace)
|
||||||
|
|
||||||
interface_name, ex_gw_port = l3_test_common.prepare_ext_gw_test(self,
|
interface_name, ex_gw_port = l3_test_common.prepare_ext_gw_test(self,
|
||||||
ri)
|
ri)
|
||||||
|
|
Loading…
Reference in New Issue