From patchwork Tue Feb 26 14:25:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Michelson X-Patchwork-Id: 1048395 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4481Zx5jn0z9sCH for ; Wed, 27 Feb 2019 01:36:09 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 083AF7935; Tue, 26 Feb 2019 14:35:43 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id BDFCE791F for ; Tue, 26 Feb 2019 14:26:02 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 408C2826 for ; Tue, 26 Feb 2019 14:26:02 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C2437C05A1D9 for ; Tue, 26 Feb 2019 14:26:01 +0000 (UTC) Received: from monae.redhat.com (ovpn-121-115.rdu2.redhat.com [10.10.121.115]) by smtp.corp.redhat.com (Postfix) with ESMTP id 57E7C2899B for ; Tue, 26 Feb 2019 14:26:01 +0000 (UTC) From: Mark Michelson To: dev@openvswitch.org Date: Tue, 26 Feb 2019 09:25:59 -0500 Message-Id: <20190226142600.3542-2-mmichels@redhat.com> In-Reply-To: <20190226142600.3542-1-mmichels@redhat.com> References: <20190226142600.3542-1-mmichels@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 26 Feb 2019 14:26:01 +0000 (UTC) X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [PATCH 2.10 v2 1/2] table: Create method for resetting table formatting. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org Table formatting has a local static integer that is intended to insert line breaks between tables. This works exactly as intended, as long as each call to table_format() is done as a single unit within the run of a process. When ovn-nbctl is run in daemon mode, it is a long-running process that makes multiple calls to table_format() throughout its lifetime. After the first call, this results in an unexpected newline prepended to table output on each subsequent ovn-nbctl invocation. The solution is to introduce a function to reset table formatting. This way, the first time after resetting table formatting, no newline is prepended. Signed-off-by: Mark Michelson Signed-off-by: Ben Pfaff Acked-by: Numan Siddique --- lib/table.c | 23 +++++++++++++++++------ lib/table.h | 1 + ovn/utilities/ovn-nbctl.c | 1 + tests/ovn-nbctl.at | 13 +++++++++++++ 4 files changed, 32 insertions(+), 6 deletions(-) diff --git a/lib/table.c b/lib/table.c index ab72668c7..48d18b651 100644 --- a/lib/table.c +++ b/lib/table.c @@ -236,15 +236,18 @@ table_print_timestamp__(const struct table *table, struct ds *s) } } +static bool first_table = true; + static void table_print_table__(const struct table *table, const struct table_style *style, struct ds *s) { - static int n = 0; int *widths; size_t x, y; - if (n++ > 0) { + if (first_table) { + first_table = false; + } else { ds_put_char(s, '\n'); } @@ -318,10 +321,11 @@ static void table_print_list__(const struct table *table, const struct table_style *style, struct ds *s) { - static int n = 0; size_t x, y; - if (n++ > 0) { + if (first_table) { + first_table = false; + } else { ds_put_char(s, '\n'); } @@ -469,10 +473,11 @@ static void table_print_csv__(const struct table *table, const struct table_style *style, struct ds *s) { - static int n = 0; size_t x, y; - if (n++ > 0) { + if (first_table) { + first_table = false; + } else { ds_put_char(s, '\n'); } @@ -614,6 +619,12 @@ table_format(const struct table *table, const struct table_style *style, } } +void +table_format_reset(void) +{ + first_table = true; +} + /* Outputs 'table' on stdout in the specified 'style'. */ void table_print(const struct table *table, const struct table_style *style) diff --git a/lib/table.h b/lib/table.h index 76e65bb70..33263e2a2 100644 --- a/lib/table.h +++ b/lib/table.h @@ -133,6 +133,7 @@ void table_parse_cell_format(struct table_style *, const char *format); void table_print(const struct table *, const struct table_style *); void table_format(const struct table *, const struct table_style *, struct ds *); +void table_format_reset(void); void table_usage(void); #endif /* table.h */ diff --git a/ovn/utilities/ovn-nbctl.c b/ovn/utilities/ovn-nbctl.c index 09bbcf76a..b5ee0a6e1 100644 --- a/ovn/utilities/ovn-nbctl.c +++ b/ovn/utilities/ovn-nbctl.c @@ -5231,6 +5231,7 @@ server_cmd_run(struct unixctl_conn *conn, int argc, const char **argv_, } struct ds output = DS_EMPTY_INITIALIZER; + table_format_reset(); for (struct ctl_command *c = commands; c < &commands[n_commands]; c++) { if (c->table) { table_format(c->table, &table_style, &output); diff --git a/tests/ovn-nbctl.at b/tests/ovn-nbctl.at index a599b1bf7..7d627cdc0 100644 --- a/tests/ovn-nbctl.at +++ b/tests/ovn-nbctl.at @@ -1517,3 +1517,16 @@ AT_CHECK([ovn-nbctl create Port_Group name=pg0], [0], [ignore]) AT_CHECK([ovn-nbctl get Port_Group pg0 name], [0], [dnl "pg0" ])]) + + +OVN_NBCTL_TEST([ovn_nbctl_extra_newlines], [extra newlines], [ +dnl This test addresses a specific issue seen when running ovn-nbctl in +dnl daemon mode. All we have to do is ensure that each time we list database +dnl information, there is not an extra newline at the beginning of the output. +AT_CHECK([ovn-nbctl ls-add sw1], [0], [ignore]) +AT_CHECK([ovn-nbctl --columns=name list logical_switch sw1], [0], [dnl +name : "sw1" +]) +AT_CHECK([ovn-nbctl --columns=name list logical_switch sw1], [0], [dnl +name : "sw1" +])]) From patchwork Tue Feb 26 14:26:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Michelson X-Patchwork-Id: 1048396 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4481bS4h7Qz9sBL for ; Wed, 27 Feb 2019 01:36:36 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id DA919793A; Tue, 26 Feb 2019 14:35:43 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id EFA90791F for ; Tue, 26 Feb 2019 14:26:02 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 9F0EF828 for ; Tue, 26 Feb 2019 14:26:02 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4E2BB68557 for ; Tue, 26 Feb 2019 14:26:02 +0000 (UTC) Received: from monae.redhat.com (ovpn-121-115.rdu2.redhat.com [10.10.121.115]) by smtp.corp.redhat.com (Postfix) with ESMTP id EEF62289A9 for ; Tue, 26 Feb 2019 14:26:01 +0000 (UTC) From: Mark Michelson To: dev@openvswitch.org Date: Tue, 26 Feb 2019 09:26:00 -0500 Message-Id: <20190226142600.3542-3-mmichels@redhat.com> In-Reply-To: <20190226142600.3542-1-mmichels@redhat.com> References: <20190226142600.3542-1-mmichels@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 26 Feb 2019 14:26:02 +0000 (UTC) X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [PATCH 2.10 v2 2/2] ovn-nbctl: Don't parse table-formatting options in nbctl_client X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org When ovn-nbctl is running in daemon mode, nbctl_client attempts to parse table formatting options. The problem is that this then removes the table formatting options from the array of options passed to the server loop. The server loop resets the table formatting options to the defaults and then attempts again to parse table formatting options. Unfortunately, they aren't present any longer. The result is that tables are always formatted with the default style. This patch solves the issue by not parsing the table formatting options in nbctl_client. Instead, the table formatting options are passed to the server loop and parsed there instead. Signed-off-by: Mark Michelson Signed-off-by: Ben Pfaff Acked-by: Numan Siddique --- ovn/utilities/ovn-nbctl.c | 1 - tests/ovn-nbctl.at | 9 +++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/ovn/utilities/ovn-nbctl.c b/ovn/utilities/ovn-nbctl.c index b5ee0a6e1..206f3b3eb 100644 --- a/ovn/utilities/ovn-nbctl.c +++ b/ovn/utilities/ovn-nbctl.c @@ -5365,7 +5365,6 @@ nbctl_client(const char *socket_name, break; VLOG_OPTION_HANDLERS - TABLE_OPTION_HANDLERS(&table_style) case OPT_LOCAL: default: diff --git a/tests/ovn-nbctl.at b/tests/ovn-nbctl.at index 7d627cdc0..3f89874ba 100644 --- a/tests/ovn-nbctl.at +++ b/tests/ovn-nbctl.at @@ -1530,3 +1530,12 @@ name : "sw1" AT_CHECK([ovn-nbctl --columns=name list logical_switch sw1], [0], [dnl name : "sw1" ])]) + +OVN_NBCTL_TEST([ovn_nbctl_table_formatting], [table formatting], [ +dnl This test addresses a specific issue seen when running ovn-nbctl in +dnl daemon mode. We need to ensure that table formatting options are honored +dnl when listing database information. +AT_CHECK([ovn-nbctl ls-add sw1], [0], [ignore]) +AT_CHECK([ovn-nbctl --bare --columns=name list logical_switch sw1], [0], [dnl +sw1 +])])