From c390d6139c088765c561a5d62d804228e4f961f1 Mon Sep 17 00:00:00 2001 From: Mikhail Sandakov Date: Mon, 19 Feb 2024 07:41:14 +0200 Subject: [PATCH] Make it possible to failfast on minimum php version checking if database is unreacable --- pleskdistup/actions/common_checks.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/pleskdistup/actions/common_checks.py b/pleskdistup/actions/common_checks.py index 639054a..e41de59 100644 --- a/pleskdistup/actions/common_checks.py +++ b/pleskdistup/actions/common_checks.py @@ -140,13 +140,16 @@ def _do_check(self) -> bool: class AssertMinPhpVersionUsedByWebsites(action.CheckAction): min_version: version.PHPVersion + optional: bool def __init__( self, min_version: str, + optional: bool = True, ): self.name = "checking domains uses outdated PHP" self.min_version = version.PHPVersion(min_version) + self.optional = optional self.description = """We have identified that the domains are using older versions of PHP. \tSwitch the following domains to {modern} or later in order to continue with the conversion process: \t- {domains} @@ -158,8 +161,10 @@ def __init__( def _do_check(self) -> bool: log.debug(f"Checking the minimum PHP version being used by the websites. The restriction is: {self.min_version}") if not plesk.is_plesk_database_ready(): - log.info("Plesk database is not ready. Skipping the minimum PHP for websites check.") - return True + if self.optional: + log.info("Plesk database is not ready. Skipping the minimum PHP for websites check.") + return True + raise RuntimeError("Plesk database is not ready. Skipping the minimum PHP for websites check.") outdated_php_handlers = [f"'{handler}'" for handler in php.get_outdated_php_handlers(self.min_version)] log.debug(f"Outdated PHP handlers: {outdated_php_handlers}") @@ -187,13 +192,16 @@ def _do_check(self) -> bool: class AssertMinPhpVersionUsedByCron(action.CheckAction): min_version: version.PHPVersion + optional: bool def __init__( self, min_version: str, + optional: bool = True, ): self.name = "checking cronjob uses outdated PHP" self.min_version = version.PHPVersion(min_version) + self.optional = optional self.description = """We have detected that some cronjobs are using outdated PHP versions. \tSwitch the following cronjobs to {modern} or later in order to continue with the conversion process:" \t- {cronjobs} @@ -204,8 +212,10 @@ def __init__( def _do_check(self) -> bool: log.debug(f"Checking the minimum PHP version used in cronjobs. Restriction is: {self.min_version}") if not plesk.is_plesk_database_ready(): - log.info("Plesk database is not ready. Skipping the minimum PHP for websites check.") - return True + if self.optional: + log.info("Plesk database is not ready. Skipping the minimum PHP for cronjobs check.") + return True + raise RuntimeError("Plesk database is not ready. Skipping the minimum PHP for cronjobs check.") outdated_php_handlers = [f"'{handler}'" for handler in php.get_outdated_php_handlers(self.min_version)] log.debug(f"Outdated PHP handlers: {outdated_php_handlers}")