Source /etc/profile before importing env variables from remote host

This also fixes SSHShellConnection.username property

Change-Id: Ie1f49bc6857480d87cfc85983cb8c7f2f26e5cda
This commit is contained in:
Federico Ressi 2022-07-20 11:43:29 +02:00
parent 18e30f0d98
commit 4aaab1ceae
2 changed files with 4 additions and 3 deletions

View File

@ -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):

View File

@ -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):