]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Use Python 3.x compatible except: construct
authorDirk Mueller <dirk@dmllr.de>
Sat, 8 Jun 2013 08:49:57 +0000 (10:49 +0200)
committerDirk Mueller <dirk@dmllr.de>
Fri, 14 Jun 2013 21:26:00 +0000 (23:26 +0200)
Per (proposed) H203 check, convert all uses of
the deprecated except x,y: construct to except
x as y:, which works with any Python version >= 2.6

Change-Id: I5528dc556f3ef8d356e01d59df04ba57f66c95b7

19 files changed:
bin/cinder-manage
bin/cinder-volume-usage-audit
cinder/api/contrib/admin_actions.py
cinder/api/contrib/volume_actions.py
cinder/api/openstack/wsgi.py
cinder/db/sqlalchemy/api.py
cinder/scheduler/scheduler_options.py
cinder/tests/api/v1/test_limits.py
cinder/tests/api/v2/test_limits.py
cinder/tests/test_migrations.py
cinder/utils.py
cinder/volume/drivers/coraid.py
cinder/volume/drivers/glusterfs.py
cinder/volume/drivers/nfs.py
cinder/volume/drivers/solidfire.py
cinder/volume/manager.py
cinder/volume/volume_types.py
cinder/wsgi.py
tools/conf/extract_opts.py

index d9df32317e48b1f80e0bb9d940121ffde7499060..f065a0f54e86f07b9d47c2a70c62484a93f75cb6 100755 (executable)
@@ -472,7 +472,7 @@ class StorageManagerCommands(object):
             db.sm_flavor_create(context.get_admin_context(),
                                 dict(label=label,
                                      description=desc))
-        except exception.DBError, e:
+        except exception.DBError as e:
             _db_error(e)
 
     @args('label', help='label of flavor to be deleted')
@@ -480,7 +480,7 @@ class StorageManagerCommands(object):
         try:
             db.sm_flavor_delete(context.get_admin_context(), label)
 
-        except exception.DBError, e:
+        except exception.DBError as e:
             _db_error(e)
 
     def _splitfun(self, item):
@@ -541,7 +541,7 @@ class StorageManagerCommands(object):
             sr_uuid = params['sr_uuid']
             try:
                 backend = db.sm_backend_conf_get_by_sr(ctxt, sr_uuid)
-            except exception.DBError, e:
+            except exception.DBError as e:
                 _db_error(e)
 
             if backend:
@@ -556,7 +556,7 @@ class StorageManagerCommands(object):
                                  flavor_id=flavors['id'],
                                  sr_type=sr_type,
                                  config_params=config_params))
-                    except exception.DBError, e:
+                    except exception.DBError as e:
                         _db_error(e)
                 return
 
@@ -572,7 +572,7 @@ class StorageManagerCommands(object):
                                                sr_uuid=sr_uuid,
                                                sr_type=sr_type,
                                                config_params=config_params))
-            except exception.DBError, e:
+            except exception.DBError as e:
                 _db_error(e)
 
     @args('backend_conf_id')
@@ -581,7 +581,7 @@ class StorageManagerCommands(object):
             db.sm_backend_conf_delete(context.get_admin_context(),
                                       backend_conf_id)
 
-        except exception.DBError, e:
+        except exception.DBError as e:
             _db_error(e)
 
 
index 3ff437efe472876aa692ca4486c0a9f1a9025a72..b3ba69e66cbd4113fd6e92457ae9723659eb2c63 100755 (executable)
@@ -82,7 +82,7 @@ if __name__ == '__main__':
         try:
             cinder.volume.utils.notify_usage_exists(admin_context,
                                                     volume_ref)
-        except Exception, e:
+        except Exception as e:
             print traceback.format_exc(e)
 
     snapshots = db.snapshot_get_active_by_window(admin_context,
@@ -95,7 +95,7 @@ if __name__ == '__main__':
                                                             snapshot_ref,
                                                             'exists',
                                                             extra_info)
-        except Exception, e:
+        except Exception as e:
             print traceback.fromat_exc(e)
 
     print _("Volume usage audit completed")
index a45b370776817c3f241dbcaafb41f0e8c08f73cf..f8491b426e047862e24d0ee6ca3a51e3ab5cd640 100644 (file)
@@ -82,7 +82,7 @@ class AdminController(wsgi.Controller):
                         'update': update})
         try:
             self._update(context, id, update)
-        except exception.NotFound, e:
+        except exception.NotFound as e:
             raise exc.HTTPNotFound(e)
         return webob.Response(status_int=202)
 
index 7ab19d710e6a0a750a7c0a9e008bd3c776f28087..3a8c79670b1645c14d8136127a2cc81b612f289b 100644 (file)
@@ -164,7 +164,7 @@ class VolumeActionsController(wsgi.Controller):
         force = params.get('force', False)
         try:
             volume = self.volume_api.get(context, id)
-        except exception.VolumeNotFound, error:
+        except exception.VolumeNotFound as error:
             raise webob.exc.HTTPNotFound(explanation=unicode(error))
         authorize(context, "upload_image")
         image_metadata = {"container_format": params.get("container_format",
@@ -176,9 +176,9 @@ class VolumeActionsController(wsgi.Controller):
                                                             volume,
                                                             image_metadata,
                                                             force)
-        except exception.InvalidVolume, error:
+        except exception.InvalidVolume as error:
             raise webob.exc.HTTPBadRequest(explanation=unicode(error))
-        except ValueError, error:
+        except ValueError as error:
             raise webob.exc.HTTPBadRequest(explanation=unicode(error))
         except rpc_common.RemoteError as error:
             msg = "%(err_type)s: %(err_msg)s" % {'err_type': error.exc_type,
index 810b779140b2a9adc79f45d02cec6e7eee49a609..34118ac66e06c17b6d56ecd2ab563ffd2975dacb 100644 (file)
@@ -894,7 +894,7 @@ class Resource(wsgi.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, e=e)
             msg = _("%(url)s returned a fault: %(e)s") % msg_dict
 
index 9bcf47e040b9c92f8e371cbbb4906012cc8d9180..24a942c164125bd086937ace2b7aa619b75e30d0 100644 (file)
@@ -1479,7 +1479,7 @@ def volume_type_create(context, values):
             volume_type_ref = models.VolumeTypes()
             volume_type_ref.update(values)
             volume_type_ref.save()
-        except Exception, e:
+        except Exception as e:
             raise db_exc.DBError(e)
         return volume_type_ref
 
@@ -1629,7 +1629,7 @@ def volume_type_extra_specs_update_or_create(context, volume_type_id,
         try:
             spec_ref = volume_type_extra_specs_get_item(
                 context, volume_type_id, key, session)
-        except exception.VolumeTypeExtraSpecsNotFound, e:
+        except exception.VolumeTypeExtraSpecsNotFound as e:
             spec_ref = models.VolumeTypeExtraSpecs()
         spec_ref.update({"key": key, "value": value,
                          "volume_type_id": volume_type_id,
index 6c4f0b3648c1e7823ef22ddc47d8bc887e025642..a8010afc6920219b884028d811c3205b504cf898 100644 (file)
@@ -66,7 +66,7 @@ class SchedulerOptions(object):
         """Get the last modified datetime. Broken out for testing."""
         try:
             return os.path.getmtime(filename)
-        except os.error, e:
+        except os.error as e:
             LOG.exception(_("Could not stat scheduler options file "
                             "%(filename)s: '%(e)s'"), locals())
             raise
@@ -75,7 +75,7 @@ class SchedulerOptions(object):
         """Decode the JSON file. Broken out for testing."""
         try:
             return json.load(handle)
-        except ValueError, e:
+        except ValueError as e:
             LOG.exception(_("Could not decode scheduler options: "
                             "'%(e)s'") % locals())
             return {}
index 147ddf70ef08b4072f4e35fcc6eb4ecc5f5abb37..a8f1b9bdd8294c80d7439ad90c56d0839284159f 100644 (file)
@@ -370,7 +370,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
index cfe78cc75cfcf2633dc70651225112c129dac566..07b63b1a9c48a32969160c8638870c985293d611 100644 (file)
@@ -370,7 +370,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
index 371f48a7cfda9081a565b63e8855b632aa575d6c..b61ea56798ad6ca3f9833fa8deb702e856cfadd8 100644 (file)
@@ -133,7 +133,7 @@ class TestMigrations(test.TestCase):
                     for key, value in defaults.items():
                         self.test_databases[key] = value
                     self.snake_walk = cp.getboolean('walk_style', 'snake_walk')
-                except ConfigParser.ParsingError, e:
+                except ConfigParser.ParsingError as e:
                     self.fail("Failed to read test_migrations.conf config "
                               "file. Got error: %s" % e)
             else:
index 98c172dbf30db85f8489aaa7e69792a9956da116..fbfcbd6a15837bd47040fef7adacfa0efa3852cd 100644 (file)
@@ -220,7 +220,7 @@ def trycmd(*args, **kwargs):
     try:
         out, err = execute(*args, **kwargs)
         failed = False
-    except exception.ProcessExecutionError, exn:
+    except exception.ProcessExecutionError as exn:
         out, err = '', str(exn)
         LOG.debug(err)
         failed = True
@@ -620,7 +620,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:
@@ -1062,7 +1062,7 @@ def tempdir(**kwargs):
     finally:
         try:
             shutil.rmtree(tmpdir)
-        except OSError, e:
+        except OSError as e:
             LOG.debug(_('Could not remove tmpdir: %s'), str(e))
 
 
index 95ebe5aaaffde60b03c3c67f36890d1b8239715a..dd14f49e95482005be107e041183f4050c4a5a22 100644 (file)
@@ -328,7 +328,7 @@ class CoraidDriver(driver.VolumeDriver):
                          % snapshot['id'])
         try:
             self.esm.create_snapshot(volume_name, snapshot_name)
-        except Exception, e:
+        except Exception as e:
             msg = _('Failed to Create Snapshot %(snapname)s')
             LOG.debug(msg % dict(snapname=snapshot_name))
             raise
index 5b3fa0cd3a99ac4c71d478c87fcc657fe342eb6f..2fcd6ab2ad9985b4d131cf4c77a0a7827fe39fa6 100644 (file)
@@ -169,7 +169,7 @@ class GlusterfsDriver(nfs.RemoteFsDriver):
             try:
                 self._ensure_share_mounted(share)
                 self._mounted_shares.append(share)
-            except Exception, exc:
+            except Exception as exc:
                 LOG.warning(_('Exception during mounting %s') % (exc,))
 
         LOG.debug('Available shares %s' % str(self._mounted_shares))
index e018b28c5e0809df2a6216e0244ca8ca0f9d01b2..e2e95d236a51a6302d424363f75939c1a8825b02 100644 (file)
@@ -310,7 +310,7 @@ class NfsDriver(RemoteFsDriver):
             try:
                 self._ensure_share_mounted(share)
                 self._mounted_shares.append(share)
-            except Exception, exc:
+            except Exception as exc:
                 LOG.warning(_('Exception during mounting %s') % (exc,))
 
         LOG.debug('Available shares %s' % str(self._mounted_shares))
index c12c3efa2aded4b93089499e9aa7e57a7002dafb..8c990606f7a03b625ec703f8845c50c9184e541f 100644 (file)
@@ -145,7 +145,7 @@ class SolidFire(SanISCSIDriver):
                 data = response.read()
                 try:
                     data = json.loads(data)
-                except (TypeError, ValueError), exc:
+                except (TypeError, ValueError) as exc:
                     connection.close()
                     msg = _("Call to json.loads() raised "
                             "an exception: %s") % exc
index e986b7cd0ee671690b8abe263cfca79deb52efb1..6babf84f29653c0c28d6faa349510c64d8c9af4b 100644 (file)
@@ -645,7 +645,7 @@ class VolumeManager(manager.SchedulerDependentManager):
                                              image_meta)
             LOG.debug(_("Uploaded volume %(volume_id)s to "
                         "image (%(image_id)s) successfully") % locals())
-        except Exception, error:
+        except Exception as error:
             with excutils.save_and_reraise_exception():
                 payload['message'] = unicode(error)
         finally:
index 7c6f09709072a559ba2e0748cc2c5c4fc012c67d..87c1b48a1c38e328247dd5e80ee586636c8a246b 100644 (file)
@@ -125,7 +125,7 @@ def get_default_volume_type():
         ctxt = context.get_admin_context()
         try:
             vol_type = get_volume_type_by_name(ctxt, name)
-        except exception.VolumeTypeNotFoundByName, e:
+        except exception.VolumeTypeNotFoundByName as e:
             # Couldn't find volume type with the name in default_volume_type
             # flag, record this issue and move on
             #TODO(zhiteng) consider add notification to warn admin
index 9b589abcfb737deea33dc587fe81c3d352c93e7f..098c1d3a6753898a34cebc907348128ad469de38 100644 (file)
@@ -155,7 +155,7 @@ class Server(object):
                 if use_ssl:
                     sock = wrap_ssl(sock)
 
-            except socket.error, err:
+            except socket.error as err:
                 if err.args[0] != errno.EADDRINUSE:
                     raise
                 eventlet.sleep(0.1)
index 4650c134f05ecc0b1717b3357594519b9c70051b..2f32cff5d85b7ed4ff8732b687699fc67d66e0c2 100644 (file)
@@ -79,7 +79,7 @@ def _print_module(mod_str):
         mod_str = mod_str[:mod_str.rfind(".")]
     try:
         mod_obj = importutils.import_module(mod_str)
-    except Exception, e:
+    except Exception as e:
         sys.stderr.write("Failed to collect options from module %s: %s\n" % (
             mod_str, str(e)))
         return
@@ -153,7 +153,7 @@ def _print_opt(opt):
     opt_type = None
     try:
         opt_type = OPTION_REGEX.search(str(type(opt))).group(0)
-    except (ValueError, AttributeError), err:
+    except (ValueError, AttributeError) as err:
         sys.stderr.write("%s\n" % str(err))
         sys.exit(1)
     opt_help += ' (' + OPT_TYPES[opt_type] + ')'