From 305a9c12b5494fdb35fbcb9609879acacdf1a920 Mon Sep 17 00:00:00 2001 From: Zhongyue Luo Date: Wed, 19 Sep 2012 17:01:13 +0800 Subject: [PATCH] Clean up pep8 E124 violations Fixed E124 errors All other ignores are to be removed in the next sequence of patches Change-Id: Ic96ebf5dff645dfdc47478beeb6965d6ad266243 --- glance/api/v1/images.py | 3 +- glance/context.py | 19 +++--- glance/image_cache/client.py | 3 +- glance/store/__init__.py | 13 ++-- glance/tests/functional/db/__init__.py | 5 +- glance/tests/unit/test_auth.py | 24 ++++---- glance/tests/unit/test_clients.py | 60 ++++++++++--------- glance/tests/unit/test_migrations.py | 3 +- .../tests/unit/v2/test_image_data_resource.py | 7 ++- glance/tests/unit/v2/test_images_resource.py | 37 +++++++----- glance/tests/utils.py | 9 +-- tox.ini | 2 +- 12 files changed, 100 insertions(+), 85 deletions(-) diff --git a/glance/api/v1/images.py b/glance/api/v1/images.py index b127c35f..96f6c467 100644 --- a/glance/api/v1/images.py +++ b/glance/api/v1/images.py @@ -29,8 +29,7 @@ from webob.exc import (HTTPError, HTTPBadRequest, HTTPForbidden, HTTPRequestEntityTooLarge, - HTTPServiceUnavailable, - ) + HTTPServiceUnavailable) from glance.api import common from glance.api import policy diff --git a/glance/context.py b/glance/context.py index eb6e4b92..e00f5976 100644 --- a/glance/context.py +++ b/glance/context.py @@ -45,15 +45,16 @@ class RequestContext(object): def to_dict(self): # NOTE(ameade): These keys are named to correspond with the default # format string for logging the context in openstack common - return {'request_id': self.request_id, - 'user_id': self.user, - 'tenant_id': self.tenant, - 'is_admin': self.is_admin, - 'project_id': self.tenant, - 'read_deleted': self.show_deleted, - 'roles': self.roles, - 'auth_token': self.auth_tok, - 'service_catalog': self.service_catalog, + return { + 'request_id': self.request_id, + 'user_id': self.user, + 'tenant_id': self.tenant, + 'is_admin': self.is_admin, + 'project_id': self.tenant, + 'read_deleted': self.show_deleted, + 'roles': self.roles, + 'auth_token': self.auth_tok, + 'service_catalog': self.service_catalog, } @classmethod diff --git a/glance/image_cache/client.py b/glance/image_cache/client.py index 9ba29617..e37e2def 100644 --- a/glance/image_cache/client.py +++ b/glance/image_cache/client.py @@ -107,8 +107,7 @@ def get_client(host, port=None, timeout=None, use_ssl=False, username=None, auth_url=auth_url or os.getenv('OS_AUTH_URL'), strategy=force_strategy or auth_strategy or os.getenv('OS_AUTH_STRATEGY', 'noauth'), - region=region or os.getenv('OS_REGION_NAME'), - ) + region=region or os.getenv('OS_REGION_NAME')) if creds['strategy'] == 'keystone' and not creds['auth_url']: msg = ("--os_auth_url option or OS_AUTH_URL environment variable " diff --git a/glance/store/__init__.py b/glance/store/__init__.py index c5949d5f..4b761271 100644 --- a/glance/store/__init__.py +++ b/glance/store/__init__.py @@ -30,12 +30,13 @@ LOG = logging.getLogger(__name__) store_opts = [ cfg.ListOpt('known_stores', - default=['glance.store.filesystem.Store', - 'glance.store.http.Store', - 'glance.store.rbd.Store', - 'glance.store.s3.Store', - 'glance.store.swift.Store', - ]), + default=[ + 'glance.store.filesystem.Store', + 'glance.store.http.Store', + 'glance.store.rbd.Store', + 'glance.store.s3.Store', + 'glance.store.swift.Store', + ]), cfg.StrOpt('scrubber_datadir', default='/var/lib/glance/scrubber'), cfg.BoolOpt('delayed_delete', default=False), diff --git a/glance/tests/functional/db/__init__.py b/glance/tests/functional/db/__init__.py index 3f1e23e0..59294644 100644 --- a/glance/tests/functional/db/__init__.py +++ b/glance/tests/functional/db/__init__.py @@ -269,9 +269,10 @@ class BaseTestCase(object): def test_image_get_all_size_min_max(self): images = self.db_api.image_get_all(self.context, - filters={'size_min': 10, + filters={ + 'size_min': 10, 'size_max': 15, - }) + }) self.assertEquals(len(images), 1) self.assertEquals(images[0]['id'], self.fixtures[0]['id']) diff --git a/glance/tests/unit/test_auth.py b/glance/tests/unit/test_auth.py index 7fce2c5d..0b477717 100644 --- a/glance/tests/unit/test_auth.py +++ b/glance/tests/unit/test_auth.py @@ -498,16 +498,20 @@ class TestEndpoints(utils.BaseTestCase): def setUp(self): self.service_catalog = [ - {'endpoint_links': [], - 'endpoints': [ - {'adminURL': 'http://localhost:8080/', - 'region': 'RegionOne', - 'internalURL': 'http://internalURL/', - 'publicURL': 'http://publicURL/'}, - ], - 'type': 'object-store', - 'name': 'Object Storage Service', - }] + { + 'endpoint_links': [], + 'endpoints': [ + { + 'adminURL': 'http://localhost:8080/', + 'region': 'RegionOne', + 'internalURL': 'http://internalURL/', + 'publicURL': 'http://publicURL/', + }, + ], + 'type': 'object-store', + 'name': 'Object Storage Service', + } + ] def test_get_endpoint_with_custom_server_type(self): endpoint = auth.get_endpoint(self.service_catalog, diff --git a/glance/tests/unit/test_clients.py b/glance/tests/unit/test_clients.py index f50d3a51..54963cc3 100644 --- a/glance/tests/unit/test_clients.py +++ b/glance/tests/unit/test_clients.py @@ -884,12 +884,13 @@ class TestRegistryClient(base.IsolatedUnitTest): def test_add_image_basic(self): """Tests that we can add image metadata and returns the new id""" - fixture = {'name': 'fake public image', - 'is_public': True, - 'disk_format': 'vmdk', - 'container_format': 'ovf', - 'size': 19, - } + fixture = { + 'name': 'fake public image', + 'is_public': True, + 'disk_format': 'vmdk', + 'container_format': 'ovf', + 'size': 19, + } new_image = self.client.add_image(fixture) @@ -925,14 +926,15 @@ class TestRegistryClient(base.IsolatedUnitTest): def test_add_image_already_exists(self): """Tests proper exception is raised if image with ID already exists""" - fixture = {'id': UUID2, - 'name': 'fake public image', - 'is_public': True, - 'disk_format': 'vmdk', - 'container_format': 'ovf', - 'size': 19, - 'location': "file:///tmp/glance-tests/2", - } + fixture = { + 'id': UUID2, + 'name': 'fake public image', + 'is_public': True, + 'disk_format': 'vmdk', + 'container_format': 'ovf', + 'size': 19, + 'location': "file:///tmp/glance-tests/2", + } self.assertRaises(exception.Duplicate, self.client.add_image, @@ -940,14 +942,15 @@ class TestRegistryClient(base.IsolatedUnitTest): def test_add_image_with_bad_status(self): """Tests proper exception is raised if a bad status is set""" - fixture = {'name': 'fake public image', - 'is_public': True, - 'disk_format': 'vmdk', - 'container_format': 'ovf', - 'status': 'bad status', - 'size': 19, - 'location': "file:///tmp/glance-tests/2", - } + fixture = { + 'name': 'fake public image', + 'is_public': True, + 'disk_format': 'vmdk', + 'container_format': 'ovf', + 'status': 'bad status', + 'size': 19, + 'location': "file:///tmp/glance-tests/2", + } self.assertRaises(exception.Invalid, self.client.add_image, @@ -968,12 +971,13 @@ class TestRegistryClient(base.IsolatedUnitTest): def test_update_image_not_existing(self): """Tests non existing image update doesn't work""" - fixture = {'name': 'fake public image', - 'is_public': True, - 'disk_format': 'vmdk', - 'container_format': 'ovf', - 'status': 'bad status', - } + fixture = { + 'name': 'fake public image', + 'is_public': True, + 'disk_format': 'vmdk', + 'container_format': 'ovf', + 'status': 'bad status', + } self.assertRaises(exception.NotFound, self.client.update_image, diff --git a/glance/tests/unit/test_migrations.py b/glance/tests/unit/test_migrations.py index 03be37e8..a7074ef3 100644 --- a/glance/tests/unit/test_migrations.py +++ b/glance/tests/unit/test_migrations.py @@ -137,8 +137,7 @@ class TestMigrations(utils.BaseTestCase): "|| tablename || ' cascade;' " "from pg_tables where schemaname = 'public';\" | " "psql -d %(database)s | grep '^\s*drop' | " - "psql -d %(database)s" - ) % locals() + "psql -d %(database)s") % locals() exitcode, out, err = utils.execute(cmd) self.assertEqual(0, exitcode) diff --git a/glance/tests/unit/v2/test_image_data_resource.py b/glance/tests/unit/v2/test_image_data_resource.py index 3dbe719a..18108899 100644 --- a/glance/tests/unit/v2/test_image_data_resource.py +++ b/glance/tests/unit/v2/test_image_data_resource.py @@ -61,9 +61,10 @@ class TestImagesController(base.StoreClearingUnitTest): self.assertEqual(4, output['meta']['size']) self.assertEqual('YYYY', output['data']) output_log = self.notifier.get_log() - expected_log = {'notification_type': "INFO", - 'event_type': "image.upload", - 'payload': output['meta'], + expected_log = { + 'notification_type': "INFO", + 'event_type': "image.upload", + 'payload': output['meta'], } self.assertEqual(output_log, expected_log) diff --git a/glance/tests/unit/v2/test_images_resource.py b/glance/tests/unit/v2/test_images_resource.py index d48f383d..b1036839 100644 --- a/glance/tests/unit/v2/test_images_resource.py +++ b/glance/tests/unit/v2/test_images_resource.py @@ -328,9 +328,10 @@ class TestImagesController(test_utils.BaseTestCase): self.assertEqual([], output['tags']) self.assertEqual(False, output['is_public']) output_log = self.notifier.get_log() - expected_log = {'notification_type': "INFO", - 'event_type': "image.update", - 'payload': output, + expected_log = { + 'notification_type': "INFO", + 'event_type': "image.update", + 'payload': output, } self.assertEqual(output_log, expected_log) @@ -340,9 +341,10 @@ class TestImagesController(test_utils.BaseTestCase): output = self.controller.create(request, image) self.assertEqual(True, output['is_public']) output_log = self.notifier.get_log() - expected_log = {'notification_type': "INFO", - 'event_type': "image.update", - 'payload': output, + expected_log = { + 'notification_type': "INFO", + 'event_type': "image.update", + 'payload': output, } self.assertEqual(output_log, expected_log) @@ -352,10 +354,11 @@ class TestImagesController(test_utils.BaseTestCase): output = self.controller.create(request, image) self.assertEqual(['ping'], output['tags']) output_log = self.notifier.get_log() - expected_log = {'notification_type': "INFO", - 'event_type': "image.update", - 'payload': output, - } + expected_log = { + 'notification_type': "INFO", + 'event_type': "image.update", + 'payload': output, + } self.assertEqual(output_log, expected_log) def test_update_no_changes(self): @@ -365,9 +368,10 @@ class TestImagesController(test_utils.BaseTestCase): self.assertEqual(output['created_at'], output['updated_at']) self.assertTrue('tags' in output) output_log = self.notifier.get_log() - expected_log = {'notification_type': "INFO", - 'event_type': "image.update", - 'payload': output, + expected_log = { + 'notification_type': "INFO", + 'event_type': "image.update", + 'payload': output, } self.assertEqual(output_log, expected_log) @@ -525,9 +529,10 @@ class TestImagesController(test_utils.BaseTestCase): output = self.controller.update(request, UUID1, changes) self.assertEqual(['ping'], output['tags']) output_log = self.notifier.get_log() - expected_log = {'notification_type': "INFO", - 'event_type': "image.update", - 'payload': output, + expected_log = { + 'notification_type': "INFO", + 'event_type': "image.update", + 'payload': output, } self.assertEqual(output_log, expected_log) diff --git a/glance/tests/utils.py b/glance/tests/utils.py index 370fc8b6..706f897d 100644 --- a/glance/tests/utils.py +++ b/glance/tests/utils.py @@ -328,10 +328,11 @@ def xattr_writes_supported(path): def minimal_headers(name, public=True): - headers = {'Content-Type': 'application/octet-stream', - 'X-Image-Meta-Name': name, - 'X-Image-Meta-disk_format': 'raw', - 'X-Image-Meta-container_format': 'ovf', + headers = { + 'Content-Type': 'application/octet-stream', + 'X-Image-Meta-Name': name, + 'X-Image-Meta-disk_format': 'raw', + 'X-Image-Meta-container_format': 'ovf', } if public: headers['X-Image-Meta-Is-Public'] = 'True' diff --git a/tox.ini b/tox.ini index 4066c118..e607a359 100644 --- a/tox.ini +++ b/tox.ini @@ -18,7 +18,7 @@ downloadcache = ~/cache/pip [testenv:pep8] deps = pep8==1.3.3 -commands = pep8 --ignore=E124,E125,E126,E127,E128,E711 --repeat --show-source --exclude=.venv,.tox,dist,doc,openstack . +commands = pep8 --ignore=E125,E126,E127,E128,E711 --repeat --show-source --exclude=.venv,.tox,dist,doc,openstack . [testenv:cover] setenv = NOSE_WITH_COVERAGE=1