diff options
author | Ilya Maximets <i.maximets@ovn.org> | 2021-05-27 15:29:06 +0200 |
---|---|---|
committer | Ilya Maximets <i.maximets@ovn.org> | 2021-06-07 21:03:16 +0200 |
commit | 4275b5b7fbb9437b265470670fa4aafb9acd8e23 (patch) | |
tree | 944753d5c8668dfdd6f33cf0072816e5975668a4 | |
parent | 0be15ad76f0f126d18257a8fe1d3753e76e57358 (diff) | |
download | openvswitch-4275b5b7fbb9437b265470670fa4aafb9acd8e23.tar.gz |
ovsdb-client: Integrate record/replay functionality.
This is primarily to be able to test recording of client connections.
Unit test added accordingly.
Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
Acked-by: Dumitru Ceara <dceara@redhat.com>
-rw-r--r-- | ovsdb/ovsdb-client.1.in | 2 | ||||
-rw-r--r-- | ovsdb/ovsdb-client.c | 5 | ||||
-rw-r--r-- | tests/ovsdb-client.at | 89 |
3 files changed, 96 insertions, 0 deletions
diff --git a/ovsdb/ovsdb-client.1.in b/ovsdb/ovsdb-client.1.in index ee329d2d7..91e0b3e25 100644 --- a/ovsdb/ovsdb-client.1.in +++ b/ovsdb/ovsdb-client.1.in @@ -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 @@ -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" . diff --git a/ovsdb/ovsdb-client.c b/ovsdb/ovsdb-client.c index ba28e36d7..ffa8f8df2 100644 --- a/ovsdb/ovsdb-client.c +++ b/ovsdb/ovsdb-client.c @@ -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" @@ -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'}, @@ -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); @@ -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); @@ -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"); diff --git a/tests/ovsdb-client.at b/tests/ovsdb-client.at index 5e3b26aea..06b671df8 100644 --- a/tests/ovsdb-client.at +++ b/tests/ovsdb-client.at @@ -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 |