From 7f82a19155abfb88f6f1d463ac90de3198ad67c9 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Tue, 27 Nov 2018 23:31:34 +0900 Subject: [PATCH] Remove unnecessary mocking of get_admin_context Because: - They are not necessary. - Neutron agent scheduler code (reschedule_resources_from_down_agents) seems to (correctly) assume each get_admin_context() call returns a fresh context. This mocking breaks it. - Right now, Neutron agentdb uses the new engine facade [1] and Neutron agent scheduler doesn't. It causes caching issue in our unit tests. (See the Related-Bug) Stopping reusing contexts (thus sessions) would prevent the issue. [1] https://review.openstack.org/#/c/611462/ Related-Bug: #1803745 Change-Id: Ia986f98f8bda9c7cde33af3dfdf2e45a2685fd6d --- .../services/bgp/scheduler/test_bgp_dragent_scheduler.py | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/neutron_dynamic_routing/tests/unit/services/bgp/scheduler/test_bgp_dragent_scheduler.py b/neutron_dynamic_routing/tests/unit/services/bgp/scheduler/test_bgp_dragent_scheduler.py index e4a04e3b..4e7ef994 100644 --- a/neutron_dynamic_routing/tests/unit/services/bgp/scheduler/test_bgp_dragent_scheduler.py +++ b/neutron_dynamic_routing/tests/unit/services/bgp/scheduler/test_bgp_dragent_scheduler.py @@ -90,10 +90,6 @@ class TestSchedulerCallback(TestBgpDrAgentSchedulerBaseTestCase): bgp_notify_p.start() rpc_conn_p = mock.patch('neutron.common.rpc.Connection') rpc_conn_p.start() - admin_ctx_p = mock.patch('neutron_lib.context.get_admin_context') - admin_ctx_p = mock.patch('neutron_lib.context.get_admin_context') - self.admin_ctx_m = admin_ctx_p.start() - self.admin_ctx_m.return_value = self.ctx self.plugin = bgp_plugin.BgpPlugin() self.scheduler = bgp_dras.ChanceScheduler() @@ -127,7 +123,7 @@ class TestSchedulerCallback(TestBgpDrAgentSchedulerBaseTestCase): dr_resources.BGP_SPEAKER, events.AFTER_CREATE, self.scheduler, payload) - sched_bgp.assert_called_once_with(self.ctx, + sched_bgp.assert_called_once_with(mock.ANY, payload['bgp_speaker']) def test_schedule_bgp_speaker_callback_with_invalid_event(self): @@ -305,9 +301,6 @@ class TestRescheduleBgpSpeaker(TestBgpDrAgentSchedulerBaseTestCase, bgp_notify_p.start() rpc_conn_p = mock.patch('neutron.common.rpc.Connection') rpc_conn_p.start() - admin_ctx_p = mock.patch('neutron_lib.context.get_admin_context') - self.admin_ctx_m = admin_ctx_p.start() - self.admin_ctx_m.return_value = self.ctx self.plugin = bgp_plugin.BgpPlugin() self.scheduler = bgp_dras.ChanceScheduler() self.host1 = 'host-a'