koder aka kdanilov | e7e1a4d | 2016-12-17 20:29:52 +0200 | [diff] [blame] | 1 | import contextlib |
| 2 | |
| 3 | from wally import ssh_utils, node, node_interfaces |
| 4 | |
| 5 | |
| 6 | CONNECT_URI = "localhost" |
| 7 | |
| 8 | |
| 9 | @contextlib.contextmanager |
koder aka kdanilov | a732a60 | 2017-02-01 20:29:56 +0200 | [diff] [blame^] | 10 | def rpc_conn_ctx(uri, log_level=None): |
koder aka kdanilov | e7e1a4d | 2016-12-17 20:29:52 +0200 | [diff] [blame] | 11 | creds = ssh_utils.parse_ssh_uri(uri) |
| 12 | rpc_code, modules = node.get_rpc_server_code() |
| 13 | |
| 14 | ssh_conn = node.connect(node_interfaces.NodeInfo(creds, set())) |
| 15 | try: |
koder aka kdanilov | a732a60 | 2017-02-01 20:29:56 +0200 | [diff] [blame^] | 16 | rpc_conn = node.setup_rpc(ssh_conn, rpc_code, plugins=modules, log_level=log_level) |
koder aka kdanilov | e7e1a4d | 2016-12-17 20:29:52 +0200 | [diff] [blame] | 17 | try: |
| 18 | yield rpc_conn |
| 19 | finally: |
| 20 | rpc_conn.conn.server.stop() |
| 21 | rpc_conn.disconnect() |
| 22 | finally: |
| 23 | ssh_conn.disconnect() |
| 24 | |
| 25 | |
| 26 | def test_rpc_simple(): |
| 27 | with rpc_conn_ctx(CONNECT_URI) as conn: |
| 28 | names = conn.conn.server.rpc_info() |
| 29 | assert 'server.list_modules' in names |
| 30 | assert 'server.load_module' in names |
| 31 | assert 'server.rpc_info' in names |
| 32 | assert 'server.stop' in names |
| 33 | |
| 34 | |
| 35 | def test_rpc_plugins(): |
| 36 | with rpc_conn_ctx(CONNECT_URI) as conn: |
| 37 | print(conn.conn.server.rpc_info()) |
| 38 | assert conn.conn.fs.file_exists("/") |