Merge "Deploy Templates: add 'extra' field to DB & object"

This commit is contained in:
Zuul 2019-02-27 05:57:57 +00:00 committed by Gerrit Code Review
commit 6afb2906bd
9 changed files with 60 additions and 3 deletions

View File

@ -138,7 +138,7 @@ RELEASE_MAPPING = {
'Node': ['1.32', '1.31', '1.30', '1.29', '1.28'],
'Conductor': ['1.3'],
'Chassis': ['1.3'],
'DeployTemplate': ['1.0'],
'DeployTemplate': ['1.0', '1.1'],
'Port': ['1.9'],
'Portgroup': ['1.4'],
'Trait': ['1.0'],

View File

@ -0,0 +1,31 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""add extra column to deploy_templates
Revision ID: 1e15e7122cc9
Revises: 2aac7e0872f6
Create Date: 2019-02-26 15:08:18.419157
"""
# revision identifiers, used by Alembic.
revision = '1e15e7122cc9'
down_revision = '2aac7e0872f6'
from alembic import op
import sqlalchemy as sa
def upgrade():
op.add_column('deploy_templates',
sa.Column('extra', sa.Text(), nullable=True))

View File

@ -361,6 +361,7 @@ class DeployTemplate(Base):
id = Column(Integer, primary_key=True)
uuid = Column(String(36))
name = Column(String(255), nullable=False)
extra = Column(db_types.JsonEncodedDict)
class DeployTemplateStep(Base):

View File

@ -20,7 +20,8 @@ from ironic.objects import fields as object_fields
@base.IronicObjectRegistry.register
class DeployTemplate(base.IronicObject, object_base.VersionedObjectDictCompat):
# Version 1.0: Initial version
VERSION = '1.0'
# Version 1.1: Added 'extra' field
VERSION = '1.1'
dbapi = db_api.get_instance()
@ -29,6 +30,7 @@ class DeployTemplate(base.IronicObject, object_base.VersionedObjectDictCompat):
'uuid': object_fields.UUIDField(nullable=False),
'name': object_fields.StringField(nullable=False),
'steps': object_fields.ListOfFlexibleDictsField(nullable=False),
'extra': object_fields.FlexibleDictField(nullable=True),
}
# NOTE(mgoddard): We don't want to enable RPC on this call just yet.

View File

@ -954,6 +954,16 @@ class MigrationCheckersMixin(object):
# Insert another step for the same template.
deploy_template_steps.insert().execute(step)
def _check_1e15e7122cc9(self, engine, data):
# Deploy template 'extra' field.
deploy_templates = db_utils.get_table(engine, 'deploy_templates')
col_names = [column.name for column in deploy_templates.c]
expected = ['created_at', 'updated_at', 'version',
'id', 'uuid', 'name', 'extra']
self.assertEqual(sorted(expected), sorted(col_names))
self.assertIsInstance(deploy_templates.c.extra.type,
sqlalchemy.types.TEXT)
def test_upgrade_and_version(self):
with patch_with_engine(self.engine):
self.migration_api.upgrade('head')

View File

@ -36,6 +36,7 @@ class DbDeployTemplateTestCase(base.DbTestCase):
self.assertEqual('create_configuration', step.step)
self.assertEqual({'logical_disks': []}, step.args)
self.assertEqual(10, step.priority)
self.assertEqual({}, self.template.extra)
def test_create_no_steps(self):
uuid = uuidutils.generate_uuid()
@ -104,6 +105,11 @@ class DbDeployTemplateTestCase(base.DbTestCase):
template = self.dbapi.update_deploy_template(self.template.id, values)
self.assertEqual([], template.steps)
def test_update_extra(self):
values = {'extra': {'foo': 'bar'}}
template = self.dbapi.update_deploy_template(self.template.id, values)
self.assertEqual({'foo': 'bar'}, template.extra)
def test_update_duplicate_name(self):
uuid = uuidutils.generate_uuid()
template2 = db_utils.create_test_deploy_template(uuid=uuid,

View File

@ -634,6 +634,7 @@ def get_test_deploy_template(**kw):
'uuid': kw.get('uuid', default_uuid),
'steps': kw.get('steps', [get_test_deploy_template_step(
deploy_template_id=kw.get('id', 234))]),
'extra': kw.get('extra', {}),
}

View File

@ -41,6 +41,7 @@ class TestDeployTemplateObject(db_base.DbTestCase, obj_utils.SchemasTestMixIn):
self.assertEqual(self.fake_template['name'], template.name)
self.assertEqual(self.fake_template['steps'], template.steps)
self.assertEqual(self.fake_template['extra'], template.extra)
@mock.patch.object(dbapi.IMPL, 'update_deploy_template', autospec=True)
def test_save(self, mock_update):
@ -80,6 +81,7 @@ class TestDeployTemplateObject(db_base.DbTestCase, obj_utils.SchemasTestMixIn):
self.assertEqual(self.fake_template['name'], template.name)
self.assertEqual(self.fake_template['uuid'], template.uuid)
self.assertEqual(self.fake_template['steps'], template.steps)
self.assertEqual(self.fake_template['extra'], template.extra)
@mock.patch.object(dbapi.IMPL, 'get_deploy_template_by_uuid',
autospec=True)
@ -93,6 +95,7 @@ class TestDeployTemplateObject(db_base.DbTestCase, obj_utils.SchemasTestMixIn):
self.assertEqual(self.fake_template['name'], template.name)
self.assertEqual(self.fake_template['uuid'], template.uuid)
self.assertEqual(self.fake_template['steps'], template.steps)
self.assertEqual(self.fake_template['extra'], template.extra)
@mock.patch.object(dbapi.IMPL, 'get_deploy_template_by_name',
autospec=True)
@ -106,6 +109,7 @@ class TestDeployTemplateObject(db_base.DbTestCase, obj_utils.SchemasTestMixIn):
self.assertEqual(self.fake_template['name'], template.name)
self.assertEqual(self.fake_template['uuid'], template.uuid)
self.assertEqual(self.fake_template['steps'], template.steps)
self.assertEqual(self.fake_template['extra'], template.extra)
@mock.patch.object(dbapi.IMPL, 'get_deploy_template_list', autospec=True)
def test_list(self, mock_list):
@ -119,6 +123,7 @@ class TestDeployTemplateObject(db_base.DbTestCase, obj_utils.SchemasTestMixIn):
self.assertEqual(self.fake_template['name'], templates[0].name)
self.assertEqual(self.fake_template['uuid'], templates[0].uuid)
self.assertEqual(self.fake_template['steps'], templates[0].steps)
self.assertEqual(self.fake_template['extra'], templates[0].extra)
@mock.patch.object(dbapi.IMPL, 'get_deploy_template_list_by_names',
autospec=True)
@ -133,6 +138,7 @@ class TestDeployTemplateObject(db_base.DbTestCase, obj_utils.SchemasTestMixIn):
self.assertEqual(self.fake_template['name'], templates[0].name)
self.assertEqual(self.fake_template['uuid'], templates[0].uuid)
self.assertEqual(self.fake_template['steps'], templates[0].steps)
self.assertEqual(self.fake_template['extra'], templates[0].extra)
@mock.patch.object(dbapi.IMPL, 'get_deploy_template_by_uuid',
autospec=True)

View File

@ -717,7 +717,7 @@ expected_object_fingerprints = {
'Allocation': '1.0-25ebf609743cd3f332a4f80fcb818102',
'AllocationCRUDNotification': '1.0-59acc533c11d306f149846f922739c15',
'AllocationCRUDPayload': '1.0-a82389d019f37cfe54b50049f73911b3',
'DeployTemplate': '1.0-c20a91a34a5518e13b2a1bf5072eb119',
'DeployTemplate': '1.1-4e30c8e9098595e359bb907f095bf1a9',
}