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

@@ -61,7 +61,7 @@ def create_test_audit_template(**kwargs):
def get_test_audit(**kwargs):
return {
audit_data = {
'id': kwargs.get('id', 1),
'uuid': kwargs.get('uuid', '10a47dd1-4874-4298-91cf-eff046dbdb8d'),
'audit_type': kwargs.get('audit_type', 'ONESHOT'),
@@ -76,6 +76,15 @@ def get_test_audit(**kwargs):
'scope': kwargs.get('scope', []),
}
# 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('goal'):
audit_data['goal'] = kwargs.get('goal')
if kwargs.get('strategy'):
audit_data['strategy'] = kwargs.get('strategy')
return audit_data
def create_test_audit(**kwargs):
"""Create test audit entry in DB and return Audit DB object.