Implement goal_id, strategy_id and host_aggregate into Audit api

Modifying the api controller for audit objects to allow
creation of audit objects by specifying either an
audit_template uuid/id and/or a goal_id.

strategy_id is optional.

Partially Implements: blueprint persistent-audit-parameters
Change-Id: I7b3eae4d0752a11208f5f92ee13ab1018d8521ad
This commit is contained in:
Michael Gugino
2016-06-15 15:13:15 -04:00
parent 0769e53f93
commit 52ffc2c8e2
15 changed files with 296 additions and 379 deletions

View File

@@ -318,58 +318,6 @@ class DbAuditTestCase(base.DbTestCase):
self.assertRaises(exception.AuditNotFound,
self.dbapi.get_audit_by_id, self.context, 1234)
def test_get_audit_list_with_filter_by_audit_template_uuid(self):
audit_template = self.dbapi.create_audit_template(
utils.get_test_audit_template(
uuid=w_utils.generate_uuid(),
name='My Audit Template 1',
description='Description of my audit template 1',
host_aggregate=5,
goal='DUMMY',
extra={'automatic': True})
)
audit = self._create_test_audit(
audit_type='ONESHOT',
uuid=w_utils.generate_uuid(),
deadline=None,
state='ONGOING',
audit_template_id=audit_template.id)
res = self.dbapi.get_audit_list(
self.context,
filters={'audit_template_uuid': audit_template.uuid})
for r in res:
self.assertEqual(audit['audit_template_id'], r.audit_template_id)
def test_get_audit_list_with_filter_by_audit_template_name(self):
audit_template = self.dbapi.create_audit_template(
utils.get_test_audit_template(
uuid=w_utils.generate_uuid(),
name='My Audit Template 1',
description='Description of my audit template 1',
host_aggregate=5,
goal='DUMMY',
extra={'automatic': True})
)
audit = self._create_test_audit(
audit_type='ONESHOT',
uuid=w_utils.generate_uuid(),
deadline=None,
state='ONGOING',
audit_template_id=audit_template.id)
res = self.dbapi.get_audit_list(
self.context,
filters={'audit_template_name': audit_template.name})
for r in res:
self.assertEqual(audit['audit_template_id'], r.audit_template_id)
def test_update_audit(self):
audit = self._create_test_audit()
res = self.dbapi.update_audit(audit['id'], {'name': 'updated-model'})

View File

@@ -143,14 +143,14 @@ class TestPurgeCommand(base.DbTestCase):
with freezegun.freeze_time(self.expired_date):
self.audit1 = obj_utils.create_test_audit(
self.context, audit_template_id=self.audit_template1.id,
id=self._generate_id(), uuid=None)
self.context, id=self._generate_id(), uuid=None,
goal_id=self.goal1.id, strategy_id=self.strategy1.id)
self.audit2 = obj_utils.create_test_audit(
self.context, audit_template_id=self.audit_template2.id,
id=self._generate_id(), uuid=None)
self.context, id=self._generate_id(), uuid=None,
goal_id=self.goal2.id, strategy_id=self.strategy2.id)
self.audit3 = obj_utils.create_test_audit(
self.context, audit_template_id=self.audit_template3.id,
id=self._generate_id(), uuid=None)
self.context, id=self._generate_id(), uuid=None,
goal_id=self.goal3.id, strategy_id=self.strategy3.id)
self.audit1.soft_delete()
with freezegun.freeze_time(self.expired_date):
@@ -316,11 +316,11 @@ class TestPurgeCommand(base.DbTestCase):
m_destroy_audit_template.assert_called_once_with(
self.audit_template1.uuid)
m_destroy_audit.assert_called_once_with(
m_destroy_audit.assert_called_with(
self.audit1.uuid)
m_destroy_action_plan.assert_called_once_with(
m_destroy_action_plan.assert_called_with(
self.action_plan1.uuid)
m_destroy_action.assert_called_once_with(
m_destroy_action.assert_called_with(
self.action1.uuid)
@mock.patch.object(dbapi.Connection, "destroy_action")
@@ -404,32 +404,23 @@ class TestPurgeCommand(base.DbTestCase):
@mock.patch.object(dbapi.Connection, "destroy_audit_template")
@mock.patch.object(dbapi.Connection, "destroy_strategy")
@mock.patch.object(dbapi.Connection, "destroy_goal")
def test_purge_command_with_audit_template_ok(
def test_purge_command_with_strategy_uuid(
self, m_destroy_goal, m_destroy_strategy,
m_destroy_audit_template, m_destroy_audit,
m_destroy_action_plan, m_destroy_action):
self.cmd.orphans = False
self.cmd.uuid = self.audit_template1.uuid
self.cmd.exclude_orphans = False
self.cmd.uuid = self.strategy1.uuid
with freezegun.freeze_time(self.fake_today):
self.cmd.execute()
self.assertEqual(m_destroy_goal.call_count, 0)
self.assertEqual(m_destroy_strategy.call_count, 0)
self.assertEqual(m_destroy_strategy.call_count, 1)
self.assertEqual(m_destroy_audit_template.call_count, 1)
self.assertEqual(m_destroy_audit.call_count, 1)
self.assertEqual(m_destroy_action_plan.call_count, 1)
self.assertEqual(m_destroy_action.call_count, 1)
m_destroy_audit_template.assert_called_once_with(
self.audit_template1.uuid)
m_destroy_audit.assert_called_once_with(
self.audit1.uuid)
m_destroy_action_plan.assert_called_once_with(
self.action_plan1.uuid)
m_destroy_action.assert_called_once_with(
self.action1.uuid)
@mock.patch.object(dbapi.Connection, "destroy_action")
@mock.patch.object(dbapi.Connection, "destroy_action_plan")
@mock.patch.object(dbapi.Connection, "destroy_audit")
@@ -440,7 +431,7 @@ class TestPurgeCommand(base.DbTestCase):
self, m_destroy_goal, m_destroy_strategy,
m_destroy_audit_template, m_destroy_audit,
m_destroy_action_plan, m_destroy_action):
self.cmd.orphans = False
self.cmd.exclude_orphans = True
self.cmd.uuid = self.audit_template2.uuid
with freezegun.freeze_time(self.fake_today):
@@ -463,7 +454,7 @@ class TestPurgeCommand(base.DbTestCase):
self, m_destroy_goal, m_destroy_strategy,
m_destroy_audit_template, m_destroy_audit,
m_destroy_action_plan, m_destroy_action):
self.cmd.orphans = False
self.cmd.exclude_orphans = False
self.cmd.uuid = self.audit_template3.uuid
with freezegun.freeze_time(self.fake_today):

View File

@@ -57,12 +57,14 @@ def get_test_audit(**kwargs):
'audit_type': kwargs.get('audit_type', 'ONESHOT'),
'state': kwargs.get('state'),
'deadline': kwargs.get('deadline'),
'audit_template_id': kwargs.get('audit_template_id', 1),
'created_at': kwargs.get('created_at'),
'updated_at': kwargs.get('updated_at'),
'deleted_at': kwargs.get('deleted_at'),
'parameters': kwargs.get('parameters', {}),
'interval': kwargs.get('period', 3600),
'goal_id': kwargs.get('goal_id', 1),
'strategy_id': kwargs.get('strategy_id', None),
'host_aggregate': kwargs.get('host_aggregate', 1),
}