Revised dispatcher notification

This patch revised the interface for notifying an action's readiness for
execution (we execute them right away at the moment). The revision set
the default engine_id to be None, which is the most common cases, thus
we don't have to pass None into notify(). It also eliminates the passing
of NEW_ACTION (renamed to START_ACTION) by providing a more user
friendly interface function.

This patch also fixed the incorrect usage of engline_life_timeout, where
we should use rpc_response_timeout if needed. Currently, we leave it to
the oslo.messaing library to use the configuration option instead of
injecting new values from an inappropriate place.

Change-Id: Ic4d872d8c2995614aba966ccd179181ab11bc640
This commit is contained in:
tengqm 2015-05-26 10:52:35 -04:00
parent dff45b2bfc
commit 094fcab073
9 changed files with 145 additions and 217 deletions

View File

@ -123,8 +123,7 @@ class ClusterAction(base.Action):
db_api.action_add_dependency(self.context, action.id, self.id) db_api.action_add_dependency(self.context, action.id, self.id)
action.set_status(self.READY) action.set_status(self.READY)
dispatcher.notify(self.context, dispatcher.Dispatcher.NEW_ACTION, dispatcher.start_action(self.context, action_id=action.id)
None, action_id=action.id)
if count > 0: if count > 0:
# Wait for cluster creation to complete # Wait for cluster creation to complete
@ -172,9 +171,7 @@ class ClusterAction(base.Action):
db_api.action_add_dependency(self.context, action.id, self.id) db_api.action_add_dependency(self.context, action.id, self.id)
action.set_status(self.READY) action.set_status(self.READY)
dispatcher.notify(self.context, dispatcher.start_action(self.context, action_id=action.id)
dispatcher.Dispatcher.NEW_ACTION,
None, action_id=action.id)
# Wait for nodes to complete update # Wait for nodes to complete update
result = self.RES_OK result = self.RES_OK
@ -211,8 +208,7 @@ class ClusterAction(base.Action):
db_api.action_add_dependency(self.context, action.id, self.id) db_api.action_add_dependency(self.context, action.id, self.id)
action.set_status(self.READY) action.set_status(self.READY)
dispatcher.notify(self.context, dispatcher.Dispatcher.NEW_ACTION, dispatcher.start_action(self.context, action_id=action.id)
None, action_id=action.id)
if len(nodes) > 0: if len(nodes) > 0:
return self._wait_for_dependents() return self._wait_for_dependents()
@ -292,8 +288,7 @@ class ClusterAction(base.Action):
action.store(self.context) action.store(self.context)
db_api.action_add_dependency(self.context, action.id, self.id) db_api.action_add_dependency(self.context, action.id, self.id)
action.set_status(self.READY) action.set_status(self.READY)
dispatcher.notify(self.context, dispatcher.Dispatcher.NEW_ACTION, dispatcher.start_action(self.context, action_id=action.id)
None, action_id=action.id)
# Wait for dependent action if any # Wait for dependent action if any
result, new_reason = self._wait_for_dependents() result, new_reason = self._wait_for_dependents()

View File

@ -10,7 +10,6 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
from oslo_config import cfg
from oslo_log import log as logging from oslo_log import log as logging
import oslo_messaging import oslo_messaging
@ -21,19 +20,18 @@ from senlin.openstack.common import service
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
OPERATIONS = (
START_ACTION, CANCEL_ACTION, STOP
) = (
'start_action', 'cancel_action', 'stop'
)
class Dispatcher(service.Service): class Dispatcher(service.Service):
'''Listen on an AMQP queue named for the engine. '''Listen on an AMQP queue named for the engine.
Receive notification from engine services and schedule actions. Receive notification from engine services and schedule actions.
''' '''
OPERATIONS = (
NEW_ACTION, CANCEL_ACTION, STOP
) = (
'new_action', 'cancel_action', 'stop'
)
def __init__(self, engine_service, topic, version, thread_group_mgr): def __init__(self, engine_service, topic, version, thread_group_mgr):
super(Dispatcher, self).__init__() super(Dispatcher, self).__init__()
self.TG = thread_group_mgr self.TG = thread_group_mgr
@ -53,7 +51,7 @@ class Dispatcher(service.Service):
'''Respond affirmatively to confirm that engine is still alive.''' '''Respond affirmatively to confirm that engine is still alive.'''
return True return True
def new_action(self, context, action_id=None): def start_action(self, context, action_id=None):
self.TG.start_action(context, action_id, self.engine_id) self.TG.start_action(context, action_id, self.engine_id)
def cancel_action(self, context, action_id): def cancel_action(self, context, action_id):
@ -78,33 +76,34 @@ class Dispatcher(service.Service):
LOG.info(_LI("All action threads have been finished")) LOG.info(_LI("All action threads have been finished"))
def notify(context, call, engine_id, *args, **kwargs): def notify(context, method, engine_id=None, **kwargs):
'''Send notification to dispatcher '''Send notification to dispatcher
:param context: rpc request context :param context: rpc request context
:param call: remote method want to call :param method: remote method to call
:param engine_id: dispatcher want to notify, if None, broadcast :param engine_id: dispatcher to notify; None implies broadcast
''' '''
timeout = cfg.CONF.engine_life_check_timeout
client = rpc_messaging.get_rpc_client(version=consts.RPC_API_VERSION) client = rpc_messaging.get_rpc_client(version=consts.RPC_API_VERSION)
if engine_id: if engine_id:
# Notify specific dispatcher identified by engine_id # Notify specific dispatcher identified by engine_id
call_context = client.prepare( call_context = client.prepare(
version=consts.RPC_API_VERSION, version=consts.RPC_API_VERSION,
timeout=timeout,
topic=consts.ENGINE_DISPATCHER_TOPIC, topic=consts.ENGINE_DISPATCHER_TOPIC,
server=engine_id) server=engine_id)
else: else:
# Broadcast to all disptachers # Broadcast to all disptachers
call_context = client.prepare( call_context = client.prepare(
version=consts.RPC_API_VERSION, version=consts.RPC_API_VERSION,
timeout=timeout,
topic=consts.ENGINE_DISPATCHER_TOPIC) topic=consts.ENGINE_DISPATCHER_TOPIC)
try: try:
call_context.call(context, call, *args, **kwargs) call_context.call(context, method, **kwargs)
return True return True
except oslo_messaging.MessagingTimeout: except oslo_messaging.MessagingTimeout:
return False return False
def start_action(context, engine_id=None, **kwargs):
return notify(context, START_ACTION, engine_id, **kwargs)

View File

@ -91,12 +91,12 @@ class Health_Manager(service.Service, periodic_task.PeriodicTasks):
super(Health_Manager, self).stop() super(Health_Manager, self).stop()
def notify(context, call, engine_id, *args, **kwargs): def notify(context, method, engine_id, *args, **kwargs):
'''Send notification to dispatcher '''Send notification to dispatcher
:param context: rpc request context :param context: rpc request context
:param call: remote method want to call :param method: remote method to call
:param engine_id: dispatcher want to notify, if None, broadcast :param engine_id: dispatcher to notify; broadcast if value is None
''' '''
timeout = cfg.CONF.engine_life_check_timeout timeout = cfg.CONF.engine_life_check_timeout
@ -117,7 +117,7 @@ def notify(context, call, engine_id, *args, **kwargs):
topic=consts.ENGINE_DISPATCHER_TOPIC) topic=consts.ENGINE_DISPATCHER_TOPIC)
try: try:
call_context.call(context, call, *args, **kwargs) call_context.call(context, method, *args, **kwargs)
return True return True
except oslo_messaging.MessagingTimeout: except oslo_messaging.MessagingTimeout:
return False return False

View File

@ -10,9 +10,9 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import eventlet
import time import time
import eventlet
from oslo_config import cfg from oslo_config import cfg
from oslo_log import log as logging from oslo_log import log as logging
@ -67,8 +67,7 @@ class ThreadGroupManager(object):
action = action_mod.Action.load(context, action_id) action = action_mod.Action.load(context, action_id)
# This is for actions with RETRY # This is for actions with RETRY
if action.status == action.READY: if action.status == action.READY:
dispatcher.notify(context, dispatcher.Dispatcher.NEW_ACTION, dispatcher.start_action(context, action_id=action_id)
None, action_id=action_id)
def release(gt, context, action_id): def release(gt, context, action_id):
'''Callback function that will be passed to GreenThread.link().''' '''Callback function that will be passed to GreenThread.link().'''

View File

@ -483,9 +483,7 @@ class EngineService(service.Service):
target=cluster.id, target=cluster.id,
cause=action_mod.CAUSE_RPC) cause=action_mod.CAUSE_RPC)
action.store(context) action.store(context)
dispatcher.start_action(context, action_id=action.id)
dispatcher.notify(context, self.dispatcher.NEW_ACTION,
None, action_id=action.id)
# We return a cluster dictionary with an additional key carried # We return a cluster dictionary with an additional key carried
result = cluster.to_dict() result = cluster.to_dict()
@ -554,8 +552,7 @@ class EngineService(service.Service):
cause=action_mod.CAUSE_RPC, cause=action_mod.CAUSE_RPC,
inputs=inputs) inputs=inputs)
action.store(context) action.store(context)
dispatcher.notify(context, self.dispatcher.NEW_ACTION, dispatcher.start_action(context, action_id=action.id)
None, action_id=action.id)
result = cluster.to_dict() result = cluster.to_dict()
result['action'] = action.id result['action'] = action.id
@ -603,8 +600,7 @@ class EngineService(service.Service):
cause=action_mod.CAUSE_RPC, cause=action_mod.CAUSE_RPC,
inputs={'nodes': found}) inputs={'nodes': found})
action.store(context) action.store(context)
dispatcher.notify(context, self.dispatcher.NEW_ACTION, dispatcher.start_action(context, action_id=action.id)
None, action_id=action.id)
return {'action': action.id} return {'action': action.id}
@ -643,8 +639,7 @@ class EngineService(service.Service):
cause=action_mod.CAUSE_RPC, cause=action_mod.CAUSE_RPC,
inputs={'nodes': found}) inputs={'nodes': found})
action.store(context) action.store(context)
dispatcher.notify(context, self.dispatcher.NEW_ACTION, dispatcher.start_action(context, action_id=action.id)
None, action_id=action.id)
return {'action': action.id} return {'action': action.id}
@ -740,8 +735,7 @@ class EngineService(service.Service):
cause=action_mod.CAUSE_RPC, cause=action_mod.CAUSE_RPC,
inputs=inputs) inputs=inputs)
action.store(context) action.store(context)
dispatcher.notify(context, self.dispatcher.NEW_ACTION, dispatcher.start_action(context, action_id=action.id)
None, action_id=action.id)
result = cluster.to_dict() result = cluster.to_dict()
result['action'] = action.id result['action'] = action.id
@ -768,8 +762,7 @@ class EngineService(service.Service):
inputs=inputs, inputs=inputs,
cause=action_mod.CAUSE_RPC) cause=action_mod.CAUSE_RPC)
action.store(context) action.store(context)
dispatcher.notify(context, self.dispatcher.NEW_ACTION, dispatcher.start_action(context, action_id=action.id)
None, action_id=action.id)
return {'action': action.id} return {'action': action.id}
@ -793,8 +786,7 @@ class EngineService(service.Service):
inputs=inputs, inputs=inputs,
cause=action_mod.CAUSE_RPC) cause=action_mod.CAUSE_RPC)
action.store(context) action.store(context)
dispatcher.notify(context, self.dispatcher.NEW_ACTION, dispatcher.start_action(context, action_id=action.id)
None, action_id=action.id)
return {'action': action.id} return {'action': action.id}
@ -808,8 +800,7 @@ class EngineService(service.Service):
target=cluster.id, target=cluster.id,
cause=action_mod.CAUSE_RPC) cause=action_mod.CAUSE_RPC)
action.store(context) action.store(context)
dispatcher.notify(context, self.dispatcher.NEW_ACTION, dispatcher.start_action(context, action_id=action.id)
None, action_id=action.id)
return {'action': action.id} return {'action': action.id}
@ -889,9 +880,7 @@ class EngineService(service.Service):
target=node.id, target=node.id,
cause=action_mod.CAUSE_RPC) cause=action_mod.CAUSE_RPC)
action.store(context) action.store(context)
dispatcher.start_action(context, action_id=action.id)
dispatcher.notify(context, self.dispatcher.NEW_ACTION,
None, action_id=action.id)
# We return a node dictionary with an additional key (action) carried # We return a node dictionary with an additional key (action) carried
result = node.to_dict() result = node.to_dict()
@ -955,8 +944,7 @@ class EngineService(service.Service):
action.store(context) action.store(context)
# TODO(someone): uncomment this when it is implemented # TODO(someone): uncomment this when it is implemented
# dispatcher.notify(context, self.dispatcher.NEW_ACTION, # dispatcher.start_action(context, action_id=action.id)
# None, action_id=action.id)
return return
@request_context @request_context
@ -970,8 +958,7 @@ class EngineService(service.Service):
target=node.id, target=node.id,
cause=action_mod.CAUSE_RPC) cause=action_mod.CAUSE_RPC)
action.store(context) action.store(context)
dispatcher.notify(context, self.dispatcher.NEW_ACTION, dispatcher.start_action(context, action_id=action.id)
None, action_id=action.id)
return {'action': action.id} return {'action': action.id}
@ -997,8 +984,7 @@ class EngineService(service.Service):
cause=action_mod.CAUSE_RPC, cause=action_mod.CAUSE_RPC,
inputs={'cluster_id': db_cluster.id}) inputs={'cluster_id': db_cluster.id})
action.store(context) action.store(context)
dispatcher.notify(context, self.dispatcher.NEW_ACTION, dispatcher.start_action(context, action_id=action.id)
None, action_id=action.id)
return {'action': action.id} return {'action': action.id}
@ -1016,8 +1002,7 @@ class EngineService(service.Service):
target=db_node.id, target=db_node.id,
cause=action_mod.CAUSE_RPC) cause=action_mod.CAUSE_RPC)
action.store(context) action.store(context)
dispatcher.notify(context, self.dispatcher.NEW_ACTION, dispatcher.start_action(context, action_id=action.id)
None, action_id=action.id)
return {'action': action.id} return {'action': action.id}
@ -1071,8 +1056,7 @@ class EngineService(service.Service):
inputs=inputs, inputs=inputs,
cause=action_mod.CAUSE_RPC) cause=action_mod.CAUSE_RPC)
action.store(context) action.store(context)
dispatcher.notify(context, self.dispatcher.NEW_ACTION, dispatcher.start_action(context, action_id=action.id)
None, action_id=action.id)
return {'action': action.id} return {'action': action.id}
@ -1096,8 +1080,7 @@ class EngineService(service.Service):
inputs={'policy_id': db_policy.id}, inputs={'policy_id': db_policy.id},
cause=action_mod.CAUSE_RPC) cause=action_mod.CAUSE_RPC)
action.store(context) action.store(context)
dispatcher.notify(context, self.dispatcher.NEW_ACTION, dispatcher.start_action(context, action_id=action.id)
None, action_id=action.id)
return {'action': action.id} return {'action': action.id}
@ -1137,8 +1120,7 @@ class EngineService(service.Service):
inputs=inputs, inputs=inputs,
cause=action_mod.CAUSE_RPC) cause=action_mod.CAUSE_RPC)
action.store(context) action.store(context)
dispatcher.notify(context, self.dispatcher.NEW_ACTION, dispatcher.start_action(context, action_id=action.id)
None, action_id=action.id)
return {'action': action.id} return {'action': action.id}
@ -1273,8 +1255,7 @@ class EngineService(service.Service):
inputs=input_params, inputs=input_params,
cause=action_mod.CAUSE_RPC) cause=action_mod.CAUSE_RPC)
action.store(context) action.store(context)
dispatcher.notify(context, self.dispatcher.NEW_ACTION, dispatcher.start_action(context, action_id=action.id)
None, action_id=action.id)
return {'action': action.id} return {'action': action.id}
@ -1331,8 +1312,7 @@ class EngineService(service.Service):
act.store(context) act.store(context)
# TODO(Anyone): Uncomment this to notify the dispatcher # TODO(Anyone): Uncomment this to notify the dispatcher
# dispatcher.notify(context, self.dispatcher.NEW_ACTION, # dispatcher.start_action(context, action_id=action.id)
# None, action_id=action.id)
return act.to_dict() return act.to_dict()

View File

@ -60,7 +60,7 @@ class ClusterPolicyTest(base.SenlinTestCase):
self.assertEqual(cause, obj['cause']) self.assertEqual(cause, obj['cause'])
self.assertEqual(inputs, obj['inputs']) self.assertEqual(inputs, obj['inputs'])
@mock.patch.object(dispatcher, 'notify') @mock.patch.object(dispatcher, 'start_action')
def test_cluster_policy_attach(self, notify): def test_cluster_policy_attach(self, notify):
cluster_id = self.cluster['id'] cluster_id = self.cluster['id']
policy_id = self.policy['id'] policy_id = self.policy['id']
@ -81,9 +81,7 @@ class ClusterPolicyTest(base.SenlinTestCase):
'cluster_attach_policy_%s' % cluster_id[:8], 'cluster_attach_policy_%s' % cluster_id[:8],
cluster_id, cause=action_mod.CAUSE_RPC, cluster_id, cause=action_mod.CAUSE_RPC,
inputs=inputs) inputs=inputs)
notify.assert_called_with(self.ctx, notify.assert_called_with(self.ctx, action_id=action_id)
self.eng.dispatcher.NEW_ACTION,
None, action_id=action_id)
self.assertEqual(1, notify.call_count) self.assertEqual(1, notify.call_count)
@ -105,7 +103,7 @@ class ClusterPolicyTest(base.SenlinTestCase):
self.assertEqual("The policy (Bogus) could not be found.", self.assertEqual("The policy (Bogus) could not be found.",
six.text_type(ex.exc_info[1])) six.text_type(ex.exc_info[1]))
@mock.patch.object(dispatcher, 'notify') @mock.patch.object(dispatcher, 'start_action')
def test_cluster_policy_attach_priority_not_int(self, notify): def test_cluster_policy_attach_priority_not_int(self, notify):
cluster_id = self.cluster['id'] cluster_id = self.cluster['id']
policy_id = self.policy['id'] policy_id = self.policy['id']
@ -118,7 +116,7 @@ class ClusterPolicyTest(base.SenlinTestCase):
self.assertEqual("Invalid value 'High' specified for 'priority'", self.assertEqual("Invalid value 'High' specified for 'priority'",
six.text_type(ex.exc_info[1])) six.text_type(ex.exc_info[1]))
@mock.patch.object(dispatcher, 'notify') @mock.patch.object(dispatcher, 'start_action')
def test_cluster_policy_attach_level_not_int(self, notify): def test_cluster_policy_attach_level_not_int(self, notify):
cluster_id = self.cluster['id'] cluster_id = self.cluster['id']
policy_id = self.policy['id'] policy_id = self.policy['id']
@ -131,7 +129,7 @@ class ClusterPolicyTest(base.SenlinTestCase):
self.assertEqual("Invalid value 'High' specified for 'level'", self.assertEqual("Invalid value 'High' specified for 'level'",
six.text_type(ex.exc_info[1])) six.text_type(ex.exc_info[1]))
@mock.patch.object(dispatcher, 'notify') @mock.patch.object(dispatcher, 'start_action')
def test_cluster_policy_attach_cooldown_not_int(self, notify): def test_cluster_policy_attach_cooldown_not_int(self, notify):
cluster_id = self.cluster['id'] cluster_id = self.cluster['id']
policy_id = self.policy['id'] policy_id = self.policy['id']
@ -144,7 +142,7 @@ class ClusterPolicyTest(base.SenlinTestCase):
self.assertEqual("Invalid value '1min' specified for 'cooldown'", self.assertEqual("Invalid value '1min' specified for 'cooldown'",
six.text_type(ex.exc_info[1])) six.text_type(ex.exc_info[1]))
@mock.patch.object(dispatcher, 'notify') @mock.patch.object(dispatcher, 'start_action')
def test_cluster_policy_attach_enabled_not_boolean(self, notify): def test_cluster_policy_attach_enabled_not_boolean(self, notify):
cluster_id = self.cluster['id'] cluster_id = self.cluster['id']
policy_id = self.policy['id'] policy_id = self.policy['id']
@ -157,7 +155,7 @@ class ClusterPolicyTest(base.SenlinTestCase):
self.assertEqual("Invalid value 'No' specified for 'enabled'", self.assertEqual("Invalid value 'No' specified for 'enabled'",
six.text_type(ex.exc_info[1])) six.text_type(ex.exc_info[1]))
@mock.patch.object(dispatcher, 'notify') @mock.patch.object(dispatcher, 'start_action')
def test_cluster_policy_detach(self, notify): def test_cluster_policy_detach(self, notify):
cluster_id = self.cluster['id'] cluster_id = self.cluster['id']
policy_id = self.policy['id'] policy_id = self.policy['id']
@ -173,9 +171,7 @@ class ClusterPolicyTest(base.SenlinTestCase):
'cluster_detach_policy_%s' % cluster_id[:8], 'cluster_detach_policy_%s' % cluster_id[:8],
cluster_id, cause=action_mod.CAUSE_RPC, cluster_id, cause=action_mod.CAUSE_RPC,
inputs={'policy_id': policy_id}) inputs={'policy_id': policy_id})
notify.assert_called_with(self.ctx, notify.assert_called_with(self.ctx, action_id=action_id)
self.eng.dispatcher.NEW_ACTION,
None, action_id=action_id)
# called twice: attach and detach # called twice: attach and detach
self.assertEqual(2, notify.call_count) self.assertEqual(2, notify.call_count)
@ -401,7 +397,7 @@ class ClusterPolicyTest(base.SenlinTestCase):
self.assertIn(policy1['id'], policy_ids[1]) self.assertIn(policy1['id'], policy_ids[1])
self.assertIn(policy3['id'], policy_ids[2]) self.assertIn(policy3['id'], policy_ids[2])
@mock.patch.object(dispatcher, 'notify') @mock.patch.object(dispatcher, 'start_action')
def test_cluster_policy_update(self, notify): def test_cluster_policy_update(self, notify):
cluster_id = self.cluster['id'] cluster_id = self.cluster['id']
policy_id = self.policy['id'] policy_id = self.policy['id']
@ -429,9 +425,7 @@ class ClusterPolicyTest(base.SenlinTestCase):
'level': 10, 'level': 10,
'cooldown': 60, 'cooldown': 60,
'enabled': False}) 'enabled': False})
notify.assert_called_once_with(self.ctx, notify.assert_called_once_with(self.ctx, action_id=action_id)
self.eng.dispatcher.NEW_ACTION,
None, action_id=action_id)
def test_cluster_policy_update_cluster_not_found(self): def test_cluster_policy_update_cluster_not_found(self):
ex = self.assertRaises(rpc.ExpectedException, ex = self.assertRaises(rpc.ExpectedException,

View File

@ -58,7 +58,7 @@ class ClusterTest(base.SenlinTestCase):
self.assertEqual(cause, obj['cause']) self.assertEqual(cause, obj['cause'])
self.assertEqual(inputs, obj['inputs']) self.assertEqual(inputs, obj['inputs'])
@mock.patch.object(dispatcher, 'notify') @mock.patch.object(dispatcher, 'start_action')
def test_cluster_create_default(self, notify): def test_cluster_create_default(self, notify):
result = self.eng.cluster_create(self.ctx, 'c-1', 0, result = self.eng.cluster_create(self.ctx, 'c-1', 0,
self.profile['id']) self.profile['id'])
@ -79,11 +79,9 @@ class ClusterTest(base.SenlinTestCase):
'cluster_create_%s' % result['id'][:8], 'cluster_create_%s' % result['id'][:8],
result['id'], result['id'],
cause=action_mod.CAUSE_RPC) cause=action_mod.CAUSE_RPC)
notify.assert_called_once_with(self.ctx, notify.assert_called_once_with(self.ctx, action_id=action_id)
self.eng.dispatcher.NEW_ACTION,
None, action_id=action_id)
@mock.patch.object(dispatcher, 'notify') @mock.patch.object(dispatcher, 'start_action')
def test_cluster_create_with_timeout(self, notify): def test_cluster_create_with_timeout(self, notify):
result = self.eng.cluster_create(self.ctx, 'c-1', 0, result = self.eng.cluster_create(self.ctx, 'c-1', 0,
self.profile['id'], self.profile['id'],
@ -101,7 +99,7 @@ class ClusterTest(base.SenlinTestCase):
self.assertEqual(exception.InvalidParameter, ex.exc_info[0]) self.assertEqual(exception.InvalidParameter, ex.exc_info[0])
@mock.patch.object(dispatcher, 'notify') @mock.patch.object(dispatcher, 'start_action')
def test_cluster_create_with_desired_capacity(self, notify): def test_cluster_create_with_desired_capacity(self, notify):
result = self.eng.cluster_create(self.ctx, 'c-1', 2, result = self.eng.cluster_create(self.ctx, 'c-1', 2,
self.profile['id']) self.profile['id'])
@ -117,7 +115,7 @@ class ClusterTest(base.SenlinTestCase):
self.assertEqual(exception.InvalidParameter, ex.exc_info[0]) self.assertEqual(exception.InvalidParameter, ex.exc_info[0])
@mock.patch.object(dispatcher, 'notify') @mock.patch.object(dispatcher, 'start_action')
def test_cluster_create_with_parent(self, notify): def test_cluster_create_with_parent(self, notify):
result = self.eng.cluster_create(self.ctx, 'c-1', 2, result = self.eng.cluster_create(self.ctx, 'c-1', 2,
self.profile['id'], self.profile['id'],
@ -127,7 +125,7 @@ class ClusterTest(base.SenlinTestCase):
self.assertEqual('c-1', result['name']) self.assertEqual('c-1', result['name'])
self.assertEqual('fake id', result['parent']) self.assertEqual('fake id', result['parent'])
@mock.patch.object(dispatcher, 'notify') @mock.patch.object(dispatcher, 'start_action')
def test_cluster_create_with_metadata(self, notify): def test_cluster_create_with_metadata(self, notify):
result = self.eng.cluster_create(self.ctx, 'c-1', 2, result = self.eng.cluster_create(self.ctx, 'c-1', 2,
self.profile['id'], self.profile['id'],
@ -143,7 +141,7 @@ class ClusterTest(base.SenlinTestCase):
self.ctx, 'c-1', 0, 'Bogus') self.ctx, 'c-1', 0, 'Bogus')
self.assertEqual(exception.ProfileNotFound, ex.exc_info[0]) self.assertEqual(exception.ProfileNotFound, ex.exc_info[0])
@mock.patch.object(dispatcher, 'notify') @mock.patch.object(dispatcher, 'start_action')
def test_cluster_create_with_profile_name_or_short_id(self, notify): def test_cluster_create_with_profile_name_or_short_id(self, notify):
result = self.eng.cluster_create(self.ctx, 'c-1', 0, result = self.eng.cluster_create(self.ctx, 'c-1', 0,
self.profile['id'][:8]) self.profile['id'][:8])
@ -228,7 +226,7 @@ class ClusterTest(base.SenlinTestCase):
self.assertEqual("The request is malformed: %s" % expected, self.assertEqual("The request is malformed: %s" % expected,
six.text_type(ex)) six.text_type(ex))
@mock.patch.object(dispatcher, 'notify') @mock.patch.object(dispatcher, 'start_action')
def test_cluster_get(self, notify): def test_cluster_get(self, notify):
c = self.eng.cluster_create(self.ctx, 'c-1', 0, c = self.eng.cluster_create(self.ctx, 'c-1', 0,
self.profile['id']) self.profile['id'])
@ -242,7 +240,7 @@ class ClusterTest(base.SenlinTestCase):
self.eng.cluster_get, self.ctx, 'Bogus') self.eng.cluster_get, self.ctx, 'Bogus')
self.assertEqual(exception.ClusterNotFound, ex.exc_info[0]) self.assertEqual(exception.ClusterNotFound, ex.exc_info[0])
@mock.patch.object(dispatcher, 'notify') @mock.patch.object(dispatcher, 'start_action')
def test_cluster_list(self, notify): def test_cluster_list(self, notify):
c1 = self.eng.cluster_create(self.ctx, 'c-1', 0, self.profile['id']) c1 = self.eng.cluster_create(self.ctx, 'c-1', 0, self.profile['id'])
c2 = self.eng.cluster_create(self.ctx, 'c-2', 0, self.profile['id']) c2 = self.eng.cluster_create(self.ctx, 'c-2', 0, self.profile['id'])
@ -255,7 +253,7 @@ class ClusterTest(base.SenlinTestCase):
self.assertEqual(c1['id'], ids[0]) self.assertEqual(c1['id'], ids[0])
self.assertEqual(c2['id'], ids[1]) self.assertEqual(c2['id'], ids[1])
@mock.patch.object(dispatcher, 'notify') @mock.patch.object(dispatcher, 'start_action')
def test_cluster_list_with_limit_marker(self, notify): def test_cluster_list_with_limit_marker(self, notify):
c1 = self.eng.cluster_create(self.ctx, 'c-1', 0, self.profile['id']) c1 = self.eng.cluster_create(self.ctx, 'c-1', 0, self.profile['id'])
c2 = self.eng.cluster_create(self.ctx, 'c-2', 0, self.profile['id']) c2 = self.eng.cluster_create(self.ctx, 'c-2', 0, self.profile['id'])
@ -281,7 +279,7 @@ class ClusterTest(base.SenlinTestCase):
result = self.eng.cluster_list(self.ctx, limit=2, marker=c1['id']) result = self.eng.cluster_list(self.ctx, limit=2, marker=c1['id'])
self.assertEqual(2, len(result)) self.assertEqual(2, len(result))
@mock.patch.object(dispatcher, 'notify') @mock.patch.object(dispatcher, 'start_action')
def test_cluster_list_with_sort_keys(self, notify): def test_cluster_list_with_sort_keys(self, notify):
c1 = self.eng.cluster_create(self.ctx, 'CC', 0, self.profile['id']) c1 = self.eng.cluster_create(self.ctx, 'CC', 0, self.profile['id'])
c2 = self.eng.cluster_create(self.ctx, 'BB', 0, self.profile['id']) c2 = self.eng.cluster_create(self.ctx, 'BB', 0, self.profile['id'])
@ -300,7 +298,7 @@ class ClusterTest(base.SenlinTestCase):
result = self.eng.cluster_list(self.ctx, sort_keys=['duang']) result = self.eng.cluster_list(self.ctx, sort_keys=['duang'])
self.assertIsNotNone(result) self.assertIsNotNone(result)
@mock.patch.object(dispatcher, 'notify') @mock.patch.object(dispatcher, 'start_action')
def test_cluster_list_with_sort_dir(self, notify): def test_cluster_list_with_sort_dir(self, notify):
c1 = self.eng.cluster_create(self.ctx, 'BB', 0, self.profile['id']) c1 = self.eng.cluster_create(self.ctx, 'BB', 0, self.profile['id'])
c2 = self.eng.cluster_create(self.ctx, 'AA', 0, self.profile['id']) c2 = self.eng.cluster_create(self.ctx, 'AA', 0, self.profile['id'])
@ -329,7 +327,7 @@ class ClusterTest(base.SenlinTestCase):
self.assertEqual("Unknown sort direction, must be " self.assertEqual("Unknown sort direction, must be "
"'desc' or 'asc'", six.text_type(ex)) "'desc' or 'asc'", six.text_type(ex))
@mock.patch.object(dispatcher, 'notify') @mock.patch.object(dispatcher, 'start_action')
def test_cluster_list_show_deleted(self, notify): def test_cluster_list_show_deleted(self, notify):
c = self.eng.cluster_create(self.ctx, 'c-1', 0, self.profile['id']) c = self.eng.cluster_create(self.ctx, 'c-1', 0, self.profile['id'])
result = self.eng.cluster_list(self.ctx) result = self.eng.cluster_list(self.ctx)
@ -345,7 +343,7 @@ class ClusterTest(base.SenlinTestCase):
self.assertEqual(1, len(result)) self.assertEqual(1, len(result))
self.assertEqual(c['id'], result[0]['id']) self.assertEqual(c['id'], result[0]['id'])
@mock.patch.object(dispatcher, 'notify') @mock.patch.object(dispatcher, 'start_action')
def test_cluster_list_show_nested(self, notify): def test_cluster_list_show_nested(self, notify):
c = self.eng.cluster_create(self.ctx, 'c-1', 0, self.profile['id'], c = self.eng.cluster_create(self.ctx, 'c-1', 0, self.profile['id'],
parent='other-cluster') parent='other-cluster')
@ -356,7 +354,7 @@ class ClusterTest(base.SenlinTestCase):
self.assertEqual(1, len(result)) self.assertEqual(1, len(result))
self.assertEqual(c['id'], result[0]['id']) self.assertEqual(c['id'], result[0]['id'])
@mock.patch.object(dispatcher, 'notify') @mock.patch.object(dispatcher, 'start_action')
def test_cluster_list_project_safe(self, notify): def test_cluster_list_project_safe(self, notify):
c1 = self.eng.cluster_create(self.ctx, 'c1', 0, self.profile['id']) c1 = self.eng.cluster_create(self.ctx, 'c1', 0, self.profile['id'])
new_ctx = utils.dummy_context(project='a_diff_project') new_ctx = utils.dummy_context(project='a_diff_project')
@ -380,7 +378,7 @@ class ClusterTest(base.SenlinTestCase):
self.assertEqual(c1['id'], result[0]['id']) self.assertEqual(c1['id'], result[0]['id'])
self.assertEqual(c2['id'], result[1]['id']) self.assertEqual(c2['id'], result[1]['id'])
@mock.patch.object(dispatcher, 'notify') @mock.patch.object(dispatcher, 'start_action')
def test_cluster_list_with_filters(self, notify): def test_cluster_list_with_filters(self, notify):
self.eng.cluster_create(self.ctx, 'BB', 0, self.profile['id']) self.eng.cluster_create(self.ctx, 'BB', 0, self.profile['id'])
self.eng.cluster_create(self.ctx, 'AA', 0, self.profile['id']) self.eng.cluster_create(self.ctx, 'AA', 0, self.profile['id'])
@ -418,7 +416,7 @@ class ClusterTest(base.SenlinTestCase):
self.assertIsInstance(result, list) self.assertIsInstance(result, list)
self.assertEqual(0, len(result)) self.assertEqual(0, len(result))
@mock.patch.object(dispatcher, 'notify') @mock.patch.object(dispatcher, 'start_action')
def test_cluster_find(self, notify): def test_cluster_find(self, notify):
c = self.eng.cluster_create(self.ctx, 'c-1', 0, self.profile['id']) c = self.eng.cluster_create(self.ctx, 'c-1', 0, self.profile['id'])
cid = c['id'] cid = c['id']
@ -438,7 +436,7 @@ class ClusterTest(base.SenlinTestCase):
self.assertRaises(exception.ClusterNotFound, self.assertRaises(exception.ClusterNotFound,
self.eng.cluster_find, self.ctx, 'Bogus') self.eng.cluster_find, self.ctx, 'Bogus')
@mock.patch.object(dispatcher, 'notify') @mock.patch.object(dispatcher, 'start_action')
def test_cluster_find_show_deleted(self, notify): def test_cluster_find_show_deleted(self, notify):
c = self.eng.cluster_create(self.ctx, 'c-1', 0, self.profile['id']) c = self.eng.cluster_create(self.ctx, 'c-1', 0, self.profile['id'])
cid = c['id'] cid = c['id']
@ -457,7 +455,7 @@ class ClusterTest(base.SenlinTestCase):
result = self.eng.cluster_find(self.ctx, cid, show_deleted=True) result = self.eng.cluster_find(self.ctx, cid, show_deleted=True)
self.assertIsNotNone(result) self.assertIsNotNone(result)
@mock.patch.object(dispatcher, 'notify') @mock.patch.object(dispatcher, 'start_action')
def test_cluster_update_simple_success(self, notify): def test_cluster_update_simple_success(self, notify):
c1 = self.eng.cluster_create(self.ctx, 'c-1', 0, self.profile['id']) c1 = self.eng.cluster_create(self.ctx, 'c-1', 0, self.profile['id'])
cid = c1['id'] cid = c1['id']
@ -493,7 +491,7 @@ class ClusterTest(base.SenlinTestCase):
self.assertEqual(exception.ClusterNotFound, ex.exc_info[0]) self.assertEqual(exception.ClusterNotFound, ex.exc_info[0])
@mock.patch.object(dispatcher, 'notify') @mock.patch.object(dispatcher, 'start_action')
def test_cluster_update_cluster_bad_status(self, notify): def test_cluster_update_cluster_bad_status(self, notify):
c = self.eng.cluster_create(self.ctx, 'c-1', 0, self.profile['id']) c = self.eng.cluster_create(self.ctx, 'c-1', 0, self.profile['id'])
cluster = cluster_mod.Cluster.load(self.ctx, c['id']) cluster = cluster_mod.Cluster.load(self.ctx, c['id'])
@ -505,7 +503,7 @@ class ClusterTest(base.SenlinTestCase):
self.assertEqual(exception.ClusterNotFound, ex.exc_info[0]) self.assertEqual(exception.ClusterNotFound, ex.exc_info[0])
@mock.patch.object(dispatcher, 'notify') @mock.patch.object(dispatcher, 'start_action')
def test_cluster_update_parent_not_found(self, notify): def test_cluster_update_parent_not_found(self, notify):
c = self.eng.cluster_create(self.ctx, 'c-1', 0, self.profile['id']) c = self.eng.cluster_create(self.ctx, 'c-1', 0, self.profile['id'])
@ -515,7 +513,7 @@ class ClusterTest(base.SenlinTestCase):
self.assertEqual(exception.ClusterNotFound, ex.exc_info[0]) self.assertEqual(exception.ClusterNotFound, ex.exc_info[0])
@mock.patch.object(dispatcher, 'notify') @mock.patch.object(dispatcher, 'start_action')
def test_cluster_update_timeout_not_integer(self, notify): def test_cluster_update_timeout_not_integer(self, notify):
c = self.eng.cluster_create(self.ctx, 'c-1', 0, self.profile['id']) c = self.eng.cluster_create(self.ctx, 'c-1', 0, self.profile['id'])
@ -525,7 +523,7 @@ class ClusterTest(base.SenlinTestCase):
self.assertEqual(exception.InvalidParameter, ex.exc_info[0]) self.assertEqual(exception.InvalidParameter, ex.exc_info[0])
@mock.patch.object(dispatcher, 'notify') @mock.patch.object(dispatcher, 'start_action')
def test_cluster_update_cluster_status_error(self, notify): def test_cluster_update_cluster_status_error(self, notify):
c = self.eng.cluster_create(self.ctx, 'c-1', 0, self.profile['id']) c = self.eng.cluster_create(self.ctx, 'c-1', 0, self.profile['id'])
cluster = cluster_mod.Cluster.load(self.ctx, c['id']) cluster = cluster_mod.Cluster.load(self.ctx, c['id'])
@ -537,7 +535,7 @@ class ClusterTest(base.SenlinTestCase):
self.assertEqual(exception.NotSupported, ex.exc_info[0]) self.assertEqual(exception.NotSupported, ex.exc_info[0])
@mock.patch.object(dispatcher, 'notify') @mock.patch.object(dispatcher, 'start_action')
def test_cluster_update_update_to_same_profile(self, notify): def test_cluster_update_update_to_same_profile(self, notify):
c = self.eng.cluster_create(self.ctx, 'c-1', 0, self.profile['id']) c = self.eng.cluster_create(self.ctx, 'c-1', 0, self.profile['id'])
self.eng.cluster_update(self.ctx, c['id'], self.eng.cluster_update(self.ctx, c['id'],
@ -550,7 +548,7 @@ class ClusterTest(base.SenlinTestCase):
# was not causing any new action to be dispatched # was not causing any new action to be dispatched
notify.assert_called_once() notify.assert_called_once()
@mock.patch.object(dispatcher, 'notify') @mock.patch.object(dispatcher, 'start_action')
def test_cluster_update_update_to_diff_profile_type(self, notify): def test_cluster_update_update_to_diff_profile_type(self, notify):
# Register a different profile # Register a different profile
env = environment.global_env() env = environment.global_env()
@ -566,7 +564,7 @@ class ClusterTest(base.SenlinTestCase):
self.assertEqual(exception.ProfileTypeNotMatch, ex.exc_info[0]) self.assertEqual(exception.ProfileTypeNotMatch, ex.exc_info[0])
@mock.patch.object(dispatcher, 'notify') @mock.patch.object(dispatcher, 'start_action')
def test_cluster_update_profile_not_found(self, notify): def test_cluster_update_profile_not_found(self, notify):
c = self.eng.cluster_create(self.ctx, 'c-1', 0, self.profile['id']) c = self.eng.cluster_create(self.ctx, 'c-1', 0, self.profile['id'])
ex = self.assertRaises(rpc.ExpectedException, ex = self.assertRaises(rpc.ExpectedException,
@ -575,7 +573,7 @@ class ClusterTest(base.SenlinTestCase):
self.assertEqual(exception.ProfileNotFound, ex.exc_info[0]) self.assertEqual(exception.ProfileNotFound, ex.exc_info[0])
@mock.patch.object(dispatcher, 'notify') @mock.patch.object(dispatcher, 'start_action')
def test_cluster_update_profile_normal(self, notify): def test_cluster_update_profile_normal(self, notify):
new_profile = self.eng.profile_create( new_profile = self.eng.profile_create(
self.ctx, 'p-new', 'TestProfile', self.ctx, 'p-new', 'TestProfile',
@ -594,11 +592,9 @@ class ClusterTest(base.SenlinTestCase):
# result['id'], # result['id'],
# cause=action_mod.CAUSE_RPC) # cause=action_mod.CAUSE_RPC)
# notify.assert_called_once_with(self.ctx, # notify.assert_called_once_with(self.ctx, action_id=action_id)
# self.eng.dispatcher.NEW_ACTION,
# None, action_id=action_id)
@mock.patch.object(dispatcher, 'notify') @mock.patch.object(dispatcher, 'start_action')
def test_cluster_delete(self, notify): def test_cluster_delete(self, notify):
c = self.eng.cluster_create(self.ctx, 'c-1', 0, self.profile['id']) c = self.eng.cluster_create(self.ctx, 'c-1', 0, self.profile['id'])
cid = c['id'] cid = c['id']
@ -614,9 +610,7 @@ class ClusterTest(base.SenlinTestCase):
c['id'], c['id'],
cause=action_mod.CAUSE_RPC) cause=action_mod.CAUSE_RPC)
expected_call = mock.call(self.ctx, expected_call = mock.call(self.ctx, action_id=mock.ANY)
self.eng.dispatcher.NEW_ACTION,
None, action_id=mock.ANY)
# two calls: one for create, the other for delete # two calls: one for create, the other for delete
notify.assert_has_calls([expected_call] * 2) notify.assert_has_calls([expected_call] * 2)
@ -654,7 +648,7 @@ class ClusterTest(base.SenlinTestCase):
nodes.append(six.text_type(db_node.id)) nodes.append(six.text_type(db_node.id))
return nodes return nodes
@mock.patch.object(dispatcher, 'notify') @mock.patch.object(dispatcher, 'start_action')
def test_cluster_add_nodes(self, notify): def test_cluster_add_nodes(self, notify):
c = self.eng.cluster_create(self.ctx, 'c-1', 0, self.profile['id']) c = self.eng.cluster_create(self.ctx, 'c-1', 0, self.profile['id'])
cid = c['id'] cid = c['id']
@ -670,9 +664,7 @@ class ClusterTest(base.SenlinTestCase):
cid, cause=action_mod.CAUSE_RPC, cid, cause=action_mod.CAUSE_RPC,
inputs={'nodes': nodes}) inputs={'nodes': nodes})
expected_call = mock.call(self.ctx, expected_call = mock.call(self.ctx, action_id=mock.ANY)
self.eng.dispatcher.NEW_ACTION,
None, action_id=mock.ANY)
# two calls: one for create, the other for adding nodes # two calls: one for create, the other for adding nodes
notify.assert_has_calls([expected_call] * 2) notify.assert_has_calls([expected_call] * 2)
@ -686,7 +678,7 @@ class ClusterTest(base.SenlinTestCase):
self.assertEqual('The cluster (Bogus) could not be found.', self.assertEqual('The cluster (Bogus) could not be found.',
six.text_type(ex.exc_info[1])) six.text_type(ex.exc_info[1]))
@mock.patch.object(dispatcher, 'notify') @mock.patch.object(dispatcher, 'start_action')
def test_cluster_add_nodes_empty_list(self, notify): def test_cluster_add_nodes_empty_list(self, notify):
c = self.eng.cluster_create(self.ctx, 'c-1', 0, self.profile['id']) c = self.eng.cluster_create(self.ctx, 'c-1', 0, self.profile['id'])
cid = c['id'] cid = c['id']
@ -699,7 +691,7 @@ class ClusterTest(base.SenlinTestCase):
self.assertEqual('The request is malformed: No nodes to add: []', self.assertEqual('The request is malformed: No nodes to add: []',
six.text_type(ex.exc_info[1])) six.text_type(ex.exc_info[1]))
@mock.patch.object(dispatcher, 'notify') @mock.patch.object(dispatcher, 'start_action')
def test_cluster_add_nodes_node_not_found(self, notify): def test_cluster_add_nodes_node_not_found(self, notify):
c = self.eng.cluster_create(self.ctx, 'c-1', 0, self.profile['id']) c = self.eng.cluster_create(self.ctx, 'c-1', 0, self.profile['id'])
cid = c['id'] cid = c['id']
@ -712,7 +704,7 @@ class ClusterTest(base.SenlinTestCase):
self.assertEqual("The request is malformed: Nodes not found: " self.assertEqual("The request is malformed: Nodes not found: "
"['Bogus']", six.text_type(ex.exc_info[1])) "['Bogus']", six.text_type(ex.exc_info[1]))
@mock.patch.object(dispatcher, 'notify') @mock.patch.object(dispatcher, 'start_action')
def test_cluster_add_nodes_node_not_active(self, notify): def test_cluster_add_nodes_node_not_active(self, notify):
c = self.eng.cluster_create(self.ctx, 'c-1', 0, self.profile['id']) c = self.eng.cluster_create(self.ctx, 'c-1', 0, self.profile['id'])
cid = c['id'] cid = c['id']
@ -726,7 +718,7 @@ class ClusterTest(base.SenlinTestCase):
self.assertEqual(_("The request is malformed: %(msg)s") % {'msg': msg}, self.assertEqual(_("The request is malformed: %(msg)s") % {'msg': msg},
six.text_type(ex.exc_info[1])) six.text_type(ex.exc_info[1]))
@mock.patch.object(dispatcher, 'notify') @mock.patch.object(dispatcher, 'start_action')
def test_cluster_add_nodes_node_already_owned(self, notify): def test_cluster_add_nodes_node_already_owned(self, notify):
c1 = self.eng.cluster_create(self.ctx, 'c-1', 0, self.profile['id']) c1 = self.eng.cluster_create(self.ctx, 'c-1', 0, self.profile['id'])
cid1 = c1['id'] cid1 = c1['id']
@ -757,7 +749,7 @@ class ClusterTest(base.SenlinTestCase):
self.assertEqual(_("The request is malformed: %(msg)s") % {'msg': msg}, self.assertEqual(_("The request is malformed: %(msg)s") % {'msg': msg},
six.text_type(ex.exc_info[1])) six.text_type(ex.exc_info[1]))
@mock.patch.object(dispatcher, 'notify') @mock.patch.object(dispatcher, 'start_action')
def test_cluster_del_nodes(self, notify): def test_cluster_del_nodes(self, notify):
c = self.eng.cluster_create(self.ctx, 'c-1', 0, self.profile['id']) c = self.eng.cluster_create(self.ctx, 'c-1', 0, self.profile['id'])
cid = c['id'] cid = c['id']
@ -773,9 +765,7 @@ class ClusterTest(base.SenlinTestCase):
cid, cause=action_mod.CAUSE_RPC, cid, cause=action_mod.CAUSE_RPC,
inputs={'nodes': nodes}) inputs={'nodes': nodes})
expected_call = mock.call(self.ctx, expected_call = mock.call(self.ctx, action_id=mock.ANY)
self.eng.dispatcher.NEW_ACTION,
None, action_id=mock.ANY)
# two calls: one for create, the other for adding nodes # two calls: one for create, the other for adding nodes
notify.assert_has_calls([expected_call] * 2) notify.assert_has_calls([expected_call] * 2)
@ -789,7 +779,7 @@ class ClusterTest(base.SenlinTestCase):
self.assertEqual('The cluster (Bogus) could not be found.', self.assertEqual('The cluster (Bogus) could not be found.',
six.text_type(ex.exc_info[1])) six.text_type(ex.exc_info[1]))
@mock.patch.object(dispatcher, 'notify') @mock.patch.object(dispatcher, 'start_action')
def test_cluster_del_nodes_empty_list(self, notify): def test_cluster_del_nodes_empty_list(self, notify):
c = self.eng.cluster_create(self.ctx, 'c-1', 0, self.profile['id']) c = self.eng.cluster_create(self.ctx, 'c-1', 0, self.profile['id'])
cid = c['id'] cid = c['id']
@ -802,7 +792,7 @@ class ClusterTest(base.SenlinTestCase):
self.assertEqual('The request is malformed: No nodes specified.', self.assertEqual('The request is malformed: No nodes specified.',
six.text_type(ex.exc_info[1])) six.text_type(ex.exc_info[1]))
@mock.patch.object(dispatcher, 'notify') @mock.patch.object(dispatcher, 'start_action')
def test_cluster_del_nodes_node_not_found(self, notify): def test_cluster_del_nodes_node_not_found(self, notify):
c = self.eng.cluster_create(self.ctx, 'c-1', 0, self.profile['id']) c = self.eng.cluster_create(self.ctx, 'c-1', 0, self.profile['id'])
cid = c['id'] cid = c['id']
@ -815,7 +805,7 @@ class ClusterTest(base.SenlinTestCase):
self.assertEqual("The request is malformed: Nodes not found: " self.assertEqual("The request is malformed: Nodes not found: "
"['Bogus']", six.text_type(ex.exc_info[1])) "['Bogus']", six.text_type(ex.exc_info[1]))
@mock.patch.object(dispatcher, 'notify') @mock.patch.object(dispatcher, 'start_action')
def test_cluster_del_nodes_node_in_other_cluster(self, notify): def test_cluster_del_nodes_node_in_other_cluster(self, notify):
c = self.eng.cluster_create(self.ctx, 'c-1', 0, self.profile['id']) c = self.eng.cluster_create(self.ctx, 'c-1', 0, self.profile['id'])
c2 = self.eng.cluster_create(self.ctx, 'c-2', 0, self.profile['id']) c2 = self.eng.cluster_create(self.ctx, 'c-2', 0, self.profile['id'])
@ -831,7 +821,7 @@ class ClusterTest(base.SenlinTestCase):
"specified cluster: %s" % nodes, "specified cluster: %s" % nodes,
six.text_type(ex.exc_info[1])) six.text_type(ex.exc_info[1]))
@mock.patch.object(dispatcher, 'notify') @mock.patch.object(dispatcher, 'start_action')
def test_cluster_del_nodes_orphan_nodes(self, notify): def test_cluster_del_nodes_orphan_nodes(self, notify):
c = self.eng.cluster_create(self.ctx, 'c-1', 0, self.profile['id']) c = self.eng.cluster_create(self.ctx, 'c-1', 0, self.profile['id'])
cid = c['id'] cid = c['id']
@ -847,7 +837,7 @@ class ClusterTest(base.SenlinTestCase):
"specified cluster: %s" % nodes, "specified cluster: %s" % nodes,
six.text_type(ex.exc_info[1])) six.text_type(ex.exc_info[1]))
@mock.patch.object(dispatcher, 'notify') @mock.patch.object(dispatcher, 'start_action')
def test_cluster_scale_out(self, notify): def test_cluster_scale_out(self, notify):
c = self.eng.cluster_create(self.ctx, 'c-1', 0, self.profile['id']) c = self.eng.cluster_create(self.ctx, 'c-1', 0, self.profile['id'])
cid = c['id'] cid = c['id']
@ -862,14 +852,12 @@ class ClusterTest(base.SenlinTestCase):
cid, cause=action_mod.CAUSE_RPC, cid, cause=action_mod.CAUSE_RPC,
inputs={'count': 1}) inputs={'count': 1})
expected_call = mock.call(self.ctx, expected_call = mock.call(self.ctx, action_id=mock.ANY)
self.eng.dispatcher.NEW_ACTION,
None, action_id=mock.ANY)
# two calls: one for create, the other for scaling operation # two calls: one for create, the other for scaling operation
notify.assert_has_calls([expected_call] * 2) notify.assert_has_calls([expected_call] * 2)
@mock.patch.object(dispatcher, 'notify') @mock.patch.object(dispatcher, 'start_action')
def test_cluster_scale_out_cluster_not_found(self, notify): def test_cluster_scale_out_cluster_not_found(self, notify):
ex = self.assertRaises(rpc.ExpectedException, ex = self.assertRaises(rpc.ExpectedException,
self.eng.cluster_scale_out, self.eng.cluster_scale_out,
@ -879,7 +867,7 @@ class ClusterTest(base.SenlinTestCase):
self.assertEqual('The cluster (Bogus) could not be found.', self.assertEqual('The cluster (Bogus) could not be found.',
six.text_type(ex.exc_info[1])) six.text_type(ex.exc_info[1]))
@mock.patch.object(dispatcher, 'notify') @mock.patch.object(dispatcher, 'start_action')
def test_cluster_scale_out_count_is_none(self, notify): def test_cluster_scale_out_count_is_none(self, notify):
c = self.eng.cluster_create(self.ctx, 'c-1', 0, self.profile['id']) c = self.eng.cluster_create(self.ctx, 'c-1', 0, self.profile['id'])
cid = c['id'] cid = c['id']
@ -894,14 +882,12 @@ class ClusterTest(base.SenlinTestCase):
cid, cause=action_mod.CAUSE_RPC, cid, cause=action_mod.CAUSE_RPC,
inputs={}) inputs={})
expected_call = mock.call(self.ctx, expected_call = mock.call(self.ctx, action_id=mock.ANY)
self.eng.dispatcher.NEW_ACTION,
None, action_id=mock.ANY)
# two calls: one for create, the other for scaling operation # two calls: one for create, the other for scaling operation
notify.assert_has_calls([expected_call] * 2) notify.assert_has_calls([expected_call] * 2)
@mock.patch.object(dispatcher, 'notify') @mock.patch.object(dispatcher, 'start_action')
def test_cluster_scale_out_count_not_int_or_zero(self, notify): def test_cluster_scale_out_count_not_int_or_zero(self, notify):
c = self.eng.cluster_create(self.ctx, 'c-1', 0, self.profile['id']) c = self.eng.cluster_create(self.ctx, 'c-1', 0, self.profile['id'])
cid = c['id'] cid = c['id']
@ -922,7 +908,7 @@ class ClusterTest(base.SenlinTestCase):
self.assertEqual("Invalid value '0' specified for 'count'", self.assertEqual("Invalid value '0' specified for 'count'",
six.text_type(ex.exc_info[1])) six.text_type(ex.exc_info[1]))
@mock.patch.object(dispatcher, 'notify') @mock.patch.object(dispatcher, 'start_action')
def test_cluster_scale_in(self, notify): def test_cluster_scale_in(self, notify):
c = self.eng.cluster_create(self.ctx, 'c-1', 2, self.profile['id']) c = self.eng.cluster_create(self.ctx, 'c-1', 2, self.profile['id'])
cid = c['id'] cid = c['id']
@ -937,14 +923,12 @@ class ClusterTest(base.SenlinTestCase):
cid, cause=action_mod.CAUSE_RPC, cid, cause=action_mod.CAUSE_RPC,
inputs={'count': 1}) inputs={'count': 1})
expected_call = mock.call(self.ctx, expected_call = mock.call(self.ctx, action_id=mock.ANY)
self.eng.dispatcher.NEW_ACTION,
None, action_id=mock.ANY)
# two calls: one for create, the other for scaling operation # two calls: one for create, the other for scaling operation
notify.assert_has_calls([expected_call] * 2) notify.assert_has_calls([expected_call] * 2)
@mock.patch.object(dispatcher, 'notify') @mock.patch.object(dispatcher, 'start_action')
def test_cluster_scale_in_cluster_not_found(self, notify): def test_cluster_scale_in_cluster_not_found(self, notify):
ex = self.assertRaises(rpc.ExpectedException, ex = self.assertRaises(rpc.ExpectedException,
self.eng.cluster_scale_in, self.eng.cluster_scale_in,
@ -954,7 +938,7 @@ class ClusterTest(base.SenlinTestCase):
self.assertEqual('The cluster (Bogus) could not be found.', self.assertEqual('The cluster (Bogus) could not be found.',
six.text_type(ex.exc_info[1])) six.text_type(ex.exc_info[1]))
@mock.patch.object(dispatcher, 'notify') @mock.patch.object(dispatcher, 'start_action')
def test_cluster_scale_in_count_is_none(self, notify): def test_cluster_scale_in_count_is_none(self, notify):
c = self.eng.cluster_create(self.ctx, 'c-1', 2, self.profile['id']) c = self.eng.cluster_create(self.ctx, 'c-1', 2, self.profile['id'])
cid = c['id'] cid = c['id']
@ -969,14 +953,12 @@ class ClusterTest(base.SenlinTestCase):
cid, cause=action_mod.CAUSE_RPC, cid, cause=action_mod.CAUSE_RPC,
inputs={}) inputs={})
expected_call = mock.call(self.ctx, expected_call = mock.call(self.ctx, action_id=mock.ANY)
self.eng.dispatcher.NEW_ACTION,
None, action_id=mock.ANY)
# two calls: one for create, the other for scaling operation # two calls: one for create, the other for scaling operation
notify.assert_has_calls([expected_call] * 2) notify.assert_has_calls([expected_call] * 2)
@mock.patch.object(dispatcher, 'notify') @mock.patch.object(dispatcher, 'start_action')
def test_cluster_scale_in_count_not_int_or_zero(self, notify): def test_cluster_scale_in_count_not_int_or_zero(self, notify):
c = self.eng.cluster_create(self.ctx, 'c-1', 2, self.profile['id']) c = self.eng.cluster_create(self.ctx, 'c-1', 2, self.profile['id'])
cid = c['id'] cid = c['id']

View File

@ -51,7 +51,7 @@ class NodeTest(base.SenlinTestCase):
self.assertEqual(cause, obj['cause']) self.assertEqual(cause, obj['cause'])
self.assertEqual(inputs, obj['inputs']) self.assertEqual(inputs, obj['inputs'])
@mock.patch.object(dispatcher, 'notify') @mock.patch.object(dispatcher, 'start_action')
def test_node_create_default(self, notify): def test_node_create_default(self, notify):
node = self.eng.node_create(self.ctx, 'n-1', self.profile['id']) node = self.eng.node_create(self.ctx, 'n-1', self.profile['id'])
self.assertIsNotNone(node) self.assertIsNotNone(node)
@ -69,9 +69,7 @@ class NodeTest(base.SenlinTestCase):
'node_create_%s' % node['id'][:8], 'node_create_%s' % node['id'][:8],
node['id'], node['id'],
cause=action_mod.CAUSE_RPC) cause=action_mod.CAUSE_RPC)
notify.assert_called_once_with(self.ctx, notify.assert_called_once_with(self.ctx, action_id=action_id)
self.eng.dispatcher.NEW_ACTION,
None, action_id=action_id)
def test_node_create_profile_not_found(self): def test_node_create_profile_not_found(self):
ex = self.assertRaises(rpc.ExpectedException, ex = self.assertRaises(rpc.ExpectedException,
@ -79,7 +77,7 @@ class NodeTest(base.SenlinTestCase):
self.ctx, 'n-1', 'Bogus') self.ctx, 'n-1', 'Bogus')
self.assertEqual(exception.ProfileNotFound, ex.exc_info[0]) self.assertEqual(exception.ProfileNotFound, ex.exc_info[0])
@mock.patch.object(dispatcher, 'notify') @mock.patch.object(dispatcher, 'start_action')
def test_node_create_with_role_and_metadata(self, notify): def test_node_create_with_role_and_metadata(self, notify):
node = self.eng.node_create(self.ctx, 'n-1', self.profile['id'], node = self.eng.node_create(self.ctx, 'n-1', self.profile['id'],
role='master', metadata={'k': 'v'}) role='master', metadata={'k': 'v'})
@ -89,7 +87,7 @@ class NodeTest(base.SenlinTestCase):
self.assertEqual('master', node['role']) self.assertEqual('master', node['role'])
self.assertEqual({'k': 'v'}, node['metadata']) self.assertEqual({'k': 'v'}, node['metadata'])
@mock.patch.object(dispatcher, 'notify') @mock.patch.object(dispatcher, 'start_action')
def test_node_create_with_profile_name_or_short_id(self, notify): def test_node_create_with_profile_name_or_short_id(self, notify):
node = self.eng.node_create(self.ctx, 'n-1', self.profile['id'][:8]) node = self.eng.node_create(self.ctx, 'n-1', self.profile['id'][:8])
self.assertIsNotNone(node) self.assertIsNotNone(node)
@ -109,7 +107,7 @@ class NodeTest(base.SenlinTestCase):
self.assertEqual("The cluster (Bogus) could not be found.", self.assertEqual("The cluster (Bogus) could not be found.",
six.text_type(ex.exc_info[1])) six.text_type(ex.exc_info[1]))
@mock.patch.object(dispatcher, 'notify') @mock.patch.object(dispatcher, 'start_action')
def test_node_create_project_not_match(self, notify): def test_node_create_project_not_match(self, notify):
ctx_cluster = utils.dummy_context(project='a-different-project') ctx_cluster = utils.dummy_context(project='a-different-project')
cluster = self.eng.cluster_create(ctx_cluster, 'c-1', 0, cluster = self.eng.cluster_create(ctx_cluster, 'c-1', 0,
@ -125,7 +123,7 @@ class NodeTest(base.SenlinTestCase):
"" % cluster['id'], "" % cluster['id'],
six.text_type(ex.exc_info[1])) six.text_type(ex.exc_info[1]))
@mock.patch.object(dispatcher, 'notify') @mock.patch.object(dispatcher, 'start_action')
def test_node_create_profile_type_not_match(self, notify): def test_node_create_profile_type_not_match(self, notify):
env = environment.global_env() env = environment.global_env()
env.register_profile('SecondProfile', fakes.TestProfile) env.register_profile('SecondProfile', fakes.TestProfile)
@ -146,7 +144,7 @@ class NodeTest(base.SenlinTestCase):
"operation aborted.", "operation aborted.",
six.text_type(ex.exc_info[1])) six.text_type(ex.exc_info[1]))
@mock.patch.object(dispatcher, 'notify') @mock.patch.object(dispatcher, 'start_action')
def test_node_get(self, notify): def test_node_get(self, notify):
node = self.eng.node_create(self.ctx, 'n-1', self.profile['id']) node = self.eng.node_create(self.ctx, 'n-1', self.profile['id'])
@ -159,7 +157,7 @@ class NodeTest(base.SenlinTestCase):
self.eng.node_get, self.ctx, 'Bogus') self.eng.node_get, self.ctx, 'Bogus')
self.assertEqual(exception.NodeNotFound, ex.exc_info[0]) self.assertEqual(exception.NodeNotFound, ex.exc_info[0])
@mock.patch.object(dispatcher, 'notify') @mock.patch.object(dispatcher, 'start_action')
def test_node_list(self, notify): def test_node_list(self, notify):
node1 = self.eng.node_create(self.ctx, 'n1', self.profile['id']) node1 = self.eng.node_create(self.ctx, 'n1', self.profile['id'])
node2 = self.eng.node_create(self.ctx, 'n2', self.profile['id']) node2 = self.eng.node_create(self.ctx, 'n2', self.profile['id'])
@ -173,7 +171,7 @@ class NodeTest(base.SenlinTestCase):
self.assertEqual(node1['id'], ids[0]) self.assertEqual(node1['id'], ids[0])
self.assertEqual(node2['id'], ids[1]) self.assertEqual(node2['id'], ids[1])
@mock.patch.object(dispatcher, 'notify') @mock.patch.object(dispatcher, 'start_action')
def test_node_list_with_limit_marker(self, notify): def test_node_list_with_limit_marker(self, notify):
node1 = self.eng.node_create(self.ctx, 'n1', self.profile['id']) node1 = self.eng.node_create(self.ctx, 'n1', self.profile['id'])
node2 = self.eng.node_create(self.ctx, 'n2', self.profile['id']) node2 = self.eng.node_create(self.ctx, 'n2', self.profile['id'])
@ -199,7 +197,7 @@ class NodeTest(base.SenlinTestCase):
result = self.eng.node_list(self.ctx, limit=2, marker=node1['id']) result = self.eng.node_list(self.ctx, limit=2, marker=node1['id'])
self.assertEqual(2, len(result)) self.assertEqual(2, len(result))
@mock.patch.object(dispatcher, 'notify') @mock.patch.object(dispatcher, 'start_action')
def test_node_list_with_sort_keys(self, notify): def test_node_list_with_sort_keys(self, notify):
node1 = self.eng.node_create(self.ctx, 'CC', self.profile['id']) node1 = self.eng.node_create(self.ctx, 'CC', self.profile['id'])
node2 = self.eng.node_create(self.ctx, 'BB', self.profile['id']) node2 = self.eng.node_create(self.ctx, 'BB', self.profile['id'])
@ -218,7 +216,7 @@ class NodeTest(base.SenlinTestCase):
result = self.eng.node_list(self.ctx, sort_keys=['duang']) result = self.eng.node_list(self.ctx, sort_keys=['duang'])
self.assertIsNotNone(result) self.assertIsNotNone(result)
@mock.patch.object(dispatcher, 'notify') @mock.patch.object(dispatcher, 'start_action')
def test_node_list_with_sort_dir(self, notify): def test_node_list_with_sort_dir(self, notify):
node1 = self.eng.node_create(self.ctx, 'BB', self.profile['id']) node1 = self.eng.node_create(self.ctx, 'BB', self.profile['id'])
node2 = self.eng.node_create(self.ctx, 'AA', self.profile['id']) node2 = self.eng.node_create(self.ctx, 'AA', self.profile['id'])
@ -247,7 +245,7 @@ class NodeTest(base.SenlinTestCase):
self.assertEqual("Unknown sort direction, must be " self.assertEqual("Unknown sort direction, must be "
"'desc' or 'asc'", six.text_type(ex)) "'desc' or 'asc'", six.text_type(ex))
@mock.patch.object(dispatcher, 'notify') @mock.patch.object(dispatcher, 'start_action')
def test_node_list_show_deleted(self, notify): def test_node_list_show_deleted(self, notify):
node = self.eng.node_create(self.ctx, 'n1', self.profile['id']) node = self.eng.node_create(self.ctx, 'n1', self.profile['id'])
result = self.eng.node_list(self.ctx) result = self.eng.node_list(self.ctx)
@ -263,7 +261,7 @@ class NodeTest(base.SenlinTestCase):
self.assertEqual(1, len(result)) self.assertEqual(1, len(result))
self.assertEqual(node['id'], result[0]['id']) self.assertEqual(node['id'], result[0]['id'])
@mock.patch.object(dispatcher, 'notify') @mock.patch.object(dispatcher, 'start_action')
def test_node_list_project_safe(self, notify): def test_node_list_project_safe(self, notify):
node1 = self.eng.node_create(self.ctx, 'n1', self.profile['id']) node1 = self.eng.node_create(self.ctx, 'n1', self.profile['id'])
new_ctx = utils.dummy_context(project='a_diff_project') new_ctx = utils.dummy_context(project='a_diff_project')
@ -287,7 +285,7 @@ class NodeTest(base.SenlinTestCase):
self.assertEqual(node1['id'], result[0]['id']) self.assertEqual(node1['id'], result[0]['id'])
self.assertEqual(node2['id'], result[1]['id']) self.assertEqual(node2['id'], result[1]['id'])
@mock.patch.object(dispatcher, 'notify') @mock.patch.object(dispatcher, 'start_action')
def test_node_list_with_cluster_id(self, notify): def test_node_list_with_cluster_id(self, notify):
c = self.eng.cluster_create(self.ctx, 'c-1', 0, self.profile['id']) c = self.eng.cluster_create(self.ctx, 'c-1', 0, self.profile['id'])
node = self.eng.node_create(self.ctx, 'n1', self.profile['id'], node = self.eng.node_create(self.ctx, 'n1', self.profile['id'],
@ -305,7 +303,7 @@ class NodeTest(base.SenlinTestCase):
self.assertEqual('The cluster (Bogus) could not be found.', self.assertEqual('The cluster (Bogus) could not be found.',
six.text_type(ex.exc_info[1])) six.text_type(ex.exc_info[1]))
@mock.patch.object(dispatcher, 'notify') @mock.patch.object(dispatcher, 'start_action')
def test_node_list_with_filters(self, notify): def test_node_list_with_filters(self, notify):
self.eng.node_create(self.ctx, 'BB', self.profile['id']) self.eng.node_create(self.ctx, 'BB', self.profile['id'])
self.eng.node_create(self.ctx, 'AA', self.profile['id']) self.eng.node_create(self.ctx, 'AA', self.profile['id'])
@ -338,7 +336,7 @@ class NodeTest(base.SenlinTestCase):
self.assertIsInstance(result, list) self.assertIsInstance(result, list)
self.assertEqual(0, len(result)) self.assertEqual(0, len(result))
@mock.patch.object(dispatcher, 'notify') @mock.patch.object(dispatcher, 'start_action')
def test_node_find(self, notify): def test_node_find(self, notify):
node = self.eng.node_create(self.ctx, 'n1', self.profile['id']) node = self.eng.node_create(self.ctx, 'n1', self.profile['id'])
nodeid = node['id'] nodeid = node['id']
@ -358,7 +356,7 @@ class NodeTest(base.SenlinTestCase):
self.assertRaises(exception.NodeNotFound, self.assertRaises(exception.NodeNotFound,
self.eng.node_find, self.ctx, 'Bogus') self.eng.node_find, self.ctx, 'Bogus')
@mock.patch.object(dispatcher, 'notify') @mock.patch.object(dispatcher, 'start_action')
def test_node_find_show_deleted(self, notify): def test_node_find_show_deleted(self, notify):
node = self.eng.node_create(self.ctx, 'n1', self.profile['id']) node = self.eng.node_create(self.ctx, 'n1', self.profile['id'])
nodeid = node['id'] nodeid = node['id']
@ -377,7 +375,7 @@ class NodeTest(base.SenlinTestCase):
result = self.eng.node_find(self.ctx, nodeid, show_deleted=True) result = self.eng.node_find(self.ctx, nodeid, show_deleted=True)
self.assertIsNotNone(result) self.assertIsNotNone(result)
@mock.patch.object(dispatcher, 'notify') @mock.patch.object(dispatcher, 'start_action')
def test_node_update_simple(self, notify): def test_node_update_simple(self, notify):
node = self.eng.node_create(self.ctx, 'node-1', self.profile['id'], node = self.eng.node_create(self.ctx, 'node-1', self.profile['id'],
role='Master', metadata={'foo': 'bar'}) role='Master', metadata={'foo': 'bar'})
@ -409,7 +407,7 @@ class NodeTest(base.SenlinTestCase):
self.assertEqual('The node (Bogus) could not be found.', self.assertEqual('The node (Bogus) could not be found.',
six.text_type(ex.exc_info[1])) six.text_type(ex.exc_info[1]))
@mock.patch.object(dispatcher, 'notify') @mock.patch.object(dispatcher, 'start_action')
def test_node_update_with_new_profile(self, notify): def test_node_update_with_new_profile(self, notify):
node = self.eng.node_create(self.ctx, 'node-1', self.profile['id']) node = self.eng.node_create(self.ctx, 'node-1', self.profile['id'])
new_profile = self.eng.profile_create( new_profile = self.eng.profile_create(
@ -427,11 +425,9 @@ class NodeTest(base.SenlinTestCase):
# result['id'], # result['id'],
# cause=action_mod.CAUSE_RPC) # cause=action_mod.CAUSE_RPC)
# notify.assert_called_once_with(self.ctx, # notify.assert_called_once_with(self.ctx, action_id=action_id)
# self.eng.dispatcher.NEW_ACTION,
# None, action_id=action_id)
@mock.patch.object(dispatcher, 'notify') @mock.patch.object(dispatcher, 'start_action')
def test_node_update_profile_not_found(self, notify): def test_node_update_profile_not_found(self, notify):
node = self.eng.node_create(self.ctx, 'node-1', self.profile['id']) node = self.eng.node_create(self.ctx, 'node-1', self.profile['id'])
ex = self.assertRaises(rpc.ExpectedException, ex = self.assertRaises(rpc.ExpectedException,
@ -442,7 +438,7 @@ class NodeTest(base.SenlinTestCase):
self.assertEqual('The profile (Bogus) could not be found.', self.assertEqual('The profile (Bogus) could not be found.',
six.text_type(ex.exc_info[1])) six.text_type(ex.exc_info[1]))
@mock.patch.object(dispatcher, 'notify') @mock.patch.object(dispatcher, 'start_action')
def test_node_update_with_diff_profile_type(self, notify): def test_node_update_with_diff_profile_type(self, notify):
env = environment.global_env() env = environment.global_env()
env.register_profile('NewProfileType', fakes.TestProfile) env.register_profile('NewProfileType', fakes.TestProfile)
@ -461,7 +457,7 @@ class NodeTest(base.SenlinTestCase):
'operation aborted.', 'operation aborted.',
six.text_type(ex.exc_info[1])) six.text_type(ex.exc_info[1]))
@mock.patch.object(dispatcher, 'notify') @mock.patch.object(dispatcher, 'start_action')
def test_node_delete(self, notify): def test_node_delete(self, notify):
node = self.eng.node_create(self.ctx, 'node-1', self.profile['id']) node = self.eng.node_create(self.ctx, 'node-1', self.profile['id'])
nodeid = node['id'] nodeid = node['id']
@ -477,9 +473,7 @@ class NodeTest(base.SenlinTestCase):
node['id'], node['id'],
cause=action_mod.CAUSE_RPC) cause=action_mod.CAUSE_RPC)
expected_call = mock.call(self.ctx, expected_call = mock.call(self.ctx, action_id=mock.ANY)
self.eng.dispatcher.NEW_ACTION,
None, action_id=mock.ANY)
# two calls: one for create, the other for delete # two calls: one for create, the other for delete
notify.assert_has_calls([expected_call] * 2) notify.assert_has_calls([expected_call] * 2)
@ -492,7 +486,7 @@ class NodeTest(base.SenlinTestCase):
self.assertEqual('The node (Bogus) could not be found.', self.assertEqual('The node (Bogus) could not be found.',
six.text_type(ex.exc_info[1])) six.text_type(ex.exc_info[1]))
@mock.patch.object(dispatcher, 'notify') @mock.patch.object(dispatcher, 'start_action')
def test_node_join(self, notify): def test_node_join(self, notify):
c = self.eng.cluster_create(self.ctx, 'c-1', 0, self.profile['id']) c = self.eng.cluster_create(self.ctx, 'c-1', 0, self.profile['id'])
cluster_id = c['id'] cluster_id = c['id']
@ -509,13 +503,11 @@ class NodeTest(base.SenlinTestCase):
'node_join_%s' % node_id[:8], node_id, 'node_join_%s' % node_id[:8], node_id,
cause=action_mod.CAUSE_RPC, cause=action_mod.CAUSE_RPC,
inputs={'cluster_id': cluster_id}) inputs={'cluster_id': cluster_id})
notify.assert_called_with(self.ctx, notify.assert_called_with(self.ctx, action_id=action_id)
self.eng.dispatcher.NEW_ACTION,
None, action_id=action_id)
# Two creations plus one join # Two creations plus one join
self.assertEqual(3, notify.call_count) self.assertEqual(3, notify.call_count)
@mock.patch.object(dispatcher, 'notify') @mock.patch.object(dispatcher, 'start_action')
def test_node_join_from_other_cluster(self, notify): def test_node_join_from_other_cluster(self, notify):
c = self.eng.cluster_create(self.ctx, 'c-1', 0, self.profile['id']) c = self.eng.cluster_create(self.ctx, 'c-1', 0, self.profile['id'])
cluster_id = c['id'] cluster_id = c['id']
@ -535,8 +527,7 @@ class NodeTest(base.SenlinTestCase):
'node_join_%s' % node_id[:8], node_id, 'node_join_%s' % node_id[:8], node_id,
cause=action_mod.CAUSE_RPC, cause=action_mod.CAUSE_RPC,
inputs={'cluster_id': new_cluster_id}) inputs={'cluster_id': new_cluster_id})
notify.assert_called_with(self.ctx, self.eng.dispatcher.NEW_ACTION, notify.assert_called_with(self.ctx, action_id=mock.ANY)
mock.ANY, action_id=mock.ANY)
# Three creations plus one join # Three creations plus one join
self.assertEqual(4, notify.call_count) self.assertEqual(4, notify.call_count)
@ -549,7 +540,7 @@ class NodeTest(base.SenlinTestCase):
self.assertEqual('The node (BogusNode) could not be found.', self.assertEqual('The node (BogusNode) could not be found.',
six.text_type(ex.exc_info[1])) six.text_type(ex.exc_info[1]))
@mock.patch.object(dispatcher, 'notify') @mock.patch.object(dispatcher, 'start_action')
def test_node_join_cluster_not_found(self, notify): def test_node_join_cluster_not_found(self, notify):
node = self.eng.node_create(self.ctx, 'node1', self.profile['id']) node = self.eng.node_create(self.ctx, 'node1', self.profile['id'])
node_id = node['id'] node_id = node['id']
@ -562,7 +553,7 @@ class NodeTest(base.SenlinTestCase):
self.assertEqual('The cluster (BogusCluster) could not be found.', self.assertEqual('The cluster (BogusCluster) could not be found.',
six.text_type(ex.exc_info[1])) six.text_type(ex.exc_info[1]))
@mock.patch.object(dispatcher, 'notify') @mock.patch.object(dispatcher, 'start_action')
def test_node_join_profile_type_not_match(self, notify): def test_node_join_profile_type_not_match(self, notify):
# prepare a cluster with different profile type # prepare a cluster with different profile type
env = environment.global_env() env = environment.global_env()
@ -586,7 +577,7 @@ class NodeTest(base.SenlinTestCase):
'operation aborted.', 'operation aborted.',
six.text_type(ex.exc_info[1])) six.text_type(ex.exc_info[1]))
@mock.patch.object(dispatcher, 'notify') @mock.patch.object(dispatcher, 'start_action')
def test_node_leave(self, notify): def test_node_leave(self, notify):
c = self.eng.cluster_create(self.ctx, 'c-1', 0, self.profile['id']) c = self.eng.cluster_create(self.ctx, 'c-1', 0, self.profile['id'])
cluster_id = c['id'] cluster_id = c['id']
@ -602,9 +593,7 @@ class NodeTest(base.SenlinTestCase):
self._verify_action(action, 'NODE_LEAVE', self._verify_action(action, 'NODE_LEAVE',
'node_leave_%s' % node_id[:8], node_id, 'node_leave_%s' % node_id[:8], node_id,
cause=action_mod.CAUSE_RPC) cause=action_mod.CAUSE_RPC)
notify.assert_called_with(self.ctx, notify.assert_called_with(self.ctx, action_id=mock.ANY)
self.eng.dispatcher.NEW_ACTION,
None, action_id=mock.ANY)
# Two creations plus one leave # Two creations plus one leave
self.assertEqual(3, notify.call_count) self.assertEqual(3, notify.call_count)
@ -617,7 +606,7 @@ class NodeTest(base.SenlinTestCase):
self.assertEqual('The node (BogusNode) could not be found.', self.assertEqual('The node (BogusNode) could not be found.',
six.text_type(ex.exc_info[1])) six.text_type(ex.exc_info[1]))
@mock.patch.object(dispatcher, 'notify') @mock.patch.object(dispatcher, 'start_action')
def test_node_leave_already_orphan(self, notify): def test_node_leave_already_orphan(self, notify):
node = self.eng.node_create(self.ctx, 'node1', self.profile['id']) node = self.eng.node_create(self.ctx, 'node1', self.profile['id'])
node_id = node['id'] node_id = node['id']

View File

@ -51,7 +51,7 @@ class WebhookTest(base.SenlinTestCase):
self.assertEqual(cause, obj['cause']) self.assertEqual(cause, obj['cause'])
self.assertEqual(inputs, obj['inputs']) self.assertEqual(inputs, obj['inputs'])
@mock.patch.object(dispatcher, 'notify') @mock.patch.object(dispatcher, 'start_action')
def _create_cluster(self, name, notify): def _create_cluster(self, name, notify):
cluster = self.eng.cluster_create(self.ctx, name, 0, cluster = self.eng.cluster_create(self.ctx, name, 0,
self.profile['id']) self.profile['id'])
@ -422,7 +422,7 @@ class WebhookTest(base.SenlinTestCase):
self.assertEqual("Unknown sort direction, must be " self.assertEqual("Unknown sort direction, must be "
"'desc' or 'asc'", six.text_type(ex)) "'desc' or 'asc'", six.text_type(ex))
@mock.patch.object(dispatcher, 'notify') @mock.patch.object(dispatcher, 'start_action')
@mock.patch.object(service.EngineService, 'cluster_find') @mock.patch.object(service.EngineService, 'cluster_find')
def test_webhook_trigger(self, cluster_find, notify): def test_webhook_trigger(self, cluster_find, notify):
mock_call = self.patchobject(webhook_mod.Webhook, 'generate_url') mock_call = self.patchobject(webhook_mod.Webhook, 'generate_url')
@ -452,14 +452,9 @@ class WebhookTest(base.SenlinTestCase):
obj_id, cause=action_mod.CAUSE_RPC, obj_id, cause=action_mod.CAUSE_RPC,
inputs=params) inputs=params)
expected_call = mock.call(self.ctx, notify.assert_called_once_with(self.ctx, action_id=mock.ANY)
self.eng.dispatcher.NEW_ACTION,
None, action_id=mock.ANY)
# two calls: one for create, the other for scaling operation @mock.patch.object(dispatcher, 'start_action')
notify.assert_has_calls([expected_call] * 1)
@mock.patch.object(dispatcher, 'notify')
@mock.patch.object(service.EngineService, 'cluster_find') @mock.patch.object(service.EngineService, 'cluster_find')
def test_webhook_trigger_with_params(self, cluster_find, notify): def test_webhook_trigger_with_params(self, cluster_find, notify):
mock_call = self.patchobject(webhook_mod.Webhook, 'generate_url') mock_call = self.patchobject(webhook_mod.Webhook, 'generate_url')
@ -490,12 +485,7 @@ class WebhookTest(base.SenlinTestCase):
obj_id, cause=action_mod.CAUSE_RPC, obj_id, cause=action_mod.CAUSE_RPC,
inputs=params2) inputs=params2)
expected_call = mock.call(self.ctx, notify.assert_called_once_with(self.ctx, action_id=mock.ANY)
self.eng.dispatcher.NEW_ACTION,
None, action_id=mock.ANY)
# two calls: one for create, the other for scaling operation
notify.assert_has_calls([expected_call] * 1)
def test_webhook_delete(self): def test_webhook_delete(self):
mock_call = self.patchobject(webhook_mod.Webhook, 'generate_url') mock_call = self.patchobject(webhook_mod.Webhook, 'generate_url')