Patch _get_callback_manager for callback fixture

The existing version of the callback fixture patches the global var
_CALLBACK_MANAGER, which, is returned from the callback registry
via _get_callback_manager() using a singleton checking pattern.
While this is fine in a number of cases, the implementation of
_get_callback_manager() will enclose a reference to the
_CALLBACK_MANAGER under certain testing conditions causing the fixture
to not work properly.

This patch proposes that we just mock the _get_callback_manager() return
value, which works in all cases.

No release note included because this only changes internal semantics.

Change-Id: I9966c90e3f90552b41ed84a68b19f3e540426432
This commit is contained in:
Boden R 2017-04-17 12:21:46 -06:00
parent d136fd4c62
commit 714b810a06
1 changed files with 8 additions and 2 deletions

View File

@ -12,6 +12,7 @@
import copy
import fixtures
import mock
from neutron_lib.api import definitions
from neutron_lib.callbacks import manager
@ -55,14 +56,19 @@ class CallbackRegistryFixture(fixtures.Fixture):
"""
super(CallbackRegistryFixture, self).__init__()
self.callback_manager = callback_manager or manager.CallbacksManager()
self.patcher = None
def _setUp(self):
self._orig_manager = registry._CALLBACK_MANAGER
registry._CALLBACK_MANAGER = self.callback_manager
self._orig_manager = registry._get_callback_manager()
self.patcher = mock.patch.object(
registry, '_get_callback_manager',
return_value=self.callback_manager)
self.patcher.start()
self.addCleanup(self._restore)
def _restore(self):
registry._CALLBACK_MANAGER = self._orig_manager
self.patcher.stop()
class SqlFixture(fixtures.Fixture):