提交 0b7d745a 编写于 作者: L Lukáš Doktor 提交者: Cleber Rosa

avocado.utils.process: Add method to check whether sudo is configured

The `avocado.utils.process` allows the use of sudo, but it might not be
always enabled/configured in the system. This method should allow
detecting whether it is or is not available.
Signed-off-by: NLukáš Doktor <ldoktor@redhat.com>
上级 deaef79f
......@@ -98,6 +98,18 @@ class CmdError(Exception):
return "CmdError"
def can_sudo():
"""
:return: True when sudo is available (or is root)
"""
if os.getuid() == 0:
return True
elif system_output("id -u", ignore_status=True, sudo=True).strip() == "0":
return True
else:
return False
def pid_exists(pid):
"""
Return True if a given PID exists.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册