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 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)
MOCK_TRIGGER.pack = 'dummypack1' MOCK_TRIGGER_INSTANCE = TriggerInstanceDB() MOCK_TRIGGER_INSTANCE.id = 'triggerinstance-test' MOCK_TRIGGER_INSTANCE.trigger = reference.get_ref_from_model(MOCK_TRIGGER) MOCK_TRIGGER_INSTANCE.payload = {} MOCK_TRIGGER_INSTANCE.occurrence_time = datetime.datetime.utcnow() MOCK_ACTION = ActionDB() MOCK_ACTION.id = 'action-test-1.id' MOCK_ACTION.name = 'action-test-1.name' MOCK_ACTION_EXECUTION = ActionExecutionDB() MOCK_ACTION_EXECUTION.id = 'actionexec-test-1.id' MOCK_ACTION_EXECUTION.name = 'actionexec-test-1.name' MOCK_ACTION_EXECUTION.status = 'scheduled' MOCK_RULE_1 = RuleDB() MOCK_RULE_1.id = 'rule-test-1' MOCK_RULE_1.trigger = reference.get_str_resource_ref_from_model(MOCK_TRIGGER) MOCK_RULE_1.criteria = {} MOCK_RULE_1.action = ActionExecutionSpecDB() MOCK_RULE_1.action.ref = reference.get_ref_from_model(MOCK_ACTION) MOCK_RULE_1.enabled = True MOCK_RULE_2 = RuleDB() MOCK_RULE_2.id = 'rule-test-2' MOCK_RULE_2.trigger = reference.get_str_resource_ref_from_model(MOCK_TRIGGER) MOCK_RULE_2.criteria = {} MOCK_RULE_2.action = ActionExecutionSpecDB() MOCK_RULE_2.action.ref = reference.get_ref_from_model(MOCK_ACTION)