grimoirelab-perceval icon indicating copy to clipboard operation
grimoirelab-perceval copied to clipboard

[gerrit] Use native ssh python library

Open albertinisg opened this issue 9 years ago • 1 comments

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.

albertinisg avatar Sep 14 '16 14:09 albertinisg

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()

valeriocos avatar Jan 23 '18 13:01 valeriocos