From 762fe935760aa0f6dc0f68f4ee3f901323f9cc72 Mon Sep 17 00:00:00 2001 From: LingxianKong Date: Fri, 10 Apr 2015 18:03:32 +0800 Subject: [PATCH] Apply input schema to workflow/action input * apply the schema introduced in previous patch(https://review.openstack.org/#/c/172438/). * add some unit tests accordingly. things need to be done in the subsequent patches: - consider the input default value when validating inputs of workflow/action. - add some unit tests for input default value. - add some samples in mistral-extra repository if needed. Partially Implements: blueprint mistral-default-input-values Change-Id: I9737dbffe0e6913d976990fbdc31086539b5956e --- mistral/tests/unit/workbook/v2/test_actions.py | 7 ++++++- mistral/tests/unit/workbook/v2/test_workflows.py | 7 ++++++- mistral/workbook/v2/actions.py | 2 +- mistral/workbook/v2/workflows.py | 2 +- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/mistral/tests/unit/workbook/v2/test_actions.py b/mistral/tests/unit/workbook/v2/test_actions.py index e9ff6d80..7af5292a 100644 --- a/mistral/tests/unit/workbook/v2/test_actions.py +++ b/mistral/tests/unit/workbook/v2/test_actions.py @@ -73,7 +73,12 @@ class ActionSpecValidation(base.WorkbookSpecValidationTestCase): ({'input': ['']}, True), ({'input': None}, True), ({'input': ['k1', 'k2']}, False), - ({'input': ['k1', 12345]}, True) + ({'input': ['k1', 12345]}, True), + ({'input': ['k1', {'k2': 2}]}, False), + ({'input': [{'k1': 1}, {'k2': 2}]}, False), + ({'input': [{'k1': None}]}, False), + ({'input': [{'k1': 1}, {'k1': 1}]}, True), + ({'input': [{'k1': 1, 'k2': 2}]}, True) ] actions = { diff --git a/mistral/tests/unit/workbook/v2/test_workflows.py b/mistral/tests/unit/workbook/v2/test_workflows.py index 05272345..47a9c916 100644 --- a/mistral/tests/unit/workbook/v2/test_workflows.py +++ b/mistral/tests/unit/workbook/v2/test_workflows.py @@ -132,7 +132,12 @@ class WorkflowSpecValidation(base.WorkflowSpecValidationTestCase): ({'input': [None]}, True), ({'input': ['']}, True), ({'input': None}, True), - ({'input': []}, True) + ({'input': []}, True), + ({'input': ['var1', {'var2': 2}]}, False), + ({'input': [{'var1': 1}, {'var2': 2}]}, False), + ({'input': [{'var1': None}]}, False), + ({'input': [{'var1': 1}, {'var1': 1}]}, True), + ({'input': [{'var1': 1, 'var2': 2}]}, True) ] for wf_input, expect_error in tests: diff --git a/mistral/workbook/v2/actions.py b/mistral/workbook/v2/actions.py index ab5aa8ea..44a1500e 100644 --- a/mistral/workbook/v2/actions.py +++ b/mistral/workbook/v2/actions.py @@ -25,7 +25,7 @@ class ActionSpec(base.BaseSpec): "properties": { "base": types.NONEMPTY_STRING, "base-input": types.NONEMPTY_DICT, - "input": types.UNIQUE_STRING_LIST, + "input": types.UNIQUE_STRING_OR_ONE_KEY_DICT_LIST, "output": types.ANY_NULLABLE, }, "required": ["base"], diff --git a/mistral/workbook/v2/workflows.py b/mistral/workbook/v2/workflows.py index 46560678..c5caead1 100644 --- a/mistral/workbook/v2/workflows.py +++ b/mistral/workbook/v2/workflows.py @@ -37,7 +37,7 @@ class WorkflowSpec(base.BaseSpec): "properties": { "type": types.WORKFLOW_TYPE, "task-defaults": _task_defaults_schema, - "input": types.UNIQUE_STRING_LIST, + "input": types.UNIQUE_STRING_OR_ONE_KEY_DICT_LIST, "output": types.NONEMPTY_DICT, "tasks": { "type": "object",