def test_action_get_all_project_safe(self): parser.simple_parse(shared.sample_action) _create_action(self.ctx) new_ctx = utils.dummy_context(project='another-project') actions = db_api.action_get_all(new_ctx, project_safe=True) self.assertEqual(0, len(actions)) actions = db_api.action_get_all(new_ctx, project_safe=False) self.assertEqual(1, len(actions))
def test_action_delete_by_target_with_exceptions(self): for name in ['CLUSTER_CREATE', 'CLUSTER_RESIZE', 'CLUSTER_DELETE']: action = _create_action(self.ctx, action=name, target='CLUSTER_ID') self.assertIsNotNone(action) actions = db_api.action_get_all(self.ctx) self.assertEqual(3, len(actions)) db_api.action_delete_by_target(self.ctx, 'CLUSTER_ID', ['CLUSTER_DELETE']) actions = db_api.action_get_all(self.ctx) self.assertEqual(1, len(actions)) self.assertEqual('CLUSTER_DELETE', actions[0].action)
def test_action_delete_by_target_with_action_excluded(self): for name in ['CLUSTER_CREATE', 'CLUSTER_RESIZE', 'CLUSTER_DELETE']: action = _create_action(self.ctx, action=name, target='CLUSTER_ID') self.assertIsNotNone(action) actions = db_api.action_get_all(self.ctx) self.assertEqual(3, len(actions)) db_api.action_delete_by_target(self.ctx, 'CLUSTER_ID', action_excluded=['CLUSTER_DELETE']) actions = db_api.action_get_all(self.ctx) self.assertEqual(1, len(actions)) self.assertEqual('CLUSTER_DELETE', actions[0].action)
def test_action_delete_by_target_with_status(self): action1 = _create_action(self.ctx, action='CLUSTER_CREATE', target='CLUSTER_ID', status='SUCCEEDED') action2 = _create_action(self.ctx, action='CLUSTER_DELETE', target='CLUSTER_ID', status='INIT') self.assertIsNotNone(action1) self.assertIsNotNone(action2) actions = db_api.action_get_all(self.ctx) self.assertEqual(2, len(actions)) db_api.action_delete_by_target(self.ctx, 'CLUSTER_ID', status=['SUCCEEDED']) actions = db_api.action_get_all(self.ctx) self.assertEqual(1, len(actions)) self.assertEqual('CLUSTER_DELETE', actions[0].action)
def test_action_purge(self): old_timestamp = tu.utcnow(True) - datetime.timedelta(days=6) spec = {"owner": "test_owner", "created_at": old_timestamp} _create_action(self.ctx, **spec) _create_action(self.ctx, **spec) _create_action(self.ctx, **spec) new_timestamp = tu.utcnow(True) spec = {"owner": "test_owner", "created_at": new_timestamp} _create_action(self.ctx, **spec) _create_action(self.ctx, **spec) _create_action(self.ctx, **spec) actions = db_api.action_get_all(self.ctx) self.assertEqual(6, len(actions)) db_api.action_purge(project=None, granularity='days', age=5) actions = db_api.action_get_all(self.ctx) self.assertEqual(3, len(actions))
def test_action_get_all(self): specs = [ {'name': 'A01', 'target': 'cluster_001'}, {'name': 'A02', 'target': 'node_001'}, ] for spec in specs: _create_action(self.ctx, **spec) actions = db_api.action_get_all(self.ctx) self.assertEqual(2, len(actions)) names = [p.name for p in actions] for spec in specs: self.assertIn(spec['name'], names)