From patchwork Mon Apr 12 22:00:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Maximets X-Patchwork-Id: 1465459 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.137; helo=smtp4.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp4.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FK2kV0dDYz9sRK for ; Tue, 13 Apr 2021 08:01:22 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 93CAC405B8; Mon, 12 Apr 2021 22:01:20 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id KGoHl1Br-3wJ; Mon, 12 Apr 2021 22:01:19 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp4.osuosl.org (Postfix) with ESMTP id 822E440644; Mon, 12 Apr 2021 22:01:18 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 59776C000A; Mon, 12 Apr 2021 22:01:18 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by lists.linuxfoundation.org (Postfix) with ESMTP id 2DC3EC000F for ; Mon, 12 Apr 2021 22:01:17 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 73CA683DE6 for ; Mon, 12 Apr 2021 22:00:49 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id c2dbA1Oof3g4 for ; Mon, 12 Apr 2021 22:00:46 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) by smtp1.osuosl.org (Postfix) with ESMTPS id 4E73283E07 for ; Mon, 12 Apr 2021 22:00:44 +0000 (UTC) X-Originating-IP: 78.45.89.65 Received: from im-t490s.redhat.com (ip-78-45-89-65.net.upcbroadband.cz [78.45.89.65]) (Authenticated sender: i.maximets@ovn.org) by relay4-d.mail.gandi.net (Postfix) with ESMTPSA id C8461E0013; Mon, 12 Apr 2021 22:00:42 +0000 (UTC) From: Ilya Maximets To: ovs-dev@openvswitch.org Date: Tue, 13 Apr 2021 00:00:19 +0200 Message-Id: <20210412220020.2286954-9-i.maximets@ovn.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210412220020.2286954-1-i.maximets@ovn.org> References: <20210412220020.2286954-1-i.maximets@ovn.org> MIME-Version: 1.0 Cc: Ilya Maximets , Dumitru Ceara Subject: [ovs-dev] [PATCH v2 8/9] ovsdb-client: Integrate record/replay functionality. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" This is primarily to be able to test recording of client connections. Unit test added accordingly. Signed-off-by: Ilya Maximets Acked-by: Dumitru Ceara --- ovsdb/ovsdb-client.1.in | 2 + ovsdb/ovsdb-client.c | 5 +++ tests/ovsdb-client.at | 89 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 96 insertions(+) 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..e4f1fcfc4 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 --replay-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/\.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