Added action_plan ObjectField for Action

In this changeset, I added the "action_plan" 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 object fields is not actually needed.

Change-Id: Iae255d9a0a919e2b6db710be24dbf9033b72166e
Partially-Implements: blueprint watcher-versioned-objects
This commit is contained in:
Vincent Françoise
2016-10-04 11:29:38 +02:00
parent 060c369838
commit b4b17ba395
7 changed files with 203 additions and 109 deletions

View File

@@ -265,13 +265,13 @@ class TestPurgeCommand(base.DbTestCase):
with freezegun.freeze_time(self.fake_today):
# orphan audit template
audit_template4 = obj_utils.create_test_audit_template(
self.context, goal_id=self.goal2.id, # Does not exist
self.context, goal_id=self.goal2.id,
name=self.generate_unique_name(prefix="Audit Template 4 "),
strategy_id=None, id=self._generate_id(),
strategy_id=self.strategy1.id, id=self._generate_id(),
uuid=utils.generate_uuid())
audit4 = obj_utils.create_test_audit(
self.context, audit_template_id=audit_template4.id,
id=self._generate_id(),
strategy_id=self.strategy1.id, id=self._generate_id(),
uuid=utils.generate_uuid())
action_plan4 = obj_utils.create_test_action_plan(
self.context,
@@ -289,7 +289,7 @@ class TestPurgeCommand(base.DbTestCase):
uuid=utils.generate_uuid())
audit5 = obj_utils.create_test_audit(
self.context, audit_template_id=audit_template5.id,
id=self._generate_id(),
strategy_id=self.strategy1.id, id=self._generate_id(),
uuid=utils.generate_uuid())
action_plan5 = obj_utils.create_test_action_plan(
self.context,
@@ -362,7 +362,7 @@ class TestPurgeCommand(base.DbTestCase):
with freezegun.freeze_time(self.fake_today):
# orphan audit template
audit_template4 = obj_utils.create_test_audit_template(
self.context, goal_id=self.goal2.id, # Does not exist
self.context, goal_id=self.goal2.id,
name=self.generate_unique_name(prefix="Audit Template 4 "),
strategy_id=None, id=self._generate_id(),
uuid=utils.generate_uuid())
@@ -386,7 +386,7 @@ class TestPurgeCommand(base.DbTestCase):
uuid=utils.generate_uuid())
audit5 = obj_utils.create_test_audit(
self.context, audit_template_id=audit_template5.id,
id=self._generate_id(),
strategy_id=self.strategy1.id, id=self._generate_id(),
uuid=utils.generate_uuid())
action_plan5 = obj_utils.create_test_action_plan(
self.context,

View File

@@ -102,7 +102,7 @@ def create_test_audit(**kwargs):
def get_test_action(**kwargs):
return {
action_data = {
'id': kwargs.get('id', 1),
'uuid': kwargs.get('uuid', '10a47dd1-4874-4298-91cf-eff046dbdb8d'),
'action_plan_id': kwargs.get('action_plan_id', 1),
@@ -120,6 +120,13 @@ def get_test_action(**kwargs):
'deleted_at': kwargs.get('deleted_at'),
}
# ObjectField doesn't allow None nor dict, so if we want to simulate a
# non-eager object loading, the field should not be referenced at all.
if kwargs.get('action_plan'):
action_data['action_plan'] = kwargs.get('action_plan')
return action_data
def create_test_action(**kwargs):
"""Create test action entry in DB and return Action DB object.