]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
The exception type is wrong and makes the except block not work
authorHong Hui Xiao <xiaohhui@cn.ibm.com>
Fri, 16 Oct 2015 16:39:32 +0000 (12:39 -0400)
committerAssaf Muller <amuller@redhat.com>
Fri, 16 Oct 2015 19:12:20 +0000 (15:12 -0400)
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

neutron/agent/l3/ha.py
neutron/tests/unit/agent/l3/test_agent.py

index bafc7e71c637c8ba53e64634ccdefd900ee83a3f..93e0789358c994d08253a8c9b86166b92d45dbc1 100644 (file)
@@ -117,7 +117,7 @@ class AgentMixin(object):
 
         try:
             ri = self.router_info[router_id]
-        except AttributeError:
+        except KeyError:
             LOG.info(_LI('Router %s is not managed by this agent. It was '
                          'possibly deleted concurrently.'), router_id)
             return
index a3649d9ee6c393b9c2b223cb02507456dd4fb13e..88c9d4fec06aaa2c261c2f169128b8ba018c427e 100644 (file)
@@ -178,6 +178,13 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
             l3_agent.L3NATAgent(HOSTNAME, self.conf)
             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):
         agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
         self.plugin_api.get_routers.side_effect = ValueError