Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/extension/src/ActionHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 5 additions & 2 deletions src/extension/src/InstallCommandHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment thread
rane-rajasi marked this conversation as resolved.
self.validate_environment()
self.logger.log("Install Command Completed")
return Constants.ExitCode.Okay
Expand All @@ -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):
Expand Down
19 changes: 17 additions & 2 deletions src/extension/tests/Test_ActionHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import json
import os
import shutil
import sys
import tempfile
import unittest

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
11 changes: 10 additions & 1 deletion src/extension/tests/Test_InstallCommandHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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'
Expand Down
Loading