Merge "unit test: unbreak test cases for callbacks.subscribe"

This commit is contained in:
Zuul 2018-04-12 05:27:23 +00:00 committed by Gerrit Code Review
commit a0bbfba8c5
4 changed files with 50 additions and 18 deletions

View File

@ -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.

View File

@ -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)

View File

@ -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)

View File

@ -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)