Python 3.x compatibility fixes

Mechanical translation of the easy-to-fix Python 2.x->3.x
compatibility issues. Should work with all Python versions
>= 2.6.

Change-Id: I693ff5d72b2db8d9d3a3347f70f22290897e9cff
This commit is contained in:
Dirk Mueller 2013-06-25 14:19:56 +02:00
parent eafc62f61b
commit 7b0ed4f49c
16 changed files with 34 additions and 34 deletions

View File

@ -210,7 +210,7 @@ class LoopingCall(object):
if not self._running:
break
greenthread.sleep(interval)
except LoopingCallDone, e:
except LoopingCallDone as e:
self.stop()
done.send(e.retvalue)
except Exception:

View File

@ -52,7 +52,7 @@ class MgmtInstanceController(InstanceController):
deleted = False
try:
instances = models.load_mgmt_instances(context, deleted=deleted)
except nova_exceptions.ClientException, e:
except nova_exceptions.ClientException as e:
LOG.error(e)
return wsgi.Result(str(e), 403)
@ -139,7 +139,7 @@ class MgmtInstanceController(InstanceController):
context = req.environ[wsgi.CONTEXT_KEY]
try:
server = instance_models.Instance.load(context=context, id=id)
except exception.TroveError, e:
except exception.TroveError as e:
LOG.error(e)
return wsgi.Result(str(e), 404)
reh = mysql_models.RootHistory.load(context=context, instance_id=id)

View File

@ -64,7 +64,7 @@ class SecurityGroup(DatabaseModelBase):
user=context.user,
tenant_id=context.tenant)
except exception.SecurityGroupCreationError, e:
except exception.SecurityGroupCreationError as e:
LOG.exception("Failed to create remote security group")
raise e
@ -155,7 +155,7 @@ class SecurityGroupRule(DatabaseModelBase):
cidr=cidr,
group_id=sec_group['id'])
except exception.SecurityGroupRuleCreationError, e:
except exception.SecurityGroupRuleCreationError as e:
LOG.exception("Failed to create remote security group")
raise e
@ -203,9 +203,9 @@ class RemoteSecurityGroup(NovaRemoteModelBase):
try:
client = trove.common.remote.create_nova_client(context)
self._data_object = client.security_groups.get(id)
except nova_exceptions.NotFound, e:
except nova_exceptions.NotFound as e:
raise exception.NotFound(id=id)
except nova_exceptions.ClientException, e:
except nova_exceptions.ClientException as e:
raise exception.TroveError(str(e))
else:
self._data_object = security_group
@ -217,7 +217,7 @@ class RemoteSecurityGroup(NovaRemoteModelBase):
try:
sec_group = client.security_groups.create(name=name,
description=description)
except nova_exceptions.ClientException, e:
except nova_exceptions.ClientException as e:
LOG.exception('Failed to create remote security group')
raise exception.SecurityGroupCreationError(str(e))
@ -229,7 +229,7 @@ class RemoteSecurityGroup(NovaRemoteModelBase):
try:
client.security_groups.delete(sec_group_id)
except nova_exceptions.ClientException, e:
except nova_exceptions.ClientException as e:
LOG.exception('Failed to delete remote security group')
raise exception.SecurityGroupDeletionError(str(e))
@ -248,7 +248,7 @@ class RemoteSecurityGroup(NovaRemoteModelBase):
cidr=cidr)
return sec_group_rule.id
except nova_exceptions.ClientException, e:
except nova_exceptions.ClientException as e:
LOG.exception('Failed to add rule to remote security group')
raise exception.SecurityGroupRuleCreationError(str(e))
@ -259,6 +259,6 @@ class RemoteSecurityGroup(NovaRemoteModelBase):
try:
client.security_group_rules.delete(sec_group_rule_id)
except nova_exceptions.ClientException, e:
except nova_exceptions.ClientException as e:
LOG.exception('Failed to delete rule to remote security group')
raise exception.SecurityGroupRuleDeletionError(str(e))

View File

@ -38,9 +38,9 @@ class Flavor(object):
try:
client = create_nova_client(context)
self.flavor = client.flavors.get(flavor_id)
except nova_exceptions.NotFound, e:
except nova_exceptions.NotFound as e:
raise exception.NotFound(uuid=flavor_id)
except nova_exceptions.ClientException, e:
except nova_exceptions.ClientException as e:
raise exception.TroveError(str(e))
return
msg = ("Flavor is not defined, and"

View File

@ -563,7 +563,7 @@ class KeepAliveConnection(interfaces.PoolListener):
dbapi_con.ping(False)
except TypeError:
dbapi_con.ping()
except dbapi_con.OperationalError, ex:
except dbapi_con.OperationalError as ex:
if ex.args[0] in (2006, 2013, 2014, 2045, 2055):
raise exc.DisconnectionError()
else:
@ -818,7 +818,7 @@ class MySqlApp(object):
# don't let a rouge process wander around.
try:
utils.execute_with_timeout("sudo", "pkill", "-9", "mysql")
except exception.ProcessExecutionError, p:
except exception.ProcessExecutionError as p:
LOG.error("Error killing stalled mysql start command.")
LOG.error(p)
# There's nothing more we can do...
@ -869,7 +869,7 @@ class MySqlRootAccess(object):
user.host = "%"
user.password = generate_random_password()
with LocalSqlClient(get_engine()) as client:
print client
print(client)
try:
cu = query.CreateUser(user.name, host=user.host)
t = text(str(cu))
@ -879,7 +879,7 @@ class MySqlRootAccess(object):
# TODO(rnirmal): More fine grained error checking later on
LOG.debug(err)
with LocalSqlClient(get_engine()) as client:
print client
print(client)
uu = query.UpdateUser(user.name, host=user.host,
clear=user.password)
t = text(str(uu))

View File

@ -59,7 +59,7 @@ class SwiftStorage(base.Storage):
# Check each segment MD5 hash against swift etag
# Raise an error and mark backup as failed
if etag != stream.schecksum.hexdigest():
print etag, stream.schecksum.hexdigest()
print("%s %s" % (etag, stream.schecksum.hexdigest()))
return (False, "Error saving data to Swift!", None, None)
checksum = stream.checksum.hexdigest()

View File

@ -49,7 +49,7 @@ def load_server(context, instance_id, server_id):
LOG.debug("Could not find nova server_id(%s)" % server_id)
raise exception.ComputeInstanceNotFound(instance_id=instance_id,
server_id=server_id)
except nova_exceptions.ClientException, e:
except nova_exceptions.ClientException as e:
raise exception.TroveError(str(e))
return server

View File

@ -496,7 +496,7 @@ class BuiltInstanceTasks(BuiltInstance, NotifyMixin):
# when the reboot completes and MySQL is running.
self._set_service_status_to_paused()
LOG.debug("Successfully rebooted instance %s" % self.id)
except Exception, e:
except Exception as e:
LOG.error("Failed to reboot instance %s: %s" % (self.id, str(e)))
finally:
LOG.debug("Rebooting FINALLY %s" % self.id)

View File

@ -1178,7 +1178,7 @@ class CheckInstance(AttrCheck):
return
if self.volume_key_exists():
expected_attrs = ['size', 'used']
print self.instance
print(self.instance)
self.attrs_exist(self.instance['volume'], expected_attrs,
msg="Volumes")
@ -1192,7 +1192,7 @@ class CheckInstance(AttrCheck):
def addresses(self):
expected_attrs = ['addr', 'version']
print self.instance
print(self.instance)
networks = ['usernet']
for network in networks:
for address in self.instance['addresses'][network]:
@ -1251,11 +1251,11 @@ class BadInstanceStatusBug():
def verify_instance_is_active():
result = self.client.instances.get(id)
print result.status
print(result.status)
return result.status == 'ACTIVE'
def attempt_migrate():
print 'attempting migration'
print('attempting migration')
try:
self.mgmt.migrate(id)
except exceptions.UnprocessableEntity:

View File

@ -145,7 +145,7 @@ class AllAccounts(object):
except exceptions.NotFound:
deleted_count += 1
except Exception:
print "Failed to delete instance"
print("Failed to delete instance")
if deleted_count == len(user_instances):
break
@ -201,7 +201,7 @@ class AccountWithBrokenInstance(object):
lambda instance: instance.status == 'ERROR',
time_out=10)
self.instance = self.client.instances.get(self.response.id)
print "Status: %s" % self.instance.status
print("Status: %s" % self.instance.status)
msg = "Instance did not drop to error after server prov failure."
assert_equal(self.instance.status, "ERROR", msg)

View File

@ -60,7 +60,7 @@ class MgmtInstanceBase(object):
def _make_request(self, path='/', context=None, **kwargs):
from webob import Request
path = '/'
print "path:", path
print("path: %s" % path)
return Request.blank(path=path, environ={'trove.context': context},
**kwargs)

View File

@ -102,7 +102,7 @@ class FakeGuest(object):
if hostname is None:
hostname = '%'
self.users[(username, hostname)] = user
print "CREATING %s @ %s" % (username, hostname)
print("CREATING %s @ %s" % (username, hostname))
databases = [db['_name'] for db in user['_databases']]
self.grant_access(username, hostname, databases)
return user
@ -173,7 +173,7 @@ class FakeGuest(object):
def get_user(self, username, hostname):
self._check_username(username)
for (u, h) in self.users:
print "%r @ %r" % (u, h)
print("%r @ %r" % (u, h))
if (username, hostname) not in self.users:
raise rd_exception.UserNotFound(
"User %s@%s cannot be found on the instance."

View File

@ -571,9 +571,9 @@ class FakeHost(object):
self.totalRAM = 2004 # 16384
self.usedRAM = 0
for server in self.servers.list():
print server
print(server)
if server.host != self.name:
print "\t...not on this host."
print("\t...not on this host.")
continue
self.instances.append({
'uuid': server.id,

View File

@ -329,7 +329,7 @@ class ParseLimitsTest(BaseLimitTestSuite):
'(PUT, /foo*, /foo.*, 10, hour);'
'(POST, /bar*, /bar.*, 5, second);'
'(Say, /derp*, /derp.*, 1, day)')
except ValueError, e:
except ValueError as e:
assert False, str(e)
# Make sure the number of returned limits are correct

View File

@ -702,7 +702,7 @@ class TextClauseMatcher(matchers.Matcher):
return "TextClause(%s)" % self.contains.sub
def matches(self, arg):
print "Matching", arg.text
print("Matching %s" % arg.text)
return self.contains.matches(arg.text)

View File

@ -40,7 +40,7 @@ class UsageVerifier(object):
def check_message(self, resource_id, event_type, **attrs):
messages = self.get_messages(resource_id)
print messages, resource_id
print("%s %s" % (messages, resource_id))
found = None
for message in messages:
if message['event_type'] == event_type: