summaryrefslogtreecommitdiff
path: root/ironic/tests/unit/db/utils.py
diff options
context:
space:
mode:
authorMark Goddard <mark@stackhpc.com>2018-12-27 12:48:11 +0000
committerMark Goddard <mark@stackhpc.com>2019-02-13 19:26:21 +0000
commitb137af30b9ab6523e779ef3e63d0c569b92fb04b (patch)
tree2258c42bbdf07e25200c9ba64701b35b39d2a220 /ironic/tests/unit/db/utils.py
parent0d19732089f70422bd8344fbd8d53911f64c2453 (diff)
downloadironic-b137af30b9ab6523e779ef3e63d0c569b92fb04b.tar.gz
Deploy templates: data model, DB API & objects
Adds deploy_templates and deploy_template_steps tables to the database, provides a DB API for these tables, and a DeployTemplate versioned object. Change-Id: I5b8b59bbea1594b1220438050b80f1c603dbc346 Story: 1722275 Task: 28674
Diffstat (limited to 'ironic/tests/unit/db/utils.py')
-rw-r--r--ironic/tests/unit/db/utils.py49
1 files changed, 49 insertions, 0 deletions
diff --git a/ironic/tests/unit/db/utils.py b/ironic/tests/unit/db/utils.py
index 40fddf7c6..7b6be120a 100644
--- a/ironic/tests/unit/db/utils.py
+++ b/ironic/tests/unit/db/utils.py
@@ -25,6 +25,7 @@ from ironic.objects import allocation
from ironic.objects import bios
from ironic.objects import chassis
from ironic.objects import conductor
+from ironic.objects import deploy_template
from ironic.objects import node
from ironic.objects import port
from ironic.objects import portgroup
@@ -620,3 +621,51 @@ def create_test_allocation(**kw):
del allocation['id']
dbapi = db_api.get_instance()
return dbapi.create_allocation(allocation)
+
+
+def get_test_deploy_template(**kw):
+ return {
+ 'version': kw.get('version', deploy_template.DeployTemplate.VERSION),
+ 'created_at': kw.get('created_at'),
+ 'updated_at': kw.get('updated_at'),
+ 'id': kw.get('id', 234),
+ 'name': kw.get('name', u'CUSTOM_DT1'),
+ 'uuid': kw.get('uuid', 'aa75a317-2929-47d4-b676-fd9bff578bf1'),
+ 'steps': kw.get('steps', [get_test_deploy_template_step(
+ deploy_template_id=kw.get('id', 234))]),
+ }
+
+
+def get_test_deploy_template_step(**kw):
+ return {
+ 'created_at': kw.get('created_at'),
+ 'updated_at': kw.get('updated_at'),
+ 'id': kw.get('id', 345),
+ 'deploy_template_id': kw.get('deploy_template_id', 234),
+ 'interface': kw.get('interface', 'raid'),
+ 'step': kw.get('step', 'create_configuration'),
+ 'args': kw.get('args', {'logical_disks': []}),
+ 'priority': kw.get('priority', 10),
+ }
+
+
+def create_test_deploy_template(**kw):
+ """Create a deployment template in the DB and return DeployTemplate model.
+
+ :param kw: kwargs with overriding values for the deploy template.
+ :returns: Test DeployTemplate DB object.
+ """
+ template = get_test_deploy_template(**kw)
+ dbapi = db_api.get_instance()
+ # Let DB generate an ID if one isn't specified explicitly.
+ if 'id' not in kw:
+ del template['id']
+ if 'steps' not in kw:
+ for step in template['steps']:
+ del step['id']
+ del step['deploy_template_id']
+ else:
+ for kw_step, template_step in zip(kw['steps'], template['steps']):
+ if 'id' not in kw_step:
+ del template_step['id']
+ return dbapi.create_deploy_template(template, template['version'])