From 8f9873709d0163eed73fed938a637f32fdde77d3 Mon Sep 17 00:00:00 2001 From: Narine Mossikyan Date: Thu, 14 Jul 2022 14:57:34 -0700 Subject: [PATCH 1/3] use python3 over python2 if both versions are installed in dsc metaconfig --- installer/scripts/omsadmin.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/installer/scripts/omsadmin.sh b/installer/scripts/omsadmin.sh index bb7de3ad2..b42ed4f9a 100755 --- a/installer/scripts/omsadmin.sh +++ b/installer/scripts/omsadmin.sh @@ -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 From 9a9099501b316b57f6f142892ce0b87d2874c810 Mon Sep 17 00:00:00 2001 From: Narine Mossikyan Date: Fri, 15 Jul 2022 09:26:33 -0700 Subject: [PATCH 2/3] update dsc plugin to use python3 over python2 for TestDscConfiguration.py --- source/code/plugins/in_dsc_monitor.rb | 4 ++-- test/code/plugins/in_dsc_monitor_plugintest.rb | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/source/code/plugins/in_dsc_monitor.rb b/source/code/plugins/in_dsc_monitor.rb index 915bf6c4e..3adedffc7 100644 --- a/source/code/plugins/in_dsc_monitor.rb +++ b/source/code/plugins/in_dsc_monitor.rb @@ -57,8 +57,8 @@ def run_check_install def get_dsc_status begin - python = %x(which python2) - if !python.empty? + python = (%x(command -v python3)).to_i + if python == 1 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) diff --git a/test/code/plugins/in_dsc_monitor_plugintest.rb b/test/code/plugins/in_dsc_monitor_plugintest.rb index 11e5ff0d3..dc5c1efbd 100644 --- a/test/code/plugins/in_dsc_monitor_plugintest.rb +++ b/test/code/plugins/in_dsc_monitor_plugintest.rb @@ -10,7 +10,7 @@ class DscMonitorTest < Test::Unit::TestCase 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_PYTHON = "command -v python3" def setup Fluent::Test.setup @@ -65,7 +65,7 @@ def test_dsc_check_failure_message 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_PYTHON).and_return(0) # as if python3 is installed end d = create_driver @@ -92,7 +92,7 @@ def test_dsc_check_success_emits_no_messages 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_PYTHON).and_return(1) # as if python2 is installed end d = create_driver From 275e8d922f643e44fce6f0f8a4bf2f47670366a4 Mon Sep 17 00:00:00 2001 From: Narine Mossikyan Date: Wed, 20 Jul 2022 14:20:19 -0700 Subject: [PATCH 3/3] use which instead of command in dsc ruby plugin --- source/code/plugins/in_dsc_monitor.rb | 8 ++++---- test/code/plugins/in_dsc_monitor_plugintest.rb | 14 +++++++------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/source/code/plugins/in_dsc_monitor.rb b/source/code/plugins/in_dsc_monitor.rb index 3adedffc7..ce7299e79 100644 --- a/source/code/plugins/in_dsc_monitor.rb +++ b/source/code/plugins/in_dsc_monitor.rb @@ -57,11 +57,11 @@ def run_check_install def get_dsc_status begin - python = (%x(command -v python3)).to_i - if python == 1 - 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 + python = %x(which python3) + if !python.empty? 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}") diff --git a/test/code/plugins/in_dsc_monitor_plugintest.rb b/test/code/plugins/in_dsc_monitor_plugintest.rb index dc5c1efbd..8352f8921 100644 --- a/test/code/plugins/in_dsc_monitor_plugintest.rb +++ b/test/code/plugins/in_dsc_monitor_plugintest.rb @@ -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 = "command -v python3" + 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 @@ -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(0) # as if python3 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 @@ -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(1) # 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