unit test: unbreak test cases for callbacks.subscribe
patch set of [1] added callback priority so that a new argument, priority, was added to subscribe method. Thus its signature was changed. It caused to break some unit tests.[2] Those test cases check arguments passed to subscribe method. The fix to those test cases needs to be compatible with older version of neutron-lib. So add a helper method, get_subscribe_args, to produce argument to subscribe by checking if neutron-lib supports callback priority or not. and apply it to broken test cases. [1] https://review.openstack.org/#/c/541766/ [2] http://logs.openstack.org/periodic/git.openstack.org/openstack/neutron/master/openstack-tox-py35-with-neutron-lib-master/66d328a/testr_results.html.gz test_capabilities.CapabilitiesTest.test_register test_ovs_capabilities.CapabilitiesTest.test_register test_backend.ServerSideRpcBackendTest.test___init__ Change-Id: I94066ff8a8dae5c5637478aa52883b3b451f2857
This commit is contained in:
parent
7a714aeb13
commit
5a1934da8e
@ -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.
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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,
|
||||
calls = [mock.call(
|
||||
*tools.get_subscribe_args(
|
||||
test_obj.process_event,
|
||||
trunk_consts.TRUNK,
|
||||
events.AFTER_CREATE),
|
||||
mock.call(test_obj.process_event,
|
||||
events.AFTER_CREATE)),
|
||||
mock.call(
|
||||
*tools.get_subscribe_args(
|
||||
test_obj.process_event,
|
||||
trunk_consts.TRUNK,
|
||||
events.AFTER_DELETE),
|
||||
mock.call(test_obj.process_event,
|
||||
events.AFTER_DELETE)),
|
||||
mock.call(
|
||||
*tools.get_subscribe_args(
|
||||
test_obj.process_event,
|
||||
trunk_consts.SUBPORTS,
|
||||
events.AFTER_CREATE),
|
||||
mock.call(test_obj.process_event,
|
||||
events.AFTER_CREATE)),
|
||||
mock.call(
|
||||
*tools.get_subscribe_args(
|
||||
test_obj.process_event,
|
||||
trunk_consts.SUBPORTS,
|
||||
events.AFTER_DELETE)
|
||||
events.AFTER_DELETE))
|
||||
]
|
||||
self._mgr.subscribe.assert_has_calls(calls, any_order=True)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user