File: paramiko_util.py

package info (click to toggle)
pyinfra 0.2.2%2Bgit20161227.ec708ef-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 11,804 kB
  • ctags: 677
  • sloc: python: 5,944; sh: 71; makefile: 11
file content (65 lines) | stat: -rw-r--r-- 1,374 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# pyinfra
# File: tests/paramiko_util.py
# Desc: paramiko fake test classes/shim for full API tests

from inspect import isclass


class FakeAgentRequestHandler(object):
    def __init__(self, arg):
        pass


class FakeChannel(object):
    def __init__(self, exit_status):
        self.exit_status = exit_status

    def exit_status_ready(self):
        return True


class FakeBuffer(object):
    def __init__(self, data, channel):
        self.channel = channel
        self.data = data

    def __iter__(self):
        return iter(self.data)


class FakeSSHClient(object):
    def set_missing_host_key_policy(self, _):
        pass

    def connect(self, hostname, *args, **kwargs):
        if isclass(hostname) and issubclass(hostname, Exception):
            raise hostname()

    def get_transport(self):
        return self

    def open_session(self):
        pass

    def exec_command(self, command, get_pty=None):
        channel = FakeChannel(0)
        return (
            channel,
            FakeBuffer([], channel),
            FakeBuffer([], channel)
        )


class FakeSFTPClient(object):
    @classmethod
    def from_transport(cls, transport):
        return cls()

    def putfo(self, file_io, remote_location):
        pass


class FakeRSAKey(object):
    @classmethod
    def from_private_key_file(cls, *args, **kwargs):
        return cls()