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
This commit is contained in:
parent
aebd8e706b
commit
3234098624
@ -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
|
||||
|
@ -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()
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user