def setup_action_models(cls): action_db = ActionDB() action_db.name = 'action-1' action_db.description = 'awesomeness' action_db.enabled = True action_db.pack = 'wolfpack' action_db.entry_point = '' action_db.runner_type = {'name': 'test-runner'} action_db.parameters = { 'actionstr': {'type': 'string', 'position': 1, 'required': True}, 'actionint': {'type': 'number', 'default': 10, 'position': 0}, 'runnerdummy': {'type': 'string', 'default': 'actiondummy'} } ActionDBUtilsTestCase.action_db = Action.add_or_update(action_db) actionexec_db = ActionExecutionDB() actionexec_db.status = 'initializing' actionexec_db.start_timestamp = datetime.datetime.utcnow() actionexec_db.action = ResourceReference( name=ActionDBUtilsTestCase.action_db.name, pack=ActionDBUtilsTestCase.action_db.pack).ref params = { 'actionstr': 'foo', 'some_key_that_aint_exist_in_action_or_runner': 'bar', 'runnerint': 555 } actionexec_db.parameters = params ActionDBUtilsTestCase.actionexec_db = ActionExecution.add_or_update(actionexec_db)
def _get_action_exec_db_model(self, params): actionexec_db = ActionExecutionDB() actionexec_db.status = 'initializing' actionexec_db.start_timestamp = datetime.datetime.utcnow() actionexec_db.action = ResourceReference(name=ParamsUtilsTest.action_db.name, pack=ParamsUtilsTest.action_db.pack).ref actionexec_db.parameters = params return actionexec_db
def _get_action_exec_db_model(self, params): actionexec_db = ActionExecutionDB() actionexec_db.status = 'initializing' actionexec_db.start_timestamp = datetime.datetime.utcnow() actionexec_db.action = ResourceReference( name=ParamsUtilsTest.action_db.name, pack=ParamsUtilsTest.action_db.pack).ref actionexec_db.parameters = params return actionexec_db
def _get_failingaction_exec_db_model(self, params): actionexec_db = ActionExecutionDB() actionexec_db.status = 'initializing' actionexec_db.start_timestamp = datetime.datetime.now() actionexec_db.action = ResourceReference( name=RunnerContainerTest.failingaction_db.name, pack=RunnerContainerTest.failingaction_db.pack).ref actionexec_db.parameters = params actionexec_db.context = {'user': cfg.CONF.system_user.user} return actionexec_db
def _get_failingaction_exec_db_model(self, params): actionexec_db = ActionExecutionDB() actionexec_db.status = 'initializing' actionexec_db.start_timestamp = datetime.datetime.now() actionexec_db.action = ResourceReference( name=RunnerContainerTest.failingaction_db.name, pack=RunnerContainerTest.failingaction_db.pack).ref actionexec_db.parameters = params actionexec_db.context = {'user': cfg.CONF.system_user.user} return actionexec_db
def _run_action(action_ref, parent_execution_id, params, wait_for_completion=True): execution = ActionExecutionDB(action=action_ref) execution.parameters = ActionChainRunner._cast_params(action_ref, params) execution.context = {'parent': str(parent_execution_id)} execution = action_service.schedule(execution) while (wait_for_completion and execution.status != ACTIONEXEC_STATUS_SUCCEEDED and execution.status != ACTIONEXEC_STATUS_FAILED): eventlet.sleep(1) execution = action_db_util.get_actionexec_by_id(execution.id) return execution
def _run_action(action_ref, parent_execution_id, params, wait_for_completion=True): execution = ActionExecutionDB(action=action_ref) execution.parameters = ActionChainRunner._cast_params( action_ref, params) execution.context = {'parent': str(parent_execution_id)} execution = action_service.schedule(execution) while (wait_for_completion and execution.status != ACTIONEXEC_STATUS_SUCCEEDED and execution.status != ACTIONEXEC_STATUS_FAILED): eventlet.sleep(1) execution = action_db_util.get_actionexec_by_id(execution.id) return execution
def test_update_actionexecution_status_invalid(self): actionexec_db = ActionExecutionDB() actionexec_db.status = 'initializing' actionexec_db.start_timestamp = datetime.datetime.utcnow() actionexec_db.action = ResourceReference( name=ActionDBUtilsTestCase.action_db.name, pack=ActionDBUtilsTestCase.action_db.pack).ref params = { 'actionstr': 'foo', 'some_key_that_aint_exist_in_action_or_runner': 'bar', 'runnerint': 555 } actionexec_db.parameters = params actionexec_db = ActionExecution.add_or_update(actionexec_db) # Update by id. self.assertRaises(ValueError, action_db_utils.update_actionexecution_status, 'mea culpa', actionexec_id=actionexec_db.id)
def test_update_actionexecution_status(self): actionexec_db = ActionExecutionDB() actionexec_db.status = 'initializing' actionexec_db.start_timestamp = datetime.datetime.utcnow() actionexec_db.action = ResourceReference( name=ActionDBUtilsTestCase.action_db.name, pack=ActionDBUtilsTestCase.action_db.pack).ref params = { 'actionstr': 'foo', 'some_key_that_aint_exist_in_action_or_runner': 'bar', 'runnerint': 555 } actionexec_db.parameters = params actionexec_db = ActionExecution.add_or_update(actionexec_db) origactionexec_db = copy.copy(actionexec_db) # Update by id. newactionexec_db = action_db_utils.update_actionexecution_status( 'running', actionexec_id=actionexec_db.id) # Verify id didn't change. self.assertEqual(origactionexec_db.id, newactionexec_db.id) self.assertEqual(newactionexec_db.status, 'running')
def test_update_actionexecution_status_and_end_timestamp(self): actionexec_db = ActionExecutionDB() actionexec_db.status = 'initializing' actionexec_db.start_timestamp = datetime.datetime.utcnow() actionexec_db.action = ResourceReference( name=ActionDBUtilsTestCase.action_db.name, pack=ActionDBUtilsTestCase.action_db.pack).ref actionexec_db.parameters = {} actionexec_db = ActionExecution.add_or_update(actionexec_db) origactionexec_db = copy.copy(actionexec_db) # Update by id now = datetime.datetime.now() newactionexec_db = action_db_utils.update_actionexecution_status( status='running', end_timestamp=now, actionexec_id=actionexec_db.id) # Verify id didn't change and end_timestamp has been set self.assertEqual(origactionexec_db.id, newactionexec_db.id) self.assertEqual(newactionexec_db.status, 'running') self.assertEqual(newactionexec_db.end_timestamp, now)