BIOS Settings: Add DB model

Adds the following items for BIOS Setting operations:

* bios_settings table
* database migration
* BIOSSetting object entry

Co-Authored-By: Yolanda Robla Mota <yroblamo@redhat.com>
Depends-On: I48c96d5da0cb747b3ca3fceea9b4ffa85a9ebe22
Change-Id: Ia2c14c5674e34decaa075c2754e7a552bbb1beab
Story: #1712032
This commit is contained in:
zshi 2017-10-11 15:39:54 +08:00 committed by Zenghui Shi
parent 084c9161f1
commit 3ca9ec58f3
4 changed files with 92 additions and 1 deletions

View File

@ -0,0 +1,42 @@
# 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 bios settings
Revision ID: 82c315d60161
Revises: e918ff30eb42
Create Date: 2017-10-11 14:56:47.813290
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '82c315d60161'
down_revision = 'e918ff30eb42'
def upgrade():
op.create_table(
'bios_settings',
sa.Column('node_id', sa.Integer(), nullable=False),
sa.Column('created_at', sa.DateTime(), nullable=True),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('name', sa.String(length=255), nullable=False),
sa.Column('value', sa.Text(), nullable=True),
sa.Column('version', sa.String(length=15), nullable=True),
sa.ForeignKeyConstraint(['node_id'], ['nodes.id'], ),
sa.PrimaryKeyConstraint('node_id', 'name'),
mysql_ENGINE='InnoDB',
mysql_DEFAULT_CHARSET='UTF8'
)

View File

@ -300,6 +300,17 @@ class NodeTrait(Base):
)
class BIOSSetting(Base):
"""Represents a bios setting of a bare metal node."""
__tablename__ = 'bios_settings'
__table_args__ = (table_args())
node_id = Column(Integer, ForeignKey('nodes.id'),
primary_key=True, nullable=False)
name = Column(String(255), primary_key=True, nullable=False)
value = Column(Text, nullable=True)
def get_class(model_name):
"""Returns the model class with the specified name.

View File

@ -84,7 +84,7 @@ class ReleaseMappingsTestCase(base.TestCase):
self.assertIn('master', release_mappings.RELEASE_MAPPING)
model_names = set((s.__name__ for s in models.Base.__subclasses__()))
exceptions = set(['NodeTag', 'ConductorHardwareInterfaces',
'NodeTrait'])
'NodeTrait', 'BIOSSetting'])
# NOTE(xek): As a rule, all models which can be changed between
# releases or are sent through RPC should have their counterpart
# versioned objects.

View File

@ -667,6 +667,44 @@ class MigrationCheckersMixin(object):
node_traits.c.node_id == data['id']).execute().first()
self.assertEqual('trait1', trait['trait'])
def _pre_upgrade_82c315d60161(self, engine):
# Create a node to which bios setting can be added.
data = {'uuid': uuidutils.generate_uuid()}
nodes = db_utils.get_table(engine, 'nodes')
nodes.insert().execute(data)
node = nodes.select(nodes.c.uuid == data['uuid']).execute().first()
data['id'] = node['id']
return data
def _check_82c315d60161(self, engine, data):
bios_settings = db_utils.get_table(engine, 'bios_settings')
col_names = [column.name for column in bios_settings.c]
expected_names = ['node_id', 'created_at', 'updated_at',
'name', 'value', 'version']
self.assertEqual(sorted(expected_names), sorted(col_names))
self.assertIsInstance(bios_settings.c.node_id.type,
sqlalchemy.types.Integer)
self.assertIsInstance(bios_settings.c.created_at.type,
sqlalchemy.types.DateTime)
self.assertIsInstance(bios_settings.c.updated_at.type,
sqlalchemy.types.DateTime)
self.assertIsInstance(bios_settings.c.name.type,
sqlalchemy.types.String)
self.assertIsInstance(bios_settings.c.version.type,
sqlalchemy.types.String)
self.assertIsInstance(bios_settings.c.value.type,
sqlalchemy.types.Text)
setting = {'node_id': data['id'],
'name': 'virtualization',
'value': 'on'}
bios_settings.insert().execute(setting)
setting = bios_settings.select(
sqlalchemy.sql.and_(
bios_settings.c.node_id == data['id'],
bios_settings.c.name == setting['name'])).execute().first()
self.assertEqual('on', setting['value'])
def test_upgrade_and_version(self):
with patch_with_engine(self.engine):
self.migration_api.upgrade('head')