From 4715fc36ffcd23e68a1c6e16d36abe423ec24d57 Mon Sep 17 00:00:00 2001 From: Chase Engelbrecht Date: Tue, 5 Apr 2022 14:36:17 -0500 Subject: [PATCH 1/2] Implement ExceptionHandlingInstaller Signed-off-by: Chase Engelbrecht --- .../exception_handling_installer.py | 20 +++++++++++++++++++ osbenchmark/exceptions.py | 5 +++++ 2 files changed, 25 insertions(+) create mode 100644 osbenchmark/builder/installers/exception_handling_installer.py diff --git a/osbenchmark/builder/installers/exception_handling_installer.py b/osbenchmark/builder/installers/exception_handling_installer.py new file mode 100644 index 000000000..4cf3d9748 --- /dev/null +++ b/osbenchmark/builder/installers/exception_handling_installer.py @@ -0,0 +1,20 @@ +from osbenchmark.builder.installers.installer import Installer +from osbenchmark.exceptions import InstallError + + +class ExceptionHandlingInstaller(Installer): + def __init__(self, installer, executor=None): + super().__init__(executor) + self.installer = installer + + def install(self, host, binaries, all_node_ips): + try: + return self.installer.install(host, binaries, all_node_ips) + except Exception as e: + raise InstallError("Installing node on host \"{}\" failed".format(host), e) + + def cleanup(self, host): + try: + return self.installer.cleanup(host) + except Exception as e: + raise InstallError("Cleaning up install data on host \"{}\" failed".format(host), e) diff --git a/osbenchmark/exceptions.py b/osbenchmark/exceptions.py index 60d49b125..19a90a412 100644 --- a/osbenchmark/exceptions.py +++ b/osbenchmark/exceptions.py @@ -45,6 +45,11 @@ class LaunchError(BenchmarkError): Thrown whenever there was a problem launching the benchmark candidate """ +class InstallError(BenchmarkError): + """ + Thrown whenever there was a problem installing the benchmark candidate + """ + class ExecutorError(BenchmarkError): """ From 77bd8f49f6fc127a9715736410521f0c4f80fcc0 Mon Sep 17 00:00:00 2001 From: Chase Engelbrecht Date: Tue, 5 Apr 2022 16:28:16 -0500 Subject: [PATCH 2/2] Used f-strings instead of format Signed-off-by: Chase Engelbrecht --- .../builder/installers/exception_handling_installer.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osbenchmark/builder/installers/exception_handling_installer.py b/osbenchmark/builder/installers/exception_handling_installer.py index 4cf3d9748..d120af4b3 100644 --- a/osbenchmark/builder/installers/exception_handling_installer.py +++ b/osbenchmark/builder/installers/exception_handling_installer.py @@ -11,10 +11,10 @@ def install(self, host, binaries, all_node_ips): try: return self.installer.install(host, binaries, all_node_ips) except Exception as e: - raise InstallError("Installing node on host \"{}\" failed".format(host), e) + raise InstallError(f"Installing node on host \"{host}\" failed", e) def cleanup(self, host): try: return self.installer.cleanup(host) except Exception as e: - raise InstallError("Cleaning up install data on host \"{}\" failed".format(host), e) + raise InstallError(f"Cleaning up install data on host \"{host}\" failed", e)