Merge "Set existing ports pxe_enabled=True when adding pxe_enabled column"
This commit is contained in:
commit
42db426bc2
|
@ -0,0 +1,38 @@
|
|||
# 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.
|
||||
|
||||
"""Set Port.pxe_enabled to True if NULL
|
||||
|
||||
Revision ID: f6fdb920c182
|
||||
Revises: 5ea1b0d310e
|
||||
Create Date: 2016-02-12 16:53:21.008580
|
||||
|
||||
"""
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = 'f6fdb920c182'
|
||||
down_revision = '5ea1b0d310e'
|
||||
|
||||
from alembic import op
|
||||
from sqlalchemy import Boolean, String
|
||||
from sqlalchemy.sql import table, column, null
|
||||
|
||||
port = table('ports',
|
||||
column('uuid', String(36)),
|
||||
column('pxe_enabled', Boolean()))
|
||||
|
||||
|
||||
def upgrade():
|
||||
op.execute(
|
||||
port.update().where(
|
||||
port.c.pxe_enabled == null()).values(
|
||||
{'pxe_enabled': True}))
|
|
@ -393,6 +393,27 @@ class MigrationCheckersMixin(object):
|
|||
isinstance(ports.c.pxe_enabled.type,
|
||||
sqlalchemy.types.Integer))
|
||||
|
||||
def _pre_upgrade_f6fdb920c182(self, engine):
|
||||
# add some ports.
|
||||
ports = db_utils.get_table(engine, 'ports')
|
||||
data = [{'uuid': uuidutils.generate_uuid(), 'pxe_enabled': None},
|
||||
{'uuid': uuidutils.generate_uuid(), 'pxe_enabled': None}]
|
||||
ports.insert().values(data).execute()
|
||||
return data
|
||||
|
||||
def _check_f6fdb920c182(self, engine, data):
|
||||
ports = db_utils.get_table(engine, 'ports')
|
||||
result = engine.execute(ports.select())
|
||||
|
||||
def _was_inserted(uuid):
|
||||
for row in data:
|
||||
if row['uuid'] == uuid:
|
||||
return True
|
||||
|
||||
for row in result:
|
||||
if _was_inserted(row['uuid']):
|
||||
self.assertTrue(row['pxe_enabled'])
|
||||
|
||||
def test_upgrade_and_version(self):
|
||||
with patch_with_engine(self.engine):
|
||||
self.migration_api.upgrade('head')
|
||||
|
|
Loading…
Reference in New Issue