From f77068f73f29dbecf4f5264c47dbd9559f9896ac Mon Sep 17 00:00:00 2001 From: Jason Ertel Date: Mon, 6 Mar 2023 18:37:37 -0500 Subject: [PATCH] setup and so-verify/so-status interop --- salt/common/tools/sbin/so-status | 17 ++++++++++++++--- setup/so-functions | 4 ++++ setup/so-verify | 19 ++++++++++++++----- 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/salt/common/tools/sbin/so-status b/salt/common/tools/sbin/so-status index da20fcacd..ec0ce94b1 100755 --- a/salt/common/tools/sbin/so-status +++ b/salt/common/tools/sbin/so-status @@ -24,11 +24,13 @@ def showUsage(options, args): print(' -h - Prints this usage information') print(' -q - Suppress output; useful for automation of exit code value') print(' -j - Output in JSON format') + print(' -i - Consider the installation outcome regardless of whether the system appears healthy') print('') print(' Exit codes:') print(' 0 - Success, system appears to be running correctly') print(' 1 - Error, one or more subsystems are not running') print(' 2 - System is starting') + print(' 3 - System installation encountered errors') print(' 99 - Installation in progress') sys.exit(1) @@ -38,6 +40,12 @@ def fail(msg): sys.exit(1) +def check_installation_status(options, console): + if "-i" in options and os.path.isfile('/root/failure'): + return 3 + return 0 + + def check_system_status(options, console): code = 0 highstate_end_time = 0 @@ -64,6 +72,8 @@ def output(options, console, code, data): elif "-q" not in options: if code == 2: console.print(" [bold yellow]:hourglass: [bold white]System appears to be starting. No highstate has completed since the system was restarted.") + if code == 3: + console.print(" [bold red]:exclamation: [bold white]Installation encountered errors.") elif code == 99: console.print(" [bold red]:exclamation: [bold white]Installation does not appear to be complete. A highstate has not fully completed.") else: @@ -137,7 +147,9 @@ def check_container_status(options, console): def check_status(options, console): container_list = [] - code = check_system_status(options, console) + code = check_installation_status(options, console) + if code == 0: + code = check_system_status(options, console) if code == 0: code, container_list = check_container_status(options, console) output(options, console, code, container_list) @@ -150,9 +162,8 @@ def main(): for option in args: if option.startswith("-"): options.append(option) - args.remove(option) - if len(args) != 0 or "-h" in options: + if "-h" in options or "--help" in options or "-?" in options: showUsage(options, None) if os.environ["USER"] != "root": diff --git a/setup/so-functions b/setup/so-functions index ede539a6c..0ca635872 100755 --- a/setup/so-functions +++ b/setup/so-functions @@ -1774,6 +1774,10 @@ reinstall_init() { local service_retry_count=20 + # Disregard previous install outcomes + rm -f /root/failure + rm -f /root/success + { # remove all of root's cronjobs logCmd "crontab -r -u root" diff --git a/setup/so-verify b/setup/so-verify index 20aedb890..2ccc76b09 100755 --- a/setup/so-verify +++ b/setup/so-verify @@ -81,18 +81,27 @@ status_failed() { main() { exit_code=0 - if log_has_errors; then - echo "WARNING: Errors detected during setup" + if [ -f /root/success ]; then + echo "Successfully completed setup a while ago" + elif [ -f /root/failure ]; then + echo "WARNING: Failed setup a while ago" exit_code=1 + elif log_has_errors; then + echo "WARNING: Errors detected during setup" + exit_code=1 + touch /root/failure elif using_iso && cron_error_in_mail_spool; then - echo "WARNING: Unexpected cron job output in mail spool" + echo "WARNING: Unexpected cron job output in mail spool" exit_code=1 + touch /root/failure elif is_manager_node && status_failed; then echo "WARNING: Containers are not in a healthy state" exit_code=1 + touch /root/failure else - echo "Successfully completed setup!" - fi + echo "Successfully completed setup!" + touch /root/success + fi exit $exit_code }