From 45e6c14b60f615725e45ffeb2c272506a98cbec5 Mon Sep 17 00:00:00 2001 From: Matthew Booth Date: Sun, 17 Dec 2017 23:22:10 +0000 Subject: [PATCH] Add test for assignment of uuid to a deleted BDM We eventually want to make the BDM uuid column not nullable. This will require that there are no null values in the column, including in deleted BDMs. This change adds a test which asserts the online migration correctly assigns a uuid to soft deleted BDMs. Part of bp local-disk-serial-numbers Change-Id: Icf7dd4e3ecf0257d59f82cea80f76f12495594db --- nova/tests/unit/objects/test_block_device.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/nova/tests/unit/objects/test_block_device.py b/nova/tests/unit/objects/test_block_device.py index 574384383e63..961ae0150933 100644 --- a/nova/tests/unit/objects/test_block_device.py +++ b/nova/tests/unit/objects/test_block_device.py @@ -429,12 +429,16 @@ class TestBlockDeviceMappingUUIDMigration(test.TestCase): @staticmethod @db_api.pick_context_manager_writer - def _create_legacy_bdm(context): + def _create_legacy_bdm(context, deleted=False): # Create a BDM with no uuid values = {'instance_uuid': uuids.instance_uuid} bdm_ref = db_models.BlockDeviceMapping() bdm_ref.update(values) bdm_ref.save(context.session) + + if deleted: + bdm_ref.soft_delete(context.session) + return bdm_ref @mock.patch.object(objects.BlockDeviceMapping, '_create_uuid') @@ -512,6 +516,10 @@ class TestBlockDeviceMappingUUIDMigration(test.TestCase): # Run the online migration again to see nothing was processed self._assert_online_migration(0, 0) + # Assert that we assign a uuid to a deleted bdm. + self._create_legacy_bdm(self.context, deleted=True) + self._assert_online_migration(1, 1) + # Test that we don't migrate more than the limit for i in range(0, 3): self._create_legacy_bdm(self.context)