From 856d1d7154146856e05f66a909fbea6014d0aaa5 Mon Sep 17 00:00:00 2001 From: Limor Stotland Date: Mon, 13 Jul 2015 15:37:01 +0000 Subject: [PATCH] Make update behavior consistent Keep behavior of updating workflow consistent with that of workbook and environment. The update command will fail if the workflow doesn't exist. Change-Id: I7a871c2ac378ac0b7f6360f03f395816b9d0f4b0 Closes-Bug: #1418545 --- mistral/services/workflows.py | 8 ++++---- mistral/tests/unit/api/v2/test_workflows.py | 6 +++--- .../unit/services/test_workflow_service.py | 20 +++++++++++++++++++ 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/mistral/services/workflows.py b/mistral/services/workflows.py index 53870546..0ff5daae 100644 --- a/mistral/services/workflows.py +++ b/mistral/services/workflows.py @@ -25,7 +25,7 @@ def register_standard_workflows(): for wf_path in workflow_paths: workflow_definition = open(wf_path).read() - update_workflows(workflow_definition, scope='public') + create_workflows(workflow_definition, scope='public') def sync_db(): @@ -51,7 +51,7 @@ def update_workflows(definition, scope='private'): with db_api.transaction(): for wf_spec in wf_list_spec.get_workflows(): - db_wfs.append(_create_or_update_workflow( + db_wfs.append(_update_workflow( wf_spec, definition, scope @@ -78,7 +78,7 @@ def _create_workflow(wf_spec, definition, scope): ) -def _create_or_update_workflow(wf_spec, definition, scope): +def _update_workflow(wf_spec, definition, scope): values = _get_workflow_values(wf_spec, definition, scope) - return db_api.create_or_update_workflow_definition(values['name'], values) + return db_api.update_workflow_definition(values['name'], values) diff --git a/mistral/tests/unit/api/v2/test_workflows.py b/mistral/tests/unit/api/v2/test_workflows.py index de311f92..e47952cd 100644 --- a/mistral/tests/unit/api/v2/test_workflows.py +++ b/mistral/tests/unit/api/v2/test_workflows.py @@ -167,7 +167,7 @@ class TestWorkflowsController(base.FunctionalTest): self.assertEqual(resp.status_int, 404) @mock.patch.object( - db_api, "create_or_update_workflow_definition", MOCK_UPDATED_WF + db_api, "update_workflow_definition", MOCK_UPDATED_WF ) def test_put(self): resp = self.app.put( @@ -182,7 +182,7 @@ class TestWorkflowsController(base.FunctionalTest): self.assertDictEqual({'workflows': [UPDATED_WF]}, resp.json) @mock.patch.object( - db_api, "create_or_update_workflow_definition", MOCK_WF_WITH_INPUT + db_api, "update_workflow_definition", MOCK_WF_WITH_INPUT ) def test_put_with_input(self): resp = self.app.put( @@ -197,7 +197,7 @@ class TestWorkflowsController(base.FunctionalTest): self.assertDictEqual({'workflows': [WF_WITH_DEFAULT_INPUT]}, resp.json) @mock.patch.object( - db_api, "create_or_update_workflow_definition", MOCK_NOT_FOUND + db_api, "update_workflow_definition", MOCK_NOT_FOUND ) def test_put_not_found(self): resp = self.app.put( diff --git a/mistral/tests/unit/services/test_workflow_service.py b/mistral/tests/unit/services/test_workflow_service.py index 469ba7ca..748e7157 100644 --- a/mistral/tests/unit/services/test_workflow_service.py +++ b/mistral/tests/unit/services/test_workflow_service.py @@ -77,6 +77,17 @@ wf1: result: "{$}" """ +WORKFLOW = """ +--- +version: '2.0' + +list_servers: + + tasks: + list_servers: + action: nova.servers_list + +""" INVALID_WORKFLOW = """ --- @@ -149,6 +160,15 @@ class WorkflowServiceTest(base.DbTestCase): utils.NotDefined ) + def test_update_non_existing_workflow_failed(self): + exception = self.assertRaises( + exc.NotFoundException, + wf_service.update_workflows, + WORKFLOW + ) + + self.assertIn("Workflow not found", exception.message) + def test_invalid_workflow_list(self): exception = self.assertRaises( exc.InvalidModelException,