Fixing workbook events creation
* Workbook events creation is now called from a REST controller rather than from DB API. This is more proper place (level of abstraction). * Fixed workbook definition controller and evets tests. Change-Id: Ib17d0b0dae614c474c161cd12ecbb1b05aea74a8
This commit is contained in:
parent
2a8f9a7745
commit
d17ea38b27
@ -18,6 +18,7 @@ from pecan import request
|
||||
|
||||
from mistral.openstack.common import log as logging
|
||||
from mistral.db import api as db_api
|
||||
from mistral.services import scheduler
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
@ -38,4 +39,7 @@ class WorkbookDefinitionController(rest.RestController):
|
||||
LOG.debug("Update workbook definition [workbook_name=%s, text=%s]" %
|
||||
(workbook_name, text))
|
||||
|
||||
return db_api.workbook_definition_put(workbook_name, text)
|
||||
wb = db_api.workbook_definition_put(workbook_name, text)
|
||||
scheduler.create_associated_events(wb)
|
||||
|
||||
return wb['definition']
|
||||
|
@ -16,7 +16,6 @@
|
||||
|
||||
from mistral.openstack.common.db import api as db_api
|
||||
from mistral.openstack.common import log as logging
|
||||
from mistral.services import scheduler
|
||||
|
||||
# Workbooks
|
||||
|
||||
@ -83,9 +82,7 @@ def workbook_definition_get(workbook_name):
|
||||
|
||||
|
||||
def workbook_definition_put(workbook_name, text):
|
||||
workbook = IMPL.workbook_update(workbook_name, {'definition': text})
|
||||
scheduler.create_associated_events(workbook)
|
||||
return workbook
|
||||
return IMPL.workbook_update(workbook_name, {'definition': text})
|
||||
|
||||
|
||||
# Executions
|
||||
|
@ -46,10 +46,21 @@ class TestWorkbookDefinitionController(base.FunctionalTest):
|
||||
self.assertEqual(DEFINITION, resp.text)
|
||||
|
||||
def test_put(self):
|
||||
new_definition = "new definition"
|
||||
new_definition = """
|
||||
Workflow:
|
||||
events:
|
||||
create-vms:
|
||||
type: periodic
|
||||
tasks: create-vms
|
||||
parameters:
|
||||
cron-pattern: "* * * * *"
|
||||
"""
|
||||
|
||||
db_api.workbook_definition_put = \
|
||||
mock.MagicMock(return_value=new_definition)
|
||||
mock.MagicMock(return_value={
|
||||
'name': 'my_workbook',
|
||||
'definition': new_definition
|
||||
})
|
||||
|
||||
resp = self.app.put('/v1/workbooks/my_workbook/definition',
|
||||
new_definition,
|
||||
@ -57,3 +68,10 @@ class TestWorkbookDefinitionController(base.FunctionalTest):
|
||||
|
||||
self.assertEqual(resp.status_int, 200)
|
||||
self.assertEqual(new_definition, resp.body)
|
||||
|
||||
# Check that associated events have been created in DB.
|
||||
events = db_api.events_get(workbook_name='my_workbook')
|
||||
|
||||
self.assertEqual(events[0]['name'], 'create-vms')
|
||||
self.assertEqual(events[0]['pattern'], '* * * * *')
|
||||
self.assertEqual(events[0]['workbook_name'], 'my_workbook')
|
||||
|
@ -20,6 +20,7 @@ from mistral.db import api as db_api
|
||||
from mistral import dsl
|
||||
from mistral.tests.unit import base
|
||||
from mistral import version
|
||||
from mistral.services import scheduler
|
||||
|
||||
|
||||
class EventsTest(base.DbTestCase):
|
||||
@ -30,9 +31,14 @@ class EventsTest(base.DbTestCase):
|
||||
"tests/resources/test_rest.yaml")).read()
|
||||
self.dsl = dsl.Parser(self.doc)
|
||||
|
||||
def test_events_create_after_wb_put(self):
|
||||
db_api.workbook_create({'name': 'my_workbook'})
|
||||
db_api.workbook_definition_put('my_workbook', self.doc)
|
||||
def test_create_associated_events(self):
|
||||
workbook = {
|
||||
'name': 'my_workbook',
|
||||
'definition': self.doc
|
||||
}
|
||||
|
||||
scheduler.create_associated_events(workbook)
|
||||
|
||||
events = db_api.events_get(workbook_name='my_workbook')
|
||||
|
||||
self.assertEqual(events[0]['name'], 'create-vms')
|
||||
|
Loading…
Reference in New Issue
Block a user