From patchwork Tue Jul 17 13:34:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Sitnicki X-Patchwork-Id: 945044 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 41VLq624sFz9rvt for ; Tue, 17 Jul 2018 23:34:25 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 98F9FCBE; Tue, 17 Jul 2018 13:34:22 +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 E08A4CBB for ; Tue, 17 Jul 2018 13:34:20 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-wr1-f51.google.com (mail-wr1-f51.google.com [209.85.221.51]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 2C6B9711 for ; Tue, 17 Jul 2018 13:34:20 +0000 (UTC) Received: by mail-wr1-f51.google.com with SMTP id c13-v6so1312090wrt.1 for ; Tue, 17 Jul 2018 06:34:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=pxCkanAygDC1kZ9s4Ej69x26mf2vkF+wJfbRvmGfP3Q=; b=alwSiW1AKGt/sDm8P4it0QmJkZdPGoWlxpExCbRPwnPqoDklEF1K9DNxKBNTSbOJuY sC6r+azptDekxQHctnRXzJHSdOuk+XC75qJgWYO+x1ZX2OhpBPC1LONVFoRO5kIv8j1g Xe9rMGa1aA/EsNjCCC+InVdPiv9NrVedi2u6LNVcSbNtwGm4EZPRSuU2jL25GoJg+7if bS/sckLTeVy5uFAnIL7O7Tp+uNIvj2JsYtQMKxFJFZGX4gs2UlXgXMvcd7qnXEj/Etg8 YXGIeLGFI0MWx5wa+LU3cL3gzKlvKLbtZknpZrUCprNy16wL3vkyH/tpHtTTopdvC5sC AAZQ== X-Gm-Message-State: AOUpUlGFvWHaHqGT7nHgS3ZJSuLOOkbdlAaMGs17laANykd5GSbUDYRz A2QB3qsAOpVehCWztHMABaviS4cnr48= X-Google-Smtp-Source: AAOMgpfsKQOCM+KD7HIFrt10kB3WhZ93DjhFYWDCEvSW6gBMNcsV8Nh8Y20c780AZCrqVfRPOgN+fg== X-Received: by 2002:a5d:52c4:: with SMTP id r4-v6mr1393151wrv.98.1531834458607; Tue, 17 Jul 2018 06:34:18 -0700 (PDT) Received: from redhat.com (218.red-2-136-166.dynamicip.rima-tde.net. [2.136.166.218]) by smtp.gmail.com with ESMTPSA id q11-v6sm2378361wrp.58.2018.07.17.06.34.17 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 17 Jul 2018 06:34:18 -0700 (PDT) From: Jakub Sitnicki To: dev@openvswitch.org Date: Tue, 17 Jul 2018 15:34:05 +0200 Message-Id: <20180717133415.23781-2-jkbs@redhat.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180717133415.23781-1-jkbs@redhat.com> References: <20180717133415.23781-1-jkbs@redhat.com> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE 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 01/11] ovn-nbctl: Don't die in pg_by_name_or_uuid(). 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 Let the caller handle the error. This prepares us for reporting errors in daemon mode. Also, extend the tests to cover this error path. Signed-off-by: Jakub Sitnicki Acked-by: Mark Michelson --- ovn/utilities/ovn-nbctl.c | 23 ++++++++++++++++------- tests/ovn-nbctl.at | 5 +++++ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/ovn/utilities/ovn-nbctl.c b/ovn/utilities/ovn-nbctl.c index d07524697..0cd11e845 100644 --- a/ovn/utilities/ovn-nbctl.c +++ b/ovn/utilities/ovn-nbctl.c @@ -609,10 +609,12 @@ lb_by_name_or_uuid(struct ctl_context *ctx, const char *id, bool must_exist, return NULL; } -static const struct nbrec_port_group * -pg_by_name_or_uuid(struct ctl_context *ctx, const char *id, bool must_exist) +static char * OVS_WARN_UNUSED_RESULT +pg_by_name_or_uuid(struct ctl_context *ctx, const char *id, bool must_exist, + const struct nbrec_port_group **pg_p) { const struct nbrec_port_group *pg = NULL; + *pg_p = NULL; struct uuid pg_uuid; bool is_uuid = uuid_from_string(&pg_uuid, id); @@ -632,11 +634,12 @@ pg_by_name_or_uuid(struct ctl_context *ctx, const char *id, bool must_exist) } if (!pg && must_exist) { - ctl_fatal("%s: port group %s not found", id, - is_uuid ? "UUID" : "name"); + return xasprintf("%s: port group %s not found", id, + is_uuid ? "UUID" : "name"); } - return pg; + *pg_p = pg; + return NULL; } static void @@ -1559,7 +1562,10 @@ acl_cmd_get_pg_or_ls(struct ctl_context *ctx, char *error; if (!opt_type) { - *pg = pg_by_name_or_uuid(ctx, ctx->argv[1], false); + error = pg_by_name_or_uuid(ctx, ctx->argv[1], false, pg); + if (error) { + return error; + } error = ls_by_name_or_uuid(ctx, ctx->argv[1], false, ls); if (error) { return error; @@ -1574,7 +1580,10 @@ acl_cmd_get_pg_or_ls(struct ctl_context *ctx, ctx->argv[1]); } } else if (!strcmp(opt_type, "port-group")) { - *pg = pg_by_name_or_uuid(ctx, ctx->argv[1], true); + error = pg_by_name_or_uuid(ctx, ctx->argv[1], true, pg); + if (error) { + return error; + } *ls = NULL; } else if (!strcmp(opt_type, "switch")) { error = ls_by_name_or_uuid(ctx, ctx->argv[1], true, ls); diff --git a/tests/ovn-nbctl.at b/tests/ovn-nbctl.at index 73a61a4be..9f6a2783b 100644 --- a/tests/ovn-nbctl.at +++ b/tests/ovn-nbctl.at @@ -234,6 +234,11 @@ OVN_NBCTL_TEST_ACL([ls1], [--type=switch]) AT_CHECK([ovn-nbctl create port_group name=pg0], [0], [ignore]) OVN_NBCTL_TEST_ACL([pg0], [--type=port-group]) +dnl Test when port group doesn't exist +AT_CHECK([ovn-nbctl --type=port-group acl-add pg1 to-lport 100 ip drop], [1], [], [dnl +ovn-nbctl: pg1: port group name not found +]) + dnl Test when same name exists in logical switches and portgroups AT_CHECK([ovn-nbctl create port_group name=ls0], [0], [ignore]) AT_CHECK([ovn-nbctl acl-add ls0 to-lport 100 ip drop], [1], [], [stderr])