From ba90d5276184afb06106e57f5da1224277e497b5 Mon Sep 17 00:00:00 2001 From: Dirk Mueller Date: Mon, 29 Apr 2013 11:41:46 +0200 Subject: [PATCH] Improve Python 3.x compatibility Replace the deprecated except x,y: construct with except x as y:, as that one works with all Python versions starting with 2.6.x Change-Id: I13080cfdad32eaef21aa2707fe5d2818bda68535 --- quantum/agent/dhcp_agent.py | 4 +- quantum/agent/linux/ovs_lib.py | 10 ++--- quantum/db/api.py | 2 +- quantum/db/migration/cli.py | 2 +- quantum/openstack/common/rpc/impl_zmq.py | 2 +- .../plugins/cisco/tests/unit/test_database.py | 44 +++++++++---------- quantum/plugins/nec/common/ofc_client.py | 2 +- .../plugins/ryu/agent/ryu_quantum_agent.py | 2 +- .../drivers/haproxy/namespace_driver.py | 2 +- quantum/server/__init__.py | 2 +- quantum/tests/unit/database_stubs.py | 24 +++++----- quantum/wsgi.py | 2 +- 12 files changed, 49 insertions(+), 49 deletions(-) diff --git a/quantum/agent/dhcp_agent.py b/quantum/agent/dhcp_agent.py index 804983a6eb3..fd811f02218 100644 --- a/quantum/agent/dhcp_agent.py +++ b/quantum/agent/dhcp_agent.py @@ -656,11 +656,11 @@ class DhcpLeaseRelay(object): ip_address = str(netaddr.IPAddress(data['ip_address'])) lease_remaining = int(data['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(_('Exception value: %s'), e) LOG.warn(_('Message representation: %s'), repr(msg)) - except Exception, e: + except Exception as e: LOG.exception(_('Unable update lease. Exception')) def start(self): diff --git a/quantum/agent/linux/ovs_lib.py b/quantum/agent/linux/ovs_lib.py index 5c38b58b744..f435a342a47 100644 --- a/quantum/agent/linux/ovs_lib.py +++ b/quantum/agent/linux/ovs_lib.py @@ -64,7 +64,7 @@ class OVSBridge: full_args = ["ovs-vsctl", "--timeout=2"] + args try: 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"), {'cmd': full_args, 'exception': e}) @@ -93,7 +93,7 @@ class OVSBridge: full_args = ["ovs-ofctl", cmd, self.br_name] + args try: 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"), {'cmd': full_args, 'exception': e}) @@ -215,7 +215,7 @@ class OVSBridge: "param-key=nicira-iface-id", "uuid=%s" % xs_vif_uuid] try: 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"), {'cmd': args, 'exception': e}) @@ -270,7 +270,7 @@ class OVSBridge: port_name = match.group('port_name') ofport = int(match.group('ofport')) 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) return @@ -297,6 +297,6 @@ def get_bridges(root_helper): args = ["ovs-vsctl", "--timeout=2", "list-br"] try: 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) return [] diff --git a/quantum/db/api.py b/quantum/db/api.py index 5919ecccec6..d6d40dbd4cb 100644 --- a/quantum/db/api.py +++ b/quantum/db/api.py @@ -89,7 +89,7 @@ class MySQLPingListener(object): def checkout(self, dbapi_con, con_record, con_proxy): try: 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): LOG.warn(_('Got mysql server has gone away: %s'), ex) raise DisconnectionError(_("Database server went away")) diff --git a/quantum/db/migration/cli.py b/quantum/db/migration/cli.py index 8aac59ebc71..8a033115be4 100644 --- a/quantum/db/migration/cli.py +++ b/quantum/db/migration/cli.py @@ -51,7 +51,7 @@ CONF.register_opts(_quota_opts, 'QUOTAS') def do_alembic_command(config, cmd, *args, **kwargs): try: getattr(alembic_command, cmd)(config, *args, **kwargs) - except alembic_util.CommandError, e: + except alembic_util.CommandError as e: alembic_util.err(str(e)) diff --git a/quantum/openstack/common/rpc/impl_zmq.py b/quantum/openstack/common/rpc/impl_zmq.py index d69abe4eef1..170e8a109fe 100644 --- a/quantum/openstack/common/rpc/impl_zmq.py +++ b/quantum/openstack/common/rpc/impl_zmq.py @@ -282,7 +282,7 @@ class InternalContext(object): except greenlet.GreenletExit: # ignore these since they are just from shutdowns pass - except rpc_common.ClientException, e: + except rpc_common.ClientException as e: LOG.debug(_("Expected exception during message handling (%s)") % e._exc_info[1]) return {'exc': diff --git a/quantum/plugins/cisco/tests/unit/test_database.py b/quantum/plugins/cisco/tests/unit/test_database.py index 798ad045b10..fb054c51089 100644 --- a/quantum/plugins/cisco/tests/unit/test_database.py +++ b/quantum/plugins/cisco/tests/unit/test_database.py @@ -42,7 +42,7 @@ class NexusDB(object): bind_dict["port-id"] = str(bind.port_id) bind_dict["vlan-id"] = str(bind.vlan_id) bindings.append(bind_dict) - except Exception, exc: + except Exception as exc: LOG.error("Failed to get all bindings: %s" % str(exc)) return bindings @@ -56,7 +56,7 @@ class NexusDB(object): bind_dict["port-id"] = str(bind.port_id) bind_dict["vlan-id"] = str(bind.vlan_id) binding.append(bind_dict) - except Exception, exc: + except Exception as exc: LOG.error("Failed to get all bindings: %s" % str(exc)) return binding @@ -69,7 +69,7 @@ class NexusDB(object): bind_dict["port-id"] = str(res.port_id) bind_dict["vlan-id"] = str(res.vlan_id) return bind_dict - except Exception, exc: + except Exception as exc: LOG.error("Failed to create nexus binding: %s" % str(exc)) def delete_nexusportbinding(self, vlan_id): @@ -83,7 +83,7 @@ class NexusDB(object): bind_dict["port-id"] = res.port_id bindings.append(bind_dict) return bindings - except Exception, exc: + except Exception as exc: raise Exception("Failed to delete nexus port binding: %s" % str(exc)) @@ -96,7 +96,7 @@ class NexusDB(object): bind_dict["port-id"] = str(res.port_id) bind_dict["vlan-id"] = str(res.vlan_id) return bind_dict - except Exception, exc: + except Exception as exc: raise Exception("Failed to update nexus port binding vnic: %s" % str(exc)) @@ -115,7 +115,7 @@ class L2networkDB(object): vlan_dict["vlan-name"] = vlan_bind.vlan_name vlan_dict["net-id"] = str(vlan_bind.network_id) vlans.append(vlan_dict) - except Exception, exc: + except Exception as exc: LOG.error("Failed to get all vlan bindings: %s" % str(exc)) return vlans @@ -131,7 +131,7 @@ class L2networkDB(object): vlan_dict["vlan-name"] = vlan_bind.vlan_name vlan_dict["net-id"] = str(vlan_bind.network_id) vlan.append(vlan_dict) - except Exception, exc: + except Exception as exc: LOG.error("Failed to get vlan binding: %s" % str(exc)) return vlan @@ -145,7 +145,7 @@ class L2networkDB(object): vlan_dict["vlan-name"] = res.vlan_name vlan_dict["net-id"] = str(res.network_id) return vlan_dict - except Exception, exc: + except Exception as exc: LOG.error("Failed to create vlan binding: %s" % str(exc)) def delete_vlan_binding(self, network_id): @@ -156,7 +156,7 @@ class L2networkDB(object): vlan_dict = {} vlan_dict["vlan-id"] = str(res.vlan_id) return vlan_dict - except Exception, exc: + except Exception as exc: raise Exception("Failed to delete vlan binding: %s" % str(exc)) 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["net-id"] = str(res.network_id) return vlan_dict - except Exception, exc: + except Exception as 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-name"] = net.name nets.append(net_dict) - except Exception, exc: + except Exception as exc: LOG.error("Failed to get all networks: %s" % str(exc)) return nets @@ -202,7 +202,7 @@ class QuantumDB(object): net_dict["net-id"] = str(net.uuid) net_dict["net-name"] = net.name net.append(net_dict) - except Exception, exc: + except Exception as exc: LOG.error("Failed to get network: %s" % str(exc)) return net @@ -216,7 +216,7 @@ class QuantumDB(object): net_dict["net-id"] = str(res.uuid) net_dict["net-name"] = res.name return net_dict - except Exception, exc: + except Exception as exc: LOG.error("Failed to create network: %s" % str(exc)) def delete_network(self, net_id): @@ -227,7 +227,7 @@ class QuantumDB(object): net_dict = {} net_dict["net-id"] = str(net.uuid) return net_dict - except Exception, exc: + except Exception as exc: raise Exception("Failed to delete port: %s" % str(exc)) 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-name"] = net.name return net_dict - except Exception, exc: + except Exception as exc: raise Exception("Failed to update network: %s" % str(exc)) def get_all_ports(self, net_id): @@ -256,7 +256,7 @@ class QuantumDB(object): port_dict["net"] = port.network ports.append(port_dict) return ports - except Exception, exc: + except Exception as exc: LOG.error("Failed to get all ports: %s" % str(exc)) def get_port(self, net_id, port_id): @@ -272,7 +272,7 @@ class QuantumDB(object): port_dict["state"] = port.state port_list.append(port_dict) return port_list - except Exception, exc: + except Exception as exc: LOG.error("Failed to get port: %s" % str(exc)) def create_port(self, net_id): @@ -286,7 +286,7 @@ class QuantumDB(object): port_dict["int-id"] = port.interface_id port_dict["state"] = port.state return port_dict - except Exception, exc: + except Exception as exc: LOG.error("Failed to create port: %s" % str(exc)) def delete_port(self, net_id, port_id): @@ -297,7 +297,7 @@ class QuantumDB(object): port_dict = {} port_dict["port-id"] = str(port.uuid) return port_dict - except Exception, exc: + except Exception as exc: raise Exception("Failed to delete port: %s" % str(exc)) 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["state"] = port.state return port_dict - except Exception, exc: + except Exception as exc: raise Exception("Failed to update port state: %s" % str(exc)) 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["state"] = port.state return port_dict - except Exception, exc: + except Exception as exc: raise Exception("Failed to plug interface: %s" % str(exc)) def unplug_interface(self, net_id, port_id): @@ -339,7 +339,7 @@ class QuantumDB(object): port_dict["int-id"] = port.interface_id port_dict["state"] = port.state return port_dict - except Exception, exc: + except Exception as exc: raise Exception("Failed to unplug interface: %s" % str(exc)) diff --git a/quantum/plugins/nec/common/ofc_client.py b/quantum/plugins/nec/common/ofc_client.py index d6559dc86fe..ae2896c084d 100644 --- a/quantum/plugins/nec/common/ofc_client.py +++ b/quantum/plugins/nec/common/ofc_client.py @@ -85,7 +85,7 @@ class OFCClient(object): else: reason = _("An operation on OFC is failed.") raise nexc.OFCException(reason=reason) - except (socket.error, IOError), e: + except (socket.error, IOError) as e: reason = _("Failed to connect OFC : %s") % str(e) LOG.error(reason) raise nexc.OFCException(reason=reason) diff --git a/quantum/plugins/ryu/agent/ryu_quantum_agent.py b/quantum/plugins/ryu/agent/ryu_quantum_agent.py index f20cb5b306f..41f99b3b180 100755 --- a/quantum/plugins/ryu/agent/ryu_quantum_agent.py +++ b/quantum/plugins/ryu/agent/ryu_quantum_agent.py @@ -293,7 +293,7 @@ def main(): agent = OVSQuantumOFPRyuAgent(integ_br, tunnel_ip, ovsdb_ip, ovsdb_port, polling_interval, root_helper) - except httplib.HTTPException, e: + except httplib.HTTPException as e: LOG.error(_("Initialization failed: %s"), e) sys.exit(1) diff --git a/quantum/plugins/services/agent_loadbalancer/drivers/haproxy/namespace_driver.py b/quantum/plugins/services/agent_loadbalancer/drivers/haproxy/namespace_driver.py index 1b3b14590c5..4c78f755a35 100644 --- a/quantum/plugins/services/agent_loadbalancer/drivers/haproxy/namespace_driver.py +++ b/quantum/plugins/services/agent_loadbalancer/drivers/haproxy/namespace_driver.py @@ -121,7 +121,7 @@ class HaproxyNSDriver(object): break 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) return {} else: diff --git a/quantum/server/__init__.py b/quantum/server/__init__.py index 69f33913202..df9ba0fa6cd 100755 --- a/quantum/server/__init__.py +++ b/quantum/server/__init__.py @@ -37,7 +37,7 @@ def main(): try: quantum_service = service.serve_wsgi(service.QuantumApiService) quantum_service.wait() - except RuntimeError, e: + except RuntimeError as e: sys.exit(_("ERROR: %s") % e) diff --git a/quantum/tests/unit/database_stubs.py b/quantum/tests/unit/database_stubs.py index bfae58e9868..18fa77d12ff 100644 --- a/quantum/tests/unit/database_stubs.py +++ b/quantum/tests/unit/database_stubs.py @@ -39,7 +39,7 @@ class QuantumDB(object): net_dict["id"] = str(net.uuid) net_dict["name"] = net.name nets.append(net_dict) - except Exception, exc: + except Exception as exc: LOG.error("Failed to get all networks: %s", str(exc)) return nets @@ -54,7 +54,7 @@ class QuantumDB(object): net_dict["id"] = str(net.uuid) net_dict["name"] = net.name net.append(net_dict) - except Exception, exc: + except Exception as exc: LOG.error("Failed to get network: %s", str(exc)) return net @@ -68,7 +68,7 @@ class QuantumDB(object): net_dict["id"] = str(res.uuid) net_dict["name"] = res.name return net_dict - except Exception, exc: + except Exception as exc: LOG.error("Failed to create network: %s", str(exc)) def delete_network(self, net_id): @@ -79,7 +79,7 @@ class QuantumDB(object): net_dict = {} net_dict["id"] = str(net.uuid) return net_dict - except Exception, exc: + except Exception as exc: LOG.error("Failed to delete network: %s", str(exc)) 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["name"] = net.name return net_dict - except Exception, exc: + except Exception as exc: LOG.error("Failed to update network: %s", str(exc)) def get_all_ports(self, net_id): @@ -108,7 +108,7 @@ class QuantumDB(object): port_dict["state"] = port.state ports.append(port_dict) return ports - except Exception, exc: + except Exception as exc: LOG.error("Failed to get all ports: %s", str(exc)) def get_port(self, net_id, port_id): @@ -124,7 +124,7 @@ class QuantumDB(object): port_dict["state"] = port.state port_list.append(port_dict) return port_list - except Exception, exc: + except Exception as exc: LOG.error("Failed to get port: %s", str(exc)) def create_port(self, net_id): @@ -138,7 +138,7 @@ class QuantumDB(object): port_dict["attachment"] = port.interface_id port_dict["state"] = port.state return port_dict - except Exception, exc: + except Exception as exc: LOG.error("Failed to create port: %s", str(exc)) def delete_port(self, net_id, port_id): @@ -149,7 +149,7 @@ class QuantumDB(object): port_dict = {} port_dict["id"] = str(port.uuid) return port_dict - except Exception, exc: + except Exception as exc: LOG.error("Failed to delete port: %s", str(exc)) def update_port(self, net_id, port_id, **kwargs): @@ -163,7 +163,7 @@ class QuantumDB(object): port_dict["attachment"] = port.interface_id port_dict["state"] = port.state return port_dict - except Exception, exc: + except Exception as exc: LOG.error("Failed to update port state: %s", str(exc)) 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["state"] = port.state return port_dict - except Exception, exc: + except Exception as exc: LOG.error("Failed to plug interface: %s", str(exc)) def unplug_interface(self, net_id, port_id): @@ -185,5 +185,5 @@ class QuantumDB(object): try: db.port_unset_attachment(port_id, net_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)) diff --git a/quantum/wsgi.py b/quantum/wsgi.py index f3986becfcd..b68eb984f50 100644 --- a/quantum/wsgi.py +++ b/quantum/wsgi.py @@ -1043,7 +1043,7 @@ class Resource(Application): try: msg_dict = dict(url=request.url, status=response.status_int) 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 = _("%(url)s returned a fault: %(exception)s") % msg_dict