Remove aggregate uuid generation on load from DB

As the comments in the code suggest, we can remove this
code now. There was a blocking database migration which
enforced that the online data migrations to generate
uuids for aggregates has been completed:

4d0915568a

So this code is safe to remove now. As a result, we
also remove the online data migration routine which
relies on the object code.

Change-Id: I2050b5bdf906d2d2f8a87c79ca0804e0fc955755
This commit is contained in:
Matt Riedemann 2017-04-10 18:16:01 -04:00
parent 496bfb6287
commit 0d259d4cfb
9 changed files with 7 additions and 73 deletions

View File

@ -594,8 +594,6 @@ class DbCommands(object):
"""Class for managing the main database."""
online_migrations = (
# Added in Mitaka
db.aggregate_uuids_online_data_migration,
# Added in Newton
flavor_obj.migrate_flavors,
# Added in Newton

View File

@ -2044,10 +2044,6 @@ def pcidevice_online_data_migration(context, max_count):
return IMPL.pcidevice_online_data_migration(context, max_count)
def aggregate_uuids_online_data_migration(context, max_count):
return IMPL.aggregate_uuids_online_data_migration(context, max_count)
####################

View File

@ -6515,25 +6515,6 @@ def archive_deleted_rows(max_rows=None):
return table_to_rows_archived
@pick_context_manager_writer
def aggregate_uuids_online_data_migration(context, max_count):
from nova.objects import aggregate
count_all = 0
count_hit = 0
results = model_query(context, models.Aggregate).filter_by(
uuid=None).limit(max_count)
for db_agg in results:
count_all += 1
agg = aggregate.Aggregate._from_db_object(context,
aggregate.Aggregate(),
db_agg)
if 'uuid' in agg:
count_hit += 1
return count_all, count_hit
####################

View File

@ -258,20 +258,12 @@ class Aggregate(base.NovaPersistentObject, base.NovaObject):
for key in aggregate.fields:
if key == 'metadata':
db_key = 'metadetails'
elif key == 'uuid':
continue
elif key in DEPRECATED_FIELDS and key not in db_aggregate:
continue
else:
db_key = key
setattr(aggregate, key, db_aggregate[db_key])
# NOTE(danms): Remove this conditional load (and remove uuid
# special cases above) once we're in Newton and have enforced
# that all UUIDs in the database are not NULL.
if db_aggregate.get('uuid'):
aggregate.uuid = db_aggregate['uuid']
# NOTE: This can be removed when we remove compatibility with
# the old aggregate model.
if any(f not in db_aggregate for f in DEPRECATED_FIELDS):
@ -281,16 +273,6 @@ class Aggregate(base.NovaPersistentObject, base.NovaObject):
aggregate._context = context
aggregate.obj_reset_changes()
# NOTE(danms): This needs to come after obj_reset_changes() to make
# sure we only save the uuid, if we generate one.
# FIXME(danms): Remove this in Newton once we have enforced that
# all aggregates have uuids set in the database.
if 'uuid' not in aggregate:
aggregate.uuid = uuidutils.generate_uuid()
LOG.debug('Generating UUID %(uuid)s for aggregate %(agg)i',
dict(uuid=aggregate.uuid, agg=aggregate.id))
aggregate.save()
return aggregate
def _assert_no_hosts(self, action):

View File

@ -609,7 +609,8 @@ class AggregateMigrationTestCase(test.TestCase):
self.context = context.get_admin_context()
def test_migration(self):
db.aggregate_create(self.context, {'name': 'foo'})
db.aggregate_create(self.context, {'name': 'foo',
'uuid': uuidsentinel.agg_uuid})
main_aggregates_len = len(db.aggregate_get_all(self.context))
match, done = aggregate_obj.migrate_aggregates(self.context, 50)
self.assertEqual(1, main_aggregates_len)

View File

@ -31,6 +31,7 @@ from nova.tests.unit.api.openstack import fakes
from nova.tests.unit.image import fake
from nova.tests.unit import matchers
from nova.tests.unit.objects import test_service
from nova.tests import uuidsentinel
FAKE_UUID = fakes.FAKE_UUID
@ -229,7 +230,8 @@ class ServersControllerCreateTestV21(test.TestCase):
'topic': 'compute',
'report_count': 0})
agg = db.aggregate_create(admin_context,
{'name': 'agg1'}, {'availability_zone': 'nova'})
{'name': 'agg1', 'uuid': uuidsentinel.agg_uuid},
{'availability_zone': 'nova'})
db.aggregate_host_add(admin_context, agg['id'], 'host1_zones')
return self.req, body

View File

@ -9795,19 +9795,6 @@ class PciDeviceDBApiTestCase(test.TestCase, ModelsObjectComparatorMixin):
db.pci_device_update(self.admin_context, v['compute_node_id'],
v['address'], v)
def test_migrate_aggregates(self):
db.aggregate_create(self.context, {'name': 'foo'})
db.aggregate_create(self.context, {'name': 'bar',
'uuid': 'fake-uuid'})
total, done = db.aggregate_uuids_online_data_migration(
self.context, 10)
self.assertEqual(1, total)
self.assertEqual(1, done)
total, done = db.aggregate_uuids_online_data_migration(
self.context, 10)
self.assertEqual(0, total)
self.assertEqual(0, done)
@mock.patch('time.sleep', new=lambda x: None)
class RetryOnDeadlockTestCase(test.TestCase):

View File

@ -75,20 +75,6 @@ class _TestAggregateObject(object):
mock_get_api.assert_called_once_with(self.context, 123)
mock_get.assert_called_once_with(self.context, 123)
@mock.patch('nova.objects.Aggregate.save')
@mock.patch('nova.db.aggregate_get')
def test_load_allocates_uuid(self, mock_get, mock_save):
fake_agg = dict(fake_aggregate)
del fake_agg['uuid']
mock_get.return_value = fake_agg
uuid = uuidsentinel.aggregate
with mock.patch('oslo_utils.uuidutils.generate_uuid') as mock_g:
mock_g.return_value = uuid
obj = aggregate.Aggregate.get_by_id(self.context, 123)
mock_g.assert_called_once_with()
self.assertEqual(uuid, obj.uuid)
mock_save.assert_called_once_with()
@mock.patch('nova.objects.aggregate._aggregate_get_from_db_by_uuid')
@mock.patch('nova.db.aggregate_get_by_uuid')
def test_get_by_uuid(self, get_by_uuid, get_by_uuid_api):

View File

@ -26,6 +26,7 @@ from nova import context
from nova import db
from nova import objects
from nova import test
from nova.tests import uuidsentinel
CONF = nova.conf.CONF
@ -47,7 +48,7 @@ class AvailabilityZoneTestCases(test.TestCase):
super(AvailabilityZoneTestCases, self).tearDown()
def _create_az(self, agg_name, az_name):
agg_meta = {'name': agg_name}
agg_meta = {'name': agg_name, 'uuid': uuidsentinel.agg_uuid}
agg = db.aggregate_create(self.context, agg_meta)
metadata = {'availability_zone': az_name}