use neutron-lib's callback fixture

There were a few places left in the code (with TODOs) that were still
mocking out the callback manager. This patch switches them over to
the neutron-lib callback fixture.

Change-Id: I9e710db6a5103436b0f098e8f73625e3941df492
This commit is contained in:
Boden R 2017-06-05 15:16:20 -06:00
parent 1a8901a1ed
commit 85a44ee3c0
3 changed files with 31 additions and 21 deletions

View File

@ -13,6 +13,7 @@
import mock
from neutron_lib.callbacks import events
from neutron_lib import fixture
from neutron.plugins.ml2.drivers.agent import capabilities
from neutron.tests import base
@ -20,23 +21,25 @@ from neutron.tests import base
class CapabilitiesTest(base.BaseTestCase):
# TODO(boden) replace with neutron_lib fixture once working
@mock.patch("neutron_lib.callbacks.manager.CallbacksManager.notify")
def test_notify_init_event(self, mocked_manager):
def setUp(self):
super(CapabilitiesTest, self).setUp()
self._mgr = mock.Mock()
self.useFixture(fixture.CallbackRegistryFixture(
callback_manager=self._mgr))
def test_notify_init_event(self):
mock_agent_type = mock.Mock()
mock_agent = mock.Mock()
capabilities.notify_init_event(mock_agent_type, mock_agent)
mocked_manager.assert_called_with(mock_agent_type,
events.AFTER_INIT,
mock_agent,
agent=mock_agent)
self._mgr.notify.assert_called_with(mock_agent_type,
events.AFTER_INIT,
mock_agent,
agent=mock_agent)
# TODO(boden) replace with neutron_lib fixture once working
@mock.patch("neutron_lib.callbacks.manager.CallbacksManager.subscribe")
def test_register(self, mocked_subscribe):
def test_register(self):
mock_callback = mock.Mock()
mock_agent_type = mock.Mock()
capabilities.register(mock_callback, mock_agent_type)
mocked_subscribe.assert_called_with(mock_callback,
mock_agent_type,
events.AFTER_INIT)
self._mgr.subscribe.assert_called_with(mock_callback,
mock_agent_type,
events.AFTER_INIT)

View File

@ -14,6 +14,7 @@
import mock
from neutron_lib.callbacks import events
from neutron_lib import fixture
from neutron.plugins.ml2.drivers.openvswitch.agent import ovs_capabilities
from neutron.services.trunk.drivers.openvswitch.agent import driver
@ -23,10 +24,14 @@ from neutron_lib import constants
class CapabilitiesTest(base.BaseTestCase):
# TODO(boden) replace with neutron_lib fixture once working
@mock.patch("neutron_lib.callbacks.manager.CallbacksManager.subscribe")
def test_register(self, mocked_subscribe):
def setUp(self):
super(CapabilitiesTest, self).setUp()
self._mgr = mock.Mock()
self.useFixture(fixture.CallbackRegistryFixture(
callback_manager=self._mgr))
def test_register(self):
ovs_capabilities.register()
mocked_subscribe.assert_called_with(driver.init_handler,
self._mgr.subscribe.assert_called_with(driver.init_handler,
constants.AGENT_TYPE_OVS,
events.AFTER_INIT)

View File

@ -13,6 +13,7 @@
import mock
from neutron_lib.callbacks import events
from neutron_lib import fixture
from neutron.api.rpc.callbacks import resource_manager
from neutron.services.trunk import callbacks
@ -25,12 +26,13 @@ class ServerSideRpcBackendTest(base.BaseTestCase):
# TODO(fitoduarte): add more test to improve coverage of module
def setUp(self):
super(ServerSideRpcBackendTest, self).setUp()
self._mgr = mock.Mock()
self.useFixture(fixture.CallbackRegistryFixture(
callback_manager=self._mgr))
self.register_mock = mock.patch.object(
resource_manager.ResourceCallbacksManager, "register").start()
# TODO(boden) replace with neutron_lib fixture once working
@mock.patch("neutron_lib.callbacks.manager.CallbacksManager.subscribe")
def test___init__(self, mocked_subscribe):
def test___init__(self,):
test_obj = backend.ServerSideRpcBackend()
calls = [mock.call(test_obj.process_event,
@ -46,7 +48,7 @@ class ServerSideRpcBackendTest(base.BaseTestCase):
trunk_consts.SUBPORTS,
events.AFTER_DELETE)
]
mocked_subscribe.assert_has_calls(calls, any_order=True)
self._mgr.subscribe.assert_has_calls(calls, any_order=True)
def test_process_event(self):
test_obj = backend.ServerSideRpcBackend()