Merge "Improve Python 3.x compatibility"

This commit is contained in:
Jenkins 2013-04-30 06:18:07 +00:00 committed by Gerrit Code Review
commit d9c4623870
12 changed files with 49 additions and 49 deletions

View File

@ -655,11 +655,11 @@ class DhcpLeaseRelay(object):
ip_address = str(netaddr.IPAddress(data['ip_address'])) ip_address = str(netaddr.IPAddress(data['ip_address']))
lease_remaining = int(data['lease_remaining']) lease_remaining = int(data['lease_remaining'])
self.callback(network_id, ip_address, lease_remaining) self.callback(network_id, ip_address, lease_remaining)
except ValueError, e: except ValueError as e:
LOG.warn(_('Unable to parse lease relay msg to dict.')) LOG.warn(_('Unable to parse lease relay msg to dict.'))
LOG.warn(_('Exception value: %s'), e) LOG.warn(_('Exception value: %s'), e)
LOG.warn(_('Message representation: %s'), repr(msg)) LOG.warn(_('Message representation: %s'), repr(msg))
except Exception, e: except Exception as e:
LOG.exception(_('Unable update lease. Exception')) LOG.exception(_('Unable update lease. Exception'))
def start(self): def start(self):

View File

@ -64,7 +64,7 @@ class OVSBridge:
full_args = ["ovs-vsctl", "--timeout=2"] + args full_args = ["ovs-vsctl", "--timeout=2"] + args
try: try:
return utils.execute(full_args, root_helper=self.root_helper) return utils.execute(full_args, root_helper=self.root_helper)
except Exception, e: except Exception as e:
LOG.error(_("Unable to execute %(cmd)s. Exception: %(exception)s"), LOG.error(_("Unable to execute %(cmd)s. Exception: %(exception)s"),
{'cmd': full_args, 'exception': e}) {'cmd': full_args, 'exception': e})
@ -93,7 +93,7 @@ class OVSBridge:
full_args = ["ovs-ofctl", cmd, self.br_name] + args full_args = ["ovs-ofctl", cmd, self.br_name] + args
try: try:
return utils.execute(full_args, root_helper=self.root_helper) return utils.execute(full_args, root_helper=self.root_helper)
except Exception, e: except Exception as e:
LOG.error(_("Unable to execute %(cmd)s. Exception: %(exception)s"), LOG.error(_("Unable to execute %(cmd)s. Exception: %(exception)s"),
{'cmd': full_args, 'exception': e}) {'cmd': full_args, 'exception': e})
@ -215,7 +215,7 @@ class OVSBridge:
"param-key=nicira-iface-id", "uuid=%s" % xs_vif_uuid] "param-key=nicira-iface-id", "uuid=%s" % xs_vif_uuid]
try: try:
return utils.execute(args, root_helper=self.root_helper).strip() return utils.execute(args, root_helper=self.root_helper).strip()
except Exception, e: except Exception as e:
LOG.error(_("Unable to execute %(cmd)s. Exception: %(exception)s"), LOG.error(_("Unable to execute %(cmd)s. Exception: %(exception)s"),
{'cmd': args, 'exception': e}) {'cmd': args, 'exception': e})
@ -270,7 +270,7 @@ class OVSBridge:
port_name = match.group('port_name') port_name = match.group('port_name')
ofport = int(match.group('ofport')) ofport = int(match.group('ofport'))
return VifPort(port_name, ofport, vif_id, vif_mac, self) return VifPort(port_name, ofport, vif_id, vif_mac, self)
except Exception, e: except Exception as e:
LOG.info(_("Unable to parse regex results. Exception: %s"), e) LOG.info(_("Unable to parse regex results. Exception: %s"), e)
return return
@ -297,6 +297,6 @@ def get_bridges(root_helper):
args = ["ovs-vsctl", "--timeout=2", "list-br"] args = ["ovs-vsctl", "--timeout=2", "list-br"]
try: try:
return utils.execute(args, root_helper=root_helper).strip().split("\n") return utils.execute(args, root_helper=root_helper).strip().split("\n")
except Exception, e: except Exception as e:
LOG.exception(_("Unable to retrieve bridges. Exception: %s"), e) LOG.exception(_("Unable to retrieve bridges. Exception: %s"), e)
return [] return []

View File

@ -86,7 +86,7 @@ class MySQLPingListener(object):
def checkout(self, dbapi_con, con_record, con_proxy): def checkout(self, dbapi_con, con_record, con_proxy):
try: try:
dbapi_con.cursor().execute('select 1') dbapi_con.cursor().execute('select 1')
except dbapi_con.OperationalError, ex: except dbapi_con.OperationalError as ex:
if ex.args[0] in (2006, 2013, 2014, 2045, 2055): if ex.args[0] in (2006, 2013, 2014, 2045, 2055):
LOG.warn(_('Got mysql server has gone away: %s'), ex) LOG.warn(_('Got mysql server has gone away: %s'), ex)
raise DisconnectionError(_("Database server went away")) raise DisconnectionError(_("Database server went away"))

View File

@ -51,7 +51,7 @@ CONF.register_opts(_quota_opts, 'QUOTAS')
def do_alembic_command(config, cmd, *args, **kwargs): def do_alembic_command(config, cmd, *args, **kwargs):
try: try:
getattr(alembic_command, cmd)(config, *args, **kwargs) getattr(alembic_command, cmd)(config, *args, **kwargs)
except alembic_util.CommandError, e: except alembic_util.CommandError as e:
alembic_util.err(str(e)) alembic_util.err(str(e))

View File

@ -282,7 +282,7 @@ class InternalContext(object):
except greenlet.GreenletExit: except greenlet.GreenletExit:
# ignore these since they are just from shutdowns # ignore these since they are just from shutdowns
pass pass
except rpc_common.ClientException, e: except rpc_common.ClientException as e:
LOG.debug(_("Expected exception during message handling (%s)") % LOG.debug(_("Expected exception during message handling (%s)") %
e._exc_info[1]) e._exc_info[1])
return {'exc': return {'exc':

View File

@ -42,7 +42,7 @@ class NexusDB(object):
bind_dict["port-id"] = str(bind.port_id) bind_dict["port-id"] = str(bind.port_id)
bind_dict["vlan-id"] = str(bind.vlan_id) bind_dict["vlan-id"] = str(bind.vlan_id)
bindings.append(bind_dict) bindings.append(bind_dict)
except Exception, exc: except Exception as exc:
LOG.error("Failed to get all bindings: %s" % str(exc)) LOG.error("Failed to get all bindings: %s" % str(exc))
return bindings return bindings
@ -56,7 +56,7 @@ class NexusDB(object):
bind_dict["port-id"] = str(bind.port_id) bind_dict["port-id"] = str(bind.port_id)
bind_dict["vlan-id"] = str(bind.vlan_id) bind_dict["vlan-id"] = str(bind.vlan_id)
binding.append(bind_dict) binding.append(bind_dict)
except Exception, exc: except Exception as exc:
LOG.error("Failed to get all bindings: %s" % str(exc)) LOG.error("Failed to get all bindings: %s" % str(exc))
return binding return binding
@ -69,7 +69,7 @@ class NexusDB(object):
bind_dict["port-id"] = str(res.port_id) bind_dict["port-id"] = str(res.port_id)
bind_dict["vlan-id"] = str(res.vlan_id) bind_dict["vlan-id"] = str(res.vlan_id)
return bind_dict return bind_dict
except Exception, exc: except Exception as exc:
LOG.error("Failed to create nexus binding: %s" % str(exc)) LOG.error("Failed to create nexus binding: %s" % str(exc))
def delete_nexusportbinding(self, vlan_id): def delete_nexusportbinding(self, vlan_id):
@ -83,7 +83,7 @@ class NexusDB(object):
bind_dict["port-id"] = res.port_id bind_dict["port-id"] = res.port_id
bindings.append(bind_dict) bindings.append(bind_dict)
return bindings return bindings
except Exception, exc: except Exception as exc:
raise Exception("Failed to delete nexus port binding: %s" raise Exception("Failed to delete nexus port binding: %s"
% str(exc)) % str(exc))
@ -96,7 +96,7 @@ class NexusDB(object):
bind_dict["port-id"] = str(res.port_id) bind_dict["port-id"] = str(res.port_id)
bind_dict["vlan-id"] = str(res.vlan_id) bind_dict["vlan-id"] = str(res.vlan_id)
return bind_dict return bind_dict
except Exception, exc: except Exception as exc:
raise Exception("Failed to update nexus port binding vnic: %s" raise Exception("Failed to update nexus port binding vnic: %s"
% str(exc)) % str(exc))
@ -115,7 +115,7 @@ class L2networkDB(object):
vlan_dict["vlan-name"] = vlan_bind.vlan_name vlan_dict["vlan-name"] = vlan_bind.vlan_name
vlan_dict["net-id"] = str(vlan_bind.network_id) vlan_dict["net-id"] = str(vlan_bind.network_id)
vlans.append(vlan_dict) vlans.append(vlan_dict)
except Exception, exc: except Exception as exc:
LOG.error("Failed to get all vlan bindings: %s" % str(exc)) LOG.error("Failed to get all vlan bindings: %s" % str(exc))
return vlans return vlans
@ -131,7 +131,7 @@ class L2networkDB(object):
vlan_dict["vlan-name"] = vlan_bind.vlan_name vlan_dict["vlan-name"] = vlan_bind.vlan_name
vlan_dict["net-id"] = str(vlan_bind.network_id) vlan_dict["net-id"] = str(vlan_bind.network_id)
vlan.append(vlan_dict) vlan.append(vlan_dict)
except Exception, exc: except Exception as exc:
LOG.error("Failed to get vlan binding: %s" % str(exc)) LOG.error("Failed to get vlan binding: %s" % str(exc))
return vlan return vlan
@ -145,7 +145,7 @@ class L2networkDB(object):
vlan_dict["vlan-name"] = res.vlan_name vlan_dict["vlan-name"] = res.vlan_name
vlan_dict["net-id"] = str(res.network_id) vlan_dict["net-id"] = str(res.network_id)
return vlan_dict return vlan_dict
except Exception, exc: except Exception as exc:
LOG.error("Failed to create vlan binding: %s" % str(exc)) LOG.error("Failed to create vlan binding: %s" % str(exc))
def delete_vlan_binding(self, network_id): def delete_vlan_binding(self, network_id):
@ -156,7 +156,7 @@ class L2networkDB(object):
vlan_dict = {} vlan_dict = {}
vlan_dict["vlan-id"] = str(res.vlan_id) vlan_dict["vlan-id"] = str(res.vlan_id)
return vlan_dict return vlan_dict
except Exception, exc: except Exception as exc:
raise Exception("Failed to delete vlan binding: %s" % str(exc)) raise Exception("Failed to delete vlan binding: %s" % str(exc))
def update_vlan_binding(self, network_id, vlan_id, vlan_name): def update_vlan_binding(self, network_id, vlan_id, vlan_name):
@ -170,7 +170,7 @@ class L2networkDB(object):
vlan_dict["vlan-name"] = res.vlan_name vlan_dict["vlan-name"] = res.vlan_name
vlan_dict["net-id"] = str(res.network_id) vlan_dict["net-id"] = str(res.network_id)
return vlan_dict return vlan_dict
except Exception, exc: except Exception as exc:
raise Exception("Failed to update vlan binding: %s" % str(exc)) raise Exception("Failed to update vlan binding: %s" % str(exc))
@ -187,7 +187,7 @@ class QuantumDB(object):
net_dict["net-id"] = str(net.uuid) net_dict["net-id"] = str(net.uuid)
net_dict["net-name"] = net.name net_dict["net-name"] = net.name
nets.append(net_dict) nets.append(net_dict)
except Exception, exc: except Exception as exc:
LOG.error("Failed to get all networks: %s" % str(exc)) LOG.error("Failed to get all networks: %s" % str(exc))
return nets return nets
@ -202,7 +202,7 @@ class QuantumDB(object):
net_dict["net-id"] = str(net.uuid) net_dict["net-id"] = str(net.uuid)
net_dict["net-name"] = net.name net_dict["net-name"] = net.name
net.append(net_dict) net.append(net_dict)
except Exception, exc: except Exception as exc:
LOG.error("Failed to get network: %s" % str(exc)) LOG.error("Failed to get network: %s" % str(exc))
return net return net
@ -216,7 +216,7 @@ class QuantumDB(object):
net_dict["net-id"] = str(res.uuid) net_dict["net-id"] = str(res.uuid)
net_dict["net-name"] = res.name net_dict["net-name"] = res.name
return net_dict return net_dict
except Exception, exc: except Exception as exc:
LOG.error("Failed to create network: %s" % str(exc)) LOG.error("Failed to create network: %s" % str(exc))
def delete_network(self, net_id): def delete_network(self, net_id):
@ -227,7 +227,7 @@ class QuantumDB(object):
net_dict = {} net_dict = {}
net_dict["net-id"] = str(net.uuid) net_dict["net-id"] = str(net.uuid)
return net_dict return net_dict
except Exception, exc: except Exception as exc:
raise Exception("Failed to delete port: %s" % str(exc)) raise Exception("Failed to delete port: %s" % str(exc))
def update_network(self, tenant_id, net_id, **kwargs): def update_network(self, tenant_id, net_id, **kwargs):
@ -239,7 +239,7 @@ class QuantumDB(object):
net_dict["net-id"] = str(net.uuid) net_dict["net-id"] = str(net.uuid)
net_dict["net-name"] = net.name net_dict["net-name"] = net.name
return net_dict return net_dict
except Exception, exc: except Exception as exc:
raise Exception("Failed to update network: %s" % str(exc)) raise Exception("Failed to update network: %s" % str(exc))
def get_all_ports(self, net_id): def get_all_ports(self, net_id):
@ -256,7 +256,7 @@ class QuantumDB(object):
port_dict["net"] = port.network port_dict["net"] = port.network
ports.append(port_dict) ports.append(port_dict)
return ports return ports
except Exception, exc: except Exception as exc:
LOG.error("Failed to get all ports: %s" % str(exc)) LOG.error("Failed to get all ports: %s" % str(exc))
def get_port(self, net_id, port_id): def get_port(self, net_id, port_id):
@ -272,7 +272,7 @@ class QuantumDB(object):
port_dict["state"] = port.state port_dict["state"] = port.state
port_list.append(port_dict) port_list.append(port_dict)
return port_list return port_list
except Exception, exc: except Exception as exc:
LOG.error("Failed to get port: %s" % str(exc)) LOG.error("Failed to get port: %s" % str(exc))
def create_port(self, net_id): def create_port(self, net_id):
@ -286,7 +286,7 @@ class QuantumDB(object):
port_dict["int-id"] = port.interface_id port_dict["int-id"] = port.interface_id
port_dict["state"] = port.state port_dict["state"] = port.state
return port_dict return port_dict
except Exception, exc: except Exception as exc:
LOG.error("Failed to create port: %s" % str(exc)) LOG.error("Failed to create port: %s" % str(exc))
def delete_port(self, net_id, port_id): def delete_port(self, net_id, port_id):
@ -297,7 +297,7 @@ class QuantumDB(object):
port_dict = {} port_dict = {}
port_dict["port-id"] = str(port.uuid) port_dict["port-id"] = str(port.uuid)
return port_dict return port_dict
except Exception, exc: except Exception as exc:
raise Exception("Failed to delete port: %s" % str(exc)) raise Exception("Failed to delete port: %s" % str(exc))
def update_port(self, net_id, port_id, port_state): def update_port(self, net_id, port_id, port_state):
@ -311,7 +311,7 @@ class QuantumDB(object):
port_dict["int-id"] = port.interface_id port_dict["int-id"] = port.interface_id
port_dict["state"] = port.state port_dict["state"] = port.state
return port_dict return port_dict
except Exception, exc: except Exception as exc:
raise Exception("Failed to update port state: %s" % str(exc)) raise Exception("Failed to update port state: %s" % str(exc))
def plug_interface(self, net_id, port_id, int_id): def plug_interface(self, net_id, port_id, int_id):
@ -325,7 +325,7 @@ class QuantumDB(object):
port_dict["int-id"] = port.interface_id port_dict["int-id"] = port.interface_id
port_dict["state"] = port.state port_dict["state"] = port.state
return port_dict return port_dict
except Exception, exc: except Exception as exc:
raise Exception("Failed to plug interface: %s" % str(exc)) raise Exception("Failed to plug interface: %s" % str(exc))
def unplug_interface(self, net_id, port_id): def unplug_interface(self, net_id, port_id):
@ -339,7 +339,7 @@ class QuantumDB(object):
port_dict["int-id"] = port.interface_id port_dict["int-id"] = port.interface_id
port_dict["state"] = port.state port_dict["state"] = port.state
return port_dict return port_dict
except Exception, exc: except Exception as exc:
raise Exception("Failed to unplug interface: %s" % str(exc)) raise Exception("Failed to unplug interface: %s" % str(exc))

View File

@ -85,7 +85,7 @@ class OFCClient(object):
else: else:
reason = _("An operation on OFC is failed.") reason = _("An operation on OFC is failed.")
raise nexc.OFCException(reason=reason) raise nexc.OFCException(reason=reason)
except (socket.error, IOError), e: except (socket.error, IOError) as e:
reason = _("Failed to connect OFC : %s") % str(e) reason = _("Failed to connect OFC : %s") % str(e)
LOG.error(reason) LOG.error(reason)
raise nexc.OFCException(reason=reason) raise nexc.OFCException(reason=reason)

View File

@ -293,7 +293,7 @@ def main():
agent = OVSQuantumOFPRyuAgent(integ_br, tunnel_ip, ovsdb_ip, agent = OVSQuantumOFPRyuAgent(integ_br, tunnel_ip, ovsdb_ip,
ovsdb_port, polling_interval, ovsdb_port, polling_interval,
root_helper) root_helper)
except httplib.HTTPException, e: except httplib.HTTPException as e:
LOG.error(_("Initialization failed: %s"), e) LOG.error(_("Initialization failed: %s"), e)
sys.exit(1) sys.exit(1)

View File

@ -121,7 +121,7 @@ class HaproxyNSDriver(object):
break break
return self._parse_stats(raw_stats) return self._parse_stats(raw_stats)
except socket.error, e: except socket.error as e:
LOG.warn(_('Error while connecting to stats socket: %s') % e) LOG.warn(_('Error while connecting to stats socket: %s') % e)
return {} return {}
else: else:

View File

@ -37,7 +37,7 @@ def main():
try: try:
quantum_service = service.serve_wsgi(service.QuantumApiService) quantum_service = service.serve_wsgi(service.QuantumApiService)
quantum_service.wait() quantum_service.wait()
except RuntimeError, e: except RuntimeError as e:
sys.exit(_("ERROR: %s") % e) sys.exit(_("ERROR: %s") % e)

View File

@ -39,7 +39,7 @@ class QuantumDB(object):
net_dict["id"] = str(net.uuid) net_dict["id"] = str(net.uuid)
net_dict["name"] = net.name net_dict["name"] = net.name
nets.append(net_dict) nets.append(net_dict)
except Exception, exc: except Exception as exc:
LOG.error("Failed to get all networks: %s", str(exc)) LOG.error("Failed to get all networks: %s", str(exc))
return nets return nets
@ -54,7 +54,7 @@ class QuantumDB(object):
net_dict["id"] = str(net.uuid) net_dict["id"] = str(net.uuid)
net_dict["name"] = net.name net_dict["name"] = net.name
net.append(net_dict) net.append(net_dict)
except Exception, exc: except Exception as exc:
LOG.error("Failed to get network: %s", str(exc)) LOG.error("Failed to get network: %s", str(exc))
return net return net
@ -68,7 +68,7 @@ class QuantumDB(object):
net_dict["id"] = str(res.uuid) net_dict["id"] = str(res.uuid)
net_dict["name"] = res.name net_dict["name"] = res.name
return net_dict return net_dict
except Exception, exc: except Exception as exc:
LOG.error("Failed to create network: %s", str(exc)) LOG.error("Failed to create network: %s", str(exc))
def delete_network(self, net_id): def delete_network(self, net_id):
@ -79,7 +79,7 @@ class QuantumDB(object):
net_dict = {} net_dict = {}
net_dict["id"] = str(net.uuid) net_dict["id"] = str(net.uuid)
return net_dict return net_dict
except Exception, exc: except Exception as exc:
LOG.error("Failed to delete network: %s", str(exc)) LOG.error("Failed to delete network: %s", str(exc))
def update_network(self, tenant_id, net_id, param_data): def update_network(self, tenant_id, net_id, param_data):
@ -92,7 +92,7 @@ class QuantumDB(object):
net_dict["id"] = str(net.uuid) net_dict["id"] = str(net.uuid)
net_dict["name"] = net.name net_dict["name"] = net.name
return net_dict return net_dict
except Exception, exc: except Exception as exc:
LOG.error("Failed to update network: %s", str(exc)) LOG.error("Failed to update network: %s", str(exc))
def get_all_ports(self, net_id): def get_all_ports(self, net_id):
@ -108,7 +108,7 @@ class QuantumDB(object):
port_dict["state"] = port.state port_dict["state"] = port.state
ports.append(port_dict) ports.append(port_dict)
return ports return ports
except Exception, exc: except Exception as exc:
LOG.error("Failed to get all ports: %s", str(exc)) LOG.error("Failed to get all ports: %s", str(exc))
def get_port(self, net_id, port_id): def get_port(self, net_id, port_id):
@ -124,7 +124,7 @@ class QuantumDB(object):
port_dict["state"] = port.state port_dict["state"] = port.state
port_list.append(port_dict) port_list.append(port_dict)
return port_list return port_list
except Exception, exc: except Exception as exc:
LOG.error("Failed to get port: %s", str(exc)) LOG.error("Failed to get port: %s", str(exc))
def create_port(self, net_id): def create_port(self, net_id):
@ -138,7 +138,7 @@ class QuantumDB(object):
port_dict["attachment"] = port.interface_id port_dict["attachment"] = port.interface_id
port_dict["state"] = port.state port_dict["state"] = port.state
return port_dict return port_dict
except Exception, exc: except Exception as exc:
LOG.error("Failed to create port: %s", str(exc)) LOG.error("Failed to create port: %s", str(exc))
def delete_port(self, net_id, port_id): def delete_port(self, net_id, port_id):
@ -149,7 +149,7 @@ class QuantumDB(object):
port_dict = {} port_dict = {}
port_dict["id"] = str(port.uuid) port_dict["id"] = str(port.uuid)
return port_dict return port_dict
except Exception, exc: except Exception as exc:
LOG.error("Failed to delete port: %s", str(exc)) LOG.error("Failed to delete port: %s", str(exc))
def update_port(self, net_id, port_id, **kwargs): def update_port(self, net_id, port_id, **kwargs):
@ -163,7 +163,7 @@ class QuantumDB(object):
port_dict["attachment"] = port.interface_id port_dict["attachment"] = port.interface_id
port_dict["state"] = port.state port_dict["state"] = port.state
return port_dict return port_dict
except Exception, exc: except Exception as exc:
LOG.error("Failed to update port state: %s", str(exc)) LOG.error("Failed to update port state: %s", str(exc))
def plug_interface(self, net_id, port_id, int_id): def plug_interface(self, net_id, port_id, int_id):
@ -177,7 +177,7 @@ class QuantumDB(object):
port_dict["attachment"] = port.interface_id port_dict["attachment"] = port.interface_id
port_dict["state"] = port.state port_dict["state"] = port.state
return port_dict return port_dict
except Exception, exc: except Exception as exc:
LOG.error("Failed to plug interface: %s", str(exc)) LOG.error("Failed to plug interface: %s", str(exc))
def unplug_interface(self, net_id, port_id): def unplug_interface(self, net_id, port_id):
@ -185,5 +185,5 @@ class QuantumDB(object):
try: try:
db.port_unset_attachment(port_id, net_id) db.port_unset_attachment(port_id, net_id)
LOG.debug("Detached interface from port %s", port_id) LOG.debug("Detached interface from port %s", port_id)
except Exception, exc: except Exception as exc:
LOG.error("Failed to unplug interface: %s", str(exc)) LOG.error("Failed to unplug interface: %s", str(exc))

View File

@ -1043,7 +1043,7 @@ class Resource(Application):
try: try:
msg_dict = dict(url=request.url, status=response.status_int) msg_dict = dict(url=request.url, status=response.status_int)
msg = _("%(url)s returned with HTTP %(status)d") % msg_dict msg = _("%(url)s returned with HTTP %(status)d") % msg_dict
except AttributeError, e: except AttributeError as e:
msg_dict = dict(url=request.url, exception=e) msg_dict = dict(url=request.url, exception=e)
msg = _("%(url)s returned a fault: %(exception)s") % msg_dict msg = _("%(url)s returned a fault: %(exception)s") % msg_dict