From fcb3de3404aa83e311a0281fd5c86dcd88653241 Mon Sep 17 00:00:00 2001 From: Rajasi Rane Date: Wed, 30 Sep 2026 12:26:26 -0700 Subject: [PATCH] Modify exitcode returned when operating system check fails --- src/extension/src/ActionHandler.py | 4 +++- src/extension/src/InstallCommandHandler.py | 7 +++++-- src/extension/tests/Test_ActionHandler.py | 19 +++++++++++++++++-- .../tests/Test_InstallCommandHandler.py | 11 ++++++++++- 4 files changed, 35 insertions(+), 6 deletions(-) diff --git a/src/extension/src/ActionHandler.py b/src/extension/src/ActionHandler.py index 98ca85ba..2ec6671d 100644 --- a/src/extension/src/ActionHandler.py +++ b/src/extension/src/ActionHandler.py @@ -184,7 +184,9 @@ def install(self): if exit_code_from_executing_install == Constants.ExitCode.Okay or exit_code_from_executing_install is None: self.ext_output_status_handler.write_status_file("", self.seq_no, status=Constants.Status.Success.lower()) else: - self.ext_output_status_handler.write_status_file("", self.seq_no, status=Constants.Status.Error.lower(), message="Error occurred during extension install", code=exit_code_from_executing_install) + self.ext_output_status_handler.write_status_file("", self.seq_no, status=Constants.Status.Error.lower(), + message="Error occurred during extension install. [ExitCode={0}]".format(str(exit_code_from_executing_install)), + code=exit_code_from_executing_install) return exit_code_from_executing_install except Exception as error: diff --git a/src/extension/src/InstallCommandHandler.py b/src/extension/src/InstallCommandHandler.py index f8c1b22e..ff71c038 100644 --- a/src/extension/src/InstallCommandHandler.py +++ b/src/extension/src/InstallCommandHandler.py @@ -25,7 +25,9 @@ def __init__(self, logger, ext_env_handler): self.ext_env_handler = ext_env_handler def execute_handler_action(self): - self.validate_os_type() + os_validation_result = self.validate_os_type() + if os_validation_result is not True: + return os_validation_result self.validate_environment() self.logger.log("Install Command Completed") return Constants.ExitCode.Okay @@ -35,7 +37,8 @@ def validate_os_type(self): self.logger.log("Validating OS. [Platform={0}]".format(os_type)) if not os_type.__contains__('linux'): error_msg = "Incompatible system: This update is for Linux OS" - self.logger.log_error_and_raise_new_exception(error_msg, Exception) + self.logger.log_error(error_msg) + return Constants.ExitCode.UnsupportedOperatingSystem return True def validate_environment(self): diff --git a/src/extension/tests/Test_ActionHandler.py b/src/extension/tests/Test_ActionHandler.py index d9fffacd..35c21d62 100644 --- a/src/extension/tests/Test_ActionHandler.py +++ b/src/extension/tests/Test_ActionHandler.py @@ -18,6 +18,7 @@ import json import os import shutil +import sys import tempfile import unittest @@ -462,11 +463,25 @@ def test_status_file_on_install_success(self): # Uninstall succeeds, seq no available in env var, status file is written self.action_handler.seq_no = 1234 - self.action_handler.install() + self.assertEqual(self.action_handler.install(), Constants.ExitCode.Okay) self.validate_status_file_on_success(self.action_handler.seq_no) InstallCommandHandler.validate_os_type = self.backup_validate_os_type + def test_status_file_on_install_unsupported_os(self): + """ An unsupported OS produces an error status with the specific exit code. """ + original_platform = sys.platform + try: + sys.platform = 'win32' + self.action_handler.seq_no = 1234 + self.assertEqual(self.action_handler.install(), Constants.ExitCode.UnsupportedOperatingSystem) + finally: + sys.platform = original_platform + + self.validate_status_file_on_failure(self.action_handler.seq_no, + "Error occurred during extension install. [ExitCode={0}]".format(Constants.ExitCode.UnsupportedOperatingSystem), + Constants.ExitCode.UnsupportedOperatingSystem) + def test_status_file_on_install_failed(self): """ Validate a basic status file is written if seq no exists in env var """ self.backup_setup = self.action_handler.setup @@ -479,7 +494,7 @@ def test_status_file_on_install_failed(self): # Uninstall fails, seq no available in env var, status file is written self.action_handler.seq_no = 1234 - self.action_handler.install() + self.assertEqual(self.action_handler.install(), Constants.ExitCode.HandlerFailed) self.validate_status_file_on_failure(self.action_handler.seq_no, "Error occurred during extension install") self.action_handler.setup = self.backup_setup diff --git a/src/extension/tests/Test_InstallCommandHandler.py b/src/extension/tests/Test_InstallCommandHandler.py index d19fe68d..68dc169e 100644 --- a/src/extension/tests/Test_InstallCommandHandler.py +++ b/src/extension/tests/Test_InstallCommandHandler.py @@ -28,6 +28,7 @@ class TestInstallCommandHandler(unittest.TestCase): def setUp(self): VirtualTerminal().print_lowlight("\n----------------- setup test runner -----------------") + self.original_platform = sys.platform runtime = RuntimeComposer() self.logger = runtime.logger self.env_layer = runtime.env_layer @@ -43,6 +44,7 @@ def setUp(self): def tearDown(self): VirtualTerminal().print_lowlight("\n----------------- tear down test runner -----------------") + sys.platform = self.original_platform # resetting mocks self.json_file_handler.get_json_file_content = self.get_json_file_content_backup # reset temp folder mock from ExtEnvHandler @@ -64,7 +66,14 @@ def test_validate_os_type_not_linux(self): ext_env_handler = ExtEnvHandler(self.logger, self.env_layer, self.json_file_handler) install_command_handler = InstallCommandHandler(self.logger, ext_env_handler) sys.platform = 'win32' - self.assertRaises(Exception, install_command_handler.validate_os_type) + self.assertEqual(install_command_handler.validate_os_type(), Constants.ExitCode.UnsupportedOperatingSystem) + + def test_execute_action_handler_not_linux(self): + ext_env_handler = ExtEnvHandler(self.logger, self.env_layer, self.json_file_handler) + install_command_handler = InstallCommandHandler(self.logger, ext_env_handler) + sys.platform = 'win32' + # The mocked environment has no content; it must not be validated on unsupported OSes. + self.assertEqual(install_command_handler.execute_handler_action(), Constants.ExitCode.UnsupportedOperatingSystem) def test_validate_environment(self): config_type = 'handlerEnvironment'