From 1ad70b828de1d4a070a6d2b41c038925e2fb9ea0 Mon Sep 17 00:00:00 2001 From: armando-migliaccio Date: Tue, 10 Feb 2015 12:17:37 -0800 Subject: [PATCH] Tweak mocking logic for L3 plugin tests 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 | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/neutron/tests/unit/test_l3_plugin.py b/neutron/tests/unit/test_l3_plugin.py index a76e82c61..e44251a1d 100644 --- a/neutron/tests/unit/test_l3_plugin.py +++ b/neutron/tests/unit/test_l3_plugin.py @@ -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: -- 2.45.2