Added goal & strategy ObjectField for Audit

In this changeset, I added the "goal" and the "strategy "ObjectField
which can either be loaded by setting the new "eager" parameter as True
or not loaded (as before) by setting it to False.
The advantage of introducing this eager parameter is that this way,
we can reduce to a minimum the overhead of DB queries whenever the
related goal is not actually needed.

Change-Id: I5a1b25e395e3d904dae954952f8e0862c3556210
Partially-Implements: blueprint watcher-versioned-objects
This commit is contained in:
Vincent Françoise
2016-10-03 16:02:49 +02:00
parent 54cf10b41c
commit f9df54c555
7 changed files with 206 additions and 100 deletions

View File

@@ -52,6 +52,8 @@ class TestListAction(api_base.FunctionalTest):
def setUp(self):
super(TestListAction, self).setUp()
obj_utils.create_test_goal(self.context)
obj_utils.create_test_strategy(self.context)
obj_utils.create_test_action_plan(self.context)
def test_empty(self):

View File

@@ -27,6 +27,11 @@ from watcher.tests.objects import utils as obj_utils
class TestListActionPlan(api_base.FunctionalTest):
def setUp(self):
super(TestListActionPlan, self).setUp()
obj_utils.create_test_goal(self.context)
obj_utils.create_test_audit(self.context)
def test_empty(self):
response = self.get_json('/action_plans')
self.assertEqual([], response['action_plans'])
@@ -131,10 +136,10 @@ class TestListActionPlan(api_base.FunctionalTest):
def test_many_with_soft_deleted_audit_uuid(self):
action_plan_list = []
audit1 = obj_utils.create_test_audit(self.context,
id=1,
id=2,
uuid=utils.generate_uuid())
audit2 = obj_utils.create_test_audit(self.context,
id=2,
id=3,
uuid=utils.generate_uuid())
for id_ in range(0, 2):

View File

@@ -683,6 +683,10 @@ class TestDelete(api_base.FunctionalTest):
class TestAuditPolicyEnforcement(api_base.FunctionalTest):
def setUp(self):
super(TestAuditPolicyEnforcement, self).setUp()
obj_utils.create_test_goal(self.context)
def _common_policy_check(self, rule, func, *arg, **kwarg):
self.policy.set_rules({
"admin_api": "(role:admin or role:administrator)",