Search code examples
pythontestingdeploymentsshfabric

Emulate SSH server for testing purposes


I have to write test for deployment script which uploads files through SSH, but I'd like to have it not depending on external servers configuration. This is how i see it:

  1. Create 2 SSH daemons without authentication on different ports of loopback interface.
  2. Run the deployment script on these two ports

The only question is how to run these dummy SSH daemons.

I use Python and Fabric.


Solution

  • If you want full control over the server's actions (e.g. in order to simulate various problem conditions and thereby do a really thorough testing) I recommend twisted: as this article shows, it makes it really easy to set up your own custom SSH server.

    If you'd rather use an existing ssh server, pick one from the list here (or use the one that comes with your system, if any; or maybe sshwindows if you're on windows) and run it with subprocess from Python as a part of starting up your tests.