From f0e0a5308dd09bd8046d6fa99033cae8c2585383 Mon Sep 17 00:00:00 2001 From: Jinesh Shah Date: Mon, 10 May 2021 09:25:10 +0530 Subject: [PATCH] Added support for python 3 for DIY DSC (#789) Summary of changes included as a part of the PR: Porting changes (Fixes) to run all scripts on python 3 Updated DSC default resources offered under nx to run on python 3. Added additional logging to all python scripts. Fixes for bugs that were introduced as a part of DROP OMI Depenedency. Description of the changes: As a part of porting the code we had decided to keep the code for python3 in a seperate forlder.(Most of these changes were done as a part of OMSConfig Py3 support PR). The updated folder for python scripts is as follows: python2 : /opt/microsoft/dsc/Scripts python3: /opt/microsoft/dsc/Scripts/python3 The python version of the machine will be determined by checking the existance of python2 and python3 command. In this version python2 takes precidence if both python 2 and 3 are present. (This is done to maintain compabality for older distros.) Instead of just logging success and failure a lot of debug and detailed logs ave been added. Going forward DSC will have two log files: /var/opt/omi/log/dsc.log /var/opt/omi/log/dscdetailed.log A lot of issues were discovered for the master branch, as the last release was done years back. I have tried to fix most of them. The issue were as a part of the DROP OMI DEPENDECY pr, which was only intended for omsconfig and ended up breaking DIY DSC. Testing: Manually tested for sanity and happy path secnarios on both python 2 and 3. Distro testing is in progress using the test suite. Bug bas planned for this week. * Initial Changes to run locally * Update InstallModule.py * Updated helper scripts to account for new paths * Updated providers to get invoked with python3 instead of python * Fix FindFirstFile Failed bug that was introduced in 2019 * Fixed path to omicli for scripts * Fixed the bug causing test to fail, it was introduced by a 2019 change DROP OMI DEPENDENCY * Update CAEngine.c * Added logs to python scripts * Updated logging to capture python major version * Added logs around compare in nxFile * Removed logging from import module to get rid of circular dependency * Removed logging from RegenerateInit to remove circular dependency * Update RegenerateInitFiles.py * Fixed comparison in case of python 3 for nxFile * Updated imports for loggig to work * Using absolute path instead of relative paths for DSCLogger * Update Makefile to respect version provided in Build Repo * Updated paths * Updated Register.py * Updated to remove warnings thrown for 'is' * Update if such that we check instance details before reginstance * Additioal logs to debug a failure in get configuration will revert the ones not required * Removed additional logging (These were just for debugging and not required to be released) * Removed additional logs * Updating content to string as OMI is not able to handle bytes * Resolving sekhar's comments --- .../ConsistencyInvoker/ConsistencyInvoker.c | 20 ++++++----------- .../ModuleLibrary/ModuleHandler.c | 2 +- LCM/dsc/engine/ca/CAInfrastructure/CAEngine.c | 13 +++++++---- LCM/scripts/GetDscConfiguration.py | 18 ++++++++++----- .../GetDscLocalConfigurationManager.py | 17 +++++++++----- LCM/scripts/InstallModule.py | 4 ++-- .../PerformRequiredConfigurationChecks.py | 9 +++++++- LCM/scripts/RegenerateInitFiles.py | 4 ++-- LCM/scripts/Register.py | 15 +++++++++++++ LCM/scripts/RemoveModule.py | 9 ++++++++ LCM/scripts/RestoreConfiguration.py | 13 +++++++++-- .../SetDscLocalConfigurationManager.py | 8 +++++++ LCM/scripts/StartDscConfiguration.py | 16 +++++++++----- LCM/scripts/TestDscConfiguration.py | 11 +++++++--- LCM/scripts/python3/GetDscConfiguration.py | 16 +++++++++----- .../GetDscLocalConfigurationManager.py | 16 +++++++++----- LCM/scripts/python3/InstallModule.py | 5 +++-- .../PerformRequiredConfigurationChecks.py | 9 +++++++- LCM/scripts/python3/RegenerateInitFiles.py | 3 +-- LCM/scripts/python3/Register.py | 19 +++++++++++++++- LCM/scripts/python3/RemoveModule.py | 12 +++++++++- LCM/scripts/python3/RestoreConfiguration.py | 12 ++++++++-- .../SetDscLocalConfigurationManager.py | 7 ++++++ LCM/scripts/python3/StartDscConfiguration.py | 15 ++++++++----- LCM/scripts/python3/TestDscConfiguration.py | 12 +++++++--- Providers/Scripts/3.x/Scripts/nxArchive.py | 2 +- .../Scripts/3.x/Scripts/nxEnvironment.py | 2 +- Providers/Scripts/3.x/Scripts/nxFile.py | 8 +++++-- Providers/Scripts/3.x/Scripts/nxFileLine.py | 2 +- Providers/Scripts/3.x/Scripts/nxGroup.py | 2 +- Providers/Scripts/3.x/Scripts/nxScript.py | 2 +- .../3.x/Scripts/nxSshAuthorizedKeys.py | 2 +- Providers/Scripts/3.x/Scripts/nxUser.py | 2 +- Providers/Scripts/nxDSCLog.py | 2 +- installbuilder/Makefile | 2 +- installbuilder/datafiles/Base_DSC.data | 22 +++++++++++++++++++ 36 files changed, 252 insertions(+), 81 deletions(-) diff --git a/LCM/dsc/engine/ConsistencyInvoker/ConsistencyInvoker.c b/LCM/dsc/engine/ConsistencyInvoker/ConsistencyInvoker.c index 6b4351ed6..5df34cad0 100644 --- a/LCM/dsc/engine/ConsistencyInvoker/ConsistencyInvoker.c +++ b/LCM/dsc/engine/ConsistencyInvoker/ConsistencyInvoker.c @@ -31,20 +31,15 @@ int main(int argc, char *argv[]) char* dscScriptPath = malloc(strlen(DSC_SCRIPT_PATH) + 1); dscScriptPath = strcpy(dscScriptPath, DSC_SCRIPT_PATH); - - //if oms config check to be added - if(strstr(dscScriptPath, "omsconfig")!= NULL) - { - pythonCommand = getPythonProvider(); - - if(strcmp(pythonCommand, PYTHON3_COMMAND) == 0) - { - dscScriptPath = realloc(dscScriptPath, strlen(dscScriptPath) + strlen("/python3") + 1 ); - dscScriptPath = strcat(dscScriptPath, "/python3"); - } - } + pythonCommand = getPythonProvider(); + if(strcmp(pythonCommand, PYTHON3_COMMAND) == 0) + { + dscScriptPath = realloc(dscScriptPath, strlen(dscScriptPath) + strlen("/python3") + 1 ); + dscScriptPath = strcat(dscScriptPath, "/python3"); + } + int fullCommandLength = strlen(pythonCommand) + 1 + strlen(dscScriptPath) + 1 + strlen(PYTHON_SCRIPT_NAME) + 1; char fullCommand[fullCommandLength]; @@ -59,7 +54,6 @@ int main(int argc, char *argv[]) } -// I may need to move this method in some file which is accessible to all other files in the project. char* getPythonProvider() { int buffer_length = 128; diff --git a/LCM/dsc/engine/ModuleLoader/ModuleLibrary/ModuleHandler.c b/LCM/dsc/engine/ModuleLoader/ModuleLibrary/ModuleHandler.c index 7efd78f68..85ae706d6 100755 --- a/LCM/dsc/engine/ModuleLoader/ModuleLibrary/ModuleHandler.c +++ b/LCM/dsc/engine/ModuleLoader/ModuleLibrary/ModuleHandler.c @@ -469,7 +469,6 @@ MI_Result GetModuleLoader( _In_ MI_Application *miApp, #if defined(BUILD_OMS) if (g_DscHost == MI_FALSE) { -#endif // Get the Registration information from shared objects r = GetRegistrationInstanceFromSharedObjects(NULL, miApp, de, options, strictOptions, &miClassArray, &miInstanceArray, extendedError); if( r != MI_RESULT_OK) @@ -482,6 +481,7 @@ MI_Result GetModuleLoader( _In_ MI_Application *miApp, CleanUpInstanceCache(&miInstanceArray); return r; } +#endif // No need to do this after removing OMI since we will discover resources directly from shared objects (except for DIY DSC) /*Perform registration against schema validation*/ diff --git a/LCM/dsc/engine/ca/CAInfrastructure/CAEngine.c b/LCM/dsc/engine/ca/CAInfrastructure/CAEngine.c index 14a59511c..dbf7329a1 100755 --- a/LCM/dsc/engine/ca/CAInfrastructure/CAEngine.c +++ b/LCM/dsc/engine/ca/CAInfrastructure/CAEngine.c @@ -1286,10 +1286,11 @@ MI_Result MoveToDesiredState(_In_ ProviderCallbackContext *provContext, if ( #if defined(BUILD_OMS) g_DscHost == MI_FALSE || + Tcscasecmp(instance->classDecl->name, METACONFIG_CLASSNAME) == 0 || // put special cases to wmiv2 code #else + Tcscasecmp(instance->classDecl->name, METACONFIG_CLASSNAME) == 0 || // put special cases to wmiv2 code Tcscasecmp(regInstance->classDecl->name, BASE_REGISTRATION_WMIV2PROVIDER) == 0 || #endif - Tcscasecmp(instance->classDecl->name, METACONFIG_CLASSNAME) == 0 || // put special cases to wmiv2 code Tcscasecmp(MSFT_LOGRESOURCENAME, instance->classDecl->name) == 0 ) { @@ -1910,15 +1911,16 @@ MI_Result GetGetMethodResult(_In_ MI_Operation *operation, *extendedError = NULL; // Explicitly set *extendedError to NULL as _Outptr_ requires setting this at least once. *outputInstance = NULL; - /*Get the operation result*/ r = MI_Operation_GetInstance(operation, &outInstance, &moreResults, &result, &errorMessage, &completionDetails); if( result != MI_RESULT_OK) { + DSC_LOG_INFO("MI_Operation_GetInstance inside GetGetMethodResult failed result not ok"); r = result; } if( r != MI_RESULT_OK) { + DSC_LOG_INFO("MI_Operation_GetInstance inside GetGetMethodResult failed r not ok"); if( completionDetails != NULL) { innerR = DSC_MI_Instance_Clone( completionDetails, extendedError); @@ -1927,6 +1929,7 @@ MI_Result GetGetMethodResult(_In_ MI_Operation *operation, { r = GetCimMIError(r, extendedError,ID_CAINFRA_GETINSTANCE_FAILED); } + return r; } @@ -2021,18 +2024,21 @@ MI_Result Get_WMIv2Provider(_In_ ProviderCallbackContext *provContext, return GetCimMIError(r, extendedError,ID_CAINFRA_GET_NEWAPPLICATIONINSTANCE_FAILED); } value.instance = instance; + r = DSC_MI_Instance_AddElement(params, OMI_BaseResource_Method_InputResource, &value, MI_INSTANCE, 0 ); if( r != MI_RESULT_OK) { MI_Instance_Delete(params); return GetCimMIError(r, extendedError,ID_CAINFRA_GET_ADDELEM_FAILED); } + r = MI_Application_NewOperationOptions(miApp, MI_FALSE, &sessionOptions); if( r != MI_RESULT_OK ) { return GetCimMIError(r, extendedError,ID_CAINFRA_GET_NEWOPERATIONOPTIONS_FAILED); } valueOperationOptions.string=g_ConfigurationDetails.jobGuidString; + r =MI_OperationOptions_SetCustomOption(&sessionOptions,DSC_JOBIDSTRING,MI_STRING,&valueOperationOptions,MI_FALSE); if( r != MI_RESULT_OK) { @@ -2041,17 +2047,16 @@ MI_Result Get_WMIv2Provider(_In_ ProviderCallbackContext *provContext, } /* Perform Get*/ - MI_Session_Invoke(miSession, 0, &sessionOptions, provNamespace, instance->classDecl->name, OMI_BaseResource_GetMethodName, NULL, params, &callbacks,&operation); - r = GetGetMethodResult(&operation, outputInstance , extendedError); MI_Instance_Delete(params); MI_OperationOptions_Delete(&sessionOptions); MI_Operation_Close(&operation); if( r != MI_RESULT_OK) { + DSC_LOG_INFO("GetGetMethodResult r is not ok"); return r; } } diff --git a/LCM/scripts/GetDscConfiguration.py b/LCM/scripts/GetDscConfiguration.py index 358ceb4d1..95b9ebaf3 100755 --- a/LCM/scripts/GetDscConfiguration.py +++ b/LCM/scripts/GetDscConfiguration.py @@ -8,24 +8,31 @@ import os import os.path from OmsConfigHostHelpers import write_omsconfig_host_telemetry, write_omsconfig_host_switch_event, write_omsconfig_host_log, stop_old_host_instances -from imp import load_source -from os.path import dirname, isfile, join, realpath -from fcntl import flock, LOCK_EX, LOCK_UN, LOCK_NB +from imp import load_source +from os.path import dirname, isfile, join, realpath +from fcntl import flock, LOCK_EX, LOCK_UN, LOCK_NB +from sys import argv + pathToCurrentScript = realpath(__file__) pathToCommonScriptsFolder = dirname(pathToCurrentScript) +DSCLogPath = join(pathToCommonScriptsFolder, 'nxDSCLog.py') +nxDSCLog = load_source('nxDSCLog', DSCLogPath) +LG = nxDSCLog.DSCLog + helperLibPath = join(pathToCommonScriptsFolder, 'helperlib.py') helperlib = load_source('helperlib', helperLibPath) -omi_bindir = "" -omicli_path = omi_bindir + "/omicli" +omicli_path = join(helperlib.CONFIG_BINDIR, 'omicli') dsc_host_base_path = helperlib.DSC_HOST_BASE_PATH dsc_host_path = join(dsc_host_base_path, 'bin/dsc_host') dsc_host_output_path = join(dsc_host_base_path, 'output') dsc_host_lock_path = join(dsc_host_base_path, 'dsc_host_lock') dsc_host_switch_path = join(dsc_host_base_path, 'dsc_host_ready') +LG().Log("DEBUG", "Starting script logic for " + argv[0]+ " runing with python " + str(sys.version_info.major)) + if ("omsconfig" in helperlib.DSC_SCRIPT_PATH): write_omsconfig_host_switch_event(pathToCurrentScript, isfile(dsc_host_switch_path)) @@ -93,4 +100,5 @@ print(stdout) print(stderr) +LG().Log("DEBUG", "End of script logic for " + argv[0] + " runing with python " + str(sys.version_info.major)) diff --git a/LCM/scripts/GetDscLocalConfigurationManager.py b/LCM/scripts/GetDscLocalConfigurationManager.py index 110d0b0e0..8410bd7d3 100755 --- a/LCM/scripts/GetDscLocalConfigurationManager.py +++ b/LCM/scripts/GetDscLocalConfigurationManager.py @@ -8,24 +8,30 @@ import os import os.path from OmsConfigHostHelpers import write_omsconfig_host_telemetry, write_omsconfig_host_switch_event, write_omsconfig_host_log, stop_old_host_instances -from imp import load_source -from os.path import dirname, isfile, join, realpath -from fcntl import flock, LOCK_EX, LOCK_UN, LOCK_NB +from imp import load_source +from os.path import dirname, isfile, join, realpath +from fcntl import flock, LOCK_EX, LOCK_UN, LOCK_NB +from sys import argv pathToCurrentScript = realpath(__file__) pathToCommonScriptsFolder = dirname(pathToCurrentScript) +DSCLogPath = join(pathToCommonScriptsFolder, 'nxDSCLog.py') +nxDSCLog = load_source('nxDSCLog', DSCLogPath) +LG = nxDSCLog.DSCLog + helperLibPath = join(pathToCommonScriptsFolder, 'helperlib.py') helperlib = load_source('helperlib', helperLibPath) -omi_bindir = "" -omicli_path = omi_bindir + "/omicli" +omicli_path = join(helperlib.CONFIG_BINDIR, 'omicli') dsc_host_base_path = helperlib.DSC_HOST_BASE_PATH dsc_host_path = join(dsc_host_base_path, 'bin/dsc_host') dsc_host_output_path = join(dsc_host_base_path, 'output') dsc_host_lock_path = join(dsc_host_base_path, 'dsc_host_lock') dsc_host_switch_path = join(dsc_host_base_path, 'dsc_host_ready') +LG().Log("DEBUG", "Starting script logic for " + argv[0]+ " runing with python " + str(sys.version_info.major)) + if ("omsconfig" in helperlib.DSC_SCRIPT_PATH): write_omsconfig_host_switch_event(pathToCurrentScript, isfile(dsc_host_switch_path)) @@ -93,4 +99,5 @@ print(stdout) print(stderr) +LG().Log("DEBUG", "End of script logic for " + argv[0] + " runing with python " + str(sys.version_info.major)) diff --git a/LCM/scripts/InstallModule.py b/LCM/scripts/InstallModule.py index 156855dcd..03f72c483 100755 --- a/LCM/scripts/InstallModule.py +++ b/LCM/scripts/InstallModule.py @@ -6,7 +6,7 @@ import subprocess import sys import platform -from os.path import basename, dirname, join, realpath, split +from os.path import basename, dirname, join, realpath, split pathToCurrentScript = realpath(__file__) pathToCommonScriptsFolder = dirname(pathToCurrentScript) @@ -357,4 +357,4 @@ def main(args): regenerateDscPythonScriptInitFiles() if __name__ == "__main__": - main(sys.argv[1:]) + main(sys.argv[1:]) \ No newline at end of file diff --git a/LCM/scripts/PerformRequiredConfigurationChecks.py b/LCM/scripts/PerformRequiredConfigurationChecks.py index 61946e211..74b5fa0c1 100755 --- a/LCM/scripts/PerformRequiredConfigurationChecks.py +++ b/LCM/scripts/PerformRequiredConfigurationChecks.py @@ -1,8 +1,9 @@ #!/usr/bin/python +import sys from imp import load_source from os.path import dirname, join, realpath, isfile from subprocess import PIPE, Popen -from sys import exc_info, exit, version_info +from sys import exc_info, exit, version_info, argv from traceback import format_exc from fcntl import flock, LOCK_EX, LOCK_UN, LOCK_NB from OmsConfigHostHelpers import write_omsconfig_host_telemetry, write_omsconfig_host_switch_event, write_omsconfig_host_log, stop_old_host_instances @@ -11,6 +12,10 @@ pathToCurrentScript = realpath(__file__) pathToCommonScriptsFolder = dirname(pathToCurrentScript) +DSCLogPath = join(pathToCommonScriptsFolder, 'nxDSCLog.py') +nxDSCLog = load_source('nxDSCLog', DSCLogPath) +LG = nxDSCLog.DSCLog + helperLibPath = join(pathToCommonScriptsFolder, 'helperlib.py') helperlib = load_source('helperlib', helperLibPath) @@ -111,4 +116,6 @@ def run_perform_required_configuration_checks(): print(stdout) if __name__ == "__main__": + LG().Log("DEBUG", "Starting Main method for " + argv[0] + " runing with python " + str(sys.version_info.major)) main() + LG().Log("DEBUG", "End of Main method for " + argv[0] + " runing with python " + str(sys.version_info.major)) diff --git a/LCM/scripts/RegenerateInitFiles.py b/LCM/scripts/RegenerateInitFiles.py index 39799bfb1..fcac66183 100644 --- a/LCM/scripts/RegenerateInitFiles.py +++ b/LCM/scripts/RegenerateInitFiles.py @@ -8,6 +8,7 @@ omi_libdir + "/2.6x-2.7x/Scripts", omi_libdir + "/3.x/Scripts"] + for current_dir in script_dirs: out_init = "__all__=" py_files = glob.glob(current_dir + "/*.py") @@ -24,5 +25,4 @@ py_files_basename.append(current_basename[:-3]) out_init = out_init + str(py_files_basename) - open(current_dir + "/__init__.py", "w").write(out_init) - + open(current_dir + "/__init__.py", "w").write(out_init) \ No newline at end of file diff --git a/LCM/scripts/Register.py b/LCM/scripts/Register.py index 3af089caa..806e3aee0 100755 --- a/LCM/scripts/Register.py +++ b/LCM/scripts/Register.py @@ -4,6 +4,9 @@ import os.path import tempfile import shutil +from sys import argv +from imp import load_source +from os.path import dirname, join, realpath def usage(): print("""Usage: Register.py [OPTIONS] @@ -18,6 +21,16 @@ def usage(): --Help """) + +pathToCurrentScript = realpath(__file__) +pathToCommonScriptsFolder = dirname(pathToCurrentScript) + +DSCLogPath = join(pathToCommonScriptsFolder, 'nxDSCLog.py') +nxDSCLog = load_source('nxDSCLog', DSCLogPath) +LG = nxDSCLog.DSCLog + +LG().Log("DEBUG", "Starting script logic for " + argv[0]+ " runing with python " + str(sys.version_info.major)) + # Apply a DSC meta configuration based on a template Variables = dict() @@ -217,3 +230,5 @@ def usage(): os.system("/SetDscLocalConfigurationManager.py -configurationmof " + meta_path) shutil.rmtree(tempdir) + +LG().Log("DEBUG", "End of script logic for " + argv[0] + " runing with python " + str(sys.version_info.major)) \ No newline at end of file diff --git a/LCM/scripts/RemoveModule.py b/LCM/scripts/RemoveModule.py index 936f90b50..cc3927939 100755 --- a/LCM/scripts/RemoveModule.py +++ b/LCM/scripts/RemoveModule.py @@ -6,9 +6,16 @@ import platform import imp from os.path import dirname, join, realpath +from sys import argv +from imp import load_source pathToCurrentScript = realpath(__file__) pathToCommonScriptsFolder = dirname(pathToCurrentScript) + +DSCLogPath = join(pathToCommonScriptsFolder, 'nxDSCLog.py') +nxDSCLog = load_source('nxDSCLog', DSCLogPath) +LG = nxDSCLog.DSCLog + helperLibPath = join(pathToCommonScriptsFolder, 'helperlib.py') helperlib = imp.load_source('helperlib', helperLibPath) fullPathDSCLogger = os.path.join(pathToCommonScriptsFolder, 'nxDSCLog.py') @@ -196,4 +203,6 @@ def main(args): shutil.rmtree(modulePath) if __name__ == "__main__": + LG().Log("DEBUG", "Starting Main method for " + argv[0] + " runing with python " + str(sys.version_info.major)) main(sys.argv[1:]) + LG().Log("DEBUG", "End of Main method for " + argv[0] + " runing with python " + str(sys.version_info.major)) diff --git a/LCM/scripts/RestoreConfiguration.py b/LCM/scripts/RestoreConfiguration.py index 45fac6b5d..461ab30fe 100755 --- a/LCM/scripts/RestoreConfiguration.py +++ b/LCM/scripts/RestoreConfiguration.py @@ -7,21 +7,28 @@ from fcntl import flock, LOCK_EX, LOCK_UN, LOCK_NB from OmsConfigHostHelpers import write_omsconfig_host_telemetry, write_omsconfig_host_switch_event, write_omsconfig_host_log, stop_old_host_instances from time import sleep +from sys import argv + pathToCurrentScript = realpath(__file__) pathToCommonScriptsFolder = dirname(pathToCurrentScript) +DSCLogPath = join(pathToCommonScriptsFolder, 'nxDSCLog.py') +nxDSCLog = load_source('nxDSCLog', DSCLogPath) +LG = nxDSCLog.DSCLog + helperLibPath = join(pathToCommonScriptsFolder, 'helperlib.py') helperlib = load_source('helperlib', helperLibPath) -omi_bindir = "" -omicli_path = omi_bindir + "/omicli" +omicli_path = join(helperlib.CONFIG_BINDIR, 'omicli') dsc_host_base_path = helperlib.DSC_HOST_BASE_PATH dsc_host_path = join(dsc_host_base_path, 'bin/dsc_host') dsc_host_output_path = join(dsc_host_base_path, 'output') dsc_host_lock_path = join(dsc_host_base_path, 'dsc_host_lock') dsc_host_switch_path = join(dsc_host_base_path, 'dsc_host_ready') +LG().Log("DEBUG", "Starting script logic for " + argv[0]+ " runing with python " + str(sys.version_info.major)) + if ("omsconfig" in helperlib.DSC_SCRIPT_PATH): write_omsconfig_host_switch_event(pathToCurrentScript, isfile(dsc_host_switch_path)) @@ -86,3 +93,5 @@ print(stdout) print(stderr) + +LG().Log("DEBUG", "End of script logic for " + argv[0] + " runing with python " + str(sys.version_info.major)) \ No newline at end of file diff --git a/LCM/scripts/SetDscLocalConfigurationManager.py b/LCM/scripts/SetDscLocalConfigurationManager.py index 5fb87169d..5fa9c160b 100755 --- a/LCM/scripts/SetDscLocalConfigurationManager.py +++ b/LCM/scripts/SetDscLocalConfigurationManager.py @@ -8,10 +8,16 @@ from OmsConfigHostHelpers import write_omsconfig_host_telemetry, write_omsconfig_host_switch_event, write_omsconfig_host_log, stop_old_host_instances from time import sleep import signal +import sys + pathToCurrentScript = realpath(__file__) pathToCommonScriptsFolder = dirname(pathToCurrentScript) +DSCLogPath = join(pathToCommonScriptsFolder, 'nxDSCLog.py') +nxDSCLog = load_source('nxDSCLog', DSCLogPath) +LG = nxDSCLog.DSCLog + helperLibPath = join(pathToCommonScriptsFolder, 'helperlib.py') helperlib = load_source('helperlib', helperLibPath) @@ -170,4 +176,6 @@ def signal_handler(signalNumber, frame): if __name__ == "__main__": # register the SIGTERM handler signal.signal(signal.SIGTERM, signal_handler) + LG().Log("DEBUG", "Starting Main method for " + argv[0] + " runing with python " + str(sys.version_info.major)) main(argv) + LG().Log("DEBUG", "End of Main method for " + argv[0] + " runing with python " + str(sys.version_info.major)) \ No newline at end of file diff --git a/LCM/scripts/StartDscConfiguration.py b/LCM/scripts/StartDscConfiguration.py index a25731963..2ceb8a327 100755 --- a/LCM/scripts/StartDscConfiguration.py +++ b/LCM/scripts/StartDscConfiguration.py @@ -8,10 +8,15 @@ from fcntl import flock, LOCK_EX, LOCK_UN, LOCK_NB from OmsConfigHostHelpers import write_omsconfig_host_telemetry, write_omsconfig_host_switch_event, write_omsconfig_host_log, stop_old_host_instances from time import sleep +import sys pathToCurrentScript = realpath(__file__) pathToCommonScriptsFolder = dirname(pathToCurrentScript) +DSCLogPath = join(pathToCommonScriptsFolder, 'nxDSCLog.py') +nxDSCLog = load_source('nxDSCLog', DSCLogPath) +LG = nxDSCLog.DSCLog + helperLibPath = join(pathToCommonScriptsFolder, 'helperlib.py') helperlib = load_source('helperlib', helperLibPath) @@ -115,8 +120,7 @@ def main(argv): configurationData.append(str(ord(char))) # # OMI CLI location - omiBinDir = "" - omiCliPath = omiBinDir + "/omicli" + omicli_path = join(helperlib.CONFIG_BINDIR, 'omicli') dsc_host_base_path = helperlib.DSC_HOST_BASE_PATH dsc_host_path = join(dsc_host_base_path, 'bin/dsc_host') dsc_host_output_path = join(dsc_host_base_path, 'output') @@ -142,7 +146,7 @@ def main(argv): if parsedArguments.force: host_parameters.append("force") else: - host_parameters.append(omiCliPath) + host_parameters.append(omicli_path) host_parameters.append("iv") host_parameters.append("") host_parameters.append("{") @@ -190,7 +194,7 @@ def main(argv): sleep(60) if dschostlock_acquired: - p = subprocess.Popen(parameters, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + p = subprocess.Popen(host_parameters, stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout, stderr = p.communicate() print(stdout) else: @@ -203,10 +207,12 @@ def main(argv): # Close dsc host lock file handle dschostlock_filehandle.close() else: - p = subprocess.Popen(parameters, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + p = Popen(host_parameters, stdout=PIPE, stderr=PIPE) stdout, stderr = p.communicate() print(stdout) print(stderr) +LG().Log("DEBUG", "Starting Main method for " + argv[0] + " runing with python " + str(sys.version_info.major)) main(argv[1:]) +LG().Log("DEBUG", "End of Main method for " + argv[0] + " runing with python " + str(sys.version_info.major)) \ No newline at end of file diff --git a/LCM/scripts/TestDscConfiguration.py b/LCM/scripts/TestDscConfiguration.py index a86286c72..76cfea078 100755 --- a/LCM/scripts/TestDscConfiguration.py +++ b/LCM/scripts/TestDscConfiguration.py @@ -7,21 +7,26 @@ from os.path import dirname, isfile, join, realpath from time import sleep from fcntl import flock, LOCK_EX, LOCK_UN, LOCK_NB +from sys import argv pathToCurrentScript = realpath(__file__) pathToCommonScriptsFolder = dirname(pathToCurrentScript) +DSCLogPath = join(pathToCommonScriptsFolder, 'nxDSCLog.py') +nxDSCLog = load_source('nxDSCLog', DSCLogPath) +LG = nxDSCLog.DSCLog helperLibPath = join(pathToCommonScriptsFolder, 'helperlib.py') helperlib = load_source('helperlib', helperLibPath) -omi_bindir = "" -omicli_path = omi_bindir + "/omicli" +omicli_path = join(helperlib.CONFIG_BINDIR, 'omicli') dsc_host_base_path = helperlib.DSC_HOST_BASE_PATH dsc_host_path = join(dsc_host_base_path, 'bin/dsc_host') dsc_host_output_path = join(dsc_host_base_path, 'output') dsc_host_lock_path = join(dsc_host_base_path, 'dsc_host_lock') dsc_host_switch_path = join(dsc_host_base_path, 'dsc_host_ready') +LG().Log("DEBUG", "Starting script logic for " + argv[0]+ " runing with python " + str(sys.version_info.major)) + if ("omsconfig" in helperlib.DSC_SCRIPT_PATH): write_omsconfig_host_switch_event(pathToCurrentScript, isfile(dsc_host_switch_path)) @@ -97,4 +102,4 @@ print(stdout) print(stderr) - +LG().Log("DEBUG", "End of script logic for " + argv[0] + " runing with python " + str(sys.version_info.major)) diff --git a/LCM/scripts/python3/GetDscConfiguration.py b/LCM/scripts/python3/GetDscConfiguration.py index e117a69de..f5632cf18 100755 --- a/LCM/scripts/python3/GetDscConfiguration.py +++ b/LCM/scripts/python3/GetDscConfiguration.py @@ -12,23 +12,29 @@ with warnings.catch_warnings(): warnings.filterwarnings("ignore",category=DeprecationWarning) from imp import load_source -from os.path import dirname, isfile, join, realpath -from fcntl import flock, LOCK_EX, LOCK_UN, LOCK_NB +from os.path import dirname, isfile, join, realpath +from fcntl import flock, LOCK_EX, LOCK_UN, LOCK_NB +from sys import argv pathToCurrentScript = realpath(__file__) pathToCommonScriptsFolder = dirname(pathToCurrentScript) +DSCLogPath = join(pathToCommonScriptsFolder, 'nxDSCLog.py') +nxDSCLog = load_source('nxDSCLog', DSCLogPath) +LG = nxDSCLog.DSCLog + helperLibPath = join(pathToCommonScriptsFolder, 'helperlib.py') helperlib = load_source('helperlib', helperLibPath) -omi_bindir = "" -omicli_path = omi_bindir + "/omicli" +omicli_path = join(helperlib.CONFIG_BINDIR, 'omicli') dsc_host_base_path = helperlib.DSC_HOST_BASE_PATH dsc_host_path = join(dsc_host_base_path, 'bin/dsc_host') dsc_host_output_path = join(dsc_host_base_path, 'output') dsc_host_lock_path = join(dsc_host_base_path, 'dsc_host_lock') dsc_host_switch_path = join(dsc_host_base_path, 'dsc_host_ready') +LG().Log("DEBUG", "Starting script logic for " + argv[0]+ " runing with python " + str(sys.version_info.major)) + if ("omsconfig" in helperlib.DSC_SCRIPT_PATH): write_omsconfig_host_switch_event(pathToCurrentScript, isfile(dsc_host_switch_path)) @@ -100,4 +106,4 @@ print(stdout) print(stderr) - +LG().Log("DEBUG", "End of script logic for " + argv[0] + " runing with python " + str(sys.version_info.major)) diff --git a/LCM/scripts/python3/GetDscLocalConfigurationManager.py b/LCM/scripts/python3/GetDscLocalConfigurationManager.py index 3c88f1d36..76de9dbda 100755 --- a/LCM/scripts/python3/GetDscLocalConfigurationManager.py +++ b/LCM/scripts/python3/GetDscLocalConfigurationManager.py @@ -12,23 +12,29 @@ with warnings.catch_warnings(): warnings.filterwarnings("ignore",category=DeprecationWarning) from imp import load_source -from os.path import dirname, isfile, join, realpath -from fcntl import flock, LOCK_EX, LOCK_UN, LOCK_NB +from os.path import dirname, isfile, join, realpath +from fcntl import flock, LOCK_EX, LOCK_UN, LOCK_NB +from sys import argv pathToCurrentScript = realpath(__file__) pathToCommonScriptsFolder = dirname(pathToCurrentScript) +DSCLogPath = join(pathToCommonScriptsFolder, 'nxDSCLog.py') +nxDSCLog = load_source('nxDSCLog', DSCLogPath) +LG = nxDSCLog.DSCLog + helperLibPath = join(pathToCommonScriptsFolder, 'helperlib.py') helperlib = load_source('helperlib', helperLibPath) -omi_bindir = "" -omicli_path = omi_bindir + "/omicli" +omicli_path = join(helperlib.CONFIG_BINDIR, 'omicli') dsc_host_base_path = helperlib.DSC_HOST_BASE_PATH dsc_host_path = join(dsc_host_base_path, 'bin/dsc_host') dsc_host_output_path = join(dsc_host_base_path, 'output') dsc_host_lock_path = join(dsc_host_base_path, 'dsc_host_lock') dsc_host_switch_path = join(dsc_host_base_path, 'dsc_host_ready') +LG().Log("DEBUG", "Starting script logic for " + argv[0]+ " runing with python " + str(sys.version_info.major)) + if ("omsconfig" in helperlib.DSC_SCRIPT_PATH): write_omsconfig_host_switch_event(pathToCurrentScript, isfile(dsc_host_switch_path)) @@ -99,4 +105,4 @@ print(stdout) print(stderr) - +LG().Log("DEBUG", "End of script logic for " + argv[0] + " runing with python " + str(sys.version_info.major)) diff --git a/LCM/scripts/python3/InstallModule.py b/LCM/scripts/python3/InstallModule.py index b9bbd2bf3..5e3c4984b 100755 --- a/LCM/scripts/python3/InstallModule.py +++ b/LCM/scripts/python3/InstallModule.py @@ -72,7 +72,8 @@ def getPlatformArchitectureFolderName(): def regenerateDscPythonScriptInitFiles(): - regenerateInitFilesResult = subprocess.call("(python3 /opt/microsoft/omsconfig/Scripts/python3/RegenerateInitFiles.py)", shell=True) + regenerateInitFilesScriptPath = join(helperlib.DSC_SCRIPT_PATH, 'RegenerateInitFiles.py') + regenerateInitFilesResult = subprocess.call("(python3 " + regenerateInitFilesScriptPath + ")", shell=True) print("The result code is", regenerateInitFilesResult) if regenerateInitFilesResult != 0: exitWithError("Failed to regenerate the DSC __init__.py files with the result code", regenerateInitFilesResult) @@ -365,4 +366,4 @@ def main(args): regenerateDscPythonScriptInitFiles() if __name__ == "__main__": - main(sys.argv[1:]) + main(sys.argv[1:]) \ No newline at end of file diff --git a/LCM/scripts/python3/PerformRequiredConfigurationChecks.py b/LCM/scripts/python3/PerformRequiredConfigurationChecks.py index add44df8c..63d09ebec 100755 --- a/LCM/scripts/python3/PerformRequiredConfigurationChecks.py +++ b/LCM/scripts/python3/PerformRequiredConfigurationChecks.py @@ -5,15 +5,20 @@ from imp import load_source from os.path import dirname, join, realpath, isfile from subprocess import PIPE, Popen -from sys import exc_info, exit, version_info +from sys import exc_info, exit, version_info, argv from traceback import format_exc from fcntl import flock, LOCK_EX, LOCK_UN, LOCK_NB from OmsConfigHostHelpers import write_omsconfig_host_telemetry, write_omsconfig_host_switch_event, write_omsconfig_host_log, stop_old_host_instances from time import sleep +import sys pathToCurrentScript = realpath(__file__) pathToCommonScriptsFolder = dirname(pathToCurrentScript) +DSCLogPath = join(pathToCommonScriptsFolder, 'nxDSCLog.py') +nxDSCLog = load_source('nxDSCLog', DSCLogPath) +LG = nxDSCLog.DSCLog + helperLibPath = join(pathToCommonScriptsFolder, 'helperlib.py') helperlib = load_source('helperlib', helperLibPath) @@ -115,4 +120,6 @@ def run_perform_required_configuration_checks(): print(stdout) if __name__ == "__main__": + LG().Log("DEBUG", "Starting Main method for " + argv[0] + " runing with python " + str(sys.version_info.major)) main() + LG().Log("DEBUG", "End of Main method for " + argv[0] + " runing with python " + str(sys.version_info.major)) diff --git a/LCM/scripts/python3/RegenerateInitFiles.py b/LCM/scripts/python3/RegenerateInitFiles.py index dbd8f7306..13d2d5b97 100644 --- a/LCM/scripts/python3/RegenerateInitFiles.py +++ b/LCM/scripts/python3/RegenerateInitFiles.py @@ -24,5 +24,4 @@ py_files_basename.append(current_basename[:-3]) out_init = out_init + str(py_files_basename) - open(current_dir + "/__init__.py", "w").write(out_init) - + open(current_dir + "/__init__.py", "w").write(out_init) \ No newline at end of file diff --git a/LCM/scripts/python3/Register.py b/LCM/scripts/python3/Register.py index 0fa846222..afd9d8bc8 100755 --- a/LCM/scripts/python3/Register.py +++ b/LCM/scripts/python3/Register.py @@ -4,6 +4,20 @@ import os.path import tempfile import shutil +from sys import argv +from os.path import dirname, join, realpath +import warnings +with warnings.catch_warnings(): + warnings.filterwarnings("ignore",category=DeprecationWarning) + from imp import load_source + +pathToCurrentScript = realpath(__file__) +pathToCommonScriptsFolder = dirname(pathToCurrentScript) + +DSCLogPath = join(pathToCommonScriptsFolder, 'nxDSCLog.py') +nxDSCLog = load_source('nxDSCLog', DSCLogPath) +LG = nxDSCLog.DSCLog + def usage(): print("""Usage: Register.py [OPTIONS] @@ -18,6 +32,8 @@ def usage(): --Help """) +LG().Log("DEBUG", "Starting script logic for " + argv[0]+ " runing with python " + str(sys.version_info.major)) + # Apply a DSC meta configuration based on a template Variables = dict() @@ -214,6 +230,7 @@ def usage(): os.system("openssl req -subj '/CN=DSC-OaaS' -new -newkey rsa:2048 -days 365 -nodes -x509 -keyout " + OAAS_KEYPATH + "_old -out " + OAAS_CERTPATH + " && openssl rsa -in " + OAAS_KEYPATH + "_old -out " + OAAS_KEYPATH + " && rm -f " + OAAS_KEYPATH + "_old"); os.system("openssl x509 -noout -in " + OAAS_CERTPATH + " -fingerprint | sed 's/^.*=//' > " + OAAS_THUMBPRINT); -os.system("/SetDscLocalConfigurationManager.py -configurationmof " + meta_path) +os.system("/python3/SetDscLocalConfigurationManager.py -configurationmof " + meta_path) shutil.rmtree(tempdir) +LG().Log("DEBUG", "End of script logic for " + argv[0] + " runing with python " + str(sys.version_info.major)) diff --git a/LCM/scripts/python3/RemoveModule.py b/LCM/scripts/python3/RemoveModule.py index 6152cadca..9678ac0d6 100755 --- a/LCM/scripts/python3/RemoveModule.py +++ b/LCM/scripts/python3/RemoveModule.py @@ -8,10 +8,17 @@ with warnings.catch_warnings(): warnings.filterwarnings("ignore",category=DeprecationWarning) import imp -from os.path import dirname, join, realpath + from imp import load_source +from os.path import dirname, join, realpath +from sys import argv pathToCurrentScript = realpath(__file__) pathToCommonScriptsFolder = dirname(pathToCurrentScript) + +DSCLogPath = join(pathToCommonScriptsFolder, 'nxDSCLog.py') +nxDSCLog = load_source('nxDSCLog', DSCLogPath) +LG = nxDSCLog.DSCLog + helperLibPath = join(pathToCommonScriptsFolder, 'helperlib.py') helperlib = imp.load_source('helperlib', helperLibPath) fullPathDSCLogger = os.path.join(pathToCommonScriptsFolder, 'nxDSCLog.py') @@ -203,4 +210,7 @@ def main(args): shutil.rmtree(modulePath) if __name__ == "__main__": + LG().Log("DEBUG", "Starting Main method for " + argv[0] + " runing with python " + str(sys.version_info.major)) main(sys.argv[1:]) + LG().Log("DEBUG", "End of Main method for " + argv[0] + " runing with python " + str(sys.version_info.major)) + diff --git a/LCM/scripts/python3/RestoreConfiguration.py b/LCM/scripts/python3/RestoreConfiguration.py index 3bad6a117..8450b09db 100755 --- a/LCM/scripts/python3/RestoreConfiguration.py +++ b/LCM/scripts/python3/RestoreConfiguration.py @@ -10,21 +10,27 @@ from fcntl import flock, LOCK_EX, LOCK_UN, LOCK_NB from OmsConfigHostHelpers import write_omsconfig_host_telemetry, write_omsconfig_host_switch_event, write_omsconfig_host_log, stop_old_host_instances from time import sleep +from sys import argv pathToCurrentScript = realpath(__file__) pathToCommonScriptsFolder = dirname(pathToCurrentScript) +DSCLogPath = join(pathToCommonScriptsFolder, 'nxDSCLog.py') +nxDSCLog = load_source('nxDSCLog', DSCLogPath) +LG = nxDSCLog.DSCLog + helperLibPath = join(pathToCommonScriptsFolder, 'helperlib.py') helperlib = load_source('helperlib', helperLibPath) -omi_bindir = "" -omicli_path = omi_bindir + "/omicli" +omicli_path = join(helperlib.CONFIG_BINDIR, 'omicli') dsc_host_base_path = helperlib.DSC_HOST_BASE_PATH dsc_host_path = join(dsc_host_base_path, 'bin/dsc_host') dsc_host_output_path = join(dsc_host_base_path, 'output') dsc_host_lock_path = join(dsc_host_base_path, 'dsc_host_lock') dsc_host_switch_path = join(dsc_host_base_path, 'dsc_host_ready') +LG().Log("DEBUG", "Starting script logic for " + argv[0]+ " runing with python " + str(sys.version_info.major)) + if ("omsconfig" in helperlib.DSC_SCRIPT_PATH): write_omsconfig_host_switch_event(pathToCurrentScript, isfile(dsc_host_switch_path)) @@ -91,3 +97,5 @@ stderr = stderr.decode() if isinstance(stderr, bytes) else stderr print(stdout) print(stderr) + +LG().Log("DEBUG", "End of script logic for " + argv[0] + " runing with python " + str(sys.version_info.major)) \ No newline at end of file diff --git a/LCM/scripts/python3/SetDscLocalConfigurationManager.py b/LCM/scripts/python3/SetDscLocalConfigurationManager.py index ef9f44220..309439101 100755 --- a/LCM/scripts/python3/SetDscLocalConfigurationManager.py +++ b/LCM/scripts/python3/SetDscLocalConfigurationManager.py @@ -1,5 +1,6 @@ #!/usr/bin/env python3 import warnings +import sys with warnings.catch_warnings(): warnings.filterwarnings("ignore",category=DeprecationWarning) from imp import load_source @@ -15,6 +16,10 @@ pathToCurrentScript = realpath(__file__) pathToCommonScriptsFolder = dirname(pathToCurrentScript) +DSCLogPath = join(pathToCommonScriptsFolder, 'nxDSCLog.py') +nxDSCLog = load_source('nxDSCLog', DSCLogPath) +LG = nxDSCLog.DSCLog + helperLibPath = join(pathToCommonScriptsFolder, 'helperlib.py') helperlib = load_source('helperlib', helperLibPath) @@ -159,4 +164,6 @@ def apply_meta_config(args): fileHandle.close() if __name__ == "__main__": + LG().Log("DEBUG", "Starting Main method for " + argv[0] + " runing with python " + str(sys.version_info.major)) main(argv) + LG().Log("DEBUG", "End of Main method for " + argv[0] + " runing with python " + str(sys.version_info.major)) \ No newline at end of file diff --git a/LCM/scripts/python3/StartDscConfiguration.py b/LCM/scripts/python3/StartDscConfiguration.py index 31b91b097..fc3003dc8 100755 --- a/LCM/scripts/python3/StartDscConfiguration.py +++ b/LCM/scripts/python3/StartDscConfiguration.py @@ -1,6 +1,7 @@ #!/usr/bin/env python3 # Standard library imports +import sys from subprocess import Popen, PIPE from sys import argv import warnings @@ -14,10 +15,13 @@ import subprocess import codecs - pathToCurrentScript = realpath(__file__) pathToCommonScriptsFolder = dirname(pathToCurrentScript) +DSCLogPath = join(pathToCommonScriptsFolder, 'nxDSCLog.py') +nxDSCLog = load_source('nxDSCLog', DSCLogPath) +LG = nxDSCLog.DSCLog + helperLibPath = join(pathToCommonScriptsFolder, 'helperlib.py') helperlib = load_source('helperlib', helperLibPath) @@ -121,8 +125,7 @@ def main(argv): configurationData.append(str(ord(char))) # # OMI CLI location - omiBinDir = "" - omiCliPath = omiBinDir + "/omicli" + omicli_path = join(helperlib.CONFIG_BINDIR, 'omicli') dsc_host_base_path = helperlib.DSC_HOST_BASE_PATH dsc_host_path = join(dsc_host_base_path, 'bin/dsc_host') dsc_host_output_path = join(dsc_host_base_path, 'output') @@ -148,7 +151,7 @@ def main(argv): if parsedArguments.force: host_parameters.append("force") else: - host_parameters.append(omiCliPath) + host_parameters.append(omicli_path) host_parameters.append("iv") host_parameters.append("") host_parameters.append("{") @@ -210,7 +213,7 @@ def main(argv): # Close dsc host lock file handle dschostlock_filehandle.close() else: - p = subprocess.Popen(parameters, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + p = subprocess.Popen(host_parameters, stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout, stderr = p.communicate() stdout = stdout.decode() if isinstance(stdout, bytes) else stdout @@ -218,4 +221,6 @@ def main(argv): print(stdout) print(stderr) +LG().Log("DEBUG", "Starting Main method for " + argv[0] + " runing with python " + str(sys.version_info.major)) main(argv[1:]) +LG().Log("DEBUG", "End of Main method for " + argv[0] + " runing with python " + str(sys.version_info.major)) diff --git a/LCM/scripts/python3/TestDscConfiguration.py b/LCM/scripts/python3/TestDscConfiguration.py index 3e22f5bad..dde9aec6f 100755 --- a/LCM/scripts/python3/TestDscConfiguration.py +++ b/LCM/scripts/python3/TestDscConfiguration.py @@ -10,21 +10,27 @@ from os.path import dirname, isfile, join, realpath from time import sleep from fcntl import flock, LOCK_EX, LOCK_UN, LOCK_NB +from sys import argv pathToCurrentScript = realpath(__file__) pathToCommonScriptsFolder = dirname(pathToCurrentScript) +DSCLogPath = join(pathToCommonScriptsFolder, 'nxDSCLog.py') +nxDSCLog = load_source('nxDSCLog', DSCLogPath) +LG = nxDSCLog.DSCLog + helperLibPath = join(pathToCommonScriptsFolder, 'helperlib.py') helperlib = load_source('helperlib', helperLibPath) -omi_bindir = "" -omicli_path = omi_bindir + "/omicli" +omicli_path = join(helperlib.CONFIG_BINDIR, 'omicli') dsc_host_base_path = helperlib.DSC_HOST_BASE_PATH dsc_host_path = join(dsc_host_base_path, 'bin/dsc_host') dsc_host_output_path = join(dsc_host_base_path, 'output') dsc_host_lock_path = join(dsc_host_base_path, 'dsc_host_lock') dsc_host_switch_path = join(dsc_host_base_path, 'dsc_host_ready') +LG().Log("DEBUG", "Starting script logic for " + argv[0]+ " runing with python " + str(sys.version_info.major)) + if ("omsconfig" in helperlib.DSC_SCRIPT_PATH): write_omsconfig_host_switch_event(pathToCurrentScript, isfile(dsc_host_switch_path)) @@ -103,4 +109,4 @@ print(stdout) print(stderr) - +LG().Log("DEBUG", "End of script logic for " + argv[0] + " runing with python " + str(sys.version_info.major)) diff --git a/Providers/Scripts/3.x/Scripts/nxArchive.py b/Providers/Scripts/3.x/Scripts/nxArchive.py index 8a8777e05..a468eb779 100644 --- a/Providers/Scripts/3.x/Scripts/nxArchive.py +++ b/Providers/Scripts/3.x/Scripts/nxArchive.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # =================================== # Copyright (c) Microsoft Corporation. All rights reserved. # See license.txt for license information. diff --git a/Providers/Scripts/3.x/Scripts/nxEnvironment.py b/Providers/Scripts/3.x/Scripts/nxEnvironment.py index 631ee7688..e1343de86 100644 --- a/Providers/Scripts/3.x/Scripts/nxEnvironment.py +++ b/Providers/Scripts/3.x/Scripts/nxEnvironment.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # =================================== # Copyright (c) Microsoft Corporation. All rights reserved. # See license.txt for license information. diff --git a/Providers/Scripts/3.x/Scripts/nxFile.py b/Providers/Scripts/3.x/Scripts/nxFile.py index 3ff577263..9734994f0 100755 --- a/Providers/Scripts/3.x/Scripts/nxFile.py +++ b/Providers/Scripts/3.x/Scripts/nxFile.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # ==================================== # Copyright (c) Microsoft Corporation. All rights reserved. # See license.txt for license information. @@ -94,6 +94,7 @@ def Get_Marshall(DestinationPath, SourcePath, Ensure, Type, Force, Contents, Che Ensure = protocol.MI_String(Ensure) Type = protocol.MI_String(Type) Force = protocol.MI_Boolean(Force) + Contents = Contents.decode("ISO-8859-1") if isinstance(Contents, bytes) else Contents Contents = protocol.MI_String(Contents) Checksum = protocol.MI_String(Checksum) Recurse = protocol.MI_Boolean(Recurse) @@ -431,16 +432,19 @@ def CompareFiles(DestinationPath, SourcePath, Checksum): src_hash.update(src_block) dest_hash.update(dest_block) if src_hash.hexdigest() != dest_hash.hexdigest(): + LG().Log('ERROR', "Exception comparing destination file using hexdigest : " + DestinationPath) return -1 if src_hash.hexdigest() == dest_hash.hexdigest(): return 0 elif Checksum == "ctime": if stat_src.st_ctime != stat_dest.st_ctime: + LG().Log('ERROR', "Exception comparing destination file using st_ctime : " + DestinationPath) return -1 else: return 0 elif Checksum == "mtime": if stat_src.st_mtime != stat_dest.st_mtime: + LG().Log('ERROR', "Exception comparing destination file using st_mtime : " + DestinationPath) return -1 else: return 0 @@ -949,7 +953,7 @@ def TestFile(DestinationPath, SourcePath, fc): elif fc.Contents: dest_file, error = ReadFile(DestinationPath) - if fc.Contents.encode('utf8') != dest_file: + if fc.Contents != dest_file: return False return True diff --git a/Providers/Scripts/3.x/Scripts/nxFileLine.py b/Providers/Scripts/3.x/Scripts/nxFileLine.py index b1c083dad..e8bd5f0f3 100644 --- a/Providers/Scripts/3.x/Scripts/nxFileLine.py +++ b/Providers/Scripts/3.x/Scripts/nxFileLine.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # =================================== # Copyright (c) Microsoft Corporation. All rights reserved. # See license.txt for license information. diff --git a/Providers/Scripts/3.x/Scripts/nxGroup.py b/Providers/Scripts/3.x/Scripts/nxGroup.py index b91a313e5..e76712d1a 100644 --- a/Providers/Scripts/3.x/Scripts/nxGroup.py +++ b/Providers/Scripts/3.x/Scripts/nxGroup.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # =================================== # Copyright (c) Microsoft Corporation. All rights reserved. # See license.txt for license information. diff --git a/Providers/Scripts/3.x/Scripts/nxScript.py b/Providers/Scripts/3.x/Scripts/nxScript.py index f9263cc88..f95683370 100644 --- a/Providers/Scripts/3.x/Scripts/nxScript.py +++ b/Providers/Scripts/3.x/Scripts/nxScript.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # =================================== # Copyright (c) Microsoft Corporation. All rights reserved. # See license.txt for license information. diff --git a/Providers/Scripts/3.x/Scripts/nxSshAuthorizedKeys.py b/Providers/Scripts/3.x/Scripts/nxSshAuthorizedKeys.py index b373faa48..6e121ba22 100644 --- a/Providers/Scripts/3.x/Scripts/nxSshAuthorizedKeys.py +++ b/Providers/Scripts/3.x/Scripts/nxSshAuthorizedKeys.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # =================================== # Copyright (c) Microsoft Corporation. All rights reserved. # See license.txt for license information. diff --git a/Providers/Scripts/3.x/Scripts/nxUser.py b/Providers/Scripts/3.x/Scripts/nxUser.py index dc41c35b8..365259d26 100644 --- a/Providers/Scripts/3.x/Scripts/nxUser.py +++ b/Providers/Scripts/3.x/Scripts/nxUser.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # =================================== # Copyright (c) Microsoft Corporation. All rights reserved. # See license.txt for license information. diff --git a/Providers/Scripts/nxDSCLog.py b/Providers/Scripts/nxDSCLog.py index fa14e6e1b..435da5274 100644 --- a/Providers/Scripts/nxDSCLog.py +++ b/Providers/Scripts/nxDSCLog.py @@ -50,7 +50,7 @@ def Log(self, log_level, message): last_frame = inspect.currentframe().f_back place = last_frame.f_globals['__file__'] + \ '('+str(last_frame.f_lineno)+')' - if message is None or len(message) is 0: + if message == None or len(message) == 0: return if log_level is None: log_level = self.current_level diff --git a/installbuilder/Makefile b/installbuilder/Makefile index 45c2f3960..c71d10e44 100644 --- a/installbuilder/Makefile +++ b/installbuilder/Makefile @@ -14,7 +14,7 @@ ifeq ($(UNAME_P),x86_64) else PF_ARCH := x86 endif -CONFIG_VERSION := 1.1.1 +CONFIG_VERSION := $(DSC_BUILDVERSION_MAJOR).$(DSC_BUILDVERSION_MINOR).$(DSC_BUILDVERSION_PATCH) ifeq ($(BUILD_OMS_VAL),1) SHORT_NAME=omsconfig diff --git a/installbuilder/datafiles/Base_DSC.data b/installbuilder/datafiles/Base_DSC.data index 48aff8f06..44787c6c7 100755 --- a/installbuilder/datafiles/Base_DSC.data +++ b/installbuilder/datafiles/Base_DSC.data @@ -426,6 +426,17 @@ if [ -d "/etc/opt/omi/conf/omsconfig" ]; then chown -R omsagent:omiusers /etc/op #else +# pythonVersion check must be repeated for each section +if [ ! "$(python2 --version 2>&1 | grep 'not found')" ]; then + echo "Using python2" + pythonVersion="python2" +elif [ ! "$(python3 --version 2>&1 | grep 'not found')" ]; then + echo "Using python3" + pythonVersion="python3" +else + echo "Python not found." +fi + # Set up built-in resource module for DIY DSC if [ "$pythonVersion" = "python3" ]; then echo "Running python3" @@ -502,6 +513,17 @@ mv /etc/crontabtmp /etc/crontab #if BUILD_OMS == 1 +# pythonVersion check must be repeated for each section +if [ ! "$(python2 --version 2>&1 | grep 'not found')" ]; then + echo "Using python2" + pythonVersion="python2" +elif [ ! "$(python3 --version 2>&1 | grep 'not found')" ]; then + echo "Using python3" + pythonVersion="python3" +else + echo "Python not found" +fi + # If omsadmin.conf exists, let's apply the metaconfig if [ -f /etc/opt/microsoft/omsagent/conf/omsadmin.conf ]; then if [ "$pythonVersion" = "python3" ]; then