Skip to content
This repository has been archived by the owner on Apr 14, 2023. It is now read-only.

Commit

Permalink
Fixed bug on copy workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin Tervala authored and Justin Tervala committed Oct 30, 2017
1 parent ec99ff3 commit 1545c5d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
13 changes: 13 additions & 0 deletions core/executionelements/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,19 @@ def get_execution_uid(self):
"""
return self._execution_uid

def regenerate_uids(self):
start_step = deepcopy(self.steps.pop(self.start, None))
if start_step is not None:
start_step = deepcopy(start_step)
super(Workflow, self).regenerate_uids()
self.steps = {step.uid: step for step in self.steps.values()}
start_step.regenerate_uids()
self.start = start_step.uid
self.steps[self.start] = start_step
else:
super(Workflow, self).regenerate_uids()


def strip_async_result(self, with_deepcopy=False):
"""Removes the AsyncResult object from all of the Steps, necessary to deepcopy a Workflow
Expand Down
4 changes: 1 addition & 3 deletions core/playbookstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,8 @@ def copy_workflow(self, old_playbook_name, new_playbook_name, old_workflow_name,

workflow_copy = deepcopy(workflow)
workflow_copy.name = new_workflow_name
workflow_copy.reset_async_result()
workflow_copy.regenerate_uids()
workflow_copy.reset_async_result()

workflow.reload_async_result(steps)

Expand All @@ -317,8 +317,6 @@ def copy_playbook(self, old_playbook_name, new_playbook_name):
for workflow in self.playbooks[old_playbook_name].workflows.values():
self.copy_workflow(old_playbook_name, new_playbook_name, workflow.name, workflow.name)

self.playbooks[new_playbook_name].regenerate_uids()

def get_workflows_by_uid(self, workflow_uids):
"""Gets a list of workflows from their UIDs
Expand Down
12 changes: 6 additions & 6 deletions tests/test_workflow_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,13 +462,13 @@ def test_copy_workflow(self):
original_workflow_json = workflow_original.read()
copy_workflow_json.pop('name', None)
original_workflow_json.pop('name', None)
self.assertNotEqual(original_workflow_json['start'], copy_workflow_json['start'])
copy_workflow_json.pop('start', None)
original_workflow_json.pop('start', None)
TestWorkflowServer.strip_uids(copy_workflow_json)
TestWorkflowServer.strip_uids(original_workflow_json)
self.assertDictEqual(copy_workflow_json, original_workflow_json)
self.assertEqual(len(workflow_original.steps), len(workflow_copy.steps))
for step in workflow_copy.steps:
self.assertEqual(len(workflow_original.steps[step].next_steps),
len(workflow_copy.steps[step].next_steps))

def test_copy_workflow_invalid_name(self):
data = {"workflow": "helloWorldWorkflow"}
Expand Down Expand Up @@ -505,15 +505,15 @@ def test_copy_workflow_different_playbook(self):
original_workflow_json = workflow_original.read()
copy_workflow_json.pop('name', None)
original_workflow_json.pop('name', None)
self.assertNotEqual(original_workflow_json['start'], copy_workflow_json['start'])
copy_workflow_json.pop('start', None)
original_workflow_json.pop('start', None)
TestWorkflowServer.strip_uids(copy_workflow_json)
TestWorkflowServer.strip_uids(original_workflow_json)

self.assertDictEqual(copy_workflow_json, original_workflow_json)

self.assertEqual(len(workflow_original.steps), len(workflow_copy.steps))
for step in workflow_copy.steps:
self.assertEqual(len(workflow_original.steps[step].next_steps),
len(workflow_copy.steps[step].next_steps))

def test_copy_playbook(self):
self.post_with_status_check('/api/playbooks/test/copy',
Expand Down

0 comments on commit 1545c5d

Please sign in to comment.