]> git.proxmox.com Git - mirror_ovs.git/blob - tests/jsonrpc-py.at
check-kmod: Remove all OVS modules in this target.
[mirror_ovs.git] / tests / jsonrpc-py.at
1 AT_BANNER([JSON-RPC - Python])
2
3 m4_define([JSONRPC_REQ_REPLY_SUCCESS_PYN],
4 [AT_SETUP([JSON-RPC request and successful reply - $1])
5 AT_SKIP_IF([test $2 = no])
6 AT_KEYWORDS([python jsonrpc])
7 AT_CHECK([$PYTHON $srcdir/test-jsonrpc.py --detach --pidfile=`pwd`/pid listen punix:socket])
8 AT_CHECK([test -s pid])
9 AT_CHECK([kill -0 `cat pid`])
10 AT_CHECK(
11 [[$3 $srcdir/test-jsonrpc.py request unix:socket echo '[{"a": "b", "x": null}]']], [0],
12 [[{"error":null,"id":0,"result":[{"a":"b","x":null}]}
13 ]], [], [test ! -e pid || kill `cat pid`])
14 AT_CHECK([kill `cat pid`])
15 AT_CLEANUP])
16
17 JSONRPC_REQ_REPLY_SUCCESS_PYN([Python2], [$HAVE_PYTHON], [$PYTHON])
18 JSONRPC_REQ_REPLY_SUCCESS_PYN([Python3], [$HAVE_PYTHON3], [$PYTHON3])
19
20 m4_define([JSONRPC_REQ_REPLY_ERROR_PYN],
21 [AT_SETUP([JSON-RPC request and error reply - $1])
22 AT_SKIP_IF([test $2 = no])
23 AT_KEYWORDS([python jsonrpc])
24 AT_CHECK([$PYTHON $srcdir/test-jsonrpc.py --detach --pidfile=`pwd`/pid listen punix:socket])
25 AT_CHECK([test -s pid])
26 AT_CHECK([kill -0 `cat pid`])
27 AT_CHECK(
28 [[$3 $srcdir/test-jsonrpc.py request unix:socket bad-request '[]']], [0],
29 [[{"error":{"error":"unknown method"},"id":0,"result":null}
30 ]], [], [test ! -e pid || kill `cat pid`])
31 AT_CHECK([kill `cat pid`])
32 AT_CLEANUP])
33
34 JSONRPC_REQ_REPLY_ERROR_PYN([Python2], [$HAVE_PYTHON], [$PYTHON])
35 JSONRPC_REQ_REPLY_ERROR_PYN([Python3], [$HAVE_PYTHON3], [$PYTHON3])
36
37 m4_define([JSONRPC_NOTIFICATION_PYN],
38 [AT_SETUP([JSON-RPC notification - $1])
39 AT_SKIP_IF([test $2 = no])
40 AT_KEYWORDS([python jsonrpc])
41 AT_CHECK([$3 $srcdir/test-jsonrpc.py --detach --pidfile=`pwd`/pid listen punix:socket])
42 AT_CHECK([test -s pid])
43 # When a daemon dies it deletes its pidfile, so make a copy.
44 AT_CHECK([cp pid pid2])
45 AT_CHECK([kill -0 `cat pid2`])
46 AT_CHECK([[$3 $srcdir/test-jsonrpc.py notify unix:socket shutdown '[]']], [0], [],
47 [], [kill `cat pid2`])
48 AT_CHECK(
49 [pid=`cat pid2`
50 # First try a quick sleep, so that the test completes very quickly
51 # in the normal case. POSIX doesn't require fractional times to
52 # work, so this might not work.
53 sleep 0.1; if kill -0 $pid; then :; else echo success; exit 0; fi
54 # Then wait up to 2 seconds.
55 sleep 1; if kill -0 $pid; then :; else echo success; exit 0; fi
56 sleep 1; if kill -0 $pid; then :; else echo success; exit 0; fi
57 echo failure; exit 1], [0], [success
58 ], [ignore])
59 AT_CHECK([test ! -e pid])
60 AT_CLEANUP])
61
62 JSONRPC_NOTIFICATION_PYN([Python2], [$HAVE_PYTHON], [$PYTHON])
63 JSONRPC_NOTIFICATION_PYN([Python3], [$HAVE_PYTHON3], [$PYTHON3])