Merge "Fix E741 issues"

This commit is contained in:
Zuul 2023-02-16 11:53:32 +00:00 committed by Gerrit Code Review
commit 410b23cfbd
4 changed files with 36 additions and 27 deletions

View File

@ -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

View File

@ -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

View File

@ -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):

View File

@ -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)