From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id B03239246E for ; Fri, 5 Apr 2024 15:18:21 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 8063F14112 for ; Fri, 5 Apr 2024 15:18:21 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Fri, 5 Apr 2024 15:18:20 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 468D746609 for ; Fri, 5 Apr 2024 15:18:20 +0200 (CEST) From: Stefan Lendl To: pve-devel@lists.proxmox.com Date: Fri, 5 Apr 2024 15:17:58 +0200 Message-ID: <20240405131806.388178-6-s.lendl@proxmox.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240405131806.388178-1-s.lendl@proxmox.com> References: <20240405131806.388178-1-s.lendl@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.020 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pve-devel] [PATCH v3 pve-network 05/12] sdn: zones: extract function that reads datacenter config X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 05 Apr 2024 13:18:21 -0000 The datacenter_config() functions in SDN::Zones::Plugin is a simple wrapper that reads datacenter.cfg via cfs. This allows mocking datacenter.cfg in tests. Signed-off-by: Stefan Lendl Reviewed-by: Max Carrara Tested-by: Max Carrara Reviewed-by: Stefan Hanreich Tested-by: Stefan Hanreich --- src/PVE/Network/SDN/Zones/EvpnPlugin.pm | 3 ++- src/PVE/Network/SDN/Zones/Plugin.pm | 5 +++++ src/PVE/Network/SDN/Zones/SimplePlugin.pm | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/PVE/Network/SDN/Zones/EvpnPlugin.pm b/src/PVE/Network/SDN/Zones/EvpnPlugin.pm index 655a9f0..4843756 100644 --- a/src/PVE/Network/SDN/Zones/EvpnPlugin.pm +++ b/src/PVE/Network/SDN/Zones/EvpnPlugin.pm @@ -3,6 +3,7 @@ package PVE::Network::SDN::Zones::EvpnPlugin; use strict; use warnings; use PVE::Network::SDN::Zones::VxlanPlugin; +use PVE::Network::SDN::Zones::Plugin; use PVE::Exception qw(raise raise_param_exc); use PVE::JSONSchema qw(get_standard_option); use PVE::Tools qw($IPV4RE); @@ -294,7 +295,7 @@ sub on_update_hook { } if (!defined($zone_cfg->{ids}->{$zoneid}->{'mac'})) { - my $dc = PVE::Cluster::cfs_read_file('datacenter.cfg'); + my $dc = PVE::Network::SDN::Zones::Plugin->datacenter_config(); $zone_cfg->{ids}->{$zoneid}->{'mac'} = PVE::Tools::random_ether_addr($dc->{mac_prefix}); } } diff --git a/src/PVE/Network/SDN/Zones/Plugin.pm b/src/PVE/Network/SDN/Zones/Plugin.pm index b55b967..247d0b2 100644 --- a/src/PVE/Network/SDN/Zones/Plugin.pm +++ b/src/PVE/Network/SDN/Zones/Plugin.pm @@ -356,4 +356,9 @@ sub get_bridge_ifaces { return @bridge_ifaces; } + +sub datacenter_config { + return PVE::Cluster::cfs_read_file('datacenter.cfg'); +} + 1; diff --git a/src/PVE/Network/SDN/Zones/SimplePlugin.pm b/src/PVE/Network/SDN/Zones/SimplePlugin.pm index c996bf3..65e9ad4 100644 --- a/src/PVE/Network/SDN/Zones/SimplePlugin.pm +++ b/src/PVE/Network/SDN/Zones/SimplePlugin.pm @@ -139,7 +139,7 @@ sub vnet_update_hook { raise_param_exc({ tag => "vlan tag is not allowed on simple zone"}) if defined($tag); if (!defined($vnet->{mac})) { - my $dc = PVE::Cluster::cfs_read_file('datacenter.cfg'); + my $dc = PVE::Network::SDN::Zones::Plugin::datacenter_config(); $vnet->{mac} = PVE::Tools::random_ether_addr($dc->{mac_prefix}); } } -- 2.44.0