koder aka kdanilov | 416b87a | 2015-05-12 00:26:04 +0300 | [diff] [blame] | 1 | import os |
| 2 | import time |
| 3 | import unittest |
| 4 | |
| 5 | |
| 6 | from oktest import ok, main, test |
| 7 | |
| 8 | |
| 9 | from wally import utils, ssh_utils |
| 10 | |
| 11 | |
| 12 | class 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 | |
| 42 | if __name__ == '__main__': |
| 43 | main() |