chaoss / grimoirelab-perceval

Send Sir Perceval on a quest to retrieve and gather data from software repositories.
http://perceval.readthedocs.io/
GNU General Public License v3.0
290 stars 177 forks source link

[gerrit] Use native ssh python library #59

Open albertinisg opened 8 years ago

albertinisg commented 8 years ago

Actually we are doing requests against Gerrit using sub-processes, forcing the user to add private keys manually in the host.

Using a library like paramiko would allow us to add the key as a parameter for the back-end, and automatize the process.

valeriocos commented 6 years ago

A new python library that mocks a ssh server could come in handy: https://github.com/carletes/mock-ssh-server

import os

from pytest import yield_fixture

import mockssh

@yield_fixture()
def server():
    users = {
        "sample-user": "/path/to/user-private-key,
    }
    with mockssh.Server(users) as s:
        yield s

def test_ssh_session(server):
    for uid in server.users:
        with server.client(uid) as c:
            _, stdout, _ = c.exec_command("ls /")
            assert stdout.read()