BP mistral-actions-design (raw action spec -> ActionSpec)

* Switched from raw action spec (dict) to using ActionSpec in
  ad-hoc actions

TODO:
* Fix all samples in mistral-extra
* Action plugin architecture

Change-Id: Id8da3642bcd9549bf2e64c07eb4d79fd856a01de
This commit is contained in:
Renat Akhmerov 2014-04-14 17:16:25 +07:00
parent 9970767a86
commit 11f236a785
3 changed files with 23 additions and 13 deletions

View File

@ -20,6 +20,7 @@ from mistral.actions import base
from mistral.actions import std_actions
from mistral import exceptions as exc
from mistral.workbook import tasks
from mistral.workbook import actions
from mistral.openstack.common import log as logging
LOG = logging.getLogger(__name__)
@ -98,17 +99,18 @@ def _create_adhoc_action(db_task):
full_action_name = task_spec.get_full_action_name()
# TODO(rakhmerov): Fix model attributes during refactoring.
# TODO(rakhmerov): ActionSpec should be used instead.
adhoc_action_spec = db_task['action_spec']
raw_action_spec = db_task['action_spec']
if not adhoc_action_spec:
if not raw_action_spec:
return None
action_spec = actions.ActionSpec(raw_action_spec)
LOG.info('Using ad-hoc action [action=%s, db_task=%s]' %
(full_action_name, db_task))
# Create an ad-hoc action.
base_cls = get_action_class(adhoc_action_spec['class'])
base_cls = get_action_class(action_spec.clazz)
action_context = None
if _has_action_context_param(base_cls):
@ -124,7 +126,7 @@ def _create_adhoc_action(db_task):
return std_actions.AdHocAction(action_context,
base_cls,
adhoc_action_spec,
action_spec,
**action_params)

View File

@ -201,8 +201,7 @@ class AdHocAction(base.Action):
self.base_action = base_action_cls(**base_params)
def _convert_params(self, params):
# TODO(rakhmerov): ActionSpec should be used instead of dict.
base_params_spec = self.action_spec.get('base-parameters')
base_params_spec = self.action_spec.base_parameters
if not base_params_spec:
return {}
@ -211,8 +210,7 @@ class AdHocAction(base.Action):
for k, v in base_params_spec.iteritems())
def _convert_result(self, result):
# TODO(rakhmerov): ActionSpec should be used instead of dict.
transformer = self.action_spec.get('output')
transformer = self.action_spec.output
if not transformer:
return result

View File

@ -14,11 +14,15 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import copy
from mistral.actions import std_actions as std
from mistral.tests import base
from mistral.workbook import namespaces as ns
NS_SPEC = {
'my_namespace': {
'name': 'my_namespace',
'actions': {
'my_action': {
'class': 'std.echo',
'base-parameters': {
@ -35,7 +39,9 @@ NS_SPEC = {
class AdHocActionTest(base.BaseTest):
def test_adhoc_echo_action(self):
action_spec = NS_SPEC['my_namespace']['my_action'].copy()
ns_raw_spec = copy.copy(NS_SPEC)
action_spec = ns.NamespaceSpec(ns_raw_spec).actions.get('my_action')
# With dic-like output formatter.
action = std.AdHocAction(None, std.EchoAction, action_spec,
@ -44,7 +50,9 @@ class AdHocActionTest(base.BaseTest):
self.assertDictEqual({'res': 'Tango and Cash'}, action.run())
# With list-like output formatter.
action_spec['output'] = ['$.base_output', '$.base_output']
ns_raw_spec['actions']['my_action']['output'] =\
['$.base_output', '$.base_output']
action_spec = ns.NamespaceSpec(ns_raw_spec).actions.get('my_action')
action = std.AdHocAction(None, std.EchoAction, action_spec,
first="Tango", second="Cash")
@ -53,7 +61,9 @@ class AdHocActionTest(base.BaseTest):
action.run())
# With single-object output formatter.
action_spec['output'] = "'{$.base_output}' is a cool movie!"
ns_raw_spec['actions']['my_action']['output'] =\
"'{$.base_output}' is a cool movie!"
action_spec = ns.NamespaceSpec(ns_raw_spec).actions.get('my_action')
action = std.AdHocAction(None, std.EchoAction, action_spec,
first="Tango", second="Cash")