Merge "Remove aggregate uuid generation on load from DB"
This commit is contained in:
commit
a2d8680cc6
nova
@ -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
|
||||
|
@ -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)
|
||||
|
||||
|
||||
####################
|
||||
|
||||
|
||||
|
@ -6516,25 +6516,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
|
||||
|
||||
|
||||
####################
|
||||
|
||||
|
||||
|
@ -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):
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
||||
|
@ -9819,19 +9819,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):
|
||||
|
@ -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):
|
||||
|
@ -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}
|
||||
|
Loading…
x
Reference in New Issue
Block a user