]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Improve Python 3.x compatibility
authorDirk Mueller <dirk@dmllr.de>
Mon, 29 Apr 2013 09:41:46 +0000 (11:41 +0200)
committerDirk Mueller <dirk@dmllr.de>
Mon, 29 Apr 2013 09:41:46 +0000 (11:41 +0200)
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

12 files changed:
quantum/agent/dhcp_agent.py
quantum/agent/linux/ovs_lib.py
quantum/db/api.py
quantum/db/migration/cli.py
quantum/openstack/common/rpc/impl_zmq.py
quantum/plugins/cisco/tests/unit/test_database.py
quantum/plugins/nec/common/ofc_client.py
quantum/plugins/ryu/agent/ryu_quantum_agent.py
quantum/plugins/services/agent_loadbalancer/drivers/haproxy/namespace_driver.py
quantum/server/__init__.py
quantum/tests/unit/database_stubs.py
quantum/wsgi.py

index 804983a6eb3c10acdb7831e519a4f4ed082d8074..fd811f0221813ba7b5cc4edebff4d3f89f866089 100644 (file)
@@ -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):
index 5c38b58b7444cb1391c465908440c5216ad5b61f..f435a342a47b147970ed19522d467ec036ed8111 100644 (file)
@@ -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 []
index 5919ecccec6737bc72b0293822f03960c3090316..d6d40dbd4cbede2106e1e85fe6989597aba57d12 100644 (file)
@@ -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"))
index 8aac59ebc716dfde678fb96d64107cfe6cad71f2..8a033115be4fe4f36995ffcc2dc591b7b091d5a5 100644 (file)
@@ -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))
 
 
index d69abe4eef14951076bc643c7b1bed65f87b4c1f..170e8a109fe0f901244d172c31a9871c54fac093 100644 (file)
@@ -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':
index 798ad045b1026f5363a790c5d9b8174b7e9d8f49..fb054c51089c9cbb7a7e7f8bee81dd3d0ffca11e 100644 (file)
@@ -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))
 
 
index d6559dc86fec145d5c26348f9416c2b90505b13b..ae2896c084d3dc83db1f5b0fca6790ecba148a31 100644 (file)
@@ -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)
index f20cb5b306fe60afdc527c9f88f69abf22007260..41f99b3b180444fadc66ca602afd79f47d5b33f8 100755 (executable)
@@ -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)
 
index 1b3b14590c554362c920dac41fec36fcb0b3b33c..4c78f755a35f67b66da6d099d9d1439cbad5f7fe 100644 (file)
@@ -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:
index 69f339132021c1876f30e3c85629ae987c3e9ada..df9ba0fa6cdf0509f79c9fbd0e03e2c11cae14ab 100755 (executable)
@@ -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)
 
 
index bfae58e98688aeb419c7c3aff1299710d87c35e4..18fa77d12ff081b2c3583141e34a268e48202336 100644 (file)
@@ -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))
index f3986becfcddee045bf47319e9a9d63e8d2c9a1c..b68eb984f50f67600d330ac008bf7e2d2c6bda6e 100644 (file)
@@ -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