Skip to content

Commit

Permalink
tests-ovsdb: Switch OVSDB_START_IDLTEST to macro.
Browse files Browse the repository at this point in the history
Define bash function as macro now. Later we can extend this macro for other
usecases.

Signed-off-by: Stefan Hoffmann <stefan.hoffmann@cloudandheat.com>
Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
Signed-off-by: Simon Horman <horms@ovn.org>
  • Loading branch information
mrhopeman authored and Simon Horman committed Jan 11, 2024
1 parent 219f1eb commit 2404ca5
Showing 1 changed file with 43 additions and 36 deletions.
79 changes: 43 additions & 36 deletions tests/ovsdb-idl.at
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
AT_BANNER([OVSDB -- interface description language (IDL)])

m4_divert_text([PREPARE_TESTS], [
# ovsdb_start_idltest [REMOTE] [SCHEMA]
#
# Creates a database using SCHEMA (default: idltest.ovsschema) and
# starts a database server listening on punix:socket and REMOTE (if
# specified).
ovsdb_start_idltest () {
ovsdb-tool create db ${2:-$abs_srcdir/idltest.ovsschema} || return $?
ovsdb-server -vconsole:warn --log-file --detach --no-chdir --pidfile --remote=punix:socket ${1:+--remote=$1} db || return $?
on_exit 'kill `cat ovsdb-server.pid`'
}

# ovsdb_cluster_leader [REMOTES] [DATABASE]
#
# Returns the leader of the DATABASE cluster.
Expand All @@ -29,6 +18,24 @@ ovsdb_cluster_leader () {
done
}])


# OVSDB_START_IDLTEST([REMOTE], [SCHEMA])
#
# Creates a database using SCHEMA (default: idltest.ovsschema) and
# starts a database server listening on punix:socket and REMOTE (if
# specified).
m4_define([OVSDB_START_IDLTEST],
[
AT_CHECK([ovsdb-tool create db dnl
m4_if([$2], [], [$abs_srcdir/idltest.ovsschema], [$2])])
AT_CHECK([ovsdb-server -vconsole:warn --log-file --detach --no-chdir dnl
--pidfile --remote=punix:socket dnl
m4_if([$1], [], [], [--remote=$1]) db dnl
])
on_exit 'kill `cat ovsdb-server.pid`'
])


# OVSDB_CLUSTER_START_IDLTEST([N], [REMOTE])
#
# Creates a clustered database using idltest.ovsschema and starts a database
Expand Down Expand Up @@ -77,7 +84,7 @@ m4_define([OVSDB_CLUSTER_START_IDLTEST],
m4_define([OVSDB_CHECK_IDL_C],
[AT_SETUP([$1 - C])
AT_KEYWORDS([ovsdb server idl positive $5])
AT_CHECK([ovsdb_start_idltest])
OVSDB_START_IDLTEST
m4_if([$2], [], [],
[AT_CHECK([ovsdb-client transact unix:socket $2], [0], [ignore], [ignore])])
AT_CHECK([test-ovsdb '-vPATTERN:console:test-ovsdb|%c|%m' -vjsonrpc -t10 idl unix:socket $3],
Expand All @@ -91,7 +98,7 @@ m4_define([OVSDB_CHECK_IDL_C],
m4_define([OVSDB_CHECK_IDL_WRITE_CHANGED_ONLY_C],
[AT_SETUP([$1 - write-changed-only - C])
AT_KEYWORDS([ovsdb server idl positive $5])
AT_CHECK([ovsdb_start_idltest])
OVSDB_START_IDLTEST
m4_if([$2], [], [],
[AT_CHECK([ovsdb-client transact unix:socket $2], [0], [ignore], [ignore])])
AT_CHECK([test-ovsdb '-vPATTERN:console:test-ovsdb|%c|%m' -vjsonrpc -t10 --write-changed-only idl unix:socket $3],
Expand All @@ -105,7 +112,7 @@ m4_define([OVSDB_CHECK_IDL_WRITE_CHANGED_ONLY_C],
m4_define([OVSDB_CHECK_IDL_TCP_C],
[AT_SETUP([$1 - C - tcp])
AT_KEYWORDS([ovsdb server idl positive tcp socket $5])
AT_CHECK([ovsdb_start_idltest "ptcp:0:127.0.0.1"])
OVSDB_START_IDLTEST(["ptcp:0:127.0.0.1"])
PARSE_LISTENING_PORT([ovsdb-server.log], [TCP_PORT])

m4_if([$2], [], [],
Expand All @@ -123,7 +130,7 @@ m4_define([OVSDB_CHECK_IDL_TCP6_C],
AT_SKIP_IF([test "$IS_WIN32" = "yes"])
AT_SKIP_IF([test $HAVE_IPV6 = no])
AT_KEYWORDS([ovsdb server idl positive tcp6 socket $5])
AT_CHECK([ovsdb_start_idltest "ptcp:0:[[::1]]"])
OVSDB_START_IDLTEST(["ptcp:0:[[::1]]"])
PARSE_LISTENING_PORT([ovsdb-server.log], [TCP_PORT])

m4_if([$2], [], [],
Expand All @@ -139,7 +146,7 @@ m4_define([OVSDB_CHECK_IDL_TCP6_C],
m4_define([OVSDB_CHECK_IDL_PY],
[AT_SETUP([$1 - Python3])
AT_KEYWORDS([ovsdb server idl positive Python $5])
AT_CHECK([ovsdb_start_idltest])
OVSDB_START_IDLTEST
m4_if([$2], [], [],
[AT_CHECK([ovsdb-client transact unix:socket $2], [0], [ignore], [ignore])])
AT_CHECK([$PYTHON3 $srcdir/test-ovsdb.py -t10 idl $srcdir/idltest.ovsschema unix:socket $3],
Expand All @@ -152,7 +159,7 @@ m4_define([OVSDB_CHECK_IDL_PY],
m4_define([OVSDB_CHECK_IDL_REGISTER_COLUMNS_PY],
[AT_SETUP([$1 - Python3 - register_columns])
AT_KEYWORDS([ovsdb server idl positive Python register_columns $5])
AT_CHECK([ovsdb_start_idltest])
OVSDB_START_IDLTEST
m4_if([$2], [], [],
[AT_CHECK([ovsdb-client transact unix:socket $2], [0], [ignore], [ignore])])
AT_CHECK([$PYTHON3 $srcdir/test-ovsdb.py -t10 idl $srcdir/idltest.ovsschema unix:socket ?simple:b,ba,i,ia,r,ra,s,sa,u,ua?simple3:name,uset,uref?simple4:name?simple6:name,weak_ref?link1:i,k,ka,l2?link2:i,l1?singleton:name $3],
Expand All @@ -166,7 +173,7 @@ m4_define([OVSDB_CHECK_IDL_REGISTER_COLUMNS_PY],
m4_define([OVSDB_CHECK_IDL_TCP_PY],
[AT_SETUP([$1 - Python3 - tcp])
AT_KEYWORDS([ovsdb server idl positive Python with tcp socket $5])
AT_CHECK([ovsdb_start_idltest "ptcp:0:127.0.0.1"])
OVSDB_START_IDLTEST(["ptcp:0:127.0.0.1"])
PARSE_LISTENING_PORT([ovsdb-server.log], [TCP_PORT])

m4_if([$2], [], [],
Expand All @@ -183,7 +190,7 @@ m4_define([OVSDB_CHECK_IDL_TCP_PY],
m4_define([OVSDB_CHECK_IDL_TCP_MULTIPLE_REMOTES_PY],
[AT_SETUP([$1 - Python3 (multiple remotes) - tcp])
AT_KEYWORDS([ovsdb server idl positive Python with tcp socket $5])
AT_CHECK([ovsdb_start_idltest "ptcp:0:127.0.0.1"])
OVSDB_START_IDLTEST(["ptcp:0:127.0.0.1"])
PARSE_LISTENING_PORT([ovsdb-server.log], [TCP_PORT])
WRONG_PORT_1=$((TCP_PORT + 101))
WRONG_PORT_2=$((TCP_PORT + 102))
Expand All @@ -203,7 +210,7 @@ m4_define([OVSDB_CHECK_IDL_TCP6_PY],
AT_SKIP_IF([test "$IS_WIN32" = "yes"])
AT_SKIP_IF([test $HAVE_IPV6 = no])
AT_KEYWORDS([ovsdb server idl positive Python with tcp6 socket $5])
AT_CHECK([ovsdb_start_idltest "ptcp:0:[[::1]]"])
OVSDB_START_IDLTEST(["ptcp:0:[[::1]]"])
PARSE_LISTENING_PORT([ovsdb-server.log], [TCP_PORT])
echo "TCP_PORT=$TCP_PORT"

Expand All @@ -221,7 +228,7 @@ m4_define([OVSDB_CHECK_IDL_TCP6_MULTIPLE_REMOTES_PY],
AT_SKIP_IF([test "$IS_WIN32" = "yes"])
AT_SKIP_IF([test $HAVE_IPV6 = no])
AT_KEYWORDS([ovsdb server idl positive Python with tcp6 socket $5])
AT_CHECK([ovsdb_start_idltest "ptcp:0:[[::1]]"])
OVSDB_START_IDLTEST(["ptcp:0:[[::1]]"])
PARSE_LISTENING_PORT([ovsdb-server.log], [TCP_PORT])
WRONG_PORT_1=$((TCP_PORT + 101))
WRONG_PORT_2=$((TCP_PORT + 102))
Expand Down Expand Up @@ -287,13 +294,13 @@ m4_define([OVSDB_CHECK_IDL_PASSIVE_TCP_PY],
[AT_SETUP([$1 - Python3 - ptcp])
AT_KEYWORDS([ovsdb server idl positive Python with tcp socket $5])
# find free TCP port
AT_CHECK([ovsdb_start_idltest "ptcp:0:127.0.0.1"])
OVSDB_START_IDLTEST(["ptcp:0:127.0.0.1"])
PARSE_LISTENING_PORT([ovsdb-server.log], [TCP_PORT])
OVSDB_SERVER_SHUTDOWN
rm -f db

# start OVSDB server in passive mode
AT_CHECK([ovsdb_start_idltest "tcp:127.0.0.1:$TCP_PORT"])
OVSDB_START_IDLTEST(["tcp:127.0.0.1:$TCP_PORT"])
AT_CHECK([$PYTHON3 $srcdir/test-ovsdb.py -t10 idl_passive $srcdir/idltest.ovsschema ptcp:127.0.0.1:$TCP_PORT $3],
[0], [stdout], [ignore])
AT_CHECK([sort stdout | uuidfilt]m4_if([$6],,, [[| $6]]),
Expand Down Expand Up @@ -473,7 +480,7 @@ OVSDB_CHECK_IDL([simple idl, writing via IDL with unicode],
m4_define([OVSDB_CHECK_IDL_PY_WITH_EXPOUT],
[AT_SETUP([$1 - Python3])
AT_KEYWORDS([ovsdb server idl positive Python $5])
AT_CHECK([ovsdb_start_idltest])
OVSDB_START_IDLTEST
m4_if([$2], [], [],
[AT_CHECK([ovsdb-client transact unix:socket $2], [0], [ignore], [ignore])])
AT_CHECK([$PYTHON3 $srcdir/test-ovsdb.py -t10 idl $srcdir/idltest.ovsschema unix:socket $3],
Expand Down Expand Up @@ -990,7 +997,7 @@ AT_KEYWORDS([ovsdb server idl positive])
# table link2 and column l2 have been deleted. But the IDL still
# expects them to be there, so this test checks that it properly
# tolerates them being missing.
AT_CHECK([ovsdb_start_idltest "" "$abs_srcdir/idltest2.ovsschema"])
OVSDB_START_IDLTEST([], ["$abs_srcdir/idltest2.ovsschema"])
AT_CHECK([test-ovsdb '-vPATTERN:console:test-ovsdb|%c|%m' -vjsonrpc -t10 idl unix:socket ['["idltest",
{"op": "insert",
"table": "link1",
Expand Down Expand Up @@ -1063,7 +1070,7 @@ AT_CLEANUP
m4_define([OVSDB_CHECK_IDL_FETCH_COLUMNS_PY],
[AT_SETUP([$1 - Python3 - fetch])
AT_KEYWORDS([ovsdb server idl positive Python increment fetch $6])
AT_CHECK([ovsdb_start_idltest])
OVSDB_START_IDLTEST
m4_if([$2], [], [],
[AT_CHECK([ovsdb-client transact unix:socket $2], [0], [ignore], [ignore])])
AT_CHECK([$PYTHON3 $srcdir/test-ovsdb.py -t10 idl $srcdir/idltest.ovsschema unix:socket [$3] $4],
Expand Down Expand Up @@ -1107,7 +1114,7 @@ OVSDB_CHECK_IDL_FETCH_COLUMNS([simple idl, initially populated],
m4_define([OVSDB_CHECK_IDL_WO_MONITOR_COND_PY],
[AT_SETUP([$1 - Python3])
AT_KEYWORDS([ovsdb server idl Python monitor $4])
AT_CHECK([ovsdb_start_idltest])
OVSDB_START_IDLTEST
AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/disable-monitor-cond])
AT_CHECK([$PYTHON3 $srcdir/test-ovsdb.py -t10 idl $srcdir/idltest.ovsschema unix:socket $2],
[0], [stdout], [ignore])
Expand Down Expand Up @@ -1200,7 +1207,7 @@ OVSDB_CHECK_IDL_WO_MONITOR_COND([simple idl disable monitor-cond],
m4_define([OVSDB_CHECK_IDL_TRACK_C],
[AT_SETUP([$1 - C])
AT_KEYWORDS([ovsdb server idl tracking positive $5])
AT_CHECK([ovsdb_start_idltest])
OVSDB_START_IDLTEST
m4_if([$2], [], [],
[AT_CHECK([ovsdb-client transact unix:socket $2], [0], [ignore], [ignore])])
AT_CHECK([test-ovsdb '-vPATTERN:console:test-ovsdb|%c|%m' -vjsonrpc -t10 -c idl unix:socket $3],
Expand All @@ -1213,7 +1220,7 @@ m4_define([OVSDB_CHECK_IDL_TRACK_C],
m4_define([OVSDB_CHECK_IDL_TRACK_WRITE_CHANGED_ONLY_C],
[AT_SETUP([$1 - write-changed-only - C])
AT_KEYWORDS([ovsdb server idl tracking positive $5])
AT_CHECK([ovsdb_start_idltest])
OVSDB_START_IDLTEST
m4_if([$2], [], [],
[AT_CHECK([ovsdb-client transact unix:socket $2], [0], [ignore], [ignore])])
AT_CHECK([test-ovsdb '-vPATTERN:console:test-ovsdb|%c|%m' -vjsonrpc -t10 -c --write-changed-only idl unix:socket $3],
Expand Down Expand Up @@ -1766,7 +1773,7 @@ OVSDB_CHECK_IDL_TRACK([track, simple idl, initially empty, various ops],
m4_define([OVSDB_CHECK_IDL_PARTIAL_UPDATE_MAP_COLUMN],
[AT_SETUP([$1 - C])
AT_KEYWORDS([ovsdb server idl partial update map column positive $5])
AT_CHECK([ovsdb_start_idltest])
OVSDB_START_IDLTEST
m4_if([$2], [], [],
[AT_CHECK([ovsdb-client transact unix:socket $2], [0], [ignore], [ignore])])
AT_CHECK([test-ovsdb '-vPATTERN:console:test-ovsdb|%c|%m' -vjsonrpc -t10 -c idl-partial-update-map-column unix:socket $3],
Expand Down Expand Up @@ -1827,7 +1834,7 @@ OVSDB_CHECK_IDL_PY([partial-map update set refmap idl],
m4_define([OVSDB_CHECK_IDL_PARTIAL_UPDATE_SET_COLUMN],
[AT_SETUP([$1 - C])
AT_KEYWORDS([ovsdb server idl partial update set column positive $5])
AT_CHECK([ovsdb_start_idltest])
OVSDB_START_IDLTEST
m4_if([$2], [], [],
[AT_CHECK([ovsdb-client transact unix:socket $2], [0], [ignore], [ignore])])
AT_CHECK([test-ovsdb '-vPATTERN:console:test-ovsdb|%c|%m' -vjsonrpc -t10 -c idl-partial-update-set-column unix:socket $3],
Expand Down Expand Up @@ -2016,7 +2023,7 @@ OVSDB_CHECK_IDL_NOTIFY([simple idl verify notify],
m4_define([OVSDB_CHECK_IDL_COMPOUND_INDEX_SINGLE_COLUMN_C],
[AT_SETUP([$1 - C])
AT_KEYWORDS([ovsdb server idl compound_index_single_column compound_index positive $5])
AT_CHECK([ovsdb_start_idltest])
OVSDB_START_IDLTEST
m4_if([$2], [], [],
[AT_CHECK([ovsdb-client transact unix:socket $2], [0], [ignore], [ignore])])
# Generate the data to be tested.
Expand Down Expand Up @@ -2163,7 +2170,7 @@ OVSDB_CHECK_IDL_COMPOUND_INDEX_SINGLE_COLUMN_C([Compound_index, single column te
m4_define([OVSDB_CHECK_IDL_COMPOUND_INDEX_DOUBLE_COLUMN_C],
[AT_SETUP([$1 - C])
AT_KEYWORDS([ovsdb server idl compound_index_double_column compound_index positive $5])
AT_CHECK([ovsdb_start_idltest])
OVSDB_START_IDLTEST
m4_if([$2], [], [],
[AT_CHECK([ovsdb-client transact unix:socket $2], [0], [ignore], [ignore])])
# Generate the data to be tested.
Expand Down Expand Up @@ -2302,7 +2309,7 @@ OVSDB_CHECK_IDL_COMPOUND_INDEX_DOUBLE_COLUMN_C([Compound_index, double column te
m4_define([OVSDB_CHECK_IDL_COMPOUND_INDEX_WITH_REF],
[AT_SETUP([$1 - C])
AT_KEYWORDS([ovsdb server idl compound_index compound_index_with_ref positive $5])
AT_CHECK([ovsdb_start_idltest])
OVSDB_START_IDLTEST
m4_if([$2], [], [],
[AT_CHECK([ovsdb-client transact unix:socket $2], [0], [ignore], [ignore])])
AT_CHECK([test-ovsdb '-vPATTERN:console:test-ovsdb|%c|%m' -vjsonrpc -t10 -c idl-compound-index-with-ref unix:socket $3],
Expand Down Expand Up @@ -2330,7 +2337,7 @@ m4_define([CHECK_STREAM_OPEN_BLOCK],
AT_SKIP_IF([test "$3" = "tcp6" && test "$IS_WIN32" = "yes"])
AT_SKIP_IF([test "$3" = "tcp6" && test "$HAVE_IPV6" = "no"])
AT_KEYWORDS([ovsdb server stream open_block $3])
AT_CHECK([ovsdb_start_idltest "ptcp:0:$4"])
OVSDB_START_IDLTEST(["ptcp:0:$4"])
PARSE_LISTENING_PORT([ovsdb-server.log], [TCP_PORT])
WRONG_PORT=$(($TCP_PORT + 101))
AT_CHECK([$2 tcp:$4:$TCP_PORT], [0], [ignore])
Expand Down Expand Up @@ -2538,7 +2545,7 @@ reconnect.*waiting .* seconds before reconnect)

AT_SETUP([idl table and column presence check])
AT_KEYWORDS([ovsdb server idl table column check])
AT_CHECK([ovsdb_start_idltest "" "$abs_srcdir/idltest2.ovsschema"])
OVSDB_START_IDLTEST([], ["$abs_srcdir/idltest2.ovsschema"])

AT_CHECK(ovsdb-tool create db2 $abs_srcdir/idltest.ovsschema)
AT_CHECK(ovsdb-server -vconsole:warn --log-file=ovsdb-server2.log --detach dnl
Expand Down

0 comments on commit 2404ca5

Please sign in to comment.