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 63434BEFFA for ; Wed, 3 Jan 2024 16:45:05 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 004BD34F06 for ; Wed, 3 Jan 2024 16:45:05 +0100 (CET) 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 ; Wed, 3 Jan 2024 16:45:03 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 56CDB48CD6 for ; Wed, 3 Jan 2024 16:45:03 +0100 (CET) From: Stefan Lendl To: pve-devel@lists.proxmox.com Date: Wed, 3 Jan 2024 16:37:48 +0100 Message-ID: <20240103153753.407079-4-s.lendl@proxmox.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240103153753.407079-3-s.lendl@proxmox.com> References: <20240103153753.407079-3-s.lendl@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.040 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 T_SCC_BODY_TEXT_LINE -0.01 - Subject: [pve-devel] [PATCH pve-network 1/8] refactor(sdn): extract cfs_read_file(datacenter.cfg) 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: Wed, 03 Jan 2024 15:45:05 -0000 to datacenter_config() functions in Zones::Plugin. This allows mocking the datacenter.cfg in tests. Signed-off-by: Stefan Lendl --- 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.42.0