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

Commit fd4f26c

Browse files
authored
Update onboarding script and dsc monitor plugin to use python3 over python2 if both versions are present (#1483)
* use python3 over python2 if both versions are installed in dsc metaconfig * update dsc plugin to use python3 over python2 for TestDscConfiguration.py * use which instead of command in dsc ruby plugin
1 parent a7d1c7b commit fd4f26c

3 files changed

Lines changed: 14 additions & 14 deletions

File tree

installer/scripts/omsadmin.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ AGENT_MAINTENANCE_MISSING_CONFIG_FILE=4
5353
AGENT_MAINTENANCE_MISSING_CONFIG=5
5454
AGENT_MAINTENANCE_ERROR_WRITING_TO_FILE=12
5555

56-
# DSC MetaConfig generation script
57-
if [ -x "$(command -v python2)" ]; then
58-
METACONFIG_PY=/opt/microsoft/omsconfig/Scripts/OMS_MetaConfigHelper.py
59-
elif [ -x "$(command -v python3)" ]; then
56+
# DSC MetaConfig generation script. User python3 over python2 if both versions are installed
57+
if [ -x "$(command -v python3)" ]; then
6058
METACONFIG_PY=/opt/microsoft/omsconfig/Scripts/python3/OMS_MetaConfigHelper.py
59+
elif [ -x "$(command -v python2)" ]; then
60+
METACONFIG_PY=/opt/microsoft/omsconfig/Scripts/OMS_MetaConfigHelper.py
6161
else
6262
# Failure to find python/the correct script path will only break onboarding (just one
6363
# of omsadmin's numerous functions); exit with failure in the onboard() function instead

source/code/plugins/in_dsc_monitor.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ def run_check_install
5757

5858
def get_dsc_status
5959
begin
60-
python = %x(which python2)
60+
python = %x(which python3)
6161
if !python.empty?
62-
dsc_status = %x(/opt/microsoft/omsconfig/Scripts/TestDscConfiguration.py)
63-
else # assume python3, since /some/ python is an install prereq and we have a rescue below regardless
6462
dsc_status = %x(/opt/microsoft/omsconfig/Scripts/python3/TestDscConfiguration.py)
63+
else # assume python2, since /some/ python is an install prereq and we have a rescue below regardless
64+
dsc_status = %x(/opt/microsoft/omsconfig/Scripts/TestDscConfiguration.py)
6565
end
6666
rescue => error
6767
OMS::Log.error_once("Running TestDscConfiguration.py returned error : #{error}")

test/code/plugins/in_dsc_monitor_plugintest.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ class DscMonitorTest < Test::Unit::TestCase
88
TMP_DIR = File.dirname(__FILE__) + "/../tmp/test_dscmonitor"
99
CHECK_IF_DPKG = "which dpkg > /dev/null 2>&1; echo $?"
1010
CHECK_DSC_INSTALL = "dpkg --list omsconfig > /dev/null 2>&1; echo $?"
11-
CHECK_DSC_STATUS = "/opt/microsoft/omsconfig/Scripts/TestDscConfiguration.py"
12-
CHECK_DSC_STATUS_PYTHON_3 = "/opt/microsoft/omsconfig/Scripts/python3/TestDscConfiguration.py"
13-
CHECK_PYTHON = "which python2"
11+
CHECK_DSC_STATUS = "/opt/microsoft/omsconfig/Scripts/python3/TestDscConfiguration.py"
12+
CHECK_DSC_STATUS_PYTHON_2 = "/opt/microsoft/omsconfig/Scripts/TestDscConfiguration.py"
13+
CHECK_PYTHON = "which python3"
1414

1515
def setup
1616
Fluent::Test.setup
@@ -64,8 +64,8 @@ def test_dsc_check_failure_message
6464
instance.should_receive(:`).with(CHECK_IF_DPKG).and_return(0)
6565
instance.should_receive(:`).with(CHECK_DSC_INSTALL).and_return(0)
6666
instance.should_receive(:`).with(CHECK_DSC_STATUS).and_return("Mock DSC config check")
67-
instance.should_receive(:`).with(CHECK_DSC_STATUS_PYTHON_3).and_return("Mock DSC config check")
68-
instance.should_receive(:`).with(CHECK_PYTHON).and_return("/usr/bin/python2") # as if python2 is installed
67+
instance.should_receive(:`).with(CHECK_DSC_STATUS_PYTHON_2).and_return("Mock DSC config check")
68+
instance.should_receive(:`).with(CHECK_PYTHON).and_return("/usr/bin/python3") # as if python3 is installed
6969
end
7070

7171
d = create_driver
@@ -91,8 +91,8 @@ def test_dsc_check_success_emits_no_messages
9191
instance.should_receive(:`).with(CHECK_IF_DPKG).and_return(0)
9292
instance.should_receive(:`).with(CHECK_DSC_INSTALL).and_return(0)
9393
instance.should_receive(:`).with(CHECK_DSC_STATUS).and_return(result)
94-
instance.should_receive(:`).with(CHECK_DSC_STATUS_PYTHON_3).and_return(result)
95-
instance.should_receive(:`).with(CHECK_PYTHON).and_return("/usr/bin/python2") # as if python2 is installed
94+
instance.should_receive(:`).with(CHECK_DSC_STATUS_PYTHON_2).and_return(result)
95+
instance.should_receive(:`).with(CHECK_PYTHON).and_return("") # as if python2 is installed
9696
end
9797

9898
d = create_driver

0 commit comments

Comments
 (0)