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

Commit bc0b029

Browse files
author
Jinesh Shah
authored
Fixed issues with python 2.6 (#799)
* Fixed issues with python 2.6 sys.version_info.major doesn't work for python 2.6 but works for 2.7 So decided to log sys.version_info which works for all python versions * Fixed case where comparing stdout bytes to a string (#800)
1 parent f0e0a53 commit bc0b029

19 files changed

+51
-44
lines changed

LCM/scripts/GetDscConfiguration.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
dsc_host_lock_path = join(dsc_host_base_path, 'dsc_host_lock')
3232
dsc_host_switch_path = join(dsc_host_base_path, 'dsc_host_ready')
3333

34-
LG().Log("DEBUG", "Starting script logic for " + argv[0]+ " runing with python " + str(sys.version_info.major))
34+
LG().Log("DEBUG", "Starting script logic for " + argv[0]+ " runing with python " + str(sys.version_info))
3535

3636
if ("omsconfig" in helperlib.DSC_SCRIPT_PATH):
3737
write_omsconfig_host_switch_event(pathToCurrentScript, isfile(dsc_host_switch_path))
@@ -100,5 +100,5 @@
100100
print(stdout)
101101
print(stderr)
102102

103-
LG().Log("DEBUG", "End of script logic for " + argv[0] + " runing with python " + str(sys.version_info.major))
103+
LG().Log("DEBUG", "End of script logic for " + argv[0] + " runing with python " + str(sys.version_info))
104104

LCM/scripts/GetDscLocalConfigurationManager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
dsc_host_lock_path = join(dsc_host_base_path, 'dsc_host_lock')
3131
dsc_host_switch_path = join(dsc_host_base_path, 'dsc_host_ready')
3232

33-
LG().Log("DEBUG", "Starting script logic for " + argv[0]+ " runing with python " + str(sys.version_info.major))
33+
LG().Log("DEBUG", "Starting script logic for " + argv[0]+ " runing with python " + str(sys.version_info))
3434

3535
if ("omsconfig" in helperlib.DSC_SCRIPT_PATH):
3636
write_omsconfig_host_switch_event(pathToCurrentScript, isfile(dsc_host_switch_path))
@@ -99,5 +99,5 @@
9999
print(stdout)
100100
print(stderr)
101101

102-
LG().Log("DEBUG", "End of script logic for " + argv[0] + " runing with python " + str(sys.version_info.major))
102+
LG().Log("DEBUG", "End of script logic for " + argv[0] + " runing with python " + str(sys.version_info))
103103

LCM/scripts/PerformRequiredConfigurationChecks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,6 @@ def run_perform_required_configuration_checks():
116116
print(stdout)
117117

118118
if __name__ == "__main__":
119-
LG().Log("DEBUG", "Starting Main method for " + argv[0] + " runing with python " + str(sys.version_info.major))
119+
LG().Log("DEBUG", "Starting Main method for " + argv[0] + " runing with python " + str(sys.version_info))
120120
main()
121-
LG().Log("DEBUG", "End of Main method for " + argv[0] + " runing with python " + str(sys.version_info.major))
121+
LG().Log("DEBUG", "End of Main method for " + argv[0] + " runing with python " + str(sys.version_info))

LCM/scripts/Register.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def usage():
2929
nxDSCLog = load_source('nxDSCLog', DSCLogPath)
3030
LG = nxDSCLog.DSCLog
3131

32-
LG().Log("DEBUG", "Starting script logic for " + argv[0]+ " runing with python " + str(sys.version_info.major))
32+
LG().Log("DEBUG", "Starting script logic for " + argv[0]+ " runing with python " + str(sys.version_info))
3333

3434
# Apply a DSC meta configuration based on a template
3535
Variables = dict()
@@ -231,4 +231,4 @@ def usage():
231231

232232
shutil.rmtree(tempdir)
233233

234-
LG().Log("DEBUG", "End of script logic for " + argv[0] + " runing with python " + str(sys.version_info.major))
234+
LG().Log("DEBUG", "End of script logic for " + argv[0] + " runing with python " + str(sys.version_info))

LCM/scripts/RemoveModule.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,6 @@ def main(args):
203203
shutil.rmtree(modulePath)
204204

205205
if __name__ == "__main__":
206-
LG().Log("DEBUG", "Starting Main method for " + argv[0] + " runing with python " + str(sys.version_info.major))
206+
LG().Log("DEBUG", "Starting Main method for " + argv[0] + " runing with python " + str(sys.version_info))
207207
main(sys.argv[1:])
208-
LG().Log("DEBUG", "End of Main method for " + argv[0] + " runing with python " + str(sys.version_info.major))
208+
LG().Log("DEBUG", "End of Main method for " + argv[0] + " runing with python " + str(sys.version_info))

LCM/scripts/RestoreConfiguration.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
dsc_host_lock_path = join(dsc_host_base_path, 'dsc_host_lock')
2828
dsc_host_switch_path = join(dsc_host_base_path, 'dsc_host_ready')
2929

30-
LG().Log("DEBUG", "Starting script logic for " + argv[0]+ " runing with python " + str(sys.version_info.major))
30+
LG().Log("DEBUG", "Starting script logic for " + argv[0]+ " runing with python " + str(sys.version_info))
3131

3232
if ("omsconfig" in helperlib.DSC_SCRIPT_PATH):
3333
write_omsconfig_host_switch_event(pathToCurrentScript, isfile(dsc_host_switch_path))
@@ -94,4 +94,4 @@
9494
print(stdout)
9595
print(stderr)
9696

97-
LG().Log("DEBUG", "End of script logic for " + argv[0] + " runing with python " + str(sys.version_info.major))
97+
LG().Log("DEBUG", "End of script logic for " + argv[0] + " runing with python " + str(sys.version_info))

LCM/scripts/SetDscLocalConfigurationManager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,6 @@ def signal_handler(signalNumber, frame):
176176
if __name__ == "__main__":
177177
# register the SIGTERM handler
178178
signal.signal(signal.SIGTERM, signal_handler)
179-
LG().Log("DEBUG", "Starting Main method for " + argv[0] + " runing with python " + str(sys.version_info.major))
179+
LG().Log("DEBUG", "Starting Main method for " + argv[0] + " runing with python " + str(sys.version_info))
180180
main(argv)
181-
LG().Log("DEBUG", "End of Main method for " + argv[0] + " runing with python " + str(sys.version_info.major))
181+
LG().Log("DEBUG", "End of Main method for " + argv[0] + " runing with python " + str(sys.version_info))

LCM/scripts/StartDscConfiguration.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,6 @@ def main(argv):
213213
print(stdout)
214214
print(stderr)
215215

216-
LG().Log("DEBUG", "Starting Main method for " + argv[0] + " runing with python " + str(sys.version_info.major))
216+
LG().Log("DEBUG", "Starting Main method for " + argv[0] + " runing with python " + str(sys.version_info))
217217
main(argv[1:])
218-
LG().Log("DEBUG", "End of Main method for " + argv[0] + " runing with python " + str(sys.version_info.major))
218+
LG().Log("DEBUG", "End of Main method for " + argv[0] + " runing with python " + str(sys.version_info))

LCM/scripts/TestDscConfiguration.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
dsc_host_lock_path = join(dsc_host_base_path, 'dsc_host_lock')
2626
dsc_host_switch_path = join(dsc_host_base_path, 'dsc_host_ready')
2727

28-
LG().Log("DEBUG", "Starting script logic for " + argv[0]+ " runing with python " + str(sys.version_info.major))
28+
LG().Log("DEBUG", "Starting script logic for " + argv[0]+ " runing with python " + str(sys.version_info))
2929

3030
if ("omsconfig" in helperlib.DSC_SCRIPT_PATH):
3131
write_omsconfig_host_switch_event(pathToCurrentScript, isfile(dsc_host_switch_path))
@@ -102,4 +102,4 @@
102102
print(stdout)
103103
print(stderr)
104104

105-
LG().Log("DEBUG", "End of script logic for " + argv[0] + " runing with python " + str(sys.version_info.major))
105+
LG().Log("DEBUG", "End of script logic for " + argv[0] + " runing with python " + str(sys.version_info))

LCM/scripts/python3/GetDscConfiguration.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
dsc_host_lock_path = join(dsc_host_base_path, 'dsc_host_lock')
3434
dsc_host_switch_path = join(dsc_host_base_path, 'dsc_host_ready')
3535

36-
LG().Log("DEBUG", "Starting script logic for " + argv[0]+ " runing with python " + str(sys.version_info.major))
36+
LG().Log("DEBUG", "Starting script logic for " + argv[0]+ " runing with python " + str(sys.version_info))
3737

3838
if ("omsconfig" in helperlib.DSC_SCRIPT_PATH):
3939
write_omsconfig_host_switch_event(pathToCurrentScript, isfile(dsc_host_switch_path))
@@ -106,4 +106,4 @@
106106
print(stdout)
107107
print(stderr)
108108

109-
LG().Log("DEBUG", "End of script logic for " + argv[0] + " runing with python " + str(sys.version_info.major))
109+
LG().Log("DEBUG", "End of script logic for " + argv[0] + " runing with python " + str(sys.version_info))

LCM/scripts/python3/GetDscLocalConfigurationManager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
dsc_host_lock_path = join(dsc_host_base_path, 'dsc_host_lock')
3434
dsc_host_switch_path = join(dsc_host_base_path, 'dsc_host_ready')
3535

36-
LG().Log("DEBUG", "Starting script logic for " + argv[0]+ " runing with python " + str(sys.version_info.major))
36+
LG().Log("DEBUG", "Starting script logic for " + argv[0]+ " runing with python " + str(sys.version_info))
3737

3838
if ("omsconfig" in helperlib.DSC_SCRIPT_PATH):
3939
write_omsconfig_host_switch_event(pathToCurrentScript, isfile(dsc_host_switch_path))
@@ -105,4 +105,4 @@
105105
print(stdout)
106106
print(stderr)
107107

108-
LG().Log("DEBUG", "End of script logic for " + argv[0] + " runing with python " + str(sys.version_info.major))
108+
LG().Log("DEBUG", "End of script logic for " + argv[0] + " runing with python " + str(sys.version_info))

LCM/scripts/python3/PerformRequiredConfigurationChecks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,6 @@ def run_perform_required_configuration_checks():
120120
print(stdout)
121121

122122
if __name__ == "__main__":
123-
LG().Log("DEBUG", "Starting Main method for " + argv[0] + " runing with python " + str(sys.version_info.major))
123+
LG().Log("DEBUG", "Starting Main method for " + argv[0] + " runing with python " + str(sys.version_info))
124124
main()
125-
LG().Log("DEBUG", "End of Main method for " + argv[0] + " runing with python " + str(sys.version_info.major))
125+
LG().Log("DEBUG", "End of Main method for " + argv[0] + " runing with python " + str(sys.version_info))

LCM/scripts/python3/Register.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def usage():
3232
--Help
3333
""")
3434

35-
LG().Log("DEBUG", "Starting script logic for " + argv[0]+ " runing with python " + str(sys.version_info.major))
35+
LG().Log("DEBUG", "Starting script logic for " + argv[0]+ " runing with python " + str(sys.version_info))
3636

3737
# Apply a DSC meta configuration based on a template
3838
Variables = dict()
@@ -233,4 +233,4 @@ def usage():
233233
os.system("<DSC_SCRIPT_PATH>/python3/SetDscLocalConfigurationManager.py -configurationmof " + meta_path)
234234

235235
shutil.rmtree(tempdir)
236-
LG().Log("DEBUG", "End of script logic for " + argv[0] + " runing with python " + str(sys.version_info.major))
236+
LG().Log("DEBUG", "End of script logic for " + argv[0] + " runing with python " + str(sys.version_info))

LCM/scripts/python3/RemoveModule.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ def main(args):
210210
shutil.rmtree(modulePath)
211211

212212
if __name__ == "__main__":
213-
LG().Log("DEBUG", "Starting Main method for " + argv[0] + " runing with python " + str(sys.version_info.major))
213+
LG().Log("DEBUG", "Starting Main method for " + argv[0] + " runing with python " + str(sys.version_info))
214214
main(sys.argv[1:])
215-
LG().Log("DEBUG", "End of Main method for " + argv[0] + " runing with python " + str(sys.version_info.major))
215+
LG().Log("DEBUG", "End of Main method for " + argv[0] + " runing with python " + str(sys.version_info))
216216

LCM/scripts/python3/RestoreConfiguration.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
dsc_host_lock_path = join(dsc_host_base_path, 'dsc_host_lock')
3030
dsc_host_switch_path = join(dsc_host_base_path, 'dsc_host_ready')
3131

32-
LG().Log("DEBUG", "Starting script logic for " + argv[0]+ " runing with python " + str(sys.version_info.major))
32+
LG().Log("DEBUG", "Starting script logic for " + argv[0]+ " runing with python " + str(sys.version_info))
3333

3434
if ("omsconfig" in helperlib.DSC_SCRIPT_PATH):
3535
write_omsconfig_host_switch_event(pathToCurrentScript, isfile(dsc_host_switch_path))
@@ -98,4 +98,4 @@
9898
print(stdout)
9999
print(stderr)
100100

101-
LG().Log("DEBUG", "End of script logic for " + argv[0] + " runing with python " + str(sys.version_info.major))
101+
LG().Log("DEBUG", "End of script logic for " + argv[0] + " runing with python " + str(sys.version_info))

LCM/scripts/python3/SetDscLocalConfigurationManager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,6 @@ def apply_meta_config(args):
164164
fileHandle.close()
165165

166166
if __name__ == "__main__":
167-
LG().Log("DEBUG", "Starting Main method for " + argv[0] + " runing with python " + str(sys.version_info.major))
167+
LG().Log("DEBUG", "Starting Main method for " + argv[0] + " runing with python " + str(sys.version_info))
168168
main(argv)
169-
LG().Log("DEBUG", "End of Main method for " + argv[0] + " runing with python " + str(sys.version_info.major))
169+
LG().Log("DEBUG", "End of Main method for " + argv[0] + " runing with python " + str(sys.version_info))

LCM/scripts/python3/StartDscConfiguration.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,6 @@ def main(argv):
221221
print(stdout)
222222
print(stderr)
223223

224-
LG().Log("DEBUG", "Starting Main method for " + argv[0] + " runing with python " + str(sys.version_info.major))
224+
LG().Log("DEBUG", "Starting Main method for " + argv[0] + " runing with python " + str(sys.version_info))
225225
main(argv[1:])
226-
LG().Log("DEBUG", "End of Main method for " + argv[0] + " runing with python " + str(sys.version_info.major))
226+
LG().Log("DEBUG", "End of Main method for " + argv[0] + " runing with python " + str(sys.version_info))

LCM/scripts/python3/TestDscConfiguration.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
dsc_host_lock_path = join(dsc_host_base_path, 'dsc_host_lock')
3030
dsc_host_switch_path = join(dsc_host_base_path, 'dsc_host_ready')
3131

32-
LG().Log("DEBUG", "Starting script logic for " + argv[0]+ " runing with python " + str(sys.version_info.major))
32+
LG().Log("DEBUG", "Starting script logic for " + argv[0]+ " runing with python " + str(sys.version_info))
3333

3434
if ("omsconfig" in helperlib.DSC_SCRIPT_PATH):
3535
write_omsconfig_host_switch_event(pathToCurrentScript, isfile(dsc_host_switch_path))
@@ -109,4 +109,4 @@
109109
print(stdout)
110110
print(stderr)
111111

112-
LG().Log("DEBUG", "End of script logic for " + argv[0] + " runing with python " + str(sys.version_info.major))
112+
LG().Log("DEBUG", "End of script logic for " + argv[0] + " runing with python " + str(sys.version_info))

Providers/Scripts/3.x/Scripts/nxService.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,8 @@ def GetSystemdState(sc):
553553
(process_stdout, process_stderr, retval) = Process(
554554
[systemctl_path, "status", sc.Name])
555555
if retval is 0:
556-
if '(running)' in process_stdout:
556+
process_stdout_str = process_stdout.decode() if isinstance(process_stdout, bytes) else process_stdout
557+
if '(running)' in process_stdout_str:
557558
return "running"
558559
return "stopped"
559560

@@ -602,7 +603,8 @@ def GetUpstartState(sc):
602603
" failed: " + process_stderr)
603604
return ""
604605

605-
if (sc.Name + " start") in process_stdout:
606+
process_stdout_str = process_stdout.decode() if isinstance(process_stdout, bytes) else process_stdout
607+
if (sc.Name + " start") in process_stdout_str:
606608
return "running"
607609
else:
608610
return "stopped"
@@ -678,7 +680,8 @@ def GetUpstartEnabled(sc):
678680
(process_stdout, process_stderr, retval) = Process(
679681
['chkconfig', sc.Name, '']) # try init style
680682
if retval is 0:
681-
if 'off' not in process_stdout:
683+
process_stdout_str = process_stdout.decode() if isinstance(process_stdout, bytes) else process_stdout
684+
if 'off' not in process_stdout_str:
682685
return True
683686
return False
684687
if start_on_exists and start_on_is_enabled:
@@ -855,7 +858,8 @@ def ServiceExistsInSystemd(sc):
855858
(process_stdout, process_stderr, retval) = Process(
856859
[systemctl_path, "status", sc.Name])
857860
if retval is not 0:
858-
if "Loaded: loaded" in process_stdout:
861+
process_stdout_str = process_stdout.decode() if isinstance(process_stdout, bytes) else process_stdout
862+
if "Loaded: loaded" in process_stdout_str:
859863
return True
860864
else:
861865
return False
@@ -926,13 +930,14 @@ def ModifySystemdService(sc):
926930
(process_stdout, process_stderr, retval) = Process(
927931
[systemctl_path, "status", sc.Name + '.service'])
928932
# retval may be non zero even if service exists for 'status'.
929-
if 'No such file or directory' in process_stdout:
933+
process_stdout_str = process_stdout.decode() if isinstance(process_stdout, bytes) else process_stdout
934+
if 'No such file or directory' in process_stdout_str:
930935
Print("Error: " + systemctl_path + " status " + sc.Name +
931936
" failed: " + process_stderr, file=sys.stderr)
932937
LG().Log('ERROR', "Error: " + systemctl_path +
933938
" status " + sc.Name + " failed: " + process_stderr)
934939
return [-1]
935-
if 'Active: active' in process_stdout:
940+
if 'Active: active' in process_stdout_str:
936941
Print("Running", file=sys.stderr)
937942
LG().Log('INFO', "Running")
938943
if sc.State and sc.State != "running":
@@ -1132,7 +1137,8 @@ def ModifyInitService(sc):
11321137
LG().Log('ERROR', "Error: " + check_enabled_program +
11331138
" -f " + sc.Name + " defaults failed: " + process_stderr)
11341139
return [-1]
1135-
if 'already exist' in process_stdout: # we need to remove them first
1140+
process_stdout_str = process_stdout.decode() if isinstance(process_stdout, bytes) else process_stdout
1141+
if 'already exist' in process_stdout_str: # we need to remove them first
11361142
(process_stdout, process_stderr, retval) = Process(
11371143
[check_enabled_program, "-f", sc.Name, "remove"])
11381144
if retval is not 0:
@@ -1190,7 +1196,8 @@ def ModifyInitService(sc):
11901196
LG().Log('ERROR', "Error: " + check_enabled_program +
11911197
" -f " + sc.Name + " defaults failed: " + process_stderr)
11921198
return [-1]
1193-
if 'already exist' in process_stdout: # we need to remove them first
1199+
process_stdout_str = process_stdout.decode() if isinstance(process_stdout, bytes) else process_stdout
1200+
if 'already exist' in process_stdout_str: # we need to remove them first
11941201
(process_stdout, process_stderr, retval) = Process(
11951202
[check_enabled_program, "-f", sc.Name, "remove"])
11961203
if retval is not 0:

0 commit comments

Comments
 (0)