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 3 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
4 changes: 2 additions & 2 deletions source/code/plugins/in_dsc_monitor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
NarineM marked this conversation as resolved.
Show resolved Hide resolved
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)
Expand Down
6 changes: 3 additions & 3 deletions test/code/plugins/in_dsc_monitor_plugintest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
NarineM marked this conversation as resolved.
Show resolved Hide resolved

def setup
Fluent::Test.setup
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down