Merge "Fix create execution when workbook does not exist"

This commit is contained in:
Jenkins 2014-06-16 05:43:28 +00:00 committed by Gerrit Code Review
commit 138f4641a6
4 changed files with 47 additions and 10 deletions

View File

@ -180,7 +180,6 @@ class AdvancedTests(base.TestCaseAdvanced):
#TODO(smurashov): Need to add test which would check task update
@testtools.skip('https://bugs.launchpad.net/mistral/+bug/1325914')
@test.attr(type='negative')
def test_create_execution_in_nonexistent_workbook(self):
self.assertRaises(exceptions.NotFound, self._create_execution,

View File

@ -116,16 +116,18 @@ class ExecutionsController(rest.RestController):
LOG.debug("Create execution [workbook_name=%s, execution=%s]" %
(workbook_name, execution))
context = None
if execution.context:
context = json.loads(execution.context)
if (db_api.workbook_get(workbook_name)
and db_api.workbook_definition_get(workbook_name)):
context = None
if execution.context:
context = json.loads(execution.context)
engine = pecan.request.context['engine']
values = engine.start_workflow_execution(execution.workbook_name,
execution.task,
context)
engine = pecan.request.context['engine']
values = engine.start_workflow_execution(execution.workbook_name,
execution.task,
context)
return Execution.from_dict(values)
return Execution.from_dict(values)
@rest_utils.wrap_wsme_controller_exception
@wsme_pecan.wsexpose(None, wtypes.text, wtypes.text, status_code=204)

View File

@ -14,6 +14,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from mistral import exceptions
from mistral.openstack.common.db import api as db_api
from mistral.openstack.common import log as logging
@ -78,7 +80,11 @@ def workbooks_get():
def workbook_definition_get(workbook_name):
return IMPL.workbook_get(workbook_name)['definition']
definition = IMPL.workbook_get(workbook_name)['definition']
if not definition:
raise exceptions.NotFoundException("Definition of workbook "
"%s is empty." % workbook_name)
return definition
def workbook_definition_put(workbook_name, text):

View File

@ -41,6 +41,16 @@ EXECS = [
}
]
WORKBOOKS = [
{
'name': "my_workbook",
'description': "My cool Mistral workbook",
'tags': ['deployment', 'demo']
}
]
UPDATED_EXEC = EXECS[0].copy()
UPDATED_EXEC['state'] = 'STOPPED'
@ -88,7 +98,13 @@ class TestExecutionsController(base.FunctionalTest):
@mock.patch.object(engine.EngineClient, 'start_workflow_execution',
mock.MagicMock(return_value=EXECS[0]))
@mock.patch.object(db_api, 'workbook_definition_get',
mock.Mock(return_value="Workflow:"))
def test_post(self):
my_workbook = WORKBOOKS[0]
self.app.post_json('/v1/workbooks',
my_workbook)
new_exec = EXECS[0].copy()
new_exec['context'] = json.dumps(new_exec['context'])
@ -97,6 +113,20 @@ class TestExecutionsController(base.FunctionalTest):
self.assertEqual(resp.status_int, 201)
self.assertDictEqual(EXECS[0], canonize(resp.json))
@mock.patch.object(engine.EngineClient, 'start_workflow_execution',
mock.MagicMock(return_value=EXECS[0]))
def test_post_definition_empty(self):
my_workbook = WORKBOOKS[0]
self.app.post_json('/v1/workbooks',
my_workbook)
new_exec = EXECS[0].copy()
new_exec['context'] = json.dumps(new_exec['context'])
resp = self.app.post_json('/v1/workbooks/my_workbook/executions',
new_exec, expect_errors=True)
self.assertEqual(resp.status_int, 404)
@mock.patch.object(engine.EngineClient, 'start_workflow_execution',
mock.MagicMock(side_effect=ex.MistralException))
def test_post_throws_exception(self):