Skip to content

Commit c343e57

Browse files
glukhmantehasdf
andauthored
Set execution status to FAILED if global/dependencies checks fail (#3083)
* Set execution status to FAILED if global/dependencies checks fail before launching the WF * exec status after failed checks: also handle dequeueing (#3084) * add a test * dequeue: ignore errors, continue to the next execution if dequeueing an execution fails, oh well. Continue to the next one. This is because now execute_workflow can throw errors. Co-authored-by: Lukasz Maksymczuk <tehasdf@users.noreply.github.com>
1 parent e978f91 commit c343e57

File tree

2 files changed

+37
-9
lines changed

2 files changed

+37
-9
lines changed

rest-service/manager_rest/resource_manager.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -235,12 +235,17 @@ def start_queued_executions(self, deployment_storage_id):
235235
amqp_client.add_handler(handler)
236236
with amqp_client:
237237
for execution in to_run:
238-
if execution.is_system_workflow:
239-
self._execute_system_workflow(
240-
execution, queue=True, send_handler=handler)
241-
else:
242-
self.execute_workflow(
243-
execution, queue=True, send_handler=handler)
238+
try:
239+
if execution.is_system_workflow:
240+
self._execute_system_workflow(
241+
execution, queue=True, send_handler=handler)
242+
else:
243+
self.execute_workflow(
244+
execution, queue=True, send_handler=handler)
245+
except Exception as e:
246+
current_app.logger.warning(
247+
'Could not dequeue execution %s: %s',
248+
execution, e)
244249

245250
def _refresh_execution(self, execution: models.Execution) -> bool:
246251
"""Prepare the execution to be started.
@@ -965,9 +970,16 @@ def execute_workflow(self, execution, *, force=False, queue=False,
965970
send_handler: 'SendHandler' = None):
966971
with self.sm.transaction():
967972
if execution.deployment:
968-
self._check_allow_global_execution(execution.deployment)
969-
self._verify_dependencies_not_affected(
970-
execution.workflow_id, execution.deployment, force)
973+
try:
974+
self._check_allow_global_execution(execution.deployment)
975+
self._verify_dependencies_not_affected(
976+
execution.workflow_id, execution.deployment, force)
977+
except Exception as e:
978+
execution.status = ExecutionState.FAILED
979+
execution.error = str(e)
980+
self.sm.update(execution)
981+
db.session.commit()
982+
raise
971983

972984
should_queue = queue
973985
if not allow_overlapping_running_wf:

rest-service/manager_rest/test/endpoints/test_executions.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,22 @@ def test_update_execution_status(self):
257257
execution, ExecutionState.STARTED)
258258
self._modify_execution_status(execution.id, 'pending')
259259

260+
def test_failed_when_global_disallowed(self):
261+
"""When check_allow_global throws, the execution is failed"""
262+
self.put_deployment(self.DEPLOYMENT_ID)
263+
264+
with mock.patch('manager_rest.resource_manager.ResourceManager'
265+
'._check_allow_global_execution',
266+
side_effect=manager_exceptions.ForbiddenError()):
267+
with self.assertRaises(exceptions.CloudifyClientError):
268+
self.client.executions.start(self.DEPLOYMENT_ID, 'install')
269+
executions = self.client.executions.list(
270+
deployment_id=self.DEPLOYMENT_ID,
271+
workflow_id='install')
272+
self.assertEqual(len(executions), 1)
273+
execution = executions[0]
274+
self.assertEqual(ExecutionState.FAILED, execution.status)
275+
260276
def test_update_execution_status_with_error(self):
261277
(blueprint_id, deployment_id, blueprint_response,
262278
deployment_response) = self.put_deployment(self.DEPLOYMENT_ID)

0 commit comments

Comments
 (0)