Merge "Add conductor_group field to nodes and conductors tables"

This commit is contained in:
Zuul 2018-07-16 12:55:45 +00:00 committed by Gerrit Code Review
commit 67045c3a55
3 changed files with 73 additions and 0 deletions

View File

@ -0,0 +1,35 @@
# All Rights Reserved.
#
# 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 conductor_group to nodes/conductors
Revision ID: 664f85c2f622
Revises: fb3f10dd262e
Create Date: 2018-07-02 13:21:54.847245
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '664f85c2f622'
down_revision = 'b9117ac17882'
def upgrade():
op.add_column('conductors', sa.Column('conductor_group',
sa.String(length=255), server_default='', nullable=False))
op.add_column('nodes', sa.Column('conductor_group', sa.String(length=255),
server_default='', nullable=False))

View File

@ -92,6 +92,8 @@ class Conductor(Base):
hostname = Column(String(255), nullable=False)
drivers = Column(db_types.JsonEncodedList)
online = Column(Boolean, default=True)
conductor_group = Column(String(255), nullable=False, default='',
server_default='')
class ConductorHardwareInterfaces(Base):
@ -163,6 +165,8 @@ class Node(Base):
ForeignKey('conductors.id',
name='nodes_conductor_affinity_fk'),
nullable=True)
conductor_group = Column(String(255), nullable=False, default='',
server_default='')
maintenance = Column(Boolean, default=False)
maintenance_reason = Column(Text, nullable=True)

View File

@ -726,6 +726,40 @@ class MigrationCheckersMixin(object):
self.assertIsInstance(nodes.c.deploy_step.type,
sqlalchemy.types.String)
def _pre_upgrade_664f85c2f622(self, engine):
# Create a node and a conductor to verify existing records
# get a conductor_group of ""
data = {
'conductor_id': 98765432,
'node_uuid': uuidutils.generate_uuid(),
}
nodes = db_utils.get_table(engine, 'nodes')
nodes.insert().execute({'uuid': data['node_uuid']})
conductors = db_utils.get_table(engine, 'conductors')
conductors.insert().execute({'id': data['conductor_id'],
'hostname': uuidutils.generate_uuid()})
return data
def _check_664f85c2f622(self, engine, data):
nodes_tbl = db_utils.get_table(engine, 'nodes')
conductors_tbl = db_utils.get_table(engine, 'conductors')
for tbl in (nodes_tbl, conductors_tbl):
col_names = [column.name for column in tbl.c]
self.assertIn('conductor_group', col_names)
self.assertIsInstance(tbl.c.conductor_group.type,
sqlalchemy.types.String)
node = nodes_tbl.select(
nodes_tbl.c.uuid == data['node_uuid']).execute().first()
self.assertEqual(node['conductor_group'], "")
conductor = conductors_tbl.select(
conductors_tbl.c.id == data['conductor_id']).execute().first()
self.assertEqual(conductor['conductor_group'], "")
def test_upgrade_and_version(self):
with patch_with_engine(self.engine):
self.migration_api.upgrade('head')