From 2eca65eb5febae59eaca9e949ecd6a6f9492350a Mon Sep 17 00:00:00 2001 From: Sergio Cazzolato Date: Fri, 29 Nov 2013 17:23:47 -0500 Subject: [PATCH] Bump hacking to 0.8 and get python 3.x compatibility Bump hacking dependency to 0.8 to get python 3.x compatibility Fixes done in order to avoid errors after enabling hacking 0.8 Change-Id: Ic878fe2e1bd3f65f7f95a9b5c7a192dac81b749d Closes-Bug: #1257282 --- glance/api/v1/members.py | 3 ++- glance/cmd/cache_manage.py | 27 ++++++++++--------- .../versions/015_quote_swift_credentials.py | 7 ++--- .../017_quote_encrypted_swift_credentials.py | 11 ++++---- glance/tests/functional/__init__.py | 5 ++-- glance/tests/unit/test_migrations.py | 25 ++++++++++------- glance/tests/unit/v1/test_registry_client.py | 4 ++- glance/tests/unit/v2/test_images_resource.py | 3 ++- glance/tests/unit/v2/test_tasks_resource.py | 3 ++- glance/tests/utils.py | 3 ++- 10 files changed, 55 insertions(+), 36 deletions(-) diff --git a/glance/api/v1/members.py b/glance/api/v1/members.py index 760e20cda4..8743fde8a0 100644 --- a/glance/api/v1/members.py +++ b/glance/api/v1/members.py @@ -119,7 +119,8 @@ class Controller(controller.BaseController): if attempted > maximum: msg = _("The limit has been exceeded on the number of allowed " "image members for this image. Attempted: %(attempted)s, " - "Maximum: %(maximum)s") % locals() + "Maximum: %(maximum)s") % {'attempted': attempted, + 'maximum': maximum} raise webob.exc.HTTPRequestEntityTooLarge(explanation=msg, request=req) diff --git a/glance/cmd/cache_manage.py b/glance/cmd/cache_manage.py index 4aab894f70..4a6c8fb91f 100755 --- a/glance/cmd/cache_manage.py +++ b/glance/cmd/cache_manage.py @@ -155,15 +155,16 @@ Queues an image for caching return FAILURE if (not options.force and - not user_confirm("Queue image %s for caching?" % (image_id,), - default=False)): + not user_confirm("Queue image %(image_id)s for caching?" % + {'image_id': image_id}, default=False)): return SUCCESS client = get_client(options) client.queue_image_for_caching(image_id) if options.verbose: - print("Queued image %(image_id)s for caching" % locals()) + print("Queued image %(image_id)s for caching" % + {'image_id': image_id}) return SUCCESS @@ -183,15 +184,15 @@ Deletes an image from the cache return FAILURE if (not options.force and - not user_confirm("Delete cached image %s?" % (image_id,), - default=False)): + not user_confirm("Delete cached image %(image_id)s?" % + {'image_id': image_id}, default=False)): return SUCCESS client = get_client(options) client.delete_cached_image(image_id) if options.verbose: - print("Deleted cached image %(image_id)s" % locals()) + print("Deleted cached image %(image_id)s" % {'image_id': image_id}) return SUCCESS @@ -210,7 +211,8 @@ Remove all images from the cache. num_deleted = client.delete_all_cached_images() if options.verbose: - print("Deleted %(num_deleted)s cached images" % locals()) + print("Deleted %(num_deleted)s cached images" % + {'num_deleted': num_deleted}) return SUCCESS @@ -230,15 +232,15 @@ Deletes an image from the cache return FAILURE if (not options.force and - not user_confirm("Delete queued image %s?" % (image_id,), - default=False)): + not user_confirm("Delete queued image %(image_id)s?" % + {'image_id': image_id}, default=False)): return SUCCESS client = get_client(options) client.delete_queued_image(image_id) if options.verbose: - print("Deleted queued image %(image_id)s" % locals()) + print("Deleted queued image %(image_id)s" % {'image_id': image_id}) return SUCCESS @@ -257,7 +259,8 @@ Remove all images from the cache queue. num_deleted = client.delete_all_queued_images() if options.verbose: - print("Deleted %(num_deleted)s queued images" % locals()) + print("Deleted %(num_deleted)s queued images" % + {'num_deleted': num_deleted}) return SUCCESS @@ -445,7 +448,7 @@ def lookup_command(parser, command_name): command = commands[command_name] except KeyError: parser.print_usage() - sys.exit("Unknown command: %s" % command_name) + sys.exit("Unknown command: %(cmd_name)s" % {'cmd_name': command_name}) return command diff --git a/glance/db/sqlalchemy/migrate_repo/versions/015_quote_swift_credentials.py b/glance/db/sqlalchemy/migrate_repo/versions/015_quote_swift_credentials.py index 0a58c9e912..c5c3f50ac3 100644 --- a/glance/db/sqlalchemy/migrate_repo/versions/015_quote_swift_credentials.py +++ b/glance/db/sqlalchemy/migrate_repo/versions/015_quote_swift_credentials.py @@ -88,7 +88,8 @@ def legacy_parse_uri(uri, to_quote, image_id): "like so: " "swift+http://user:pass@authurl.com/v1/container/obj") - LOG.error(_("Invalid store uri for image %s: %s") % (image_id, reason)) + LOG.error(_("Invalid store uri for image %(image_id)s: %(reason)s") % + {'image_id': image_id, 'reason': reason}) raise exception.BadStoreUri(message=reason) pieces = urlparse.urlparse(uri) @@ -120,7 +121,7 @@ def legacy_parse_uri(uri, to_quote, image_id): if to_quote: if len(cred_parts) == 1: reason = (_("Badly formed credentials '%(creds)s' in Swift " - "URI") % locals()) + "URI") % {'creds': creds}) LOG.error(reason) raise exception.BadStoreUri() elif len(cred_parts) == 3: @@ -150,7 +151,7 @@ def legacy_parse_uri(uri, to_quote, image_id): path_parts.insert(0, netloc) auth_or_store_url = '/'.join(path_parts) except IndexError: - reason = _("Badly formed S3 URI: %s") % uri + reason = _("Badly formed S3 URI: %(uri)s") % {'uri': uri} LOG.error(message=reason) raise exception.BadStoreUri() diff --git a/glance/db/sqlalchemy/migrate_repo/versions/017_quote_encrypted_swift_credentials.py b/glance/db/sqlalchemy/migrate_repo/versions/017_quote_encrypted_swift_credentials.py index a0041aa811..b9384f5ec7 100644 --- a/glance/db/sqlalchemy/migrate_repo/versions/017_quote_encrypted_swift_credentials.py +++ b/glance/db/sqlalchemy/migrate_repo/versions/017_quote_encrypted_swift_credentials.py @@ -86,8 +86,8 @@ def migrate_location_credentials(migrate_engine, to_quoted): .where(images_table.c.id == image['id'])\ .values(location=fixed_uri).execute() except exception.Invalid: - msg = _("Failed to decrypt location value for image %s") - LOG.warn(msg % image['id']) + msg = _("Failed to decrypt location value for image %(image_id)s") + LOG.warn(msg % {'image_id': image['id']}) def decrypt_location(uri): @@ -151,7 +151,8 @@ def legacy_parse_uri(uri, to_quote, image_id): "like so: " "swift+http://user:pass@authurl.com/v1/container/obj") - LOG.error(_("Invalid store uri for image %s: %s") % (image_id, reason)) + LOG.error(_("Invalid store uri for image %(image_id)s: %(reason)s") % + {'image_id': image_id, 'reason': reason}) raise exception.BadStoreUri(message=reason) pieces = urlparse.urlparse(uri) @@ -183,7 +184,7 @@ def legacy_parse_uri(uri, to_quote, image_id): if to_quote: if len(cred_parts) == 1: reason = (_("Badly formed credentials '%(creds)s' in Swift " - "URI") % locals()) + "URI") % {'creds': creds}) LOG.error(reason) raise exception.BadStoreUri() elif len(cred_parts) == 3: @@ -213,7 +214,7 @@ def legacy_parse_uri(uri, to_quote, image_id): path_parts.insert(0, netloc) auth_or_store_url = '/'.join(path_parts) except IndexError: - reason = _("Badly formed S3 URI: %s") % uri + reason = _("Badly formed S3 URI: %(uri)s") % {'uri': uri} LOG.error(message=reason) raise exception.BadStoreUri() diff --git a/glance/tests/functional/__init__.py b/glance/tests/functional/__init__.py index 5dc4452e0b..f2023583d0 100644 --- a/glance/tests/functional/__init__.py +++ b/glance/tests/functional/__init__.py @@ -652,9 +652,10 @@ class FunctionalTest(test_utils.BaseTestCase): if auth_pieces[1].strip(): password = "-p%s" % auth_pieces[1] sql = ("drop database if exists %(database)s; " - "create database %(database)s;") % locals() + "create database %(database)s;") % {'database': database} cmd = ("mysql -u%(user)s %(password)s -h%(host)s " - "-e\"%(sql)s\"") % locals() + "-e\"%(sql)s\"") % {'user': user, 'password': password, + 'host': host, 'sql': sql} exitcode, out, err = execute(cmd) self.assertEqual(0, exitcode) diff --git a/glance/tests/unit/test_migrations.py b/glance/tests/unit/test_migrations.py index a9a557b28a..888d7560ab 100644 --- a/glance/tests/unit/test_migrations.py +++ b/glance/tests/unit/test_migrations.py @@ -72,7 +72,8 @@ def _get_connect_string(backend, backend = "postgresql+psycopg2" return ("%(backend)s://%(user)s:%(passwd)s@localhost/%(database)s" - % locals()) + % {'backend': backend, 'user': user, 'passwd': passwd, + 'database': database}) def _is_backend_avail(backend, @@ -199,10 +200,11 @@ class TestMigrations(test_utils.BaseTestCase): if len(auth_pieces) > 1: if auth_pieces[1].strip(): password = "-p\"%s\"" % auth_pieces[1] - sql = ("drop database if exists %(database)s; " - "create database %(database)s;") % locals() + sql = ("drop database if exists %(database)s; create " + "database %(database)s;") % {'database': database} cmd = ("mysql -u \"%(user)s\" %(password)s -h %(host)s " - "-e \"%(sql)s\"") % locals() + "-e \"%(sql)s\"") % {'user': user, 'password': password, + 'host': host, 'sql': sql} execute_cmd(cmd) elif conn_string.startswith('postgresql'): database = conn_pieces.path.strip('/') @@ -217,18 +219,23 @@ class TestMigrations(test_utils.BaseTestCase): # note(boris-42): This file is used for authentication # without password prompt. createpgpass = ("echo '*:*:*:%(user)s:%(password)s' > " - "~/.pgpass && chmod 0600 ~/.pgpass" % locals()) + "~/.pgpass && chmod 0600 ~/.pgpass" % + {'user': user, 'password': password}) execute_cmd(createpgpass) # note(boris-42): We must create and drop database, we can't # drop database which we have connected to, so for such # operations there is a special database template1. sqlcmd = ("psql -w -U %(user)s -h %(host)s -c" " '%(sql)s' -d template1") - sql = ("drop database if exists %(database)s;") % locals() - droptable = sqlcmd % locals() + sql = ("drop database if exists %(database)s;") + sql = sql % {'database': database} + droptable = sqlcmd % {'user': user, 'host': host, + 'sql': sql} execute_cmd(droptable) - sql = ("create database %(database)s;") % locals() - createtable = sqlcmd % locals() + sql = ("create database %(database)s;") + sql = sql % {'database': database} + createtable = sqlcmd % {'user': user, 'host': host, + 'sql': sql} execute_cmd(createtable) def test_walk_versions(self): diff --git a/glance/tests/unit/v1/test_registry_client.py b/glance/tests/unit/v1/test_registry_client.py index d7c3fb8478..802eeeacaf 100644 --- a/glance/tests/unit/v1/test_registry_client.py +++ b/glance/tests/unit/v1/test_registry_client.py @@ -634,7 +634,9 @@ class TestRegistryV1Client(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn): el = data[k] self.assertEqual(v, data[k], "Failed v != data[k] where v = %(v)s and " - "k = %(k)s and data[k] = %(el)s" % locals()) + "k = %(k)s and data[k] = %(el)s" % {'v': v, + 'k': k, + 'el': el}) def test_get_image_non_existing(self): """Tests that NotFound is raised when getting a non-existing image""" diff --git a/glance/tests/unit/v2/test_images_resource.py b/glance/tests/unit/v2/test_images_resource.py index 6ecad9b8ae..6fabbf58e7 100644 --- a/glance/tests/unit/v2/test_images_resource.py +++ b/glance/tests/unit/v2/test_images_resource.py @@ -2285,7 +2285,8 @@ class TestImagesDeserializer(test_utils.BaseTestCase): def test_index_with_many_filter(self): name = 'My Little Image' instance_id = str(uuid.uuid4()) - path = '/images?name=%(name)s&id=%(instance_id)s' % locals() + path = ('/images?name=%(name)s&id=%(instance_id)s' % + {'name': name, 'instance_id': instance_id}) request = unit_test_utils.get_fake_request(path) output = self.deserializer.index(request) self.assertEqual(output['filters']['name'], name) diff --git a/glance/tests/unit/v2/test_tasks_resource.py b/glance/tests/unit/v2/test_tasks_resource.py index 1458da258c..090d931172 100644 --- a/glance/tests/unit/v2/test_tasks_resource.py +++ b/glance/tests/unit/v2/test_tasks_resource.py @@ -383,7 +383,8 @@ class TestTasksDeserializer(test_utils.BaseTestCase): def test_index_with_many_filter(self): status = 'success' type = 'import' - path = '/tasks?status=%(status)s&type=%(type)s' % locals() + path = '/tasks?status=%(status)s&type=%(type)s' % {'status': status, + 'type': type} request = unit_test_utils.get_fake_request(path) output = self.deserializer.index(request) self.assertEqual(output['filters']['status'], status) diff --git a/glance/tests/utils.py b/glance/tests/utils.py index c926c08a85..56c9a6dd2d 100644 --- a/glance/tests/utils.py +++ b/glance/tests/utils.py @@ -302,7 +302,8 @@ def execute(cmd, msg = "Command %(cmd)s did not succeed. Returned an exit "\ "code of %(exitcode)d."\ "\n\nSTDOUT: %(out)s"\ - "\n\nSTDERR: %(err)s" % locals() + "\n\nSTDERR: %(err)s" % {'cmd': cmd, 'exitcode': exitcode, + 'out': out, 'err': err} if context: msg += "\n\nCONTEXT: %s" % context raise RuntimeError(msg)