From ac7e32d35e4d45b093b5d47a1de1386143884249 Mon Sep 17 00:00:00 2001 From: Anders Ingemann Date: Fri, 16 Jan 2015 23:49:08 +0100 Subject: [PATCH] Preserve stacktraces when reraising exceptions --- bootstrapvz/base/fs/partitionmaps/abstract.py | 4 ++-- bootstrapvz/base/main.py | 2 +- bootstrapvz/common/tasks/apt.py | 2 +- bootstrapvz/common/tasks/grub.py | 4 ++-- bootstrapvz/common/tasks/packages.py | 2 +- bootstrapvz/remote/build_servers.py | 8 ++++---- tests/integration/tools/bootable_manifest.py | 4 ++-- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/bootstrapvz/base/fs/partitionmaps/abstract.py b/bootstrapvz/base/fs/partitionmaps/abstract.py index 15cfb91..b4475a4 100644 --- a/bootstrapvz/base/fs/partitionmaps/abstract.py +++ b/bootstrapvz/base/fs/partitionmaps/abstract.py @@ -92,13 +92,13 @@ class AbstractPartitionMap(FSMProxy): if partition.fsm.current not in ['mapped', 'formatted']: raise PartitionError('kpartx did not map partition #' + str(idx + 1)) - except PartitionError as e: + except PartitionError: # Revert any mapping and reraise the error for partition in self.partitions: if not partition.fsm.can('unmap'): partition.unmap() log_check_call(['kpartx', '-ds', volume.device_path]) - raise e + raise def unmap(self, volume): """Unmaps the partition diff --git a/bootstrapvz/base/main.py b/bootstrapvz/base/main.py index fe38e7d..55c3ec3 100644 --- a/bootstrapvz/base/main.py +++ b/bootstrapvz/base/main.py @@ -138,5 +138,5 @@ def run(manifest, debug=False, pause_on_error=False, dry_run=False, check_contin # Run the rollback tasklist rollback_tasklist.run(info=bootstrap_info, dry_run=dry_run) log.info('Successfully completed rollback') - raise e + raise return bootstrap_info diff --git a/bootstrapvz/common/tasks/apt.py b/bootstrapvz/common/tasks/apt.py index f009469..6572674 100644 --- a/bootstrapvz/common/tasks/apt.py +++ b/bootstrapvz/common/tasks/apt.py @@ -164,7 +164,7 @@ class AptUpgrade(Task): 'This can sometimes occur when package retrieval times out or a package extraction failed. ' 'apt might succeed if you try bootstrapping again.') logging.getLogger(__name__).warn(msg) - raise e + raise class PurgeUnusedPackages(Task): diff --git a/bootstrapvz/common/tasks/grub.py b/bootstrapvz/common/tasks/grub.py index ed781a1..022c4f2 100644 --- a/bootstrapvz/common/tasks/grub.py +++ b/bootstrapvz/common/tasks/grub.py @@ -76,10 +76,10 @@ class InstallGrub_1_99(Task): # Install grub log_check_call(['chroot', info.root, 'grub-install', device_path]) log_check_call(['chroot', info.root, 'update-grub']) - except Exception as e: + except Exception: if isinstance(info.volume, LoopbackVolume): remount(info.volume, unlink_fn) - raise e + raise if isinstance(info.volume, LoopbackVolume): remount(info.volume, unlink_fn) diff --git a/bootstrapvz/common/tasks/packages.py b/bootstrapvz/common/tasks/packages.py index a5b41b0..f6e41af 100644 --- a/bootstrapvz/common/tasks/packages.py +++ b/bootstrapvz/common/tasks/packages.py @@ -69,7 +69,7 @@ class InstallPackages(Task): 'This can sometimes occur when package retrieval times out or a package extraction failed. ' 'apt might succeed if you try bootstrapping again.') logging.getLogger(__name__).warn(msg) - raise e + raise @classmethod def install_local(cls, info, local_packages): diff --git a/bootstrapvz/remote/build_servers.py b/bootstrapvz/remote/build_servers.py index be117dc..e1981e6 100644 --- a/bootstrapvz/remote/build_servers.py +++ b/bootstrapvz/remote/build_servers.py @@ -110,16 +110,16 @@ class RemoteBuildServer(BuildServer): try: self.connection.ping() break - except (Pyro4.errors.ConnectionClosedError, Pyro4.errors.CommunicationError) as e: + except (Pyro4.errors.ConnectionClosedError, Pyro4.errors.CommunicationError): if remaining_retries > 0: remaining_retries -= 1 from time import sleep sleep(2) else: - raise e - except (Exception, KeyboardInterrupt) as e: + raise + except (Exception, KeyboardInterrupt): self.ssh_process.terminate() - raise e + raise return self.connection def disconnect(self): diff --git a/tests/integration/tools/bootable_manifest.py b/tests/integration/tools/bootable_manifest.py index 7a449ac..d537996 100644 --- a/tests/integration/tools/bootable_manifest.py +++ b/tests/integration/tools/bootable_manifest.py @@ -54,11 +54,11 @@ class BootableManifest(object): self.image.open() self.instance = self.image.get_instance() self.instance.up() - except (Exception, KeyboardInterrupt) as e: + except (Exception, KeyboardInterrupt): if hasattr(self, 'image'): self.image.close() self.image.destroy() - raise e + raise return self.instance def __exit__(self, type, value, traceback):