diff options
author | Zuul <zuul@review.opendev.org> | 2023-02-16 11:53:32 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2023-02-16 11:53:32 +0000 |
commit | 410b23cfbdf371f418c7d467d45f9c6c05b5c3cc (patch) | |
tree | 25b472d71db9dc713ba27be837941a1103ba0499 | |
parent | 81da9ccbdee88e77f06e42c4f121b68cf2c1389e (diff) | |
parent | 399438cd044f52915e202650db407eccd3e26c95 (diff) | |
download | glance-410b23cfbdf371f418c7d467d45f9c6c05b5c3cc.tar.gz |
Merge "Fix E741 issues"
-rw-r--r-- | glance/db/__init__.py | 4 | ||||
-rw-r--r-- | glance/db/sqlalchemy/api.py | 3 | ||||
-rw-r--r-- | glance/tests/functional/db/base.py | 12 | ||||
-rw-r--r-- | glance/tests/unit/test_db.py | 44 |
4 files changed, 36 insertions, 27 deletions
diff --git a/glance/db/__init__.py b/glance/db/__init__.py index d5d7b9210..d1e8c2400 100644 --- a/glance/db/__init__.py +++ b/glance/db/__init__.py @@ -103,8 +103,8 @@ class ImageRepo(object): if loc['status'] == 'active'] if CONF.metadata_encryption_key: key = CONF.metadata_encryption_key - for l in locations: - l['url'] = crypt.urlsafe_decrypt(key, l['url']) + for location in locations: + location['url'] = crypt.urlsafe_decrypt(key, location['url']) # NOTE(danms): If the image is shared and we are not the # owner, we must have found it because we are a member. Set diff --git a/glance/db/sqlalchemy/api.py b/glance/db/sqlalchemy/api.py index 8630fb69e..d01503fc5 100644 --- a/glance/db/sqlalchemy/api.py +++ b/glance/db/sqlalchemy/api.py @@ -739,7 +739,8 @@ def _image_get_disk_usage_by_owner(owner, session, image_id=None): total = 0 for i in images: - locations = [l for l in i.locations if l['status'] != 'deleted'] + locations = [location for location in i.locations + if location['status'] != 'deleted'] total += (i.size * len(locations)) return total diff --git a/glance/tests/functional/db/base.py b/glance/tests/functional/db/base.py index 6efab88fb..86ddecd80 100644 --- a/glance/tests/functional/db/base.py +++ b/glance/tests/functional/db/base.py @@ -193,9 +193,9 @@ class DriverTests(object): fixture = {'status': 'queued', 'locations': locations} image = self.db_api.image_create(self.context, fixture) - actual = [{'url': l['url'], 'metadata': l['metadata'], - 'status': l['status']} - for l in image['locations']] + actual = [{'url': location['url'], 'metadata': location['metadata'], + 'status': location['status']} + for location in image['locations']] self.assertEqual(locations, actual) def test_image_create_without_locations(self): @@ -211,9 +211,9 @@ class DriverTests(object): 'status': 'active'}] fixture = {'status': 'queued', 'locations': location_data} image = self.db_api.image_create(self.context, fixture) - actual = [{'url': l['url'], 'metadata': l['metadata'], - 'status': l['status']} - for l in image['locations']] + actual = [{'url': location['url'], 'metadata': location['metadata'], + 'status': location['status']} + for location in image['locations']] self.assertEqual(location_data, actual) def test_image_create_properties(self): diff --git a/glance/tests/unit/test_db.py b/glance/tests/unit/test_db.py index db8e1e7ff..025acc462 100644 --- a/glance/tests/unit/test_db.py +++ b/glance/tests/unit/test_db.py @@ -605,9 +605,11 @@ class TestEncryptedLocations(test_utils.BaseTestCase): self.image_repo.add(image) db_data = self.db.image_get(self.context, UUID1) self.assertNotEqual(db_data['locations'], ['foo', 'bar']) - decrypted_locations = [crypt.urlsafe_decrypt(self.crypt_key, l['url']) - for l in db_data['locations']] - self.assertEqual([l['url'] for l in self.foo_bar_location], + decrypted_locations = [crypt.urlsafe_decrypt(self.crypt_key, + location['url']) + for location in db_data['locations']] + self.assertEqual([location['url'] + for location in self.foo_bar_location], decrypted_locations) def test_encrypt_locations_on_save(self): @@ -617,19 +619,23 @@ class TestEncryptedLocations(test_utils.BaseTestCase): self.image_repo.save(image) db_data = self.db.image_get(self.context, UUID1) self.assertNotEqual(db_data['locations'], ['foo', 'bar']) - decrypted_locations = [crypt.urlsafe_decrypt(self.crypt_key, l['url']) - for l in db_data['locations']] - self.assertEqual([l['url'] for l in self.foo_bar_location], + decrypted_locations = [crypt.urlsafe_decrypt(self.crypt_key, + location['url']) + for location in db_data['locations']] + self.assertEqual([location['url'] + for location in self.foo_bar_location], decrypted_locations) def test_decrypt_locations_on_get(self): url_loc = ['ping', 'pong'] - orig_locations = [{'url': l, 'metadata': {}, 'status': 'active'} - for l in url_loc] - encrypted_locs = [crypt.urlsafe_encrypt(self.crypt_key, l) - for l in url_loc] - encrypted_locations = [{'url': l, 'metadata': {}, 'status': 'active'} - for l in encrypted_locs] + orig_locations = [{'url': location, 'metadata': {}, 'status': 'active'} + for location in url_loc] + encrypted_locs = [crypt.urlsafe_encrypt(self.crypt_key, location) + for location in url_loc] + encrypted_locations = [{'url': location, + 'metadata': {}, + 'status': 'active'} + for location in encrypted_locs] self.assertNotEqual(encrypted_locations, orig_locations) db_data = _db_fixture(UUID1, owner=TENANT1, locations=encrypted_locations) @@ -643,12 +649,14 @@ class TestEncryptedLocations(test_utils.BaseTestCase): def test_decrypt_locations_on_list(self): url_loc = ['ping', 'pong'] - orig_locations = [{'url': l, 'metadata': {}, 'status': 'active'} - for l in url_loc] - encrypted_locs = [crypt.urlsafe_encrypt(self.crypt_key, l) - for l in url_loc] - encrypted_locations = [{'url': l, 'metadata': {}, 'status': 'active'} - for l in encrypted_locs] + orig_locations = [{'url': location, 'metadata': {}, 'status': 'active'} + for location in url_loc] + encrypted_locs = [crypt.urlsafe_encrypt(self.crypt_key, location) + for location in url_loc] + encrypted_locations = [{'url': location, + 'metadata': {}, + 'status': 'active'} + for location in encrypted_locs] self.assertNotEqual(encrypted_locations, orig_locations) db_data = _db_fixture(UUID1, owner=TENANT1, locations=encrypted_locations) |