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
This commit is contained in:
Limor Stotland 2015-07-13 15:37:01 +00:00 committed by Lingxian Kong
parent 2e0cde447a
commit 856d1d7154
3 changed files with 27 additions and 7 deletions

View File

@ -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)

View File

@ -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(

View File

@ -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,