mirror of
https://github.com/openvswitch/ovs
synced 2025-08-31 22:35:15 +00:00
jsonrpc-py.at: Run tests with Python 2 and 3.
Convert these Python tests to run with both Python 2 and 3. Signed-off-by: Russell Bryant <russell@ovn.org> Acked-by: Ben Pfaff <blp@ovn.org>
This commit is contained in:
@@ -1,39 +1,51 @@
|
|||||||
AT_BANNER([JSON-RPC - Python])
|
AT_BANNER([JSON-RPC - Python])
|
||||||
|
|
||||||
AT_SETUP([JSON-RPC request and successful reply - Python])
|
m4_define([JSONRPC_REQ_REPLY_SUCCESS_PYN],
|
||||||
AT_SKIP_IF([test $HAVE_PYTHON = no])
|
[AT_SETUP([JSON-RPC request and successful reply - $1])
|
||||||
AT_CHECK([$PYTHON $srcdir/test-jsonrpc.py --detach --pidfile=`pwd`/pid listen punix:socket])
|
AT_SKIP_IF([test $2 = no])
|
||||||
AT_CHECK([test -s pid])
|
AT_KEYWORDS([python jsonrpc])
|
||||||
AT_CHECK([kill -0 `cat pid`])
|
AT_CHECK([$PYTHON $srcdir/test-jsonrpc.py --detach --pidfile=`pwd`/pid listen punix:socket])
|
||||||
AT_CHECK(
|
AT_CHECK([test -s pid])
|
||||||
[[$PYTHON $srcdir/test-jsonrpc.py request unix:socket echo '[{"a": "b", "x": null}]']], [0],
|
AT_CHECK([kill -0 `cat pid`])
|
||||||
[[{"error":null,"id":0,"result":[{"a":"b","x":null}]}
|
AT_CHECK(
|
||||||
|
[[$3 $srcdir/test-jsonrpc.py request unix:socket echo '[{"a": "b", "x": null}]']], [0],
|
||||||
|
[[{"error":null,"id":0,"result":[{"a":"b","x":null}]}
|
||||||
]], [], [test ! -e pid || kill `cat pid`])
|
]], [], [test ! -e pid || kill `cat pid`])
|
||||||
AT_CHECK([kill `cat pid`])
|
AT_CHECK([kill `cat pid`])
|
||||||
AT_CLEANUP
|
AT_CLEANUP])
|
||||||
|
|
||||||
AT_SETUP([JSON-RPC request and error reply - Python])
|
JSONRPC_REQ_REPLY_SUCCESS_PYN([Python2], [$HAVE_PYTHON], [$PYTHON])
|
||||||
AT_SKIP_IF([test $HAVE_PYTHON = no])
|
JSONRPC_REQ_REPLY_SUCCESS_PYN([Python3], [$HAVE_PYTHON3], [$PYTHON3])
|
||||||
AT_CHECK([$PYTHON $srcdir/test-jsonrpc.py --detach --pidfile=`pwd`/pid listen punix:socket])
|
|
||||||
AT_CHECK([test -s pid])
|
m4_define([JSONRPC_REQ_REPLY_ERROR_PYN],
|
||||||
AT_CHECK([kill -0 `cat pid`])
|
[AT_SETUP([JSON-RPC request and error reply - $1])
|
||||||
AT_CHECK(
|
AT_SKIP_IF([test $2 = no])
|
||||||
[[$PYTHON $srcdir/test-jsonrpc.py request unix:socket bad-request '[]']], [0],
|
AT_KEYWORDS([python jsonrpc])
|
||||||
[[{"error":{"error":"unknown method"},"id":0,"result":null}
|
AT_CHECK([$PYTHON $srcdir/test-jsonrpc.py --detach --pidfile=`pwd`/pid listen punix:socket])
|
||||||
|
AT_CHECK([test -s pid])
|
||||||
|
AT_CHECK([kill -0 `cat pid`])
|
||||||
|
AT_CHECK(
|
||||||
|
[[$3 $srcdir/test-jsonrpc.py request unix:socket bad-request '[]']], [0],
|
||||||
|
[[{"error":{"error":"unknown method"},"id":0,"result":null}
|
||||||
]], [], [test ! -e pid || kill `cat pid`])
|
]], [], [test ! -e pid || kill `cat pid`])
|
||||||
AT_CHECK([kill `cat pid`])
|
AT_CHECK([kill `cat pid`])
|
||||||
AT_CLEANUP
|
AT_CLEANUP])
|
||||||
|
|
||||||
AT_SETUP([JSON-RPC notification - Python])
|
JSONRPC_REQ_REPLY_ERROR_PYN([Python2], [$HAVE_PYTHON], [$PYTHON])
|
||||||
AT_SKIP_IF([test $HAVE_PYTHON = no])
|
JSONRPC_REQ_REPLY_ERROR_PYN([Python3], [$HAVE_PYTHON3], [$PYTHON3])
|
||||||
AT_CHECK([$PYTHON $srcdir/test-jsonrpc.py --detach --pidfile=`pwd`/pid listen punix:socket])
|
|
||||||
AT_CHECK([test -s pid])
|
m4_define([JSONRPC_NOTIFICATION_PYN],
|
||||||
# When a daemon dies it deletes its pidfile, so make a copy.
|
[AT_SETUP([JSON-RPC notification - $1])
|
||||||
AT_CHECK([cp pid pid2])
|
AT_SKIP_IF([test $2 = no])
|
||||||
AT_CHECK([kill -0 `cat pid2`])
|
AT_KEYWORDS([python jsonrpc])
|
||||||
AT_CHECK([[$PYTHON $srcdir/test-jsonrpc.py notify unix:socket shutdown '[]']], [0], [],
|
AT_CHECK([$3 $srcdir/test-jsonrpc.py --detach --pidfile=`pwd`/pid listen punix:socket])
|
||||||
[], [kill `cat pid2`])
|
AT_CHECK([test -s pid])
|
||||||
AT_CHECK(
|
# When a daemon dies it deletes its pidfile, so make a copy.
|
||||||
|
AT_CHECK([cp pid pid2])
|
||||||
|
AT_CHECK([kill -0 `cat pid2`])
|
||||||
|
AT_CHECK([[$3 $srcdir/test-jsonrpc.py notify unix:socket shutdown '[]']], [0], [],
|
||||||
|
[], [kill `cat pid2`])
|
||||||
|
AT_CHECK(
|
||||||
[pid=`cat pid2`
|
[pid=`cat pid2`
|
||||||
# First try a quick sleep, so that the test completes very quickly
|
# First try a quick sleep, so that the test completes very quickly
|
||||||
# in the normal case. POSIX doesn't require fractional times to
|
# in the normal case. POSIX doesn't require fractional times to
|
||||||
@@ -44,5 +56,8 @@ AT_CHECK(
|
|||||||
sleep 1; if kill -0 $pid; then :; else echo success; exit 0; fi
|
sleep 1; if kill -0 $pid; then :; else echo success; exit 0; fi
|
||||||
echo failure; exit 1], [0], [success
|
echo failure; exit 1], [0], [success
|
||||||
], [ignore])
|
], [ignore])
|
||||||
AT_CHECK([test ! -e pid])
|
AT_CHECK([test ! -e pid])
|
||||||
AT_CLEANUP
|
AT_CLEANUP])
|
||||||
|
|
||||||
|
JSONRPC_NOTIFICATION_PYN([Python2], [$HAVE_PYTHON], [$PYTHON])
|
||||||
|
JSONRPC_NOTIFICATION_PYN([Python3], [$HAVE_PYTHON3], [$PYTHON3])
|
||||||
|
Reference in New Issue
Block a user