From patchwork Tue Nov 24 22:16:06 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Zhou X-Patchwork-Id: 548320 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from archives.nicira.com (li376-54.members.linode.com [96.126.127.54]) by ozlabs.org (Postfix) with ESMTP id 045B21402A8 for ; Wed, 25 Nov 2015 09:17:16 +1100 (AEDT) Received: from archives.nicira.com (localhost [127.0.0.1]) by archives.nicira.com (Postfix) with ESMTP id 877DD10A51; Tue, 24 Nov 2015 14:16:36 -0800 (PST) X-Original-To: dev@openvswitch.org Delivered-To: dev@openvswitch.org Received: from mx3v3.cudamail.com (mx3.cudamail.com [64.34.241.5]) by archives.nicira.com (Postfix) with ESMTPS id 6C9D910A49 for ; Tue, 24 Nov 2015 14:16:34 -0800 (PST) Received: from bar3.cudamail.com (localhost [127.0.0.1]) by mx3v3.cudamail.com (Postfix) with ESMTPS id F34C9161983 for ; Tue, 24 Nov 2015 15:16:33 -0700 (MST) X-ASG-Debug-ID: 1448403393-03dd7b4647350de0001-byXFYA Received: from mx3-pf2.cudamail.com ([192.168.14.1]) by bar3.cudamail.com with ESMTP id Hyg2lctaUKg8WCFC (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Tue, 24 Nov 2015 15:16:33 -0700 (MST) X-Barracuda-Envelope-From: azhou.ovn@gmail.com X-Barracuda-RBL-Trusted-Forwarder: 192.168.14.1 Received: from unknown (HELO mail-pa0-f41.google.com) (209.85.220.41) by mx3-pf2.cudamail.com with ESMTPS (RC4-SHA encrypted); 24 Nov 2015 22:16:33 -0000 Received-SPF: pass (mx3-pf2.cudamail.com: SPF record at _netblocks.google.com designates 209.85.220.41 as permitted sender) X-Barracuda-RBL-Trusted-Forwarder: 209.85.220.41 Received: by pacej9 with SMTP id ej9so34924555pac.2 for ; Tue, 24 Nov 2015 14:16:32 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=5gJm5a4w4uI5RvC+zRZE0Yky3SXCUR82/vIuFxDAdXg=; b=d+8sQKFfVECG4WarqCQi8+Y4qsigELbtg5Gzooj1Dvr2b2N8M2IJCIcKbR5P97HUv8 035aJQEGGL+du6BSSlt0YYkClES35TGqYeuxm1yYHftV77+bXgf21b0Q1cddGKoF3Y7i fm/vTnmOYBT8l3Gmlyb3E+UX1AO81bmSFw1hCwG87bAyrix/N1kUYb53fbo2OXSO84of YS2vnToExKYx7ZRLJZ/Kep2leSLTujGStyEXBIX+4hRmDdRb9TSyugZRX10rmRo7z5Mb qgLnlu1Xbq/23KPVS1BLRmP/Uiw7F9lMNFWBN3t8XAA08gDYoCUqDtojyxkAKgRhF0Bc NnHw== X-Received: by 10.98.43.18 with SMTP id r18mr26600226pfr.2.1448403392044; Tue, 24 Nov 2015 14:16:32 -0800 (PST) Received: from ubuntu.localdomain ([208.91.1.34]) by smtp.gmail.com with ESMTPSA id b15sm16374570pfj.7.2015.11.24.14.16.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 24 Nov 2015 14:16:31 -0800 (PST) X-CudaMail-Envelope-Sender: azhou.ovn@gmail.com X-Barracuda-Apparent-Source-IP: 208.91.1.34 From: Andy Zhou To: dev@openvswitch.org X-CudaMail-Whitelist-To: dev@openvswitch.org X-CudaMail-MID: CM-V2-1123060694 X-CudaMail-DTE: 112415 X-CudaMail-Originating-IP: 209.85.220.41 Date: Tue, 24 Nov 2015 14:16:06 -0800 X-ASG-Orig-Subj: [##CM-V2-1123060694##][monitor2 v2 9/9] ovsdb: test ovs-vswitchd for backward compatibility Message-Id: <1448403366-21460-9-git-send-email-azhou@ovn.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1448403366-21460-1-git-send-email-azhou@ovn.org> References: <1448403366-21460-1-git-send-email-azhou@ovn.org> X-Barracuda-Connect: UNKNOWN[192.168.14.1] X-Barracuda-Start-Time: 1448403393 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://web.cudamail.com:443/cgi-mod/mark.cgi X-ASG-Whitelist: Header =?UTF-8?B?eFwtY3VkYW1haWxcLXdoaXRlbGlzdFwtdG8=?= X-Virus-Scanned: by bsmtpd at cudamail.com X-Barracuda-BRTS-Status: 1 Subject: [ovs-dev] [monitor2 v2 9/9] ovsdb: test ovs-vswitchd for backward compatibility X-BeenThere: dev@openvswitch.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dev-bounces@openvswitch.org Sender: "dev" From: Andy Zhou Add test to make sure ovs-vswitchd fall back to use the "monitor" method when connecting to an older ovsdb-server that does not support "monitor2". For testing backward compatibility, add an ovs-appctl command: "ovsdb-server/disable-monitor2". This command will restart all currently open jsonrpc connections, but without support for 'monitor2' JSON-RPC method for the new connections. There is no corresponding enable command, since this feature is only useful for testing. 'monitor2' will be available when ovsdb-server restarts. Signed-off-by: Andy Zhou Acked-by: Ben Pfaff --- v1->v2: no change --- ovsdb/jsonrpc-server.c | 13 ++++++++++++- ovsdb/jsonrpc-server.h | 1 + ovsdb/ovsdb-server.c | 20 ++++++++++++++++++++ tests/ovs-vswitchd.at | 24 ++++++++++++++++++++++++ 4 files changed, 57 insertions(+), 1 deletion(-) diff --git a/ovsdb/jsonrpc-server.c b/ovsdb/jsonrpc-server.c index 53c97cd..1dcd394 100644 --- a/ovsdb/jsonrpc-server.c +++ b/ovsdb/jsonrpc-server.c @@ -45,6 +45,10 @@ VLOG_DEFINE_THIS_MODULE(ovsdb_jsonrpc_server); struct ovsdb_jsonrpc_remote; struct ovsdb_jsonrpc_session; +/* Set false to defeature monitor2, causing jsonrpc to respond to monitor2 + * method with an error. */ +static bool monitor2_enable__ = true; + /* Message rate-limiting. */ static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5); @@ -845,7 +849,7 @@ ovsdb_jsonrpc_session_got_request(struct ovsdb_jsonrpc_session *s, reply = execute_transaction(s, db, request); } } else if (!strcmp(request->method, "monitor") || - !strcmp(request->method, "monitor2")) { + (monitor2_enable__ && !strcmp(request->method, "monitor2"))) { struct ovsdb *db = ovsdb_jsonrpc_lookup_db(s, request, &reply); if (!reply) { int l = strlen(request->method) - strlen("monitor"); @@ -1368,3 +1372,10 @@ ovsdb_jsonrpc_monitor_flush_all(struct ovsdb_jsonrpc_session *s) } } } + +void +ovsdb_jsonrpc_disable_monitor2() +{ + /* Once disabled, it is not possible to re-enable it. */ + monitor2_enable__ = false; +} diff --git a/ovsdb/jsonrpc-server.h b/ovsdb/jsonrpc-server.h index fce8b7b..7a0bd31 100644 --- a/ovsdb/jsonrpc-server.h +++ b/ovsdb/jsonrpc-server.h @@ -71,5 +71,6 @@ void ovsdb_jsonrpc_server_get_memory_usage(const struct ovsdb_jsonrpc_server *, struct ovsdb_jsonrpc_monitor; void ovsdb_jsonrpc_monitor_destroy(struct ovsdb_jsonrpc_monitor *); +void ovsdb_jsonrpc_disable_monitor2(void); #endif /* ovsdb/jsonrpc-server.h */ diff --git a/ovsdb/ovsdb-server.c b/ovsdb/ovsdb-server.c index 97b65b6..25fa9c6 100644 --- a/ovsdb/ovsdb-server.c +++ b/ovsdb/ovsdb-server.c @@ -79,6 +79,7 @@ static unixctl_cb_func ovsdb_server_compact; static unixctl_cb_func ovsdb_server_reconnect; static unixctl_cb_func ovsdb_server_perf_counters_clear; static unixctl_cb_func ovsdb_server_perf_counters_show; +static unixctl_cb_func ovsdb_server_disable_monitor2; struct server_config { struct sset *remotes; @@ -329,6 +330,11 @@ main(int argc, char *argv[]) unixctl_command_register("ovsdb-server/perf-counters-clear", "", 0, 0, ovsdb_server_perf_counters_clear, NULL); + /* Simulate the behavior of OVS release prior to version 2.5 that + * does not support the monitor2 method. */ + unixctl_command_register("ovsdb-server/disable-monitor2", "", 0, 0, + ovsdb_server_disable_monitor2, jsonrpc); + main_loop(jsonrpc, &all_dbs, unixctl, &remotes, run_process, &exiting); ovsdb_jsonrpc_server_destroy(jsonrpc); @@ -1052,6 +1058,20 @@ ovsdb_server_perf_counters_clear(struct unixctl_conn *conn, int argc OVS_UNUSED, unixctl_command_reply(conn, NULL); } +/* "ovsdb-server/disable-monitor2": makes ovsdb-server drop all of its + * JSON-RPC connections and reconnect. New sessions will not recognize + * the 'monitor2' method. */ +static void +ovsdb_server_disable_monitor2(struct unixctl_conn *conn, int argc OVS_UNUSED, + const char *argv[] OVS_UNUSED, void *jsonrpc_) +{ + struct ovsdb_jsonrpc_server *jsonrpc = jsonrpc_; + + ovsdb_jsonrpc_disable_monitor2(); + ovsdb_jsonrpc_server_reconnect(jsonrpc); + unixctl_command_reply(conn, NULL); +} + static void ovsdb_server_compact(struct unixctl_conn *conn, int argc, const char *argv[], void *dbs_) diff --git a/tests/ovs-vswitchd.at b/tests/ovs-vswitchd.at index 8c2b2e0..492b944 100644 --- a/tests/ovs-vswitchd.at +++ b/tests/ovs-vswitchd.at @@ -163,3 +163,27 @@ OVS_WAIT_UNTIL([test -n "`grep ERR ovs-vswitchd.log | grep overwrite.file`"]) OVS_VSWITCHD_STOP(["/Not adding Unix domain socket controller/d"]) AT_CLEANUP + +dnl ---------------------------------------------------------------------- +dnl OVSDB server before release version 2.5 does not support the monitor2 +dnl method. This test defeatures the OVSDB server to simulate an older +dnl OVSDB server and make sure ovs-vswitchd can still work with it +AT_SETUP([ovs-vswitchd -- Compatible with OVSDB server - w/o monitor2)]) +OVS_VSWITCHD_START + +dnl defeature OVSDB server -- no monitor2 +AT_CHECK([ovs-appctl -t ovsdb-server ovsdb-server/disable-monitor2]) + +sleep 1 + +AT_CHECK([ovs-vsctl add-port br0 p0 -- set interface p0 type=internal]) +AT_CHECK([ovs-vsctl add-port br0 p1 -- set interface p1 type=internal]) + +dnl ovs-vswitchd should still 'see' ovsdb change with the 'monitor' method +AT_CHECK([ovs-appctl dpif/show | tail -n +3], [0], [dnl + br0 65534/100: (dummy) + p0 1/1: (dummy) + p1 2/2: (dummy) +]) +OVS_VSWITCHD_STOP +AT_CLEANUP