Fix shell execute
- Pass environment variables using shell syntax when using SSH connections - Use real default shell command instead of sudo - Fix some typos Change-Id: I030a1403dd5ced5c1ff08e121f2e148c544dd565
This commit is contained in:
parent
ad0340fc8a
commit
11b1b120e0
@ -35,8 +35,8 @@ shell_command = _command.shell_command
|
||||
ShellError = _exception.ShellError
|
||||
ShellCommandFailed = _exception.ShellCommandFailed
|
||||
ShellTimeoutExpired = _exception.ShellTimeoutExpired
|
||||
ShellProcessTeriminated = _exception.ShellProcessTeriminated
|
||||
ShellProcessNotTeriminated = _exception.ShellProcessNotTeriminated
|
||||
ShellProcessTerminated = _exception.ShellProcessTerminated
|
||||
ShellProcessNotTerminated = _exception.ShellProcessNotTerminated
|
||||
ShellStdinClosed = _exception.ShellStdinClosed
|
||||
|
||||
execute = _execute.execute
|
||||
|
@ -40,7 +40,7 @@ class ShellTimeoutExpired(ShellError):
|
||||
"stderr:\n{stderr}")
|
||||
|
||||
|
||||
class ShellProcessTeriminated(ShellError):
|
||||
class ShellProcessTerminated(ShellError):
|
||||
message = ("command '{command}' terminated (exit status is {exit_status})"
|
||||
";\n"
|
||||
"stdin:\n{stdin}\n"
|
||||
@ -48,7 +48,7 @@ class ShellProcessTeriminated(ShellError):
|
||||
"stderr:\n{stderr}")
|
||||
|
||||
|
||||
class ShellProcessNotTeriminated(ShellError):
|
||||
class ShellProcessNotTerminated(ShellError):
|
||||
message = ("command '{command}' not terminated (time left is {time_left})"
|
||||
";\n"
|
||||
"stdin:\n{stdin}\n"
|
||||
|
@ -173,7 +173,7 @@ def execute_process(process, stdin, expect_exit_status, login=None):
|
||||
except _exception.ShellCommandFailed:
|
||||
status = ShellExecuteStatus.FAILED
|
||||
error = tobiko.exc_info()
|
||||
except _exception.ShellProcessNotTeriminated:
|
||||
except _exception.ShellProcessNotTerminated:
|
||||
status = ShellExecuteStatus.UNTERMINATED
|
||||
else:
|
||||
status = ShellExecuteStatus.SUCCEEDED
|
||||
|
@ -260,7 +260,7 @@ class ShellProcessFixture(tobiko.SharedFixture):
|
||||
def check_is_running(self):
|
||||
exit_status = self.exit_status
|
||||
if exit_status is not None:
|
||||
raise _exception.ShellProcessTeriminated(
|
||||
raise _exception.ShellProcessTerminated(
|
||||
command=str(self.command),
|
||||
exit_status=int(exit_status),
|
||||
stdin=str_from_stream(self.stdin),
|
||||
@ -395,7 +395,7 @@ class ShellProcessFixture(tobiko.SharedFixture):
|
||||
exit_status = self.poll_exit_status()
|
||||
if exit_status is None:
|
||||
time_left = self.check_timeout()
|
||||
ex = _exception.ShellProcessNotTeriminated(
|
||||
ex = _exception.ShellProcessNotTerminated(
|
||||
command=str(self.command),
|
||||
time_left=time_left,
|
||||
stdin=self.stdin,
|
||||
@ -432,7 +432,7 @@ def str_from_stream(stream):
|
||||
def default_shell_command():
|
||||
from tobiko import config
|
||||
CONF = config.CONF
|
||||
return _command.shell_command(CONF.tobiko.shell.sudo)
|
||||
return _command.shell_command(CONF.tobiko.shell.sudo.command)
|
||||
|
||||
|
||||
def default_sudo_command():
|
||||
|
@ -105,7 +105,10 @@ class SSHShellProcessFixture(_process.ShellProcessFixture):
|
||||
client = ssh_client.connect()
|
||||
process = client.get_transport().open_session()
|
||||
if environment:
|
||||
process.update_environment(environment)
|
||||
variables = " ".join(
|
||||
f"{name}='{value}'"
|
||||
for name, value in self.environment.items())
|
||||
command = variables + " " + command
|
||||
process.exec_command(command)
|
||||
LOG.debug(f"Remote process created. ({details})")
|
||||
return process
|
||||
|
Loading…
x
Reference in New Issue
Block a user