diff --git a/neutron/tests/tools.py b/neutron/tests/tools.py index df54634a2ee..82b2d493032 100644 --- a/neutron/tests/tools.py +++ b/neutron/tests/tools.py @@ -34,6 +34,17 @@ from neutron.common import constants as n_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): """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) +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): """Fail immediately, with the given message. diff --git a/neutron/tests/unit/plugins/ml2/drivers/agent/test_capabilities.py b/neutron/tests/unit/plugins/ml2/drivers/agent/test_capabilities.py index 79f56de8124..90b932af441 100644 --- a/neutron/tests/unit/plugins/ml2/drivers/agent/test_capabilities.py +++ b/neutron/tests/unit/plugins/ml2/drivers/agent/test_capabilities.py @@ -17,6 +17,7 @@ from neutron_lib import fixture from neutron.plugins.ml2.drivers.agent import capabilities from neutron.tests import base +from neutron.tests import tools class CapabilitiesTest(base.BaseTestCase): @@ -40,6 +41,6 @@ class CapabilitiesTest(base.BaseTestCase): mock_callback = mock.Mock() mock_agent_type = mock.Mock() capabilities.register(mock_callback, mock_agent_type) - self._mgr.subscribe.assert_called_with(mock_callback, - mock_agent_type, - events.AFTER_INIT) + args = tools.get_subscribe_args( + mock_callback, mock_agent_type, events.AFTER_INIT) + self._mgr.subscribe.assert_called_with(*args) diff --git a/neutron/tests/unit/plugins/ml2/drivers/openvswitch/agent/test_ovs_capabilities.py b/neutron/tests/unit/plugins/ml2/drivers/openvswitch/agent/test_ovs_capabilities.py index 6b20c86f4e2..75947922311 100644 --- a/neutron/tests/unit/plugins/ml2/drivers/openvswitch/agent/test_ovs_capabilities.py +++ b/neutron/tests/unit/plugins/ml2/drivers/openvswitch/agent/test_ovs_capabilities.py @@ -19,6 +19,7 @@ from neutron_lib import fixture from neutron.plugins.ml2.drivers.openvswitch.agent import ovs_capabilities from neutron.services.trunk.drivers.openvswitch.agent import driver from neutron.tests import base +from neutron.tests import tools from neutron_lib import constants @@ -32,6 +33,6 @@ class CapabilitiesTest(base.BaseTestCase): def test_register(self): ovs_capabilities.register() - self._mgr.subscribe.assert_called_with(driver.init_handler, - constants.AGENT_TYPE_OVS, - events.AFTER_INIT) + args = tools.get_subscribe_args( + driver.init_handler, constants.AGENT_TYPE_OVS, events.AFTER_INIT) + self._mgr.subscribe.assert_called_with(*args) diff --git a/neutron/tests/unit/services/trunk/rpc/test_backend.py b/neutron/tests/unit/services/trunk/rpc/test_backend.py index 00ec02ed847..ea1ba32c45c 100644 --- a/neutron/tests/unit/services/trunk/rpc/test_backend.py +++ b/neutron/tests/unit/services/trunk/rpc/test_backend.py @@ -20,6 +20,7 @@ from neutron.services.trunk import callbacks from neutron.services.trunk import constants as trunk_consts from neutron.services.trunk.rpc import backend from neutron.tests import base +from neutron.tests import tools class ServerSideRpcBackendTest(base.BaseTestCase): @@ -35,18 +36,26 @@ class ServerSideRpcBackendTest(base.BaseTestCase): def test___init__(self,): test_obj = backend.ServerSideRpcBackend() - calls = [mock.call(test_obj.process_event, - trunk_consts.TRUNK, - events.AFTER_CREATE), - mock.call(test_obj.process_event, - trunk_consts.TRUNK, - events.AFTER_DELETE), - mock.call(test_obj.process_event, - trunk_consts.SUBPORTS, - events.AFTER_CREATE), - mock.call(test_obj.process_event, - trunk_consts.SUBPORTS, - events.AFTER_DELETE) + calls = [mock.call( + *tools.get_subscribe_args( + test_obj.process_event, + trunk_consts.TRUNK, + events.AFTER_CREATE)), + mock.call( + *tools.get_subscribe_args( + test_obj.process_event, + trunk_consts.TRUNK, + events.AFTER_DELETE)), + mock.call( + *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)