Skip to content

Commit 410b23c

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Fix E741 issues"
2 parents 81da9cc + 399438c commit 410b23c

File tree

4 files changed

+36
-27
lines changed

4 files changed

+36
-27
lines changed

glance/db/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ def _format_image_from_db(self, db_image, db_tags):
103103
if loc['status'] == 'active']
104104
if CONF.metadata_encryption_key:
105105
key = CONF.metadata_encryption_key
106-
for l in locations:
107-
l['url'] = crypt.urlsafe_decrypt(key, l['url'])
106+
for location in locations:
107+
location['url'] = crypt.urlsafe_decrypt(key, location['url'])
108108

109109
# NOTE(danms): If the image is shared and we are not the
110110
# owner, we must have found it because we are a member. Set

glance/db/sqlalchemy/api.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,8 @@ def _image_get_disk_usage_by_owner(owner, session, image_id=None):
739739

740740
total = 0
741741
for i in images:
742-
locations = [l for l in i.locations if l['status'] != 'deleted']
742+
locations = [location for location in i.locations
743+
if location['status'] != 'deleted']
743744
total += (i.size * len(locations))
744745
return total
745746

glance/tests/functional/db/base.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,9 @@ def test_image_create_with_locations(self):
193193
fixture = {'status': 'queued',
194194
'locations': locations}
195195
image = self.db_api.image_create(self.context, fixture)
196-
actual = [{'url': l['url'], 'metadata': l['metadata'],
197-
'status': l['status']}
198-
for l in image['locations']]
196+
actual = [{'url': location['url'], 'metadata': location['metadata'],
197+
'status': location['status']}
198+
for location in image['locations']]
199199
self.assertEqual(locations, actual)
200200

201201
def test_image_create_without_locations(self):
@@ -211,9 +211,9 @@ def test_image_create_with_location_data(self):
211211
'status': 'active'}]
212212
fixture = {'status': 'queued', 'locations': location_data}
213213
image = self.db_api.image_create(self.context, fixture)
214-
actual = [{'url': l['url'], 'metadata': l['metadata'],
215-
'status': l['status']}
216-
for l in image['locations']]
214+
actual = [{'url': location['url'], 'metadata': location['metadata'],
215+
'status': location['status']}
216+
for location in image['locations']]
217217
self.assertEqual(location_data, actual)
218218

219219
def test_image_create_properties(self):

glance/tests/unit/test_db.py

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -605,9 +605,11 @@ def test_encrypt_locations_on_add(self):
605605
self.image_repo.add(image)
606606
db_data = self.db.image_get(self.context, UUID1)
607607
self.assertNotEqual(db_data['locations'], ['foo', 'bar'])
608-
decrypted_locations = [crypt.urlsafe_decrypt(self.crypt_key, l['url'])
609-
for l in db_data['locations']]
610-
self.assertEqual([l['url'] for l in self.foo_bar_location],
608+
decrypted_locations = [crypt.urlsafe_decrypt(self.crypt_key,
609+
location['url'])
610+
for location in db_data['locations']]
611+
self.assertEqual([location['url']
612+
for location in self.foo_bar_location],
611613
decrypted_locations)
612614

613615
def test_encrypt_locations_on_save(self):
@@ -617,19 +619,23 @@ def test_encrypt_locations_on_save(self):
617619
self.image_repo.save(image)
618620
db_data = self.db.image_get(self.context, UUID1)
619621
self.assertNotEqual(db_data['locations'], ['foo', 'bar'])
620-
decrypted_locations = [crypt.urlsafe_decrypt(self.crypt_key, l['url'])
621-
for l in db_data['locations']]
622-
self.assertEqual([l['url'] for l in self.foo_bar_location],
622+
decrypted_locations = [crypt.urlsafe_decrypt(self.crypt_key,
623+
location['url'])
624+
for location in db_data['locations']]
625+
self.assertEqual([location['url']
626+
for location in self.foo_bar_location],
623627
decrypted_locations)
624628

625629
def test_decrypt_locations_on_get(self):
626630
url_loc = ['ping', 'pong']
627-
orig_locations = [{'url': l, 'metadata': {}, 'status': 'active'}
628-
for l in url_loc]
629-
encrypted_locs = [crypt.urlsafe_encrypt(self.crypt_key, l)
630-
for l in url_loc]
631-
encrypted_locations = [{'url': l, 'metadata': {}, 'status': 'active'}
632-
for l in encrypted_locs]
631+
orig_locations = [{'url': location, 'metadata': {}, 'status': 'active'}
632+
for location in url_loc]
633+
encrypted_locs = [crypt.urlsafe_encrypt(self.crypt_key, location)
634+
for location in url_loc]
635+
encrypted_locations = [{'url': location,
636+
'metadata': {},
637+
'status': 'active'}
638+
for location in encrypted_locs]
633639
self.assertNotEqual(encrypted_locations, orig_locations)
634640
db_data = _db_fixture(UUID1, owner=TENANT1,
635641
locations=encrypted_locations)
@@ -643,12 +649,14 @@ def test_decrypt_locations_on_get(self):
643649

644650
def test_decrypt_locations_on_list(self):
645651
url_loc = ['ping', 'pong']
646-
orig_locations = [{'url': l, 'metadata': {}, 'status': 'active'}
647-
for l in url_loc]
648-
encrypted_locs = [crypt.urlsafe_encrypt(self.crypt_key, l)
649-
for l in url_loc]
650-
encrypted_locations = [{'url': l, 'metadata': {}, 'status': 'active'}
651-
for l in encrypted_locs]
652+
orig_locations = [{'url': location, 'metadata': {}, 'status': 'active'}
653+
for location in url_loc]
654+
encrypted_locs = [crypt.urlsafe_encrypt(self.crypt_key, location)
655+
for location in url_loc]
656+
encrypted_locations = [{'url': location,
657+
'metadata': {},
658+
'status': 'active'}
659+
for location in encrypted_locs]
652660
self.assertNotEqual(encrypted_locations, orig_locations)
653661
db_data = _db_fixture(UUID1, owner=TENANT1,
654662
locations=encrypted_locations)

0 commit comments

Comments
 (0)