Refactor action create operation

This patch refactors the action-create operation to use the 'create'
method from the Action module.

Change-Id: I01e9e06bfc454132a6d5ab67449c574eb66bd6d7
This commit is contained in:
tengqm
2016-02-28 10:01:10 -05:00
parent 1d4bf396fe
commit dc1662deac
2 changed files with 17 additions and 18 deletions

View File

@@ -1792,21 +1792,19 @@ class EngineService(service.Service):
# Create an action instance
params = {
'name': name,
'cause': action_mod.CAUSE_RPC,
'status': action_mod.Action.READY,
'inputs': inputs or {},
'user': context.user,
'project': context.project,
'domain': context.domain,
}
act = action_mod.Action(target.id, action, **params)
act.status = act.READY
act.store(context)
action_id = action_mod.Action.create(context, target.id, action,
**params)
# TODO(Anyone): Uncomment this to notify the dispatcher
# dispatcher.start_action(action_id=action.id)
LOG.info(_LI("Action '%(name)s' is created: %(id)s."),
{'name': name, 'id': act.id})
return act.to_dict()
{'name': name, 'id': action_id})
return {'action': action_id}
@request_context
def action_get(self, context, identity):

View File

@@ -181,21 +181,22 @@ class ActionTest(base.SenlinTestCase):
sort=None, marker=None,
project_safe=False)
@mock.patch.object(action_base.Action, 'create')
@mock.patch.object(service.EngineService, 'cluster_find')
def test_action_create(self, mock_find):
x_cluster = mock.Mock()
x_cluster.id = 'FAKE_CLUSTER'
mock_find.return_value = x_cluster
def test_action_create(self, mock_find, mock_action):
mock_find.return_value = mock.Mock(id='FAKE_CLUSTER')
mock_action.return_value = 'ACTION_ID'
result = self.eng.action_create(self.ctx, 'a1', 'C1', 'OBJECT_ACTION')
self.assertIsInstance(result, dict)
self.assertIsNotNone(result['id'])
self.assertEqual('a1', result['name'])
self.assertEqual('FAKE_CLUSTER', result['target'])
self.assertEqual({}, result['inputs'])
self.assertEqual({'action': 'ACTION_ID'}, result)
mock_find.assert_called_once_with(self.ctx, 'C1')
mock_action.assert_called_once_with(
self.ctx, 'FAKE_CLUSTER', 'OBJECT_ACTION',
name='a1',
cause=action_base.CAUSE_RPC,
status=action_base.Action.READY,
inputs={})
@mock.patch.object(service.EngineService, 'cluster_find')
def test_action_create_cluster_not_found(self, mock_find):