blob: db24768f5c4ed6a6e22d32746d029015f70ac913 [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
koder aka kdanilova732a602017-02-01 20:29:56 +020010def rpc_conn_ctx(uri, log_level=None):
koder aka kdanilove7e1a4d2016-12-17 20:29:52 +020011 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 kdanilova732a602017-02-01 20:29:56 +020016 rpc_conn = node.setup_rpc(ssh_conn, rpc_code, plugins=modules, log_level=log_level)
koder aka kdanilove7e1a4d2016-12-17 20:29:52 +020017 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("/")