diff options
author | Eric Harney <eharney@redhat.com> | 2019-03-21 13:02:26 -0400 |
---|---|---|
committer | Rajat Dhasmana <rajatdhasmana@gmail.com> | 2020-07-08 09:23:01 +0000 |
commit | 69d0986e8f29e4dcc7fe22ed1b5dd407566eec06 (patch) | |
tree | 9d066efac608e9a0259aa06eba154dc2d1af98b6 | |
parent | 89bdebd2a92f83a199c86855a63fd3deab9a489c (diff) | |
download | cinder-69d0986e8f29e4dcc7fe22ed1b5dd407566eec06.tar.gz |
Fix service_uuid migration for volumes with no host
For volumes that have no host assigned, this
migration will fail. Skip those volumes, as they
don't need to be updated.
Closes-Bug: #1821207
Change-Id: I08487575e52c5cfd5a268a23d97b6bd931aeaa45
(cherry picked from commit 47d2a98fa63fb1bdf122c8a40bd06ea9c1709855)
(cherry picked from commit 997af3aa6b55d24c55c7cb9d179ca63819e40157)
(cherry picked from commit d70fc16718bce37404dd62aba24e2f0b7782a7cc)
-rw-r--r-- | cinder/db/sqlalchemy/api.py | 3 | ||||
-rw-r--r-- | cinder/tests/unit/test_db_api.py | 8 |
2 files changed, 8 insertions, 3 deletions
diff --git a/cinder/db/sqlalchemy/api.py b/cinder/db/sqlalchemy/api.py index 69fe9f7b1..cc502d9e8 100644 --- a/cinder/db/sqlalchemy/api.py +++ b/cinder/db/sqlalchemy/api.py @@ -621,7 +621,8 @@ def volume_service_uuids_online_data_migration(context, max_count): updated = 0 query = model_query(context, - models.Volume).filter_by(service_uuid=None) + models.Volume).filter_by(service_uuid=None).\ + filter(models.Volume.host.isnot(None)) total = query.count() vol_refs = query.limit(max_count).all() diff --git a/cinder/tests/unit/test_db_api.py b/cinder/tests/unit/test_db_api.py index 450e638ff..6731c9da3 100644 --- a/cinder/tests/unit/test_db_api.py +++ b/cinder/tests/unit/test_db_api.py @@ -494,6 +494,8 @@ class DBAPIServiceTestCase(BaseTest): self.ctxt, {'host': 'host1@lvm-driver1#lvm-driver1'}) db.volume_create( self.ctxt, {'host': 'host1@lvm-driver1#lvm-driver1'}) + # Entries with no host should be skipped + db.volume_create(self.ctxt, {'host': None}) values = { 'host': 'host1@lvm-driver1', @@ -506,12 +508,14 @@ class DBAPIServiceTestCase(BaseTest): total, updated = db.volume_service_uuids_online_data_migration( self.ctxt, 2) + # total = number of volumes that have hosts and don't have a + # service_uuid self.assertEqual(3, total) self.assertEqual(2, updated) - # Now get the ,last one (intentionally setting max > expected) + # Now get the last one (intentionally setting max > expected) total, updated = db.volume_service_uuids_online_data_migration( - self.ctxt, 2) + self.ctxt, 99) self.assertEqual(1, total) self.assertEqual(1, updated) |