From patchwork Wed Sep 28 00:54:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ihar Hrachyshka X-Patchwork-Id: 1683647 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.136; helo=smtp3.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=hs2zwkpm; dkim-atps=neutral Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4McdMC5yzMz1yq7 for ; Wed, 28 Sep 2022 10:55:19 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 0E2DB60B36; Wed, 28 Sep 2022 00:55:18 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 0E2DB60B36 Authentication-Results: smtp3.osuosl.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=hs2zwkpm 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 e6BrNCNPlnJy; Wed, 28 Sep 2022 00:55:16 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp3.osuosl.org (Postfix) with ESMTPS id A013C60B9E; Wed, 28 Sep 2022 00:55:14 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org A013C60B9E Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id DB4CBC0078; Wed, 28 Sep 2022 00:55:13 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp2.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by lists.linuxfoundation.org (Postfix) with ESMTP id 56EAAC0086 for ; Wed, 28 Sep 2022 00:55:12 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id EFED240399 for ; Wed, 28 Sep 2022 00:55:11 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org EFED240399 Authentication-Results: smtp2.osuosl.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=hs2zwkpm 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 GbV4RYklOkbm for ; Wed, 28 Sep 2022 00:55:11 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org 03AD24033F Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by smtp2.osuosl.org (Postfix) with ESMTPS id 03AD24033F for ; Wed, 28 Sep 2022 00:55:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664326510; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6cQO9ay8y5hLlQBp9Hah1CnKuLnx7zNsmFDfwtRtYYk=; b=hs2zwkpmn3KovWDxnvl/k/+5k1cE91SenCam1VzoL5Enx23lTjRRG0tLV1ia61zHjFPlXV 2rf/h/4NuBj1JKujVZIH8goHQeGleT5swx/XbfQy8l+xXqW4pJAvVeNpPud4/K1lnBjyFs m1LjI75MBohNDAPitmycOCl66CYKm1E= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-156-UAu3DJBAPlmcQxvqxt1adA-1; Tue, 27 Sep 2022 20:55:09 -0400 X-MC-Unique: UAu3DJBAPlmcQxvqxt1adA-1 Received: by mail-qv1-f70.google.com with SMTP id om32-20020a0562143da000b004ad858a5458so6962220qvb.22 for ; Tue, 27 Sep 2022 17:55:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=6cQO9ay8y5hLlQBp9Hah1CnKuLnx7zNsmFDfwtRtYYk=; b=t1rCGHqRIvi9nrJsAMgQQ2R99K8t9Rv/GzNKrlMhKEKKFoSrtkf8mDuw7tHU6f6HlW eUnFH8NspibVgGkyXLEFsyvnbVbROzJM3BqTPhyJGncicK+F9PhGBe2VuxNCTw6ZqTYP zv6f1G5cD5NUDOKkpPFPvL6ChDz9S6TH9XCRsI+TLjhF9NmYbkHWOuRhZV0KkwRnKhyI FFuwEJWlNbxxcuXMqDVKcoadkrmAxA1gnAFv54LDXFBwO4cVrN4apk7GoOvpaRoUd8HD xFpAFuprDynOaNRmpwAUPuk6S+HQHmC63dxVpRQZFO2L//fZ2yyAsG5PVnGNP9l6meXr 04Ag== X-Gm-Message-State: ACrzQf18yDP1MoqFza+YAzi/3OKDqeXbi9ydF1pfy56IbpxV9mrUA6Gw txirLDf7u+pVWgW6xM38qVkOduPbyVTMcPNP0hozCaqLt4xLis/aBdE2v14JAiZAmKaGzq5YweT 2FgGQJ9Jhgo7nZOkYIgYd+RvIIaU2O9/5j+D/OIBUExJZ1p0px/sluUw4j/gaeYKK X-Received: by 2002:a05:6214:1d0a:b0:4af:4e78:1aed with SMTP id e10-20020a0562141d0a00b004af4e781aedmr18593483qvd.77.1664326507847; Tue, 27 Sep 2022 17:55:07 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4vi/be0CEzJ7ZnZFR0eoRfVgOBzxiet/KIEVRdcvFdcPv0cQ2z/YGoBmHGsUQpb3dqVBKVHQ== X-Received: by 2002:a05:6214:1d0a:b0:4af:4e78:1aed with SMTP id e10-20020a0562141d0a00b004af4e781aedmr18593469qvd.77.1664326507508; Tue, 27 Sep 2022 17:55:07 -0700 (PDT) Received: from fedora34.localdomain.com (cpe-172-73-180-250.carolina.res.rr.com. [172.73.180.250]) by smtp.gmail.com with ESMTPSA id bl6-20020a05620a1a8600b006ce16588056sm1997450qkb.89.2022.09.27.17.55.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Sep 2022 17:55:06 -0700 (PDT) From: Ihar Hrachyshka To: dev@openvswitch.org Date: Wed, 28 Sep 2022 00:54:56 +0000 Message-Id: <20220928005459.1979537-4-ihrachys@redhat.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220928005459.1979537-1-ihrachys@redhat.com> References: <20220928005459.1979537-1-ihrachys@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [ovs-dev] [PATCH v2 ovn 3/6] Allow to override system-id via file 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" Before the patch, system-id could be configured via a global config option in ovsdb. This patch adds another option - configure system-id via a file. This is achieved by writing the desired system-id into the following file location: ${OVN_SYSCONFDIR}/system-id-override. The file is read on controller startup. The file setting overrides configuration stored in ovsdb, if any. This may be useful when running multiple containerized controller instances using the same vswitchd. Signed-off-by: Ihar Hrachyshka --- controller/chassis.c | 6 ++++++ controller/chassis.h | 2 ++ controller/ovn-controller.c | 34 ++++++++++++++++++++++++++++++ tests/ovn.at | 42 +++++++++++++++++++++++++++++++++++++ tests/ovs-macros.at | 2 ++ 5 files changed, 86 insertions(+) diff --git a/controller/chassis.c b/controller/chassis.c index c8a332786..f121af3c3 100644 --- a/controller/chassis.c +++ b/controller/chassis.c @@ -37,6 +37,8 @@ VLOG_DEFINE_THIS_MODULE(chassis); #define HOST_NAME_MAX 255 #endif /* HOST_NAME_MAX */ +char *file_system_id = NULL; + /* * Structure for storing the chassis config parsed from the ovs table. */ @@ -277,6 +279,10 @@ chassis_parse_ovs_iface_types(char **iface_types, size_t n_iface_types, const char * get_ovs_chassis_id(const struct ovsrec_open_vswitch_table *ovs_table) { + if (file_system_id) { + return file_system_id; + } + const struct ovsrec_open_vswitch *cfg = ovsrec_open_vswitch_table_first(ovs_table); const char *chassis_id = cfg diff --git a/controller/chassis.h b/controller/chassis.h index 05a96bb0c..baa327059 100644 --- a/controller/chassis.h +++ b/controller/chassis.h @@ -31,6 +31,8 @@ struct sset; struct eth_addr; struct smap; +extern char *file_system_id; + void chassis_register_ovs_idl(struct ovsdb_idl *); const struct sbrec_chassis *chassis_run( struct ovsdb_idl_txn *ovnsb_idl_txn, diff --git a/controller/ovn-controller.c b/controller/ovn-controller.c index 1814e0f8d..3f9878b5c 100644 --- a/controller/ovn-controller.c +++ b/controller/ovn-controller.c @@ -18,10 +18,14 @@ #include "ovn-controller.h" #include +#include #include #include #include #include +#include +#include +#include #include "bfd.h" #include "binding.h" @@ -55,6 +59,7 @@ #include "lib/ip-mcast-index.h" #include "lib/mac-binding-index.h" #include "lib/mcast-group-index.h" +#include "lib/ovn-dirs.h" #include "lib/ovn-sb-idl.h" #include "lib/ovn-util.h" #include "patch.h" @@ -151,6 +156,29 @@ struct pending_pkt { /* Registered ofctrl seqno type for nb_cfg propagation. */ static size_t ofctrl_seq_type_nb_cfg; +static char *get_file_system_id(void) +{ + char *ret = NULL; + char *filename = xasprintf("%s/system-id-override", ovn_sysconfdir()); + errno = 0; + int fd = open(filename, O_RDONLY); + if (fd != -1) { + char system_id[64]; + int nread = read(fd, system_id, sizeof system_id); + if (nread) { + system_id[nread] = '\0'; + if (system_id[nread - 1] == '\n') { + system_id[nread - 1] = '\0'; + } + ret = xstrdup(system_id); + } + close(fd); + } + + free(filename); + return ret; +} + static unsigned int update_sb_monitors(struct ovsdb_idl *ovnsb_idl, const struct sbrec_chassis *chassis, @@ -3573,6 +3601,9 @@ main(int argc, char *argv[]) struct ovn_controller_exit_args exit_args = {&exiting, &restart}; int retval; + /* Read from system-id-override file once on startup. */ + file_system_id = get_file_system_id(); + ovs_cmdl_proctitle_init(argc, argv); ovn_set_program_name(argv[0]); service_start(&argc, &argv); @@ -4545,6 +4576,9 @@ loop_done: ovs_feature_support_destroy(); free(ovs_remote); + if (file_system_id) { + free(file_system_id); + } service_stop(); exit(retval); diff --git a/tests/ovn.at b/tests/ovn.at index e45df02ae..d10a582fe 100644 --- a/tests/ovn.at +++ b/tests/ovn.at @@ -32930,3 +32930,45 @@ AT_CHECK(test x$encap_hv1_ip == x) OVN_CLEANUP([hv1],[hv2]) AT_CLEANUP ]) + +OVN_FOR_EACH_NORTHD([ +AT_SETUP([chassis name override via file]) +ovn_start +net_add n1 + +sim_add hv1 +as hv1 +ovs-vsctl add-br br-phys + +ovs-vsctl \ + -- set Open_vSwitch . external-ids:ovn-encap-type-hv3=geneve \ + -- set Open_vSwitch . external-ids:ovn-encap-ip-hv3=192.168.1.1 + +as hv1 ovs-vsctl set-ssl \ + $PKIDIR/testpki-hv3-privkey.pem \ + $PKIDIR/testpki-hv3-cert.pem \ + $PKIDIR/testpki-cacert.pem + +echo hv3 > ${OVN_SYSCONFDIR}/system-id-override +ovn_attach n1 br-phys 192.168.0.1 24 vxlan + +sim_add hv2 +as hv2 +ovs-vsctl add-br br-phys +ovn_attach n1 br-phys 192.168.0.2 24 geneve + +# despite that we configured ovn-encap-ip=192.168.0.1, this setting is +# overridden by chassis specific ovn-encap-ip-hv3 +OVS_WAIT_UNTIL([ + test "1" = "$(ovn-sbctl list Encap | grep -c '192.168.1.1')" +]) + +encap_hv3_ip=$(fetch_column Encap ip chassis_name=hv3 type=geneve) +AT_CHECK(test x$encap_hv3_ip == x192.168.1.1) + +encap_hv1_ip=$(fetch_column Encap ip chassis_name=hv1 type=vxlan) +AT_CHECK(test x$encap_hv1_ip == x) + +OVN_CLEANUP([hv1],[hv2]) +AT_CLEANUP +]) diff --git a/tests/ovs-macros.at b/tests/ovs-macros.at index 5a06fe956..36b58b5ae 100644 --- a/tests/ovs-macros.at +++ b/tests/ovs-macros.at @@ -88,7 +88,9 @@ ovs_setenv() { OVS_LOGDIR=$ovs_dir; export OVS_LOGDIR OVS_DBDIR=$ovs_dir; export OVS_DBDIR OVS_SYSCONFDIR=$ovs_dir; export OVS_SYSCONFDIR + OVN_SYSCONFDIR=$ovs_dir; export OVN_SYSCONFDIR OVS_PKGDATADIR=$ovs_dir; export OVS_PKGDATADIR + OVN_PKGDATADIR=$ovs_dir; export OVN_PKGDATADIR } # Prints the integers from $1 to $2, increasing by $3 (default 1) on stdout.