Skip to content

Commit

Permalink
Add blocker migration to ensure for newton online migrations
Browse files Browse the repository at this point in the history
This adds a blocking schema migration to validate that all online
migrations required to be done in newton were finished before allowing
us to move on to ocata.

Change-Id: Iab714d9e752c334cc1cc14a0d524cc9cf5d115dc
  • Loading branch information
kk7ds committed Sep 23, 2016
1 parent 3db8995 commit be8242c
Show file tree
Hide file tree
Showing 3 changed files with 157 additions and 0 deletions.
@@ -0,0 +1,68 @@
# 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.

# This is a placeholder for backports.
# Do not use this number for new work. New work starts after
# all the placeholders.
#
# See this for more information:
# http://lists.openstack.org/pipermail/openstack-dev/2013-March/006827.html

from sqlalchemy import MetaData, Table, func, select

from nova import exception
from nova.i18n import _


def upgrade(migrate_engine):
meta = MetaData(migrate_engine)
instance_types = Table('instance_types', meta, autoload=True)
keypairs = Table('key_pairs', meta, autoload=True)
aggregates = Table('aggregates', meta, autoload=True)
instance_groups = Table('instance_groups', meta, autoload=True)

base_msg = _('Migration cannot continue until all these have '
'been migrated to the api database. Please run '
'`nova-manage db online_migrations\' on Newton '
'code before continuing.')

count = select([func.count()]).select_from(instance_types).where(
instance_types.c.deleted == 0).scalar()
if count:
msg = (base_msg +
_('There are still %(count)i unmigrated flavors. ') % {
'count': count})
raise exception.ValidationError(detail=msg)

count = select([func.count()]).select_from(keypairs).where(
keypairs.c.deleted == 0).scalar()
if count:
msg = (base_msg +
_('There are still %(count)i unmigrated keypairs. ') % {
'count': count})
raise exception.ValidationError(detail=msg)

count = select([func.count()]).select_from(aggregates).where(
aggregates.c.deleted == 0).scalar()
if count:
msg = (base_msg +
_('There are still %(count)i unmigrated aggregates. ') % {
'count': count})
raise exception.ValidationError(detail=msg)

count = select([func.count()]).select_from(instance_groups).where(
instance_groups.c.deleted == 0).scalar()
if count:
msg = (base_msg +
_('There are still %(count)i unmigrated instance groups. ') % {
'count': count})
raise exception.ValidationError(detail=msg)
4 changes: 4 additions & 0 deletions nova/tests/unit/db/test_migrations.py
Expand Up @@ -920,6 +920,10 @@ def _check_334(self, engine, data):
self.assertColumnExists(engine, 'shadow_instance_extra',
'device_metadata')

def _check_345(self, engine, data):
# NOTE(danms): Just a sanity-check migration
pass


class TestNovaMigrationsSQLite(NovaMigrationsCheckers,
test_base.DbTestCase,
Expand Down
85 changes: 85 additions & 0 deletions nova/tests/unit/db/test_sqlalchemy_migration.py
Expand Up @@ -29,6 +29,7 @@
from nova import objects
from nova import test
from nova.tests import fixtures as nova_fixtures
from nova.tests import uuidsentinel


class TestNullInstanceUuidScanDB(test.TestCase):
Expand Down Expand Up @@ -280,3 +281,87 @@ def test_pci_device_not_migrated(self):
'status': 'whatisthis?'})
self.assertRaises(exception.ValidationError,
self.migration.upgrade, self.engine)


class TestOcataCheck(test.TestCase):
def setUp(self):
super(TestOcataCheck, self).setUp()
self.context = context.get_admin_context()
self.migration = importlib.import_module(
'nova.db.sqlalchemy.migrate_repo.versions.'
'345_require_online_migration_completion')
self.engine = db_api.get_engine()
self.flavor_values = {
'name': 'foo',
'memory_mb': 256,
'vcpus': 1,
'root_gb': 10,
'ephemeral_gb': 100,
'flavorid': 'bar',
'swap': 1,
'rxtx_factor': 1.0,
'vcpu_weight': 1,
'disabled': False,
'is_public': True,
}
self.keypair_values = {
'name': 'foo',
'user_ud': 'bar',
'fingerprint': 'baz',
'public_key': 'bat',
'type': 'ssh',
}
self.aggregate_values = {
'uuid': uuidsentinel.agg,
'name': 'foo',
}
self.ig_values = {
'user_id': 'foo',
'project_id': 'bar',
'uuid': uuidsentinel.ig,
'name': 'baz',
}

def test_upgrade_clean(self):
self.migration.upgrade(self.engine)

def test_upgrade_dirty_flavors(self):
db_api.flavor_create(self.context, self.flavor_values)
self.assertRaises(exception.ValidationError,
self.migration.upgrade, self.engine)

def test_upgrade_with_deleted_flavors(self):
flavor = db_api.flavor_create(self.context, self.flavor_values)
db_api.flavor_destroy(self.context, flavor['flavorid'])
self.migration.upgrade(self.engine)

def test_upgrade_dirty_keypairs(self):
db_api.key_pair_create(self.context, self.keypair_values)
self.assertRaises(exception.ValidationError,
self.migration.upgrade, self.engine)

def test_upgrade_with_deleted_keypairs(self):
keypair = db_api.key_pair_create(self.context, self.keypair_values)
db_api.key_pair_destroy(self.context,
keypair['user_id'], keypair['name'])
self.migration.upgrade(self.engine)

def test_upgrade_dirty_aggregates(self):
db_api.aggregate_create(self.context, self.aggregate_values)
self.assertRaises(exception.ValidationError,
self.migration.upgrade, self.engine)

def test_upgrade_with_deleted_aggregates(self):
agg = db_api.aggregate_create(self.context, self.aggregate_values)
db_api.aggregate_delete(self.context, agg['id'])
self.migration.upgrade(self.engine)

def test_upgrade_dirty_instance_groups(self):
db_api.instance_group_create(self.context, self.ig_values)
self.assertRaises(exception.ValidationError,
self.migration.upgrade, self.engine)

def test_upgrade_with_deleted_instance_groups(self):
group = db_api.instance_group_create(self.context, self.ig_values)
db_api.instance_group_delete(self.context, group['uuid'])
self.migration.upgrade(self.engine)

0 comments on commit be8242c

Please sign in to comment.