From bd27de194c9c74deb8d16c4ddd72b34ffe56db9b Mon Sep 17 00:00:00 2001 From: Sergei Trofimov Date: Thu, 20 Apr 2017 17:00:17 +0100 Subject: [PATCH] SshConnection: do not try to sudo as root If a command is executed "as_root", SshConnection always prepended "sudo" invocation to the command, even if the user name is "root". This causes problems on patforms that do not have "sudo". This commit changes this behavior so that sudo is never used for root users. --- devlib/utils/ssh.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/devlib/utils/ssh.py b/devlib/utils/ssh.py index ff30346..af644bf 100644 --- a/devlib/utils/ssh.py +++ b/devlib/utils/ssh.py @@ -228,6 +228,9 @@ class SshConnection(object): def _execute_and_wait_for_prompt(self, command, timeout=None, as_root=False, strip_colors=True, log=True): self.conn.prompt(0.1) # clear an existing prompt if there is one. + if self.username == 'root': + # As we're already root, there is no need to use sudo. + as_root = False if as_root: command = "sudo -- sh -c '{}'".format(escape_single_quotes(command)) if log: