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
19 changes: 1 addition & 18 deletions src/extension/src/ProcessHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,24 +139,7 @@ def get_python_cmd(self):
return python_path
else:
self.logger.log_debug("Default python path discovery failed. [Code={0}][Out={1}]".format(str(code), str(out)))

# nothing below this is really necessary and is only there as a fallback for safety initially -----------------
command_to_check_for_python = "which python"
command_to_check_for_python3 = "which python3"
command_to_use_for_python = "python"
command_to_use_for_python3 = "python3"

# check if the machine contains python3
code_returned_for_python3_check, output_for_python3_check = self.env_layer.run_command_output(command_to_check_for_python3, False, False)
if code_returned_for_python3_check == 0 and command_to_use_for_python3 in str(output_for_python3_check):
return command_to_use_for_python3

# check if the machine contains python
code_returned_for_python_check, output_for_python_check = self.env_layer.run_command_output(command_to_check_for_python, False, False)
if code_returned_for_python_check == 0 and command_to_use_for_python in str(output_for_python_check) and command_to_use_for_python3 not in str(output_for_python_check):
return command_to_use_for_python

return Constants.PYTHON_NOT_FOUND
return Constants.PYTHON_NOT_FOUND

def __check_process_state(self, process, seq_no):
""" Checks if the process is running by polling every second for a certain period and reports an error if the process is not found """
Expand Down
22 changes: 5 additions & 17 deletions src/extension/tests/Test_ProcessHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import sys
import unittest
from extension.src.Constants import Constants
from extension.src.EnvLayer import EnvLayer
from extension.src.file_handlers.ExtOutputStatusHandler import ExtOutputStatusHandler
from extension.src.file_handlers.ExtConfigSettingsHandler import ExtConfigSettingsHandler
from extension.src.file_handlers.ExtEnvHandler import ExtEnvHandler
Expand Down Expand Up @@ -57,10 +56,7 @@ def mock_run_command_output_for_python_sys(self, cmd, no_output=False, chk_err=F
return 0, sys.executable

def mock_run_command_output_for_python(self, cmd, no_output=False, chk_err=False):
return 0, "/usr/bin/python"

def mock_run_command_output_for_python3(self, cmd, no_output=False, chk_err=False):
return 0, "/usr/bin/python3"
return 0, sys.executable

def mock_run_command_output_for_python_not_found(self, cmd, no_output=False, chk_err=False):
return 1, "which: no python in test"
Expand Down Expand Up @@ -139,27 +135,19 @@ def test_kill_process(self):

def test_get_python_cmd(self):
# setting mocks
run_command_output_backup = EnvLayer.run_command_output
run_command_output_backup = self.env_layer.run_command_output
process_handler = ProcessHandler(self.logger, self.env_layer, self.ext_output_status_handler)

# testing for 'python' command
EnvLayer.run_command_output = self.mock_run_command_output_for_python_sys
self.env_layer.run_command_output = self.mock_run_command_output_for_python
self.assertEqual(process_handler.get_python_cmd(), sys.executable)

# testing for 'python' command
EnvLayer.run_command_output = self.mock_run_command_output_for_python
self.assertEqual(process_handler.get_python_cmd(), "python")

# testing for 'python3' command
EnvLayer.run_command_output = self.mock_run_command_output_for_python3
self.assertEqual(process_handler.get_python_cmd(), "python3")

# testing when python is not found on machine
EnvLayer.run_command_output = self.mock_run_command_output_for_python_not_found
self.env_layer.run_command_output = self.mock_run_command_output_for_python_not_found
self.assertEqual(process_handler.get_python_cmd(), Constants.PYTHON_NOT_FOUND)

# resetting mocks
EnvLayer.run_command_output = run_command_output_backup
self.env_layer.run_command_output = run_command_output_backup

def test_start_daemon(self):
# setting mocks
Expand Down