From 3bf3017f853778b4e4f037ef9277c3f3e3cc945f Mon Sep 17 00:00:00 2001 From: Michele Di Giorgio Date: Tue, 1 Mar 2016 11:12:10 +0000 Subject: [PATCH] ssh: add possibility to run command in background as root Executing a command as root was not possible when running it in background. This is done in a similar way as with a standard execute call. This was also a bug in ssh.py because if you tried to run a background command on the target, the background function in target.py was passing the as_root parameter which was not present in ssh.py. Signed-off-by: Michele Di Giorgio --- devlib/utils/ssh.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/devlib/utils/ssh.py b/devlib/utils/ssh.py index e1b4381..8bf17c0 100644 --- a/devlib/utils/ssh.py +++ b/devlib/utils/ssh.py @@ -177,10 +177,12 @@ class SshConnection(object): except EOF: raise TargetError('Connection lost.') - def background(self, command, stdout=subprocess.PIPE, stderr=subprocess.PIPE): + def background(self, command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, as_root=False): try: port_string = '-p {}'.format(self.port) if self.port else '' keyfile_string = '-i {}'.format(self.keyfile) if self.keyfile else '' + if as_root: + command = "sudo -- sh -c '{}'".format(command) command = '{} {} {} {}@{} {}'.format(ssh, keyfile_string, port_string, self.username, self.host, command) logger.debug(command) if self.password: