From c72d83f483d1e616179455bc7abb342c6d7f5968 Mon Sep 17 00:00:00 2001 From: Mikhail Sandakov Date: Wed, 24 Jul 2024 09:21:42 +0300 Subject: [PATCH] fixup! Verify that the Plesk database is functioning before attempting to collaborate on any Plesk extensions --- pleskdistup/actions/extensions.py | 5 +++-- pleskdistup/common/src/plesk.py | 8 ++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/pleskdistup/actions/extensions.py b/pleskdistup/actions/extensions.py index e445565..1aef74a 100644 --- a/pleskdistup/actions/extensions.py +++ b/pleskdistup/actions/extensions.py @@ -150,13 +150,14 @@ def _is_required(self) -> bool: return self.ext_name in dict(plesk.list_installed_extensions()) except plesk.PleskDatabaseIsDown: # If database is not ready we will not be able to uninstall the extension anyway + log.warn("Mark the Tuxcare ELS extension uninstallation as unnecessary because the Plesk database isn't running") return False def _prepare_action(self) -> action.ActionResult: try: plesk.uninstall_extension(self.ext_name) except plesk.PleskDatabaseIsDown: - log.warn("Removing TuxCare ELS extension called when database is already down") + log.warn("Removing TuxCare ELS extension called when Plesk database is already down") return action.ActionResult() def _post_action(self) -> action.ActionResult: @@ -166,7 +167,7 @@ def _revert_action(self) -> action.ActionResult: try: plesk.install_extension(self.ext_name) except plesk.PleskDatabaseIsDown: - log.warn("Re-installing TuxCare ELS extension called when database is still down") + log.warn("Re-installing TuxCare ELS extension called when Plesk database is still down") return action.ActionResult() def estimate_prepare_time(self) -> int: diff --git a/pleskdistup/common/src/plesk.py b/pleskdistup/common/src/plesk.py index 801494a..e41c6ed 100644 --- a/pleskdistup/common/src/plesk.py +++ b/pleskdistup/common/src/plesk.py @@ -115,7 +115,7 @@ def remove_conversion_flag(status_flag_path: str) -> None: def list_installed_extensions() -> typing.List[typing.Tuple[str, str]]: if not is_plesk_database_ready(): - raise PleskDatabaseIsDown("on retrieving installed extensions") + raise PleskDatabaseIsDown("retrieving installed extensions") ext_info = subprocess.check_output(["/usr/sbin/plesk", "bin", "extension", "--list"], universal_newlines=True).splitlines() res: typing.List[typing.Tuple[str, str]] = [] @@ -128,14 +128,14 @@ def list_installed_extensions() -> typing.List[typing.Tuple[str, str]]: def install_extension(name: str) -> None: if not is_plesk_database_ready(): - raise PleskDatabaseIsDown(f"on extension {name!r} installation") + raise PleskDatabaseIsDown(f"extension {name!r} installation") util.logged_check_call(["/usr/sbin/plesk", "bin", "extension", "--install", name]) def uninstall_extension(name: str) -> None: if not is_plesk_database_ready(): - raise PleskDatabaseIsDown(f"on extension {name!r} uninstallation") + raise PleskDatabaseIsDown(f"extension {name!r} uninstallation") util.logged_check_call(["/usr/sbin/plesk", "bin", "extension", "--uninstall", name]) @@ -209,8 +209,8 @@ def list_installed_components() -> typing.Dict[str, PleskComponent]: class PleskDatabaseIsDown(Exception): def __init__(self, message: str = ""): - super().__init__() self.message = f"Plesk database is not ready at: {message}" + super().__init__(self.message) def is_plesk_database_ready() -> bool: