]> git.proxmox.com Git - mirror_ovs.git/blame - tests/jsonrpc-py.at
ovn: Rename "nd" action to "nd_na".
[mirror_ovs.git] / tests / jsonrpc-py.at
CommitLineData
99155935
BP
1AT_BANNER([JSON-RPC - Python])
2
58bed3df
RB
3m4_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}]}
7fcfe998 13]], [], [test ! -e pid || kill `cat pid`])
58bed3df
RB
14 AT_CHECK([kill `cat pid`])
15 AT_CLEANUP])
99155935 16
58bed3df
RB
17JSONRPC_REQ_REPLY_SUCCESS_PYN([Python2], [$HAVE_PYTHON], [$PYTHON])
18JSONRPC_REQ_REPLY_SUCCESS_PYN([Python3], [$HAVE_PYTHON3], [$PYTHON3])
19
20m4_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}
7fcfe998 30]], [], [test ! -e pid || kill `cat pid`])
58bed3df
RB
31 AT_CHECK([kill `cat pid`])
32 AT_CLEANUP])
33
34JSONRPC_REQ_REPLY_ERROR_PYN([Python2], [$HAVE_PYTHON], [$PYTHON])
35JSONRPC_REQ_REPLY_ERROR_PYN([Python3], [$HAVE_PYTHON3], [$PYTHON3])
99155935 36
58bed3df
RB
37m4_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(
99155935
BP
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])
58bed3df
RB
59 AT_CHECK([test ! -e pid])
60 AT_CLEANUP])
61
62JSONRPC_NOTIFICATION_PYN([Python2], [$HAVE_PYTHON], [$PYTHON])
63JSONRPC_NOTIFICATION_PYN([Python3], [$HAVE_PYTHON3], [$PYTHON3])