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

Commit 3358da1

Browse files
author
Jinesh Shah
authored
Fixed case where comparing stdout bytes to a string (#800)
1 parent da85692 commit 3358da1

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

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)