blob: eeffde336d82d85e8999a6631bee4734adaebda4 [file] [log] [blame]
yportnovaa47b33e2015-03-05 20:20:31 +02001import json
2import sys
3
4import run_test
5
6
7logger = run_test.logger
8tool = None
9
10
11class FakeVMContext(object):
12 def __init__(self, *args, **kwargs):
13 pass
14
15 def __enter__(self):
16 return ["fake@fake"]
17
18 def __exit__(self, *args, **kwargs):
19 pass
20
21
22def fake_start_vms(*args, **kwargs):
23 return FakeVMContext
24
25
26class FakeFD(object):
27 def __init__(self, content):
28 self.content = content
29 self.channel = FakeChannel()
30
31 def read(self):
32 return self.content
33
34
35class FakeChannel(object):
36 def recv_exit_status(self):
37 return 0
38
39
40def get_fake_out(cmd):
41 empty_fd = FakeFD("")
42 if "pgbench" == tool:
43 if "run" in cmd:
44 out = FakeFD("2 1:43\n2 1:42\n4 2:77")
45 else:
46 out = empty_fd
47 elif "iozone" == tool or "fio" == tool:
48 data = {'__meta__': {
koder aka kdanilov4e9f3ed2015-04-14 11:26:12 +030049 'direct': 1,
yportnovaa47b33e2015-03-05 20:20:31 +020050 'action': 'r',
51 'concurence': 1,
52 'blocksize': 1,
53 'sync': 's'},
koder aka kdanilov4e9f3ed2015-04-14 11:26:12 +030054 'bw': 10}
yportnovaa47b33e2015-03-05 20:20:31 +020055 out = FakeFD(json.dumps(data))
56 else:
57 raise Exception("tool not found")
58 err = empty_fd
59 return empty_fd, out, err
60
61
62def fake_ssh_connect(*args, **kwargs):
63 return FakeSSH()
64
65
66class FakeSFTP(object):
67 def put(self, what, where):
68 logger.debug("Called sftp put with %s %s" % (what, where))
69
70 def chmod(self, f, mode):
71 logger.debug("called sftp chmod %s %s" % (mode, f))
72
73 def close(self):
74 logger.debug("called sftp close")
75
76
77class FakeSSH(object):
78 def exec_command(self, cmd, **kwargs):
79 return get_fake_out(cmd)
80
81 def close(self):
82 pass
83
84 def open_sftp(self):
85 return FakeSFTP()
86
87
88class FakePopen(object):
89 def __init__(self, cmd,
90 shell=True,
91 stdout=None,
92 stderr=None,
93 stdin=None):
yportnovaa47b33e2015-03-05 20:20:31 +020094 self.stdin, self.stdout, self.stderr = get_fake_out(cmd)
95
96 def wait(self):
97 return 0
98
99
100if __name__ == '__main__':
101 run_test.subprocess.Popen = FakePopen
102 run_test.start_test_vms = fake_start_vms()
103 run_test.ssh_runner.ssh_connect = fake_ssh_connect
104 opts = run_test.parse_args(sys.argv[1:])
105 tool = opts.tool_type
106 exit(run_test.main(sys.argv[1:]))