'Test to validate the snat namespace with interface remove.
This test validates the snat namespace for all the external
and internal devices. It also validates if the internal
device corresponding to the router interface is removed
when the router interface is deleted.'

def test_dvr_router_snat_namespace_with_interface_remove(self):

    self.agent.conf.agent_mode = 'dvr_snat'
    router_info = self.generate_dvr_router_info()
    snat_internal_port = router_info[n_const.SNAT_ROUTER_INTF_KEY]
    router1 = self.manage_router(self.agent, router_info)
    csnat_internal_port = router1.router[n_const.SNAT_ROUTER_INTF_KEY]
    internal_device_name = router1._get_snat_int_device_name(csnat_internal_port[0]['id'])
    self._assert_snat_namespace_exists(router1)
    (qg_device, sg_device) = self._get_dvr_snat_namespace_device_status(router1, internal_dev_name=internal_device_name)
    self.assertTrue(qg_device)
    self.assertTrue(sg_device)
    self.assertEqual(router1.snat_ports, snat_internal_port)
    router1.router[lib_constants.INTERFACE_KEY] = []
    router1.router[n_const.SNAT_ROUTER_INTF_KEY] = []
    self.agent._process_updated_router(router1.router)
    router_updated = self.agent.router_info[router_info['id']]
    self._assert_snat_namespace_exists(router_updated)
    (qg_device, sg_device) = self._get_dvr_snat_namespace_device_status(router_updated, internal_dev_name=internal_device_name)
    self.assertFalse(sg_device)
    self.assertTrue(qg_device)
