def test_request_bad_action(self): wf_meta = self.get_wf_fixture_meta_data(TEST_PACK_PATH, TEST_FIXTURES['workflows'][0]) # Manually create the action execution object with the bad action. ac_ex_db = ex_db_models.ActionExecutionDB( action={'ref': 'mock.foobar'}) # Request the workflow execution. self.assertRaises(ac_exc.InvalidActionReferencedException, wf_svc.request, self.get_wf_def(TEST_PACK_PATH, wf_meta), ac_ex_db)
def test_request_bad_action(self): wf_meta = self.get_wf_fixture_meta_data(TEST_PACK_PATH, 'sequential.yaml') # Manually create the action execution object with the bad action. ac_ex_db = ex_db_models.ActionExecutionDB( action={'ref': 'mock.foobar'}, runner={'name': 'foobar'}) # Request the workflow execution. self.assertRaises(action_exc.InvalidActionReferencedException, workflow_service.request, self.get_wf_def(TEST_PACK_PATH, wf_meta), ac_ex_db, self.mock_st2_context(ac_ex_db))
def mock_task_records(self, parent, task_id, task_route=0, completed=True, expired=False, log=True): if not completed and expired: raise ValueError( "Task must be set completed=True if expired=True.") status = (ac_const.LIVEACTION_STATUS_SUCCEEDED if completed else ac_const.LIVEACTION_STATUS_RUNNING) parent_wf_ex_db, parent_ac_ex_db = parent[0], parent[2] # Identify end timestamp gc_max_idle = cfg.CONF.workflow_engine.gc_max_idle_sec utc_now_dt = date_utils.get_datetime_utc_now() expiry_dt = utc_now_dt - datetime.timedelta(seconds=gc_max_idle + 10) end_timestamp = expiry_dt if expired else utc_now_dt # Assign metadata. action_ref = "core.local" runner = "local-shell-cmd" user = "******" # Create the TaskExecutionDB record first since the ID needs to be # included in the LiveActionDB and ActionExecutionDB records. tk_ex_db = wf_db_models.TaskExecutionDB( workflow_execution=str(parent_wf_ex_db.id), task_id=task_id, task_route=0, status=status, start_timestamp=parent_wf_ex_db.start_timestamp, ) if status in ac_const.LIVEACTION_COMPLETED_STATES: tk_ex_db.end_timestamp = end_timestamp if expired else utc_now_dt tk_ex_db = wf_db_access.TaskExecution.insert(tk_ex_db, publish=False) # Build context for LiveActionDB and ActionExecutionDB. context = { "user": user, "orquesta": { "task_id": tk_ex_db.task_id, "task_name": tk_ex_db.task_id, "workflow_execution_id": str(parent_wf_ex_db.id), "task_execution_id": str(tk_ex_db.id), "task_route": tk_ex_db.task_route, }, "parent": { "user": user, "execution_id": str(parent_ac_ex_db.id) }, } # Create the LiveActionDB record. lv_ac_db = lv_db_models.LiveActionDB( workflow_execution=str(parent_wf_ex_db.id), task_execution=str(tk_ex_db.id), action=action_ref, action_is_workflow=False, context=context, status=status, start_timestamp=tk_ex_db.start_timestamp, end_timestamp=tk_ex_db.end_timestamp, ) lv_ac_db = lv_db_access.LiveAction.insert(lv_ac_db, publish=False) # Create the ActionExecutionDB record. ac_ex_db = ex_db_models.ActionExecutionDB( workflow_execution=str(parent_wf_ex_db.id), task_execution=str(tk_ex_db.id), action={ "runner_type": runner, "ref": action_ref }, runner={"name": runner}, liveaction={"id": str(lv_ac_db.id)}, context=context, status=status, start_timestamp=tk_ex_db.start_timestamp, end_timestamp=tk_ex_db.end_timestamp, ) if log: ac_ex_db.log = [{ "status": "running", "timestamp": tk_ex_db.start_timestamp }] if log and status in ac_const.LIVEACTION_COMPLETED_STATES: ac_ex_db.log.append({ "status": status, "timestamp": tk_ex_db.end_timestamp }) ac_ex_db = ex_db_access.ActionExecution.insert(ac_ex_db, publish=False) return tk_ex_db, lv_ac_db, ac_ex_db
def mock_workflow_records(self, completed=False, expired=True, log=True): status = (ac_const.LIVEACTION_STATUS_SUCCEEDED if completed else ac_const.LIVEACTION_STATUS_RUNNING) # Identify start and end timestamp gc_max_idle = cfg.CONF.workflow_engine.gc_max_idle_sec utc_now_dt = date_utils.get_datetime_utc_now() expiry_dt = utc_now_dt - datetime.timedelta(seconds=gc_max_idle + 30) start_timestamp = expiry_dt if expired else utc_now_dt end_timestamp = utc_now_dt if completed else None # Assign metadata. action_ref = "orquesta_tests.sequential" runner = "orquesta" user = "******" # Create the WorkflowExecutionDB record first since the ID needs to be # included in the LiveActionDB and ActionExecutionDB records. st2_ctx = { "st2": { "action_execution_id": "123", "action": "foobar", "runner": "orquesta", } } wf_ex_db = wf_db_models.WorkflowExecutionDB( context=st2_ctx, status=status, start_timestamp=start_timestamp, end_timestamp=end_timestamp, ) wf_ex_db = wf_db_access.WorkflowExecution.insert(wf_ex_db, publish=False) # Create the LiveActionDB record. lv_ac_db = lv_db_models.LiveActionDB( workflow_execution=str(wf_ex_db.id), action=action_ref, action_is_workflow=True, context={ "user": user, "workflow_execution": str(wf_ex_db.id) }, status=status, start_timestamp=start_timestamp, end_timestamp=end_timestamp, ) lv_ac_db = lv_db_access.LiveAction.insert(lv_ac_db, publish=False) # Create the ActionExecutionDB record. ac_ex_db = ex_db_models.ActionExecutionDB( workflow_execution=str(wf_ex_db.id), action={ "runner_type": runner, "ref": action_ref }, runner={"name": runner}, liveaction={"id": str(lv_ac_db.id)}, context={ "user": user, "workflow_execution": str(wf_ex_db.id) }, status=status, start_timestamp=start_timestamp, end_timestamp=end_timestamp, ) if log: ac_ex_db.log = [{ "status": "running", "timestamp": start_timestamp }] if log and status in ac_const.LIVEACTION_COMPLETED_STATES: ac_ex_db.log.append({"status": status, "timestamp": end_timestamp}) ac_ex_db = ex_db_access.ActionExecution.insert(ac_ex_db, publish=False) # Update the WorkflowExecutionDB record with cross reference to the ActionExecutionDB. wf_ex_db.action_execution = str(ac_ex_db.id) wf_ex_db = wf_db_access.WorkflowExecution.update(wf_ex_db, publish=False) return wf_ex_db, lv_ac_db, ac_ex_db
def mock_task_records(self, parent, task_id, task_route=0, completed=True, expired=False, log=True): if not completed and expired: raise ValueError( 'Task must be set completed=True if expired=True.') status = (ac_const.LIVEACTION_STATUS_SUCCEEDED if completed else ac_const.LIVEACTION_STATUS_RUNNING) parent_wf_ex_db, parent_ac_ex_db = parent[0], parent[2] # Identify end timestamp gc_max_idle = cfg.CONF.workflow_engine.gc_max_idle_sec utc_now_dt = date_utils.get_datetime_utc_now() expiry_dt = utc_now_dt - datetime.timedelta(seconds=gc_max_idle + 10) end_timestamp = expiry_dt if expired else utc_now_dt # Assign metadata. action_ref = 'core.local' runner = 'local-shell-cmd' user = '******' # Create the TaskExecutionDB record first since the ID needs to be # included in the LiveActionDB and ActionExecutionDB records. tk_ex_db = wf_db_models.TaskExecutionDB( workflow_execution=str(parent_wf_ex_db.id), task_id=task_id, task_route=0, status=status, start_timestamp=parent_wf_ex_db.start_timestamp) if status in ac_const.LIVEACTION_COMPLETED_STATES: tk_ex_db.end_timestamp = end_timestamp if expired else utc_now_dt tk_ex_db = wf_db_access.TaskExecution.insert(tk_ex_db, publish=False) # Build context for LiveActionDB and ActionExecutionDB. context = { 'user': user, 'orquesta': { 'task_id': tk_ex_db.task_id, 'task_name': tk_ex_db.task_id, 'workflow_execution_id': str(parent_wf_ex_db.id), 'task_execution_id': str(tk_ex_db.id), 'task_route': tk_ex_db.task_route }, 'parent': { 'user': user, 'execution_id': str(parent_ac_ex_db.id) } } # Create the LiveActionDB record. lv_ac_db = lv_db_models.LiveActionDB( workflow_execution=str(parent_wf_ex_db.id), task_execution=str(tk_ex_db.id), action=action_ref, action_is_workflow=False, context=context, status=status, start_timestamp=tk_ex_db.start_timestamp, end_timestamp=tk_ex_db.end_timestamp) lv_ac_db = lv_db_access.LiveAction.insert(lv_ac_db, publish=False) # Create the ActionExecutionDB record. ac_ex_db = ex_db_models.ActionExecutionDB( workflow_execution=str(parent_wf_ex_db.id), task_execution=str(tk_ex_db.id), action={ 'runner_type': runner, 'ref': action_ref }, runner={'name': runner}, liveaction={'id': str(lv_ac_db.id)}, context=context, status=status, start_timestamp=tk_ex_db.start_timestamp, end_timestamp=tk_ex_db.end_timestamp) if log: ac_ex_db.log = [{ 'status': 'running', 'timestamp': tk_ex_db.start_timestamp }] if log and status in ac_const.LIVEACTION_COMPLETED_STATES: ac_ex_db.log.append({ 'status': status, 'timestamp': tk_ex_db.end_timestamp }) ac_ex_db = ex_db_access.ActionExecution.insert(ac_ex_db, publish=False) return tk_ex_db, lv_ac_db, ac_ex_db
def mock_workflow_records(self, completed=False, expired=True, log=True): status = (ac_const.LIVEACTION_STATUS_SUCCEEDED if completed else ac_const.LIVEACTION_STATUS_RUNNING) # Identify start and end timestamp gc_max_idle = cfg.CONF.workflow_engine.gc_max_idle_sec utc_now_dt = date_utils.get_datetime_utc_now() expiry_dt = utc_now_dt - datetime.timedelta(seconds=gc_max_idle + 30) start_timestamp = expiry_dt if expired else utc_now_dt end_timestamp = utc_now_dt if completed else None # Assign metadata. action_ref = 'orquesta_tests.sequential' runner = 'orquesta' user = '******' # Create the WorkflowExecutionDB record first since the ID needs to be # included in the LiveActionDB and ActionExecutionDB records. st2_ctx = { 'st2': { 'action_execution_id': '123', 'action': 'foobar', 'runner': 'orquesta' } } wf_ex_db = wf_db_models.WorkflowExecutionDB( context=st2_ctx, status=status, start_timestamp=start_timestamp, end_timestamp=end_timestamp) wf_ex_db = wf_db_access.WorkflowExecution.insert(wf_ex_db, publish=False) # Create the LiveActionDB record. lv_ac_db = lv_db_models.LiveActionDB(workflow_execution=str( wf_ex_db.id), action=action_ref, action_is_workflow=True, context={ 'user': user, 'workflow_execution': str(wf_ex_db.id) }, status=status, start_timestamp=start_timestamp, end_timestamp=end_timestamp) lv_ac_db = lv_db_access.LiveAction.insert(lv_ac_db, publish=False) # Create the ActionExecutionDB record. ac_ex_db = ex_db_models.ActionExecutionDB( workflow_execution=str(wf_ex_db.id), action={ 'runner_type': runner, 'ref': action_ref }, runner={'name': runner}, liveaction={'id': str(lv_ac_db.id)}, context={ 'user': user, 'workflow_execution': str(wf_ex_db.id) }, status=status, start_timestamp=start_timestamp, end_timestamp=end_timestamp) if log: ac_ex_db.log = [{ 'status': 'running', 'timestamp': start_timestamp }] if log and status in ac_const.LIVEACTION_COMPLETED_STATES: ac_ex_db.log.append({'status': status, 'timestamp': end_timestamp}) ac_ex_db = ex_db_access.ActionExecution.insert(ac_ex_db, publish=False) # Update the WorkflowExecutionDB record with cross reference to the ActionExecutionDB. wf_ex_db.action_execution = str(ac_ex_db.id) wf_ex_db = wf_db_access.WorkflowExecution.update(wf_ex_db, publish=False) return wf_ex_db, lv_ac_db, ac_ex_db