Merge "Bump hacking to 0.8 and get python 3.x compatibility"

This commit is contained in:
Jenkins 2014-01-16 01:44:54 +00:00 committed by Gerrit Code Review
commit 9c0ada37c9
10 changed files with 55 additions and 36 deletions

View File

@ -117,7 +117,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)

View File

@ -154,15 +154,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
@ -182,15 +183,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
@ -209,7 +210,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
@ -229,15 +231,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
@ -256,7 +258,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
@ -444,7 +447,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

View File

@ -86,7 +86,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)
@ -118,7 +119,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:
@ -148,7 +149,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()

View File

@ -84,8 +84,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):
@ -149,7 +149,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)
@ -181,7 +182,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:
@ -211,7 +212,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()

View File

@ -650,9 +650,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)

View File

@ -70,7 +70,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,
@ -197,10 +198,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('/')
@ -215,18 +217,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):

View File

@ -632,7 +632,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"""

View File

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

View File

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

View File

@ -300,7 +300,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)