]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Tweak mocking logic for L3 plugin tests
authorarmando-migliaccio <armamig@gmail.com>
Tue, 10 Feb 2015 20:17:37 +0000 (12:17 -0800)
committerarmando-migliaccio <armamig@gmail.com>
Wed, 11 Feb 2015 23:21:37 +0000 (15:21 -0800)
I stumbled upon this and I was baffled as to why the rpc notifier
was being mocked up the way it was. I think this calls for some
sanity-checking and this patch attempts to bring some common sense
in the test, or I could be barking up at wrong tree...woof woof

Change-Id: I57cf2d6a18ce37ef65fbf9d87d6de70c0178c6ca

neutron/tests/unit/test_l3_plugin.py

index a76e82c6115bf1e6a369c4af183038ccb6001b3a..e44251a1d7b57d00efc1bde114efe765df55f823 100644 (file)
@@ -2141,20 +2141,13 @@ class L3AgentDbTestCaseBase(L3NatTestCaseMixin):
     def _test_notify_op_agent(self, target_func, *args):
         l3_rpc_agent_api_str = (
             'neutron.api.rpc.agentnotifiers.l3_rpc_agent_api.L3AgentNotifyAPI')
-        plugin = manager.NeutronManager.get_service_plugins()[
-            service_constants.L3_ROUTER_NAT]
-        oldNotify = plugin.l3_rpc_notifier
-        try:
-            with mock.patch(l3_rpc_agent_api_str) as notifyApi:
-                plugin.l3_rpc_notifier = notifyApi
-                kargs = [item for item in args]
-                kargs.append(notifyApi)
-                target_func(*kargs)
-        except Exception:
-            plugin.l3_rpc_notifier = oldNotify
-            raise
-        else:
-            plugin.l3_rpc_notifier = oldNotify
+        with mock.patch(l3_rpc_agent_api_str):
+            plugin = manager.NeutronManager.get_service_plugins()[
+                service_constants.L3_ROUTER_NAT]
+            notifyApi = plugin.l3_rpc_notifier
+            kargs = [item for item in args]
+            kargs.append(notifyApi)
+            target_func(*kargs)
 
     def _test_router_gateway_op_agent(self, notifyApi):
         with self.router() as r: