Merge "Fix HA router initialization exception"

This commit is contained in:
Zuul 2017-12-02 20:33:37 +00:00 committed by Gerrit Code Review
commit e971f0c317
3 changed files with 23 additions and 1 deletions

View File

@ -440,6 +440,7 @@ class HaRouter(router.RouterInfo):
prefix=router.EXTERNAL_DEV_PREFIX)
def delete(self):
if self.process_monitor:
self.destroy_state_change_monitor(self.process_monitor)
self.disable_keepalived()
self.ha_network_removed()

View File

@ -76,6 +76,7 @@ class RouterInfo(object):
self.routes = []
self.agent_conf = agent_conf
self.driver = interface_driver
self.process_monitor = None
# radvd is a neutron.agent.linux.ra.DaemonMonitor
self.radvd = None

View File

@ -36,6 +36,7 @@ from neutron.agent.l3 import agent as l3_agent
from neutron.agent.l3 import dvr_edge_router as dvr_router
from neutron.agent.l3 import dvr_router_base
from neutron.agent.l3 import dvr_snat_ns
from neutron.agent.l3 import ha_router
from neutron.agent.l3 import legacy_router
from neutron.agent.l3 import link_local_allocator as lla
from neutron.agent.l3 import namespace_manager
@ -3539,3 +3540,22 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
ri._create_dvr_gateway(ex_gw_port, interface_name)
self._verify_address_scopes_iptables_rule(
ri.snat_iptables_manager)
@mock.patch.object(l3router.RouterInfo, 'delete')
@mock.patch.object(ha_router.HaRouter, 'destroy_state_change_monitor')
def test_delete_ha_router_initialize_fails(self, mock_dscm, mock_delete):
router = l3_test_common.prepare_router_data(enable_ha=True)
router[lib_constants.HA_INTERFACE_KEY] = None
agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
# an early failure of an HA router initiailization shouldn't try
# and cleanup a state change monitor process that was never spawned.
# Cannot use self.assertRaises(Exception, ...) as that causes an H202
# pep8 failure.
try:
agent._router_added(router['id'], router)
raise Exception("agent._router_added() should have raised an "
"exception")
except Exception:
pass
self.assertTrue(mock_delete.called)
self.assertFalse(mock_dscm.called)