From 4aaab1ceae1751bbe6948462922e37f89821f39c Mon Sep 17 00:00:00 2001 From: Federico Ressi Date: Wed, 20 Jul 2022 11:43:29 +0200 Subject: [PATCH] Source /etc/profile before importing env variables from remote host This also fixes SSHShellConnection.username property Change-Id: Ie1f49bc6857480d87cfc85983cb8c7f2f26e5cda --- tobiko/shell/sh/_connection.py | 5 +++-- tobiko/tests/functional/shell/sh/test_connection.py | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/tobiko/shell/sh/_connection.py b/tobiko/shell/sh/_connection.py index 317ee197e..90ffc98f3 100644 --- a/tobiko/shell/sh/_connection.py +++ b/tobiko/shell/sh/_connection.py @@ -443,7 +443,7 @@ class SSHShellConnection(ShellConnection): @property def username(self) -> str: - return self.ssh_client.username + return self.ssh_client.setup_connect_parameters()['username'] _hostname: typing.Optional[str] = None @@ -462,8 +462,9 @@ class SSHShellConnection(ShellConnection): return self._sftp def get_environ(self) -> typing.Dict[str, str]: + lines = self.execute('source /etc/profile; env').stdout.splitlines() return dict(_parse_env_line(line) - for line in self.execute('env').stdout().splitlines() + for line in lines if line.strip()) def put_file(self, local_file: str, remote_file: str): diff --git a/tobiko/tests/functional/shell/sh/test_connection.py b/tobiko/tests/functional/shell/sh/test_connection.py index feaecf6d2..552bc9c1d 100644 --- a/tobiko/tests/functional/shell/sh/test_connection.py +++ b/tobiko/tests/functional/shell/sh/test_connection.py @@ -234,7 +234,7 @@ class SSHShellConnectionTest(LocalShellConnectionTest): @property def username(self) -> str: - return self.ssh_client.username + return self.ssh_client.setup_connect_parameters()['username'] class CirrosShellConnectionTest(SSHShellConnectionTest):