Skip to content

Commit 14155b2

Browse files
paullLiliDeng
authored andcommitted
Fixed the regression error caused by support_sudo change
make detection accurate for root not allowed in /bin/sh
1 parent 361b7e8 commit 14155b2

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

lisa/node.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,17 +132,16 @@ def is_remote(self) -> bool:
132132
@property
133133
def support_sudo(self) -> bool:
134134
self.initialize()
135-
136135
# self._support_sudo already set, return it directly.
137136
if self._support_sudo is not None:
138137
return self._support_sudo
139138

140-
if not self.is_posix:
141-
# Windows or non-POSIX: assume sudo not needed
139+
if self.is_posix:
140+
self._support_sudo = self._check_sudo_available()
141+
else:
142+
# set Windows to true to ignore sudo asks.
142143
self._support_sudo = True
143-
return self._support_sudo
144144

145-
self._support_sudo = self._check_sudo_available()
146145
return self._support_sudo
147146

148147
def _check_sudo_available(self) -> bool:
@@ -157,8 +156,13 @@ def _check_sudo_available(self) -> bool:
157156
process = self._execute("ls", shell=True, sudo=True, no_info_log=True)
158157
result = process.wait_result(10)
159158
if result.exit_code != 0:
160-
self.log.debug("node doesn't support sudo /bin/sh.")
161-
return False
159+
# e.g. raw error: "user is not allowed to execute '/bin/sh -c ...'"
160+
if "not allowed" in result.stderr:
161+
self.log.debug(
162+
"The command 'sudo /bin/sh -c ls' may fail due to SELinux policies"
163+
" that restrict the use of sudo in combination with /bin/sh."
164+
)
165+
return False
162166

163167
return True
164168

0 commit comments

Comments
 (0)