blob: fd35555b8270759daf2974c5c0dbeb9b43c4ab3c [file] [log] [blame]
koder aka kdanilove7e1a4d2016-12-17 20:29:52 +02001import contextlib
2
3from wally import ssh_utils, node, node_interfaces
4
5
6CONNECT_URI = "localhost"
7
8
9@contextlib.contextmanager
10def rpc_conn_ctx(uri):
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:
16 rpc_conn = node.setup_rpc(ssh_conn, rpc_code, plugins=modules)
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
26def 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
35def 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("/")