The exception type is wrong and makes the except block not work

According to the context, it should be KeyError here to catch.
AttributeError will not happen here. More details could be found
in the bug report.

Change-Id: Id6351172703ac492e86475f75bf1be03f4e4e8a3
Closes-bug: #1506934
This commit is contained in:
Hong Hui Xiao 2015-10-16 12:39:32 -04:00 committed by Assaf Muller
parent 0312b1237b
commit 9d65841200
2 changed files with 8 additions and 1 deletions

View File

@ -117,7 +117,7 @@ class AgentMixin(object):
try: try:
ri = self.router_info[router_id] ri = self.router_info[router_id]
except AttributeError: except KeyError:
LOG.info(_LI('Router %s is not managed by this agent. It was ' LOG.info(_LI('Router %s is not managed by this agent. It was '
'possibly deleted concurrently.'), router_id) 'possibly deleted concurrently.'), router_id)
return return

View File

@ -178,6 +178,13 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
l3_agent.L3NATAgent(HOSTNAME, self.conf) l3_agent.L3NATAgent(HOSTNAME, self.conf)
self.ensure_dir.assert_called_once_with('/etc/ha/') self.ensure_dir.assert_called_once_with('/etc/ha/')
def test_enqueue_state_change_router_not_found(self):
agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
non_existent_router = 42
# Make sure the exceptional code path has coverage
agent.enqueue_state_change(non_existent_router, 'master')
def test_periodic_sync_routers_task_raise_exception(self): def test_periodic_sync_routers_task_raise_exception(self):
agent = l3_agent.L3NATAgent(HOSTNAME, self.conf) agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
self.plugin_api.get_routers.side_effect = ValueError self.plugin_api.get_routers.side_effect = ValueError