Merge "Fix create execution when workbook does not exist"
This commit is contained in:
commit
138f4641a6
|
@ -180,7 +180,6 @@ class AdvancedTests(base.TestCaseAdvanced):
|
||||||
|
|
||||||
#TODO(smurashov): Need to add test which would check task update
|
#TODO(smurashov): Need to add test which would check task update
|
||||||
|
|
||||||
@testtools.skip('https://bugs.launchpad.net/mistral/+bug/1325914')
|
|
||||||
@test.attr(type='negative')
|
@test.attr(type='negative')
|
||||||
def test_create_execution_in_nonexistent_workbook(self):
|
def test_create_execution_in_nonexistent_workbook(self):
|
||||||
self.assertRaises(exceptions.NotFound, self._create_execution,
|
self.assertRaises(exceptions.NotFound, self._create_execution,
|
||||||
|
|
|
@ -116,16 +116,18 @@ class ExecutionsController(rest.RestController):
|
||||||
LOG.debug("Create execution [workbook_name=%s, execution=%s]" %
|
LOG.debug("Create execution [workbook_name=%s, execution=%s]" %
|
||||||
(workbook_name, execution))
|
(workbook_name, execution))
|
||||||
|
|
||||||
context = None
|
if (db_api.workbook_get(workbook_name)
|
||||||
if execution.context:
|
and db_api.workbook_definition_get(workbook_name)):
|
||||||
context = json.loads(execution.context)
|
context = None
|
||||||
|
if execution.context:
|
||||||
|
context = json.loads(execution.context)
|
||||||
|
|
||||||
engine = pecan.request.context['engine']
|
engine = pecan.request.context['engine']
|
||||||
values = engine.start_workflow_execution(execution.workbook_name,
|
values = engine.start_workflow_execution(execution.workbook_name,
|
||||||
execution.task,
|
execution.task,
|
||||||
context)
|
context)
|
||||||
|
|
||||||
return Execution.from_dict(values)
|
return Execution.from_dict(values)
|
||||||
|
|
||||||
@rest_utils.wrap_wsme_controller_exception
|
@rest_utils.wrap_wsme_controller_exception
|
||||||
@wsme_pecan.wsexpose(None, wtypes.text, wtypes.text, status_code=204)
|
@wsme_pecan.wsexpose(None, wtypes.text, wtypes.text, status_code=204)
|
||||||
|
|
|
@ -14,6 +14,8 @@
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
from mistral import exceptions
|
||||||
|
|
||||||
from mistral.openstack.common.db import api as db_api
|
from mistral.openstack.common.db import api as db_api
|
||||||
from mistral.openstack.common import log as logging
|
from mistral.openstack.common import log as logging
|
||||||
|
|
||||||
|
@ -78,7 +80,11 @@ def workbooks_get():
|
||||||
|
|
||||||
|
|
||||||
def workbook_definition_get(workbook_name):
|
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):
|
def workbook_definition_put(workbook_name, text):
|
||||||
|
|
|
@ -41,6 +41,16 @@ EXECS = [
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
WORKBOOKS = [
|
||||||
|
{
|
||||||
|
'name': "my_workbook",
|
||||||
|
'description': "My cool Mistral workbook",
|
||||||
|
'tags': ['deployment', 'demo']
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
UPDATED_EXEC = EXECS[0].copy()
|
UPDATED_EXEC = EXECS[0].copy()
|
||||||
UPDATED_EXEC['state'] = 'STOPPED'
|
UPDATED_EXEC['state'] = 'STOPPED'
|
||||||
|
|
||||||
|
@ -88,7 +98,13 @@ class TestExecutionsController(base.FunctionalTest):
|
||||||
|
|
||||||
@mock.patch.object(engine.EngineClient, 'start_workflow_execution',
|
@mock.patch.object(engine.EngineClient, 'start_workflow_execution',
|
||||||
mock.MagicMock(return_value=EXECS[0]))
|
mock.MagicMock(return_value=EXECS[0]))
|
||||||
|
@mock.patch.object(db_api, 'workbook_definition_get',
|
||||||
|
mock.Mock(return_value="Workflow:"))
|
||||||
def test_post(self):
|
def test_post(self):
|
||||||
|
my_workbook = WORKBOOKS[0]
|
||||||
|
self.app.post_json('/v1/workbooks',
|
||||||
|
my_workbook)
|
||||||
|
|
||||||
new_exec = EXECS[0].copy()
|
new_exec = EXECS[0].copy()
|
||||||
new_exec['context'] = json.dumps(new_exec['context'])
|
new_exec['context'] = json.dumps(new_exec['context'])
|
||||||
|
|
||||||
|
@ -97,6 +113,20 @@ class TestExecutionsController(base.FunctionalTest):
|
||||||
self.assertEqual(resp.status_int, 201)
|
self.assertEqual(resp.status_int, 201)
|
||||||
self.assertDictEqual(EXECS[0], canonize(resp.json))
|
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.patch.object(engine.EngineClient, 'start_workflow_execution',
|
||||||
mock.MagicMock(side_effect=ex.MistralException))
|
mock.MagicMock(side_effect=ex.MistralException))
|
||||||
def test_post_throws_exception(self):
|
def test_post_throws_exception(self):
|
||||||
|
|
Loading…
Reference in New Issue