From 32340986248db1654ce631ccc2bb413a6a31f594 Mon Sep 17 00:00:00 2001 From: hardik Date: Fri, 25 Sep 2015 05:47:20 +0530 Subject: [PATCH] Action definition updated, when workbook is created. While creating workbook, action definition was not saved to database. Due to which user was unable to see action definition Change-Id: I69cf129d17d8db735770fc6231062cd61b3d4156 Closes-Bug: #1504429 --- mistral/services/workbooks.py | 10 ++++++ .../unit/services/test_workbook_service.py | 9 +++++ mistral/workbook/parser.py | 36 ++++++++++++------- 3 files changed, 42 insertions(+), 13 deletions(-) diff --git a/mistral/services/workbooks.py b/mistral/services/workbooks.py index 7c07915f..a69e942d 100644 --- a/mistral/services/workbooks.py +++ b/mistral/services/workbooks.py @@ -69,6 +69,7 @@ def _create_or_update_actions(wb_db, actions_spec): 'name': action_name, 'spec': action_spec.to_dict(), 'tags': action_spec.get_tags(), + 'definition': _get_action_definition(wb_db, action_spec), 'description': action_spec.get_description(), 'is_system': False, 'input': ', '.join(input_list) if input_list else None, @@ -117,3 +118,12 @@ def _get_wf_definition(wb_db, wf_spec): ) return wf_definition + + +def _get_action_definition(wb_db, action_spec): + action_definition = spec_parser.get_action_definition( + wb_db.definition, + action_spec.get_name() + ) + + return action_definition diff --git a/mistral/tests/unit/services/test_workbook_service.py b/mistral/tests/unit/services/test_workbook_service.py index dce10cfa..e39e96af 100644 --- a/mistral/tests/unit/services/test_workbook_service.py +++ b/mistral/tests/unit/services/test_workbook_service.py @@ -96,6 +96,7 @@ WORKBOOK_WF2_DEFINITION = """wf2: result: "The result of subworkflow is '{$.final_result}'" """ + UPDATED_WORKBOOK = """ --- version: '2.0' @@ -162,6 +163,13 @@ UPDATED_WORKBOOK_WF2_DEFINITION = """wf2: """ +ACTION_DEFINITION = """concat: + base: std.echo + base-input: + output: "{$.str1}{$.str2}" +""" + + class WorkbookServiceTest(base.DbTestCase): def test_create_workbook(self): wb_db = wb_service.create_workbook_v2(WORKBOOK) @@ -185,6 +193,7 @@ class WorkbookServiceTest(base.DbTestCase): self.assertEqual('concat', action_spec.get_name()) self.assertEqual('std.echo', action_spec.get_base()) + self.assertEqual(ACTION_DEFINITION, action_db.definition) db_wfs = db_api.get_workflow_definitions() diff --git a/mistral/workbook/parser.py b/mistral/workbook/parser.py index c8b537f4..f7ad80d2 100644 --- a/mistral/workbook/parser.py +++ b/mistral/workbook/parser.py @@ -123,17 +123,27 @@ def get_task_spec(spec_dict): def get_workflow_definition(wb_def, wf_name): - wf_def = [] wf_name = wf_name + ":" - io = six.StringIO(wb_def[wb_def.index("workflows:"):]) - io.readline() - ident = 0 - # Get the indentation of the workflow name tag. (e.g. wf1:) + return _parse_def_from_wb(wb_def, "workflows:", wf_name) + + +def get_action_definition(wb_def, action_name): + action_name = action_name + ":" + + return _parse_def_from_wb(wb_def, "actions:", action_name) + + +def _parse_def_from_wb(wb_def, section_name, item_name): + io = six.StringIO(wb_def[wb_def.index(section_name):]) + io.readline() + definition = [] + ident = 0 + # Get the indentation of the action/workflow name tag. for line in io: - if wf_name == line.strip(): - ident = line.index(wf_name) - wf_def.append(line.lstrip()) + if item_name == line.strip(): + ident = line.index(item_name) + definition.append(line.lstrip()) break # Add strings to list unless same/less indentation is found. @@ -141,18 +151,18 @@ def get_workflow_definition(wb_def, wf_name): new_line = line.strip() if not new_line: - wf_def.append(line) + definition.append(line) elif new_line.startswith("#"): new_line = line if ident > line.index("#") else line[ident:] - wf_def.append(new_line) + definition.append(new_line) else: temp = line.index(line.lstrip()) if ident < temp: - wf_def.append(line[ident:]) + definition.append(line[ident:]) else: break io.close() - wf_def = ''.join(wf_def).rstrip() + '\n' + definition = ''.join(definition).rstrip() + '\n' - return wf_def + return definition