diff --git a/nova/cmd/manage.py b/nova/cmd/manage.py index f4b41d1f7b..4c0d186a8e 100644 --- a/nova/cmd/manage.py +++ b/nova/cmd/manage.py @@ -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 diff --git a/nova/db/api.py b/nova/db/api.py index ce5ef5e15b..fd285e53d9 100644 --- a/nova/db/api.py +++ b/nova/db/api.py @@ -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) - - #################### diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py index 754fac7eba..80dad6dc58 100644 --- a/nova/db/sqlalchemy/api.py +++ b/nova/db/sqlalchemy/api.py @@ -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 - - #################### diff --git a/nova/objects/aggregate.py b/nova/objects/aggregate.py index 943d0c7132..7f34c06cea 100644 --- a/nova/objects/aggregate.py +++ b/nova/objects/aggregate.py @@ -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): diff --git a/nova/tests/functional/db/test_aggregate.py b/nova/tests/functional/db/test_aggregate.py index ab05e53673..3cfc7e10f5 100644 --- a/nova/tests/functional/db/test_aggregate.py +++ b/nova/tests/functional/db/test_aggregate.py @@ -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) diff --git a/nova/tests/unit/api/openstack/compute/test_availability_zone.py b/nova/tests/unit/api/openstack/compute/test_availability_zone.py index 9a33b49f2d..d52f07239b 100644 --- a/nova/tests/unit/api/openstack/compute/test_availability_zone.py +++ b/nova/tests/unit/api/openstack/compute/test_availability_zone.py @@ -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 diff --git a/nova/tests/unit/db/test_db_api.py b/nova/tests/unit/db/test_db_api.py index 259f730d5e..46f4358f1c 100644 --- a/nova/tests/unit/db/test_db_api.py +++ b/nova/tests/unit/db/test_db_api.py @@ -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): diff --git a/nova/tests/unit/objects/test_aggregate.py b/nova/tests/unit/objects/test_aggregate.py index ebcd1e9031..6f6d1bdd2d 100644 --- a/nova/tests/unit/objects/test_aggregate.py +++ b/nova/tests/unit/objects/test_aggregate.py @@ -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): diff --git a/nova/tests/unit/test_availability_zones.py b/nova/tests/unit/test_availability_zones.py index 25b15fdc9d..f93d3d3283 100644 --- a/nova/tests/unit/test_availability_zones.py +++ b/nova/tests/unit/test_availability_zones.py @@ -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}