blob: bb3600f0ac95c80e909067d322c234e93a7642a5 [file] [log] [blame]
koder aka kdanilov416b87a2015-05-12 00:26:04 +03001import os
2import time
3import unittest
4
5
6from oktest import ok, main, test
7
8
9from wally import utils, ssh_utils
10
11
12class AgentTest(unittest.TestCase):
13 @test("test_local_executor_ls")
14 def test_ls(self):
15 expected = sorted(os.listdir('/'))
16 ok(sorted(utils.run_locally('ls /').split())) == expected
17
18 @test("test_local_executor_sleep1")
19 def test_sleep1(self):
20 t = time.time()
21 with self.assertRaises(RuntimeError):
22 utils.run_locally(['sleep', '20'], timeout=1)
23 ok(time.time() - t) < 1.2
24
25 @test("test_local_executor_sleep2")
26 def test_sleep2(self):
27 t = time.time()
28 with self.assertRaises(RuntimeError):
29 utils.run_locally('sleep 20', timeout=1)
30 ok(time.time() - t) < 1.2
31
32 @test("test_ssh_executor1")
33 def test_ssh_executor1(self):
34 id_rsa_path = os.path.expanduser('~/.ssh/id_rsa')
35 ssh_url = "ssh://localhost::" + id_rsa_path
36 expected = sorted(os.listdir('/'))
37
38 conn = ssh_utils.connect(ssh_url)
39 out = ssh_utils.run_over_ssh(conn, "ls /")
40 ok(sorted(out.split())) == expected
41
42if __name__ == '__main__':
43 main()