From: Dirk Mueller Date: Sat, 8 Jun 2013 08:49:57 +0000 (+0200) Subject: Use Python 3.x compatible except: construct X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=64a9dd5c509366aeb763b964094579c93ef0e091;p=openstack-build%2Fcinder-build.git Use Python 3.x compatible except: construct 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 --- diff --git a/bin/cinder-manage b/bin/cinder-manage index d9df32317..f065a0f54 100755 --- a/bin/cinder-manage +++ b/bin/cinder-manage @@ -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) diff --git a/bin/cinder-volume-usage-audit b/bin/cinder-volume-usage-audit index 3ff437efe..b3ba69e66 100755 --- a/bin/cinder-volume-usage-audit +++ b/bin/cinder-volume-usage-audit @@ -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") diff --git a/cinder/api/contrib/admin_actions.py b/cinder/api/contrib/admin_actions.py index a45b37077..f8491b426 100644 --- a/cinder/api/contrib/admin_actions.py +++ b/cinder/api/contrib/admin_actions.py @@ -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) diff --git a/cinder/api/contrib/volume_actions.py b/cinder/api/contrib/volume_actions.py index 7ab19d710..3a8c79670 100644 --- a/cinder/api/contrib/volume_actions.py +++ b/cinder/api/contrib/volume_actions.py @@ -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, diff --git a/cinder/api/openstack/wsgi.py b/cinder/api/openstack/wsgi.py index 810b77914..34118ac66 100644 --- a/cinder/api/openstack/wsgi.py +++ b/cinder/api/openstack/wsgi.py @@ -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 diff --git a/cinder/db/sqlalchemy/api.py b/cinder/db/sqlalchemy/api.py index 9bcf47e04..24a942c16 100644 --- a/cinder/db/sqlalchemy/api.py +++ b/cinder/db/sqlalchemy/api.py @@ -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, diff --git a/cinder/scheduler/scheduler_options.py b/cinder/scheduler/scheduler_options.py index 6c4f0b364..a8010afc6 100644 --- a/cinder/scheduler/scheduler_options.py +++ b/cinder/scheduler/scheduler_options.py @@ -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 {} diff --git a/cinder/tests/api/v1/test_limits.py b/cinder/tests/api/v1/test_limits.py index 147ddf70e..a8f1b9bdd 100644 --- a/cinder/tests/api/v1/test_limits.py +++ b/cinder/tests/api/v1/test_limits.py @@ -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 diff --git a/cinder/tests/api/v2/test_limits.py b/cinder/tests/api/v2/test_limits.py index cfe78cc75..07b63b1a9 100644 --- a/cinder/tests/api/v2/test_limits.py +++ b/cinder/tests/api/v2/test_limits.py @@ -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 diff --git a/cinder/tests/test_migrations.py b/cinder/tests/test_migrations.py index 371f48a7c..b61ea5679 100644 --- a/cinder/tests/test_migrations.py +++ b/cinder/tests/test_migrations.py @@ -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: diff --git a/cinder/utils.py b/cinder/utils.py index 98c172dbf..fbfcbd6a1 100644 --- a/cinder/utils.py +++ b/cinder/utils.py @@ -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)) diff --git a/cinder/volume/drivers/coraid.py b/cinder/volume/drivers/coraid.py index 95ebe5aaa..dd14f49e9 100644 --- a/cinder/volume/drivers/coraid.py +++ b/cinder/volume/drivers/coraid.py @@ -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 diff --git a/cinder/volume/drivers/glusterfs.py b/cinder/volume/drivers/glusterfs.py index 5b3fa0cd3..2fcd6ab2a 100644 --- a/cinder/volume/drivers/glusterfs.py +++ b/cinder/volume/drivers/glusterfs.py @@ -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)) diff --git a/cinder/volume/drivers/nfs.py b/cinder/volume/drivers/nfs.py index e018b28c5..e2e95d236 100644 --- a/cinder/volume/drivers/nfs.py +++ b/cinder/volume/drivers/nfs.py @@ -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)) diff --git a/cinder/volume/drivers/solidfire.py b/cinder/volume/drivers/solidfire.py index c12c3efa2..8c990606f 100644 --- a/cinder/volume/drivers/solidfire.py +++ b/cinder/volume/drivers/solidfire.py @@ -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 diff --git a/cinder/volume/manager.py b/cinder/volume/manager.py index e986b7cd0..6babf84f2 100644 --- a/cinder/volume/manager.py +++ b/cinder/volume/manager.py @@ -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: diff --git a/cinder/volume/volume_types.py b/cinder/volume/volume_types.py index 7c6f09709..87c1b48a1 100644 --- a/cinder/volume/volume_types.py +++ b/cinder/volume/volume_types.py @@ -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 diff --git a/cinder/wsgi.py b/cinder/wsgi.py index 9b589abcf..098c1d3a6 100644 --- a/cinder/wsgi.py +++ b/cinder/wsgi.py @@ -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) diff --git a/tools/conf/extract_opts.py b/tools/conf/extract_opts.py index 4650c134f..2f32cff5d 100644 --- a/tools/conf/extract_opts.py +++ b/tools/conf/extract_opts.py @@ -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] + ')'