summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjiaopengju <jiaopengju@cmss.chinamobile.com>2018-01-25 15:32:47 +0800
committerjiaopengju <jiaopengju@cmss.chinamobile.com>2018-01-26 13:50:37 +0800
commitbba93226e606ef92fee56a5a67b9046d7b692d08 (patch)
treee916c56940e0c417514e09efe60f42ab6a8207ab
parentfb6d0c8d65cb32f97f611ab8f51a863b25cc299e (diff)
Add trigger verification in API1.0.0
Currently, we use 'cast' instead of 'call' to send request from api to operationengine when creating a new trigger. With 'cast', it will not give a return value to api even the trigger is invalid, so users can create triggers successfully with using invalid triggers. This patch add trigger verification in API side. Before send create request to operationengine, API send a verify request to operationengine first, which type is 'call', to make sure the trigger will be created is valid. Change-Id: Iea734e1b4a63f6e35afe32cbbb2b60f79d6db085 Closes-Bug: #1736657
Notes
Notes (review): Code-Review+2: chenying <ying.chen@huawei.com> Code-Review+2: Jiao Pengju <jiaopengju@cmss.chinamobile.com> Workflow+1: Jiao Pengju <jiaopengju@cmss.chinamobile.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Fri, 26 Jan 2018 08:09:37 +0000 Reviewed-on: https://review.openstack.org/537794 Project: openstack/karbor Branch: refs/heads/master
-rw-r--r--karbor/api/v1/triggers.py1
-rw-r--r--karbor/services/operationengine/api.py3
-rw-r--r--karbor/services/operationengine/manager.py7
-rw-r--r--karbor/services/operationengine/rpcapi.py3
-rw-r--r--karbor/tests/unit/api/v1/test_triggers.py3
-rw-r--r--karbor/tests/unit/operationengine/test_manager.py9
6 files changed, 26 insertions, 0 deletions
diff --git a/karbor/api/v1/triggers.py b/karbor/api/v1/triggers.py
index 6445ab8..7fd7054 100644
--- a/karbor/api/v1/triggers.py
+++ b/karbor/api/v1/triggers.py
@@ -104,6 +104,7 @@ class TriggersController(wsgi.Controller):
104 } 104 }
105 try: 105 try:
106 trigger = objects.Trigger(context=context, **trigger_definition) 106 trigger = objects.Trigger(context=context, **trigger_definition)
107 self.operationengine_api.verify_trigger(context, trigger)
107 self.operationengine_api.create_trigger(context, trigger) 108 self.operationengine_api.create_trigger(context, trigger)
108 trigger.create() 109 trigger.create()
109 except exception.Invalid as ex: 110 except exception.Invalid as ex:
diff --git a/karbor/services/operationengine/api.py b/karbor/services/operationengine/api.py
index 858ef15..bda64bf 100644
--- a/karbor/services/operationengine/api.py
+++ b/karbor/services/operationengine/api.py
@@ -40,6 +40,9 @@ class API(base.Base):
40 self.operationengine_rpcapi.resume_scheduled_operation( 40 self.operationengine_rpcapi.resume_scheduled_operation(
41 context, operation_id, trigger_id) 41 context, operation_id, trigger_id)
42 42
43 def verify_trigger(self, context, trigger):
44 self.operationengine_rpcapi.verify_trigger(context, trigger)
45
43 def create_trigger(self, context, trigger): 46 def create_trigger(self, context, trigger):
44 self.operationengine_rpcapi.create_trigger(context, trigger) 47 self.operationengine_rpcapi.create_trigger(context, trigger)
45 48
diff --git a/karbor/services/operationengine/manager.py b/karbor/services/operationengine/manager.py
index 949cf90..c24427d 100644
--- a/karbor/services/operationengine/manager.py
+++ b/karbor/services/operationengine/manager.py
@@ -220,6 +220,13 @@ class OperationEngineManager(manager.Manager):
220 raise 220 raise
221 221
222 @messaging.expected_exceptions(exception.InvalidInput) 222 @messaging.expected_exceptions(exception.InvalidInput)
223 def verify_trigger(self, context, trigger):
224 LOG.debug('Verifying trigger (id: "%s" type: "%s")',
225 trigger.id, trigger.type)
226 self.trigger_manager.check_trigger_definition(
227 trigger.type, trigger.properties)
228
229 @messaging.expected_exceptions(exception.InvalidInput)
223 def create_trigger(self, context, trigger): 230 def create_trigger(self, context, trigger):
224 LOG.debug('Creating trigger (id: "%s" type: "%s")', 231 LOG.debug('Creating trigger (id: "%s" type: "%s")',
225 trigger.id, trigger.type) 232 trigger.id, trigger.type)
diff --git a/karbor/services/operationengine/rpcapi.py b/karbor/services/operationengine/rpcapi.py
index fce29fa..8db4884 100644
--- a/karbor/services/operationengine/rpcapi.py
+++ b/karbor/services/operationengine/rpcapi.py
@@ -63,6 +63,9 @@ class OperationEngineAPI(object):
63 operation_id=operation_id, 63 operation_id=operation_id,
64 trigger_id=trigger_id) 64 trigger_id=trigger_id)
65 65
66 def verify_trigger(self, ctxt, trigger):
67 return self._client.call(ctxt, 'verify_trigger', trigger=trigger)
68
66 def create_trigger(self, ctxt, trigger): 69 def create_trigger(self, ctxt, trigger):
67 self._client.prepare(fanout=True).cast(ctxt, 'create_trigger', 70 self._client.prepare(fanout=True).cast(ctxt, 'create_trigger',
68 trigger=trigger) 71 trigger=trigger)
diff --git a/karbor/tests/unit/api/v1/test_triggers.py b/karbor/tests/unit/api/v1/test_triggers.py
index 4779d86..59ae1c9 100644
--- a/karbor/tests/unit/api/v1/test_triggers.py
+++ b/karbor/tests/unit/api/v1/test_triggers.py
@@ -31,6 +31,9 @@ class FakeRemoteOperationApi(object):
31 msg = (_("Invalid trigger time format type")) 31 msg = (_("Invalid trigger time format type"))
32 raise exception.InvalidInput(msg) 32 raise exception.InvalidInput(msg)
33 33
34 def verify_trigger(self, context, trigger):
35 pass
36
34 def delete_trigger(self, context, trigger_id): 37 def delete_trigger(self, context, trigger_id):
35 pass 38 pass
36 39
diff --git a/karbor/tests/unit/operationengine/test_manager.py b/karbor/tests/unit/operationengine/test_manager.py
index 91330fd..c6d275f 100644
--- a/karbor/tests/unit/operationengine/test_manager.py
+++ b/karbor/tests/unit/operationengine/test_manager.py
@@ -39,6 +39,9 @@ class FakeTriggerManager(object):
39 def unregister_operation(self, trigger_id, operation_id, **kwargs): 39 def unregister_operation(self, trigger_id, operation_id, **kwargs):
40 pass 40 pass
41 41
42 def check_trigger_definition(self, trigger_type, trigger_definition):
43 pass
44
42 def add_trigger(self, trigger_id, trigger_type, trigger_property): 45 def add_trigger(self, trigger_id, trigger_type, trigger_property):
43 self._trigger[trigger_id] = [] 46 self._trigger[trigger_id] = []
44 47
@@ -150,6 +153,12 @@ class OperationEngineManagerTestCase(base.TestCase):
150 self.manager.suspend_scheduled_operation(self.ctxt, op_id, trigger_id) 153 self.manager.suspend_scheduled_operation(self.ctxt, op_id, trigger_id)
151 unregister.assert_called_once_with(trigger_id, op_id) 154 unregister.assert_called_once_with(trigger_id, op_id)
152 155
156 @mock.patch.object(FakeTriggerManager, 'check_trigger_definition')
157 def test_verify_trigger(self, check_trigger_definition):
158 self.manager.verify_trigger(self.ctxt, self._trigger)
159 check_trigger_definition.assert_called_once_with(
160 self._trigger.type, self._trigger.properties)
161
153 def _create_one_trigger(self): 162 def _create_one_trigger(self):
154 trigger_info = { 163 trigger_info = {
155 'project_id': "123", 164 'project_id': "123",