From 399438cd044f52915e202650db407eccd3e26c95 Mon Sep 17 00:00:00 2001 From: Cyril Roelandt Date: Wed, 13 Jul 2022 20:28:03 +0200 Subject: Fix E741 issues In 2.6.0, pycodestyle is going to find more E741 issues[1], which is going to break the gate by making "tox -epep8" fail. [1] https://www.flake8rules.com/rules/E741.html Change-Id: I94ee03a00dd01726de15a29424183faabdeba844 --- glance/db/__init__.py | 4 ++-- glance/db/sqlalchemy/api.py | 3 ++- glance/tests/functional/db/base.py | 12 +++++------ 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) -- cgit v1.2.1