From a6c5490d1a13c0938f3d22d977427babe8ac1302 Mon Sep 17 00:00:00 2001 From: Luis Eduardo Bonatti Date: Mon, 4 Mar 2024 21:10:04 -0300 Subject: [PATCH] Fix deploy precheck returning blank error message This commit fix the deploy precheck command output which is returning one line with an blank "Error:" when the output is correct. Test Plan: PASS: Deploy precheck returning without error. PASS: Deploy precheck returning expected error. PASS: Deploy start failed with expected error. PASS: Deploy start Note: Exit code 3 was chosen based on exit codes with special meaning which the 1 is for catchall general errors and 2 for misuse of shell builtins. The number 3 is not allocated with special meaning so it was chosen for unhealthy precheck. Closes-Bug: 2056106 Change-Id: Ifed48157f7810eec2881d8a9e011eae8941f3427 Signed-off-by: Luis Eduardo Bonatti --- software/scripts/deploy-precheck | 8 ++++++-- software/software/constants.py | 4 ++++ software/software/software_controller.py | 21 +++++++++++++-------- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/software/scripts/deploy-precheck b/software/scripts/deploy-precheck index fb6ecf24..c28a1838 100644 --- a/software/scripts/deploy-precheck +++ b/software/scripts/deploy-precheck @@ -34,6 +34,9 @@ SUPPORTED_K8S_VERSIONS = [ "v1.28.4", ] +RC_SUCCESS = 0 +RC_UNHEALTHY = 3 + class HealthCheck(object): """This class represents a general health check object @@ -327,8 +330,9 @@ def main(argv=None): # print health check output and exit print(output) if health_ok: - return 0 - return 1 + return RC_SUCCESS + else: + return RC_UNHEALTHY if __name__ == "__main__": diff --git a/software/software/constants.py b/software/software/constants.py index 8b8d6a3b..a7859563 100644 --- a/software/software/constants.py +++ b/software/software/constants.py @@ -27,6 +27,10 @@ SYSTEM_CONTROLLER_REGION = 'SystemController' SOFTWARE_STORAGE_DIR = "/opt/software" SOFTWARE_CONFIG_FILE_LOCAL = "/etc/software/software.conf" +# Deploy precheck return codes +RC_SUCCESS = 0 +RC_UNHEALTHY = 3 + DEPLOY_PRECHECK_SCRIPT = "deploy-precheck" DEPLOY_START_SCRIPT = "software-deploy-start" diff --git a/software/software/software_controller.py b/software/software/software_controller.py index c1d4da70..26f21ffb 100644 --- a/software/software/software_controller.py +++ b/software/software/software_controller.py @@ -2249,12 +2249,14 @@ class PatchController(PatchService): check=False, text=True, ) - if precheck_return.returncode != 0: - msg_error += precheck_return.stdout - else: + system_healthy = None + if precheck_return.returncode in [constants.RC_SUCCESS, constants.RC_UNHEALTHY]: + system_healthy = precheck_return.returncode == constants.RC_SUCCESS msg_info += precheck_return.stdout + else: + msg_error += precheck_return.stdout - return dict(info=msg_info, warning=msg_warning, error=msg_error) + return dict(info=msg_info, warning=msg_warning, error=msg_error, system_healthy=system_healthy) def software_deploy_precheck_api(self, deployment: str, force: bool = False, **kwargs) -> dict: """ @@ -2339,11 +2341,14 @@ class PatchController(PatchService): patch_release = False to_release = release["sw_version"] ret = self._deploy_precheck(to_release, force, patch=patch_release) - if ret["error"]: - ret["error"] = "The following issues have been detected which prevent " \ - "deploying %s\n" % deployment + \ + if ret["system_healthy"] is None: + ret["error"] = "Fail to perform deploy precheck. Internal error has occurred.\n" + \ ret["error"] - ret["error"] += "Please fix above issues then retry the deploy.\n" + return ret + elif not ret["system_healthy"]: + ret["info"] = "The following issues have been detected, which prevent " \ + "deploying %s\n" % deployment + ret["info"] + \ + "Please fix above issues then retry the deploy.\n" return ret if self._deploy_upgrade_start(to_release):