Skip to content

Commit

Permalink
ovsdb-client: Integrate record/replay functionality.
Browse files Browse the repository at this point in the history
This is primarily to be able to test recording of client connections.
Unit test added accordingly.

Signed-off-by: Ilya Maximets <[email protected]>
Acked-by: Dumitru Ceara <[email protected]>
  • Loading branch information
igsilya committed Jun 7, 2021
1 parent 0be15ad commit 4275b5b
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ovsdb/ovsdb-client.1.in
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ ovsdb\-client \- command-line interface to \fBovsdb-server\fR(1)
.so lib/ssl-syn.man
.so lib/ssl-bootstrap-syn.man
.so lib/ssl-connect-syn.man
.so lib/ovs-replay-syn.man
.so lib/common-syn.man
.
.SH DESCRIPTION
Expand Down Expand Up @@ -370,6 +371,7 @@ effect.
.SS "SSL Connection Options"
.so lib/ssl-connect.man
.SS "Other Options"
.so lib/ovs-replay.man
.so lib/common.man
.SH "SEE ALSO"
.
Expand Down
5 changes: 5 additions & 0 deletions ovsdb/ovsdb-client.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "jsonrpc.h"
#include "lib/table.h"
#include "log.h"
#include "ovs-replay.h"
#include "ovsdb.h"
#include "ovsdb-data.h"
#include "ovsdb-error.h"
Expand Down Expand Up @@ -307,6 +308,7 @@ parse_options(int argc, char *argv[])
DAEMON_OPTION_ENUMS,
TABLE_OPTION_ENUMS,
SSL_OPTION_ENUMS,
OVS_REPLAY_OPTION_ENUMS,
};
static const struct option long_options[] = {
{"help", no_argument, NULL, 'h'},
Expand All @@ -325,6 +327,7 @@ parse_options(int argc, char *argv[])
STREAM_SSL_LONG_OPTIONS,
#endif
TABLE_LONG_OPTIONS,
OVS_REPLAY_LONG_OPTIONS,
{NULL, 0, NULL, 0},
};
char *short_options = ovs_cmdl_long_options_to_short_options(long_options);
Expand Down Expand Up @@ -352,6 +355,7 @@ parse_options(int argc, char *argv[])
DAEMON_OPTION_HANDLERS
TABLE_OPTION_HANDLERS(&table_style)
STREAM_SSL_OPTION_HANDLERS
OVS_REPLAY_OPTION_HANDLERS

case OPT_BOOTSTRAP_CA_CERT:
stream_ssl_set_ca_cert_file(optarg, true);
Expand Down Expand Up @@ -467,6 +471,7 @@ usage(void)
printf(" --timestamp timestamp \"monitor\" output");
daemon_usage();
vlog_usage();
ovs_replay_usage();
printf("\nOther options:\n"
" -h, --help display this help message\n"
" -V, --version display version information\n");
Expand Down
89 changes: 89 additions & 0 deletions tests/ovsdb-client.at
Original file line number Diff line number Diff line change
Expand Up @@ -195,3 +195,92 @@ _uuid,name,number
OVS_APP_EXIT_AND_WAIT([ovsdb-server])

AT_CLEANUP

AT_SETUP([ovsdb-client record/replay])
AT_KEYWORDS([ovsdb client record replay])

on_exit 'kill `cat *.pid`'

dnl Create a database.
ordinal_schema > schema
touch .db.~lock~
AT_CHECK([ovsdb-tool create db schema])

dnl Start the database server.
AT_CHECK([ovsdb-server -vfile -vvlog:off --detach --no-chdir --pidfile dnl
--log-file --remote=punix:db.sock db], [0])
AT_CAPTURE_FILE([ovsdb-server.log])

dnl Start a monitor on the 'ordinals' db with recording enabled.
AT_CHECK([mkdir replay_dir])
AT_CHECK([ovsdb-client --record=./replay_dir dnl
-vfile -vvlog:off --detach --no-chdir dnl
--pidfile --log-file=monitor.log dnl
--db-change-aware --no-headings dnl
monitor unix:db.sock dnl
ordinals ordinals number name dnl
> monitor.stdout 2> monitor.stderr])
AT_CAPTURE_FILE([monitor.log])

dnl Put some data in the database.
AT_CHECK(
[[for txn in 'transact zero 0' \
'transact two 2' \
'transact four 4'
do
set -- $txn
ovsdb-client $1 '
["ordinals",
{"op": "insert",
"table": "ordinals",
"row": {"name": "'$2'", "number": '$3'}},
{"op": "comment",
"comment": "add row for '"$pair"'"}]'
done | uuidfilt]], [0],
[[[{"uuid":["uuid","<0>"]},{}]
[{"uuid":["uuid","<1>"]},{}]
[{"uuid":["uuid","<2>"]},{}]
]], [ignore])

AT_CHECK([ovsdb-client -f csv dump | sort -t, -k 3 | uuidfilt], [0], [dnl
ordinals table
<0>,zero,0
<1>,two,2
<2>,four,4
_uuid,name,number
])

dnl Stopping the server.
OVS_APP_EXIT_AND_WAIT([ovsdb-server])
dnl ovsdb-client should exit by itself after disconnection form the server.
OVS_WAIT_WHILE([test -e ovsdb-client.pid])

dnl Starting replay.
AT_CHECK([ovsdb-client --replay=./replay_dir dnl
-vfile -vvlog:off --detach --no-chdir dnl
--pidfile --log-file=monitor-replay.log dnl
--db-change-aware --no-headings dnl
monitor unix:db.sock dnl
ordinals ordinals number name dnl
> monitor-replay.stdout 2> monitor-replay.stderr])

dnl Waiting for client to exit the same way as it exited during recording.
OVS_WAIT_WHILE([test -e ovsdb-client.pid])

AT_CHECK([diff monitor.stdout monitor-replay.stdout])
AT_CHECK([diff monitor.stderr monitor-replay.stderr])

dnl Stripping out timestamps, PIDs and poll_loop warnings from the log.
dnl Also stripping socket_util errors as sockets are not used in replay.
m4_define([CLEAN_LOG_FILE],
[sed 's/[[0-9\-]]*T[[0-9:\.]]*Z|[[0-9]]*\(|.*$\)/\1/g' $1 | dnl
sed '/|poll_loop|/d' | dnl
sed '/|socket_util|/d' | dnl
sed 's/[[0-9]]*\.ctl/<cleared>\.ctl/g'> $2])

CLEAN_LOG_FILE([monitor.log], [monitor.log.clear])
CLEAN_LOG_FILE([monitor-replay.log], [monitor-replay.log.clear])

AT_CHECK([diff monitor.log.clear monitor-replay.log.clear])

AT_CLEANUP

0 comments on commit 4275b5b

Please sign in to comment.