From patchwork Mon Apr 12 22:00:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Maximets X-Patchwork-Id: 1465457 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=2605:bc80:3010::133; helo=smtp2.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp2.osuosl.org (smtp2.osuosl.org [IPv6:2605:bc80:3010::133]) (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 4FK2k33QBrz9sRK for ; Tue, 13 Apr 2021 08:00:59 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 11EDB40532; Mon, 12 Apr 2021 22:00:57 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 7UgECq6-b3gO; Mon, 12 Apr 2021 22:00:55 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp2.osuosl.org (Postfix) with ESMTP id C329040548; Mon, 12 Apr 2021 22:00:53 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 97F53C000C; Mon, 12 Apr 2021 22:00:53 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp3.osuosl.org (smtp3.osuosl.org [IPv6:2605:bc80:3010::136]) by lists.linuxfoundation.org (Postfix) with ESMTP id 1A400C000F for ; Mon, 12 Apr 2021 22:00:52 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 54EC060B13 for ; Mon, 12 Apr 2021 22:00:44 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id EboRubwN8ZLQ for ; Mon, 12 Apr 2021 22:00:43 +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 smtp3.osuosl.org (Postfix) with ESMTPS id D6BF360B32 for ; Mon, 12 Apr 2021 22:00:42 +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 75019E0014; Mon, 12 Apr 2021 22:00:40 +0000 (UTC) From: Ilya Maximets To: ovs-dev@openvswitch.org Date: Tue, 13 Apr 2021 00:00:18 +0200 Message-Id: <20210412220020.2286954-8-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 7/9] ovsdb-server.at: Add unit test for record/replay. 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" Signed-off-by: Ilya Maximets Acked-by: Dumitru Ceara --- tests/ovsdb-server.at | 149 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 149 insertions(+) diff --git a/tests/ovsdb-server.at b/tests/ovsdb-server.at index 926abce3a..de390fe3b 100644 --- a/tests/ovsdb-server.at +++ b/tests/ovsdb-server.at @@ -2014,3 +2014,152 @@ six 6 ]) AT_CLEANUP + +AT_BANNER([OVSDB -- ovsdb-server stream record/replay]) + +AT_SETUP([ovsdb-server record/replay]) +AT_KEYWORDS([ovsdb server record replay]) +on_exit 'kill `cat *.pid`' +ordinal_schema > schema +AT_CHECK([ovsdb-tool create db schema], [0], [ignore], [ignore]) + +dnl Create a directory for replay files. +AT_CHECK([mkdir replay_dir]) + +dnl Make a copy of a database for later replay. +AT_CHECK([cp db ./replay_dir/db.copy]) + +dnl Starting a dummy server only to reserve some tcp port. +AT_CHECK([cp db db.tmp]) +AT_CHECK([ovsdb-server -vfile -vvlog:off --log-file=listener.log dnl + --detach --no-chdir dnl + --pidfile=pid2 --unixctl=unixctl2 dnl + --remote=ptcp:0:127.0.0.1 dnl + db.tmp], [0], [stdout], [stderr]) +PARSE_LISTENING_PORT([listener.log], [BAD_TCP_PORT]) + +dnl Start ovsdb-server with recording enabled. +dnl Trying to start a tcp session on already used port to record the error. +AT_CHECK([ovsdb-server --replay-record=./replay_dir dnl + -vfile -vvlog:off -vjsonrpc:file:dbg --log-file=1.log dnl + --detach --no-chdir --pidfile dnl + --remote=punix:db.sock dnl + --remote=ptcp:$BAD_TCP_PORT:127.0.0.1 dnl + --remote=ptcp:0:127.0.0.1 dnl + db], [0], [stdout], [stderr]) +CHECK_DBS([ordinals +]) +PARSE_LISTENING_PORT([1.log], [TCP_PORT]) + +dnl Start a monitor on the 'ordinals' db to check recording of this kind +dnl of messages. +AT_CHECK([ovsdb-client -vfile -vvlog:off --detach --no-chdir dnl + --pidfile=monitor.pid --log-file=monitor.log dnl + --db-change-aware --no-headings dnl + monitor tcp:127.0.0.1:$TCP_PORT dnl + ordinals ordinals number name dnl + > monitor.stdout 2> monitor.stderr]) +OVS_WAIT_UNTIL([test -e monitor.pid]) + +dnl Do a bunch of random transactions. +AT_CHECK( + [[for pair in 'zero 0' 'one 1' 'two 2' 'three 3' 'four 4' 'five 5'; do + set -- $pair + if test "$2" -eq "5"; then + # killing the monitor to check if this correctly recorded. + kill -9 $(cat monitor.pid) + fi + ovsdb-client --db-change-aware transact unix:db.sock ' + ["ordinals", + {"op": "insert", + "table": "ordinals", + "row": {"name": "'$1'", "number": '$2'}}, + {"op": "comment", + "comment": "add row for '"$pair"'"}]' + ovsdb-client transact unix:db.sock ' + ["ordinals", + {"op": "delete", + "table": "ordinals", + "where": [["number", "==", '$2']]}, + {"op": "comment", + "comment": "delete row for '"$2"'"}]' + ovsdb-client transact unix:db.sock ' + ["ordinals", + {"op": "insert", + "table": "ordinals", + "row": {"name": "'$1'", "number": '$2'}}, + {"op": "comment", + "comment": "add back row for '"$pair"'"}]' + done]], + [0], [stdout]) + +AT_CHECK([ovsdb-client dump unix:db.sock ordinals | uuidfilt], 0, [dnl +ordinals table +_uuid name number +------------------------------------ ----- ------ +<0> five 5 +<1> four 4 +<2> one 1 +<3> three 3 +<4> two 2 +<5> zero 0 +]) + +AT_CHECK([uuidfilt monitor.stdout | sed '/^$/d'], [0], [dnl +<0> insert 0 zero +<0> delete 0 zero +<1> insert 0 zero +<2> insert 1 one +<2> delete 1 one +<3> insert 1 one +<4> insert 2 two +<4> delete 2 two +<5> insert 2 two +<6> insert 3 three +<6> delete 3 three +<7> insert 3 three +<8> insert 4 four +<8> delete 4 four +<9> insert 4 four +]) +OVSDB_SERVER_SHUTDOWN +OVSDB_SERVER_SHUTDOWN2 + +dnl Starting a replay. +AT_CHECK([ovsdb-server --replay=./replay_dir dnl + -vfile -vvlog:off -vjsonrpc:file:dbg --log-file=2.log dnl + --detach --no-chdir --pidfile dnl + --remote=punix:db.sock dnl + --remote=ptcp:$BAD_TCP_PORT:127.0.0.1 dnl + --remote=ptcp:0:127.0.0.1 dnl + ./replay_dir/db.copy], [0], [stdout], [stderr]) + +dnl Waiting for process termination. Process should exit after correct +dnl processing of the 'exit' unixctl command from the recorded session. +OVS_WAIT_WHILE([test -e ovsdb-server.pid]) + +dnl Stripping out timestamps from database files. Also clearing record +dnl hashes in database files, since dates inside are different. +m4_define([CLEAN_DB_FILE], + [sed 's/\(OVSDB JSON [[0-9]]*\).*$/\1/g' $1 | dnl + sed 's/"_date":[[0-9]]*/"_date":/g' > $2]) + +CLEAN_DB_FILE([db], [db.clear]) +CLEAN_DB_FILE([./replay_dir/db.copy], [./replay_dir/db.copy.clear]) + +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([1.log], [1.log.clear]) +CLEAN_LOG_FILE([2.log], [2.log.clear]) + +dnl Checking that databases and logs are equal. +AT_CHECK([diff db.clear ./replay_dir/db.copy.clear]) +AT_CHECK([diff 1.log.clear 2.log.clear]) + +AT_CLEANUP