Merge "Add uuid online migration for migrations"
This commit is contained in:
@@ -82,6 +82,7 @@ from nova import config
|
||||
from nova import context
|
||||
from nova import db
|
||||
from nova.db import migration
|
||||
from nova.db.sqlalchemy import api as sa_db
|
||||
from nova import exception
|
||||
from nova.i18n import _
|
||||
from nova import objects
|
||||
@@ -666,6 +667,8 @@ class DbCommands(object):
|
||||
quotas_obj.migrate_quota_limits_to_api_db,
|
||||
# Added in Pike
|
||||
quotas_obj.migrate_quota_classes_to_api_db,
|
||||
# Added in Queens
|
||||
sa_db.migration_migrate_to_uuid,
|
||||
)
|
||||
|
||||
def __init__(self):
|
||||
|
||||
@@ -4821,6 +4821,25 @@ def migration_get_all_by_filters(context, filters):
|
||||
return query.all()
|
||||
|
||||
|
||||
@pick_context_manager_writer
|
||||
def migration_migrate_to_uuid(context, count):
|
||||
# Avoid circular import
|
||||
from nova import objects
|
||||
|
||||
db_migrations = model_query(context, models.Migration).filter_by(
|
||||
uuid=None).limit(count).all()
|
||||
|
||||
done = 0
|
||||
for db_migration in db_migrations:
|
||||
mig = objects.Migration(context)
|
||||
mig._from_db_object(context, mig, db_migration)
|
||||
done += 1
|
||||
|
||||
# We don't have any situation where we can (detectably) not
|
||||
# migrate a thing, so report anything that matched as "completed".
|
||||
return done, done
|
||||
|
||||
|
||||
##################
|
||||
|
||||
|
||||
|
||||
@@ -3826,6 +3826,38 @@ class ServiceTestCase(test.TestCase, ModelsObjectComparatorMixin):
|
||||
self.assertEqual(0, total)
|
||||
self.assertEqual(0, done)
|
||||
|
||||
def test_migration_migrate_to_uuid(self):
|
||||
total, done = sqlalchemy_api.migration_migrate_to_uuid(self.ctxt, 10)
|
||||
self.assertEqual(0, total)
|
||||
self.assertEqual(0, done)
|
||||
|
||||
# Create two migrations, one with a uuid and one without.
|
||||
db.migration_create(self.ctxt,
|
||||
dict(source_compute='src', source_node='srcnode',
|
||||
dest_compute='dst', dest_node='dstnode',
|
||||
status='running'))
|
||||
db.migration_create(self.ctxt,
|
||||
dict(source_compute='src', source_node='srcnode',
|
||||
dest_compute='dst', dest_node='dstnode',
|
||||
status='running',
|
||||
uuid=uuidsentinel.migration2))
|
||||
|
||||
# Now migrate them, we should find one and update one
|
||||
total, done = sqlalchemy_api.migration_migrate_to_uuid(self.ctxt, 10)
|
||||
self.assertEqual(1, total)
|
||||
self.assertEqual(1, done)
|
||||
|
||||
# Get the migrations back to make sure the original uuid didn't change.
|
||||
migrations = db.migration_get_all_by_filters(self.ctxt, {})
|
||||
uuids = [m.uuid for m in migrations]
|
||||
self.assertIn(uuidsentinel.migration2, uuids)
|
||||
self.assertNotIn(None, uuids)
|
||||
|
||||
# Run the online migration again to see nothing was processed.
|
||||
total, done = sqlalchemy_api.migration_migrate_to_uuid(self.ctxt, 10)
|
||||
self.assertEqual(0, total)
|
||||
self.assertEqual(0, done)
|
||||
|
||||
|
||||
class BaseInstanceTypeTestCase(test.TestCase, ModelsObjectComparatorMixin):
|
||||
def setUp(self):
|
||||
|
||||
Reference in New Issue
Block a user