From: ankitagrawal Date: Tue, 4 Aug 2015 11:20:12 +0000 (-0700) Subject: Fix list comparison for empty list X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=fbeb889b97be977574b2147daa05e38be3c0c6f2;p=openstack-build%2Fcinder-build.git Fix list comparison for empty list Replaced boolean expression with 'not fields' in "_filter" method. Also updated unit test cases which calls "_filter" method with expected value of fields in restore methods. The unit test "test_restore_vol_meta" was failing for empty list because after updating the volume metadata, container was passed to the "_restore_vol_meta" method where "metadata" is expected. So fixed this unit test by passing the expected value to the "_restore_vol_meta" method. Closes-Bug: 1482619 Change-Id: I95c3a390b0b75c0514a3d63699367081440bf414 --- diff --git a/cinder/backup/driver.py b/cinder/backup/driver.py index ebbc25c81..7ec321f34 100644 --- a/cinder/backup/driver.py +++ b/cinder/backup/driver.py @@ -151,7 +151,7 @@ class BackupMetadataAPI(base.Base): If fields is empty list, the full set is returned. """ - if fields == []: + if not fields: return metadata subset = {} diff --git a/cinder/tests/unit/test_backup_driver_base.py b/cinder/tests/unit/test_backup_driver_base.py index b19664e17..b9a68d2b2 100644 --- a/cinder/tests/unit/test_backup_driver_base.py +++ b/cinder/tests/unit/test_backup_driver_base.py @@ -206,7 +206,8 @@ class BackupMetadataAPITestCase(test.TestCase): func({}, self.volume_id, fields) def test_restore_vol_glance_meta(self): - fields = {} + # Fields is an empty list for _restore_vol_glance_meta method. + fields = [] container = {} self.bak_meta_api._save_vol_glance_meta(container, self.volume_id) self.bak_meta_api._restore_vol_glance_meta(container, self.volume_id, @@ -217,16 +218,24 @@ class BackupMetadataAPITestCase(test.TestCase): fields) def test_restore_vol_meta(self): - fields = {} + # Fields is an empty list for _restore_vol_meta method. + fields = [] container = {} self.bak_meta_api._save_vol_meta(container, self.volume_id) - self.bak_meta_api._restore_vol_meta(container, self.volume_id, fields) + # Extract volume metadata from container. + metadata = container.get('volume-metadata', {}) + self.bak_meta_api._restore_vol_meta(metadata, self.volume_id, + fields) self._add_metadata(vol_meta=True) self.bak_meta_api._save_vol_meta(container, self.volume_id) - self.bak_meta_api._restore_vol_meta(container, self.volume_id, fields) + # Extract volume metadata from container. + metadata = container.get('volume-metadata', {}) + self.bak_meta_api._restore_vol_meta(metadata, self.volume_id, fields) def test_restore_vol_base_meta(self): - fields = {} + # Fields is a list with 'encryption_key_id' for + # _restore_vol_base_meta method. + fields = ['encryption_key_id'] container = {} self.bak_meta_api._save_vol_base_meta(container, self.volume_id) self.bak_meta_api._restore_vol_base_meta(container, self.volume_id,