Fix deploy precheck returning blank error message

This commit fix the deploy precheck <release> command output which
is returning one line with an blank "Error:" when the output is correct.

Test Plan:
PASS: Deploy precheck <release> returning without error.
PASS: Deploy precheck <release> 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 <LuizEduardo.Bonatti@windriver.com>
This commit is contained in:
Luis Eduardo Bonatti 2024-03-04 21:10:04 -03:00
parent 6485390ce1
commit a6c5490d1a
3 changed files with 23 additions and 10 deletions

View File

@ -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__":

View File

@ -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"

View File

@ -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):