Merge "unit test: unbreak test cases for callbacks.subscribe"
This commit is contained in:
commit
a0bbfba8c5
|
@ -34,6 +34,17 @@ from neutron.common import constants as n_const
|
||||||
from neutron.services.logapi.common import constants as log_const
|
from neutron.services.logapi.common import constants as log_const
|
||||||
|
|
||||||
|
|
||||||
|
# NOTE(yamahata): from neutron-lib 1.9.1, callback priority was added and
|
||||||
|
# priority_group module was added for constants of priority.
|
||||||
|
# test the existence of the module of priority_group to check if
|
||||||
|
# callback priority is supported or not.
|
||||||
|
CALLBACK_PRIORITY_SUPPORTED = True
|
||||||
|
try:
|
||||||
|
from neutron_lib.callbacks import priority_group # noqa
|
||||||
|
except ImportError as e:
|
||||||
|
CALLBACK_PRIORITY_SUPPORTED = False
|
||||||
|
|
||||||
|
|
||||||
class WarningsFixture(fixtures.Fixture):
|
class WarningsFixture(fixtures.Fixture):
|
||||||
"""Filters out warnings during test runs."""
|
"""Filters out warnings during test runs."""
|
||||||
|
|
||||||
|
@ -135,6 +146,16 @@ def verify_mock_calls(mocked_call, expected_calls_and_values,
|
||||||
mocked_call.assert_has_calls(expected_calls, any_order=any_order)
|
mocked_call.assert_has_calls(expected_calls, any_order=any_order)
|
||||||
|
|
||||||
|
|
||||||
|
def get_subscribe_args(*args):
|
||||||
|
# NOTE(yamahata): from neutron-lib 1.9.1, callback priority was added.
|
||||||
|
# old signature: (callback, resource, event)
|
||||||
|
# new signature: (callback, resource, event, priority=PRIORITY_DEFAULT)
|
||||||
|
if len(args) == 3 and CALLBACK_PRIORITY_SUPPORTED:
|
||||||
|
args = list(args) # don't modify original list
|
||||||
|
args.append(priority_group.PRIORITY_DEFAULT)
|
||||||
|
return args
|
||||||
|
|
||||||
|
|
||||||
def fail(msg=None):
|
def fail(msg=None):
|
||||||
"""Fail immediately, with the given message.
|
"""Fail immediately, with the given message.
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@ from neutron_lib import fixture
|
||||||
|
|
||||||
from neutron.plugins.ml2.drivers.agent import capabilities
|
from neutron.plugins.ml2.drivers.agent import capabilities
|
||||||
from neutron.tests import base
|
from neutron.tests import base
|
||||||
|
from neutron.tests import tools
|
||||||
|
|
||||||
|
|
||||||
class CapabilitiesTest(base.BaseTestCase):
|
class CapabilitiesTest(base.BaseTestCase):
|
||||||
|
@ -40,6 +41,6 @@ class CapabilitiesTest(base.BaseTestCase):
|
||||||
mock_callback = mock.Mock()
|
mock_callback = mock.Mock()
|
||||||
mock_agent_type = mock.Mock()
|
mock_agent_type = mock.Mock()
|
||||||
capabilities.register(mock_callback, mock_agent_type)
|
capabilities.register(mock_callback, mock_agent_type)
|
||||||
self._mgr.subscribe.assert_called_with(mock_callback,
|
args = tools.get_subscribe_args(
|
||||||
mock_agent_type,
|
mock_callback, mock_agent_type, events.AFTER_INIT)
|
||||||
events.AFTER_INIT)
|
self._mgr.subscribe.assert_called_with(*args)
|
||||||
|
|
|
@ -19,6 +19,7 @@ from neutron_lib import fixture
|
||||||
from neutron.plugins.ml2.drivers.openvswitch.agent import ovs_capabilities
|
from neutron.plugins.ml2.drivers.openvswitch.agent import ovs_capabilities
|
||||||
from neutron.services.trunk.drivers.openvswitch.agent import driver
|
from neutron.services.trunk.drivers.openvswitch.agent import driver
|
||||||
from neutron.tests import base
|
from neutron.tests import base
|
||||||
|
from neutron.tests import tools
|
||||||
from neutron_lib import constants
|
from neutron_lib import constants
|
||||||
|
|
||||||
|
|
||||||
|
@ -32,6 +33,6 @@ class CapabilitiesTest(base.BaseTestCase):
|
||||||
|
|
||||||
def test_register(self):
|
def test_register(self):
|
||||||
ovs_capabilities.register()
|
ovs_capabilities.register()
|
||||||
self._mgr.subscribe.assert_called_with(driver.init_handler,
|
args = tools.get_subscribe_args(
|
||||||
constants.AGENT_TYPE_OVS,
|
driver.init_handler, constants.AGENT_TYPE_OVS, events.AFTER_INIT)
|
||||||
events.AFTER_INIT)
|
self._mgr.subscribe.assert_called_with(*args)
|
||||||
|
|
|
@ -20,6 +20,7 @@ from neutron.services.trunk import callbacks
|
||||||
from neutron.services.trunk import constants as trunk_consts
|
from neutron.services.trunk import constants as trunk_consts
|
||||||
from neutron.services.trunk.rpc import backend
|
from neutron.services.trunk.rpc import backend
|
||||||
from neutron.tests import base
|
from neutron.tests import base
|
||||||
|
from neutron.tests import tools
|
||||||
|
|
||||||
|
|
||||||
class ServerSideRpcBackendTest(base.BaseTestCase):
|
class ServerSideRpcBackendTest(base.BaseTestCase):
|
||||||
|
@ -35,18 +36,26 @@ class ServerSideRpcBackendTest(base.BaseTestCase):
|
||||||
def test___init__(self,):
|
def test___init__(self,):
|
||||||
test_obj = backend.ServerSideRpcBackend()
|
test_obj = backend.ServerSideRpcBackend()
|
||||||
|
|
||||||
calls = [mock.call(test_obj.process_event,
|
calls = [mock.call(
|
||||||
trunk_consts.TRUNK,
|
*tools.get_subscribe_args(
|
||||||
events.AFTER_CREATE),
|
test_obj.process_event,
|
||||||
mock.call(test_obj.process_event,
|
trunk_consts.TRUNK,
|
||||||
trunk_consts.TRUNK,
|
events.AFTER_CREATE)),
|
||||||
events.AFTER_DELETE),
|
mock.call(
|
||||||
mock.call(test_obj.process_event,
|
*tools.get_subscribe_args(
|
||||||
trunk_consts.SUBPORTS,
|
test_obj.process_event,
|
||||||
events.AFTER_CREATE),
|
trunk_consts.TRUNK,
|
||||||
mock.call(test_obj.process_event,
|
events.AFTER_DELETE)),
|
||||||
trunk_consts.SUBPORTS,
|
mock.call(
|
||||||
events.AFTER_DELETE)
|
*tools.get_subscribe_args(
|
||||||
|
test_obj.process_event,
|
||||||
|
trunk_consts.SUBPORTS,
|
||||||
|
events.AFTER_CREATE)),
|
||||||
|
mock.call(
|
||||||
|
*tools.get_subscribe_args(
|
||||||
|
test_obj.process_event,
|
||||||
|
trunk_consts.SUBPORTS,
|
||||||
|
events.AFTER_DELETE))
|
||||||
]
|
]
|
||||||
self._mgr.subscribe.assert_has_calls(calls, any_order=True)
|
self._mgr.subscribe.assert_has_calls(calls, any_order=True)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue