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
This commit is contained in:
Sergio Cazzolato 2013-11-29 17:23:47 -05:00
parent eac47b642c
commit 2eca65eb5f
10 changed files with 55 additions and 36 deletions

View File

@ -119,7 +119,8 @@ class Controller(controller.BaseController):
if attempted > maximum: if attempted > maximum:
msg = _("The limit has been exceeded on the number of allowed " msg = _("The limit has been exceeded on the number of allowed "
"image members for this image. Attempted: %(attempted)s, " "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, raise webob.exc.HTTPRequestEntityTooLarge(explanation=msg,
request=req) request=req)

View File

@ -155,15 +155,16 @@ Queues an image for caching
return FAILURE return FAILURE
if (not options.force and if (not options.force and
not user_confirm("Queue image %s for caching?" % (image_id,), not user_confirm("Queue image %(image_id)s for caching?" %
default=False)): {'image_id': image_id}, default=False)):
return SUCCESS return SUCCESS
client = get_client(options) client = get_client(options)
client.queue_image_for_caching(image_id) client.queue_image_for_caching(image_id)
if options.verbose: 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 return SUCCESS
@ -183,15 +184,15 @@ Deletes an image from the cache
return FAILURE return FAILURE
if (not options.force and if (not options.force and
not user_confirm("Delete cached image %s?" % (image_id,), not user_confirm("Delete cached image %(image_id)s?" %
default=False)): {'image_id': image_id}, default=False)):
return SUCCESS return SUCCESS
client = get_client(options) client = get_client(options)
client.delete_cached_image(image_id) client.delete_cached_image(image_id)
if options.verbose: if options.verbose:
print("Deleted cached image %(image_id)s" % locals()) print("Deleted cached image %(image_id)s" % {'image_id': image_id})
return SUCCESS return SUCCESS
@ -210,7 +211,8 @@ Remove all images from the cache.
num_deleted = client.delete_all_cached_images() num_deleted = client.delete_all_cached_images()
if options.verbose: if options.verbose:
print("Deleted %(num_deleted)s cached images" % locals()) print("Deleted %(num_deleted)s cached images" %
{'num_deleted': num_deleted})
return SUCCESS return SUCCESS
@ -230,15 +232,15 @@ Deletes an image from the cache
return FAILURE return FAILURE
if (not options.force and if (not options.force and
not user_confirm("Delete queued image %s?" % (image_id,), not user_confirm("Delete queued image %(image_id)s?" %
default=False)): {'image_id': image_id}, default=False)):
return SUCCESS return SUCCESS
client = get_client(options) client = get_client(options)
client.delete_queued_image(image_id) client.delete_queued_image(image_id)
if options.verbose: if options.verbose:
print("Deleted queued image %(image_id)s" % locals()) print("Deleted queued image %(image_id)s" % {'image_id': image_id})
return SUCCESS return SUCCESS
@ -257,7 +259,8 @@ Remove all images from the cache queue.
num_deleted = client.delete_all_queued_images() num_deleted = client.delete_all_queued_images()
if options.verbose: if options.verbose:
print("Deleted %(num_deleted)s queued images" % locals()) print("Deleted %(num_deleted)s queued images" %
{'num_deleted': num_deleted})
return SUCCESS return SUCCESS
@ -445,7 +448,7 @@ def lookup_command(parser, command_name):
command = commands[command_name] command = commands[command_name]
except KeyError: except KeyError:
parser.print_usage() parser.print_usage()
sys.exit("Unknown command: %s" % command_name) sys.exit("Unknown command: %(cmd_name)s" % {'cmd_name': command_name})
return command return command

View File

@ -88,7 +88,8 @@ def legacy_parse_uri(uri, to_quote, image_id):
"like so: " "like so: "
"swift+http://user:pass@authurl.com/v1/container/obj") "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) raise exception.BadStoreUri(message=reason)
pieces = urlparse.urlparse(uri) pieces = urlparse.urlparse(uri)
@ -120,7 +121,7 @@ def legacy_parse_uri(uri, to_quote, image_id):
if to_quote: if to_quote:
if len(cred_parts) == 1: if len(cred_parts) == 1:
reason = (_("Badly formed credentials '%(creds)s' in Swift " reason = (_("Badly formed credentials '%(creds)s' in Swift "
"URI") % locals()) "URI") % {'creds': creds})
LOG.error(reason) LOG.error(reason)
raise exception.BadStoreUri() raise exception.BadStoreUri()
elif len(cred_parts) == 3: elif len(cred_parts) == 3:
@ -150,7 +151,7 @@ def legacy_parse_uri(uri, to_quote, image_id):
path_parts.insert(0, netloc) path_parts.insert(0, netloc)
auth_or_store_url = '/'.join(path_parts) auth_or_store_url = '/'.join(path_parts)
except IndexError: except IndexError:
reason = _("Badly formed S3 URI: %s") % uri reason = _("Badly formed S3 URI: %(uri)s") % {'uri': uri}
LOG.error(message=reason) LOG.error(message=reason)
raise exception.BadStoreUri() raise exception.BadStoreUri()

View File

@ -86,8 +86,8 @@ def migrate_location_credentials(migrate_engine, to_quoted):
.where(images_table.c.id == image['id'])\ .where(images_table.c.id == image['id'])\
.values(location=fixed_uri).execute() .values(location=fixed_uri).execute()
except exception.Invalid: except exception.Invalid:
msg = _("Failed to decrypt location value for image %s") msg = _("Failed to decrypt location value for image %(image_id)s")
LOG.warn(msg % image['id']) LOG.warn(msg % {'image_id': image['id']})
def decrypt_location(uri): def decrypt_location(uri):
@ -151,7 +151,8 @@ def legacy_parse_uri(uri, to_quote, image_id):
"like so: " "like so: "
"swift+http://user:pass@authurl.com/v1/container/obj") "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) raise exception.BadStoreUri(message=reason)
pieces = urlparse.urlparse(uri) pieces = urlparse.urlparse(uri)
@ -183,7 +184,7 @@ def legacy_parse_uri(uri, to_quote, image_id):
if to_quote: if to_quote:
if len(cred_parts) == 1: if len(cred_parts) == 1:
reason = (_("Badly formed credentials '%(creds)s' in Swift " reason = (_("Badly formed credentials '%(creds)s' in Swift "
"URI") % locals()) "URI") % {'creds': creds})
LOG.error(reason) LOG.error(reason)
raise exception.BadStoreUri() raise exception.BadStoreUri()
elif len(cred_parts) == 3: elif len(cred_parts) == 3:
@ -213,7 +214,7 @@ def legacy_parse_uri(uri, to_quote, image_id):
path_parts.insert(0, netloc) path_parts.insert(0, netloc)
auth_or_store_url = '/'.join(path_parts) auth_or_store_url = '/'.join(path_parts)
except IndexError: except IndexError:
reason = _("Badly formed S3 URI: %s") % uri reason = _("Badly formed S3 URI: %(uri)s") % {'uri': uri}
LOG.error(message=reason) LOG.error(message=reason)
raise exception.BadStoreUri() raise exception.BadStoreUri()

View File

@ -652,9 +652,10 @@ class FunctionalTest(test_utils.BaseTestCase):
if auth_pieces[1].strip(): if auth_pieces[1].strip():
password = "-p%s" % auth_pieces[1] password = "-p%s" % auth_pieces[1]
sql = ("drop database if exists %(database)s; " 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 " 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) exitcode, out, err = execute(cmd)
self.assertEqual(0, exitcode) self.assertEqual(0, exitcode)

View File

@ -72,7 +72,8 @@ def _get_connect_string(backend,
backend = "postgresql+psycopg2" backend = "postgresql+psycopg2"
return ("%(backend)s://%(user)s:%(passwd)s@localhost/%(database)s" return ("%(backend)s://%(user)s:%(passwd)s@localhost/%(database)s"
% locals()) % {'backend': backend, 'user': user, 'passwd': passwd,
'database': database})
def _is_backend_avail(backend, def _is_backend_avail(backend,
@ -199,10 +200,11 @@ class TestMigrations(test_utils.BaseTestCase):
if len(auth_pieces) > 1: if len(auth_pieces) > 1:
if auth_pieces[1].strip(): if auth_pieces[1].strip():
password = "-p\"%s\"" % auth_pieces[1] password = "-p\"%s\"" % auth_pieces[1]
sql = ("drop database if exists %(database)s; " sql = ("drop database if exists %(database)s; create "
"create database %(database)s;") % locals() "database %(database)s;") % {'database': database}
cmd = ("mysql -u \"%(user)s\" %(password)s -h %(host)s " 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) execute_cmd(cmd)
elif conn_string.startswith('postgresql'): elif conn_string.startswith('postgresql'):
database = conn_pieces.path.strip('/') database = conn_pieces.path.strip('/')
@ -217,18 +219,23 @@ class TestMigrations(test_utils.BaseTestCase):
# note(boris-42): This file is used for authentication # note(boris-42): This file is used for authentication
# without password prompt. # without password prompt.
createpgpass = ("echo '*:*:*:%(user)s:%(password)s' > " createpgpass = ("echo '*:*:*:%(user)s:%(password)s' > "
"~/.pgpass && chmod 0600 ~/.pgpass" % locals()) "~/.pgpass && chmod 0600 ~/.pgpass" %
{'user': user, 'password': password})
execute_cmd(createpgpass) execute_cmd(createpgpass)
# note(boris-42): We must create and drop database, we can't # note(boris-42): We must create and drop database, we can't
# drop database which we have connected to, so for such # drop database which we have connected to, so for such
# operations there is a special database template1. # operations there is a special database template1.
sqlcmd = ("psql -w -U %(user)s -h %(host)s -c" sqlcmd = ("psql -w -U %(user)s -h %(host)s -c"
" '%(sql)s' -d template1") " '%(sql)s' -d template1")
sql = ("drop database if exists %(database)s;") % locals() sql = ("drop database if exists %(database)s;")
droptable = sqlcmd % locals() sql = sql % {'database': database}
droptable = sqlcmd % {'user': user, 'host': host,
'sql': sql}
execute_cmd(droptable) execute_cmd(droptable)
sql = ("create database %(database)s;") % locals() sql = ("create database %(database)s;")
createtable = sqlcmd % locals() sql = sql % {'database': database}
createtable = sqlcmd % {'user': user, 'host': host,
'sql': sql}
execute_cmd(createtable) execute_cmd(createtable)
def test_walk_versions(self): def test_walk_versions(self):

View File

@ -634,7 +634,9 @@ class TestRegistryV1Client(base.IsolatedUnitTest, test_utils.RegistryAPIMixIn):
el = data[k] el = data[k]
self.assertEqual(v, data[k], self.assertEqual(v, data[k],
"Failed v != data[k] where v = %(v)s and " "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): def test_get_image_non_existing(self):
"""Tests that NotFound is raised when getting a non-existing image""" """Tests that NotFound is raised when getting a non-existing image"""

View File

@ -2285,7 +2285,8 @@ class TestImagesDeserializer(test_utils.BaseTestCase):
def test_index_with_many_filter(self): def test_index_with_many_filter(self):
name = 'My Little Image' name = 'My Little Image'
instance_id = str(uuid.uuid4()) 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) request = unit_test_utils.get_fake_request(path)
output = self.deserializer.index(request) output = self.deserializer.index(request)
self.assertEqual(output['filters']['name'], name) self.assertEqual(output['filters']['name'], name)

View File

@ -383,7 +383,8 @@ class TestTasksDeserializer(test_utils.BaseTestCase):
def test_index_with_many_filter(self): def test_index_with_many_filter(self):
status = 'success' status = 'success'
type = 'import' 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) request = unit_test_utils.get_fake_request(path)
output = self.deserializer.index(request) output = self.deserializer.index(request)
self.assertEqual(output['filters']['status'], status) self.assertEqual(output['filters']['status'], status)

View File

@ -302,7 +302,8 @@ def execute(cmd,
msg = "Command %(cmd)s did not succeed. Returned an exit "\ msg = "Command %(cmd)s did not succeed. Returned an exit "\
"code of %(exitcode)d."\ "code of %(exitcode)d."\
"\n\nSTDOUT: %(out)s"\ "\n\nSTDOUT: %(out)s"\
"\n\nSTDERR: %(err)s" % locals() "\n\nSTDERR: %(err)s" % {'cmd': cmd, 'exitcode': exitcode,
'out': out, 'err': err}
if context: if context:
msg += "\n\nCONTEXT: %s" % context msg += "\n\nCONTEXT: %s" % context
raise RuntimeError(msg) raise RuntimeError(msg)