Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Update onboarding script and dsc monitor plugin to use python3 over python2 if both versions are present #1483

Merged
merged 5 commits into from
Jul 21, 2022
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
8 changes: 4 additions & 4 deletions installer/scripts/omsadmin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ AGENT_MAINTENANCE_MISSING_CONFIG_FILE=4
AGENT_MAINTENANCE_MISSING_CONFIG=5
AGENT_MAINTENANCE_ERROR_WRITING_TO_FILE=12

# DSC MetaConfig generation script
if [ -x "$(command -v python2)" ]; then
METACONFIG_PY=/opt/microsoft/omsconfig/Scripts/OMS_MetaConfigHelper.py
elif [ -x "$(command -v python3)" ]; then
# DSC MetaConfig generation script. User python3 over python2 if both versions are installed
if [ -x "$(command -v python3)" ]; then
METACONFIG_PY=/opt/microsoft/omsconfig/Scripts/python3/OMS_MetaConfigHelper.py
elif [ -x "$(command -v python2)" ]; then
METACONFIG_PY=/opt/microsoft/omsconfig/Scripts/OMS_MetaConfigHelper.py
else
# Failure to find python/the correct script path will only break onboarding (just one
# of omsadmin's numerous functions); exit with failure in the onboard() function instead
Expand Down
6 changes: 3 additions & 3 deletions source/code/plugins/in_dsc_monitor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ def run_check_install

def get_dsc_status
begin
python = %x(which python2)
python = %x(which python3)
if !python.empty?
dsc_status = %x(/opt/microsoft/omsconfig/Scripts/TestDscConfiguration.py)
else # assume python3, since /some/ python is an install prereq and we have a rescue below regardless
dsc_status = %x(/opt/microsoft/omsconfig/Scripts/python3/TestDscConfiguration.py)
else # assume python2, since /some/ python is an install prereq and we have a rescue below regardless
dsc_status = %x(/opt/microsoft/omsconfig/Scripts/TestDscConfiguration.py)
end
rescue => error
OMS::Log.error_once("Running TestDscConfiguration.py returned error : #{error}")
Expand Down
14 changes: 7 additions & 7 deletions test/code/plugins/in_dsc_monitor_plugintest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ class DscMonitorTest < Test::Unit::TestCase
TMP_DIR = File.dirname(__FILE__) + "/../tmp/test_dscmonitor"
CHECK_IF_DPKG = "which dpkg > /dev/null 2>&1; echo $?"
CHECK_DSC_INSTALL = "dpkg --list omsconfig > /dev/null 2>&1; echo $?"
CHECK_DSC_STATUS = "/opt/microsoft/omsconfig/Scripts/TestDscConfiguration.py"
CHECK_DSC_STATUS_PYTHON_3 = "/opt/microsoft/omsconfig/Scripts/python3/TestDscConfiguration.py"
CHECK_PYTHON = "which python2"
CHECK_DSC_STATUS = "/opt/microsoft/omsconfig/Scripts/python3/TestDscConfiguration.py"
CHECK_DSC_STATUS_PYTHON_2 = "/opt/microsoft/omsconfig/Scripts/TestDscConfiguration.py"
CHECK_PYTHON = "which python3"

def setup
Fluent::Test.setup
Expand Down Expand Up @@ -64,8 +64,8 @@ def test_dsc_check_failure_message
instance.should_receive(:`).with(CHECK_IF_DPKG).and_return(0)
instance.should_receive(:`).with(CHECK_DSC_INSTALL).and_return(0)
instance.should_receive(:`).with(CHECK_DSC_STATUS).and_return("Mock DSC config check")
instance.should_receive(:`).with(CHECK_DSC_STATUS_PYTHON_3).and_return("Mock DSC config check")
instance.should_receive(:`).with(CHECK_PYTHON).and_return("/usr/bin/python2") # as if python2 is installed
instance.should_receive(:`).with(CHECK_DSC_STATUS_PYTHON_2).and_return("Mock DSC config check")
instance.should_receive(:`).with(CHECK_PYTHON).and_return("/usr/bin/python3") # as if python3 is installed
end

d = create_driver
Expand All @@ -91,8 +91,8 @@ def test_dsc_check_success_emits_no_messages
instance.should_receive(:`).with(CHECK_IF_DPKG).and_return(0)
instance.should_receive(:`).with(CHECK_DSC_INSTALL).and_return(0)
instance.should_receive(:`).with(CHECK_DSC_STATUS).and_return(result)
instance.should_receive(:`).with(CHECK_DSC_STATUS_PYTHON_3).and_return(result)
instance.should_receive(:`).with(CHECK_PYTHON).and_return("/usr/bin/python2") # as if python2 is installed
instance.should_receive(:`).with(CHECK_DSC_STATUS_PYTHON_2).and_return(result)
instance.should_receive(:`).with(CHECK_PYTHON).and_return("") # as if python2 is installed
end

d = create_driver
Expand Down