Merge "Add online data migration for populating services.uuid"
This commit is contained in:
commit
dfc3a05fe8
@ -620,6 +620,8 @@ class DbCommands(object):
|
||||
# NOTE(mriedem): This online migration is going to be backported to
|
||||
# Newton also since it's an upgrade issue when upgrading from Mitaka.
|
||||
build_request_obj.delete_build_requests_with_no_instance_uuid,
|
||||
# Added in Pike
|
||||
db.service_uuids_online_data_migration,
|
||||
)
|
||||
|
||||
def __init__(self):
|
||||
|
@ -2057,6 +2057,10 @@ def pcidevice_online_data_migration(context, max_count):
|
||||
return IMPL.pcidevice_online_data_migration(context, max_count)
|
||||
|
||||
|
||||
def service_uuids_online_data_migration(context, max_count):
|
||||
return IMPL.service_uuids_online_data_migration(context, max_count)
|
||||
|
||||
|
||||
####################
|
||||
|
||||
|
||||
|
@ -6524,6 +6524,24 @@ def archive_deleted_rows(max_rows=None):
|
||||
return table_to_rows_archived
|
||||
|
||||
|
||||
@pick_context_manager_writer
|
||||
def service_uuids_online_data_migration(context, max_count):
|
||||
from nova.objects import service
|
||||
|
||||
count_all = 0
|
||||
count_hit = 0
|
||||
|
||||
db_services = model_query(context, models.Service).filter_by(
|
||||
uuid=None).limit(max_count)
|
||||
for db_service in db_services:
|
||||
count_all += 1
|
||||
service_obj = service.Service._from_db_object(
|
||||
context, service.Service(), db_service)
|
||||
if 'uuid' in service_obj:
|
||||
count_hit += 1
|
||||
return count_all, count_hit
|
||||
|
||||
|
||||
####################
|
||||
|
||||
|
||||
|
@ -3764,6 +3764,43 @@ class ServiceTestCase(test.TestCase, ModelsObjectComparatorMixin):
|
||||
self.assertRaises(exception.ServiceTopicExists, db.service_create,
|
||||
self.ctxt, values)
|
||||
|
||||
def test_migrate_service_uuids(self):
|
||||
# Start with nothing.
|
||||
total, done = db.service_uuids_online_data_migration(self.ctxt, 10)
|
||||
self.assertEqual(0, total)
|
||||
self.assertEqual(0, done)
|
||||
|
||||
# Create two services, one with a uuid and one without.
|
||||
db.service_create(self.ctxt,
|
||||
dict(host='host1', binary='nova-compute',
|
||||
topic='compute', report_count=1,
|
||||
disabled=False))
|
||||
db.service_create(self.ctxt,
|
||||
dict(host='host2', binary='nova-compute',
|
||||
topic='compute', report_count=1,
|
||||
disabled=False, uuid=uuidsentinel.host2))
|
||||
|
||||
# Now migrate them, we should find one and update one.
|
||||
total, done = db.service_uuids_online_data_migration(
|
||||
self.ctxt, 10)
|
||||
self.assertEqual(1, total)
|
||||
self.assertEqual(1, done)
|
||||
|
||||
# Get the services back to make sure the original uuid didn't change.
|
||||
services = db.service_get_all_by_binary(self.ctxt, 'nova-compute')
|
||||
self.assertEqual(2, len(services))
|
||||
for service in services:
|
||||
if service['host'] == 'host2':
|
||||
self.assertEqual(uuidsentinel.host2, service['uuid'])
|
||||
else:
|
||||
self.assertIsNotNone(service['uuid'])
|
||||
|
||||
# Run the online migration again to see nothing was processed.
|
||||
total, done = db.service_uuids_online_data_migration(
|
||||
self.ctxt, 10)
|
||||
self.assertEqual(0, total)
|
||||
self.assertEqual(0, done)
|
||||
|
||||
|
||||
class BaseInstanceTypeTestCase(test.TestCase, ModelsObjectComparatorMixin):
|
||||
def setUp(self):
|
||||
|
@ -0,0 +1,6 @@
|
||||
---
|
||||
upgrade:
|
||||
- |
|
||||
An online data migration has been added to populate the ``services.uuid``
|
||||
column in the nova database for non-deleted services records. Listing or
|
||||
showing services out of the ``os-services`` API will have the same effect.
|
Loading…
x
Reference in New Issue
Block a user