0

Basically, I am trying to run some tests on a remote host using pytest.

Based on https://testinfra.readthedocs.io/en/latest/backends.html is it possible to do so.

I have tried commands like:

$ py.test --ssh-config=/path/to/ssh_config --hosts=node1

And it works fine, where the congif file is like this:

Host node1
  HostName 192.168.1.15
  User root
  Port 22
  UserKnownHostsFile /dev/null
  StrictHostKeyChecking no
  IdentityFile "path_to_ssh_key_file"
  PasswordAuthentication no
  IdentitiesOnly yes
  LogLevel FATAL

And I have tried this one, it works fine. But based on the link, it should also work if we try this option directly using ssh identity file:

py.test --ssh-identity-file=/path/to/key --hosts='ssh://server'

I have tried the command like this:

py.test --ssh-identity-file=/path/to/key --hosts='ssh://root@192.168.1.15'

But it is not working, Am I missing something? I really want to run it this way instead of config file...

phd
  • 82,685
  • 13
  • 120
  • 165
user14073111
  • 647
  • 5
  • 14
  • Does not work — in what way? Error message (can you please copy/paste text from the terminal)? Not connected? Connected but not authenticated? – phd Jun 29 '23 at 16:43
  • So, my scenario is that I am using a windows machine and trying to run tests on my Ubuntu VM. Basically, I am using host.run feature of testinfra to run some shell commands. With config file, it works fine, with only ssh-identity-file, I am getting this error: RuntimeError: CommandResult(command=b"sudo /bin/sh -c 'ps aux | grep dpkg'", exit_status=255, stdout=None, stderr=b"'grep' is not recognized as an internal or external command,\r\noperable program or batch file.\r\n") – user14073111 Jun 29 '23 at 16:51
  • And, just to give full information, this is happening when using a non root user: user@192.168.1.15. But when using the root user root@192.168.1.15, it is hanging forever and giving timeout after 5 minutes – user14073111 Jun 29 '23 at 17:07
  • "*'grep' is not recognized as an internal or external command,\r\noperable program or batch file.*" The error message seems to coming from Windows, not from Ubuntu. But if it's from Ubuntu it means that different users have different `PATH`; that should be fixed. But it seems you connected successfully. "*…when using the root user root@192.168.1.15, it is hanging forever and giving timeout…*" `sshd` on servers are usually configured to not allow connect directly as root. You must connect as non-root user and use `su`/`sudo` to become root. – phd Jun 29 '23 at 17:38

0 Answers0