From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 8CD3F1FF145 for ; Thu, 05 Feb 2026 15:20:05 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id E40AF125B7; Thu, 5 Feb 2026 15:20:35 +0100 (CET) From: Dominik Csapak To: pve-devel@lists.proxmox.com Subject: [PATCH qemu-server v3 1/3] tests: improve multiarch build support by introducing local get_host_arch helper Date: Thu, 5 Feb 2026 15:17:11 +0100 Message-ID: <20260205141959.3615131-2-d.csapak@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260205141959.3615131-1-d.csapak@proxmox.com> References: <20260205141959.3615131-1-d.csapak@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.031 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 RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: QKGUVN5NHKHOLFBP72KL6TCXSUDMPFZE X-Message-ID-Hash: QKGUVN5NHKHOLFBP72KL6TCXSUDMPFZE X-MailFrom: d.csapak@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Since mocking imported functions have to be done for each package that imports them, we would have to mock get_host_arch for each package that imports it from PVE::Tools. Instead, introduce one local helper here that uses the function from PVE::Tools. This allows us to only need to override it one time. Signed-off-by: Dominik Csapak --- changes from v2: * split out from first patch * use the helper everywhere in the package src/PVE/API2/Qemu/Machine.pm | 3 ++- src/PVE/QemuServer.pm | 5 ++--- src/PVE/QemuServer/CPUConfig.pm | 12 ++++++------ src/PVE/QemuServer/Helpers.pm | 8 +++++++- src/test/run_config2command_tests.pl | 6 +++--- 5 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/PVE/API2/Qemu/Machine.pm b/src/PVE/API2/Qemu/Machine.pm index 26195eae..adc36d49 100644 --- a/src/PVE/API2/Qemu/Machine.pm +++ b/src/PVE/API2/Qemu/Machine.pm @@ -7,9 +7,10 @@ use JSON; use PVE::JSONSchema qw(get_standard_option); use PVE::RESTHandler; -use PVE::Tools qw(extract_param file_get_contents get_host_arch); +use PVE::Tools qw(extract_param file_get_contents); use PVE::QemuServer::Machine; +use PVE::QemuServer::Helpers qw(get_host_arch); use base qw(PVE::RESTHandler); diff --git a/src/PVE/QemuServer.pm b/src/PVE/QemuServer.pm index 5d2dbe03..8bf23945 100644 --- a/src/PVE/QemuServer.pm +++ b/src/PVE/QemuServer.pm @@ -46,8 +46,7 @@ use PVE::SafeSyslog; use PVE::Storage; use PVE::SysFSTools; use PVE::Systemd; -use PVE::Tools - qw(run_command file_read_firstline file_get_contents dir_glob_foreach get_host_arch $IPV6RE); +use PVE::Tools qw(run_command file_read_firstline file_get_contents dir_glob_foreach $IPV6RE); use PVE::QMPClient; use PVE::QemuConfig; @@ -58,7 +57,7 @@ use PVE::QemuServer::Blockdev; use PVE::QemuServer::BlockJob; use PVE::QemuServer::Cfg2Cmd; use PVE::QemuServer::Helpers - qw(config_aware_timeout get_iscsi_initiator_name min_version kvm_user_version windows_version); + qw(config_aware_timeout get_iscsi_initiator_name get_host_arch min_version kvm_user_version windows_version); use PVE::QemuServer::Cloudinit; use PVE::QemuServer::CGroup; use PVE::QemuServer::CPUConfig qw( diff --git a/src/PVE/QemuServer/CPUConfig.pm b/src/PVE/QemuServer/CPUConfig.pm index 32ec4954..0218908e 100644 --- a/src/PVE/QemuServer/CPUConfig.pm +++ b/src/PVE/QemuServer/CPUConfig.pm @@ -11,7 +11,7 @@ use PVE::ProcFSTools; use PVE::RESTEnvironment qw(log_warn); use PVE::Tools qw(run_command); -use PVE::QemuServer::Helpers qw(min_version); +use PVE::QemuServer::Helpers qw(min_version get_host_arch); use base qw(PVE::SectionConfig Exporter); @@ -25,7 +25,7 @@ our @EXPORT_OK = qw( get_cvm_type ); -my $host_arch = PVE::Tools::get_host_arch(); +my $host_arch = get_host_arch(); my $arch_desc = { description => "Virtual processor architecture. Defaults to the host architecture.", @@ -294,7 +294,7 @@ my $supported_cpu_flags_by_arch = { sub get_supported_cpu_flags { my ($arch) = @_; - $arch = $host_arch if !defined($arch); + $arch = get_host_arch() if !defined($arch); return $supported_cpu_flags_by_arch->{$arch}; } @@ -582,7 +582,7 @@ sub add_cpu_json_properties { sub get_cpu_models { my ($include_custom, $arch) = @_; - $arch = $host_arch if !defined($arch); + $arch = get_host_arch() if !defined($arch); my $cpu_vendor_list = $cpu_models_by_arch->{$arch}; my $models = []; @@ -1077,13 +1077,13 @@ sub get_default_cpu_type { sub is_native_arch($) { my ($arch) = @_; - return $host_arch eq $arch; + return get_host_arch() eq $arch; } sub get_cpu_bitness { my ($cpu_prop_str, $arch) = @_; - $arch //= $host_arch; + $arch //= get_host_arch(); my $cputype = get_default_cpu_type($arch, 0); diff --git a/src/PVE/QemuServer/Helpers.pm b/src/PVE/QemuServer/Helpers.pm index 35c00754..e898440c 100644 --- a/src/PVE/QemuServer/Helpers.pm +++ b/src/PVE/QemuServer/Helpers.pm @@ -10,7 +10,7 @@ use JSON; use PVE::Cluster; use PVE::INotify; use PVE::ProcFSTools; -use PVE::Tools qw(get_host_arch); +use PVE::Tools; use base 'Exporter'; our @EXPORT_OK = qw( @@ -20,6 +20,7 @@ our @EXPORT_OK = qw( kvm_user_version parse_number_sets windows_version + get_host_arch ); my $nodename = PVE::INotify::nodename(); @@ -29,6 +30,11 @@ my $arch_to_qemu_binary = { x86_64 => '/usr/bin/qemu-system-x86_64', }; +# wrapper around the Tools helper, having it here makes it easier for testing +sub get_host_arch { + return PVE::Tools::get_host_arch(); +} + sub get_command_for_arch($) { my ($arch) = @_; return '/usr/bin/kvm' if get_host_arch() eq $arch; # i.e. native arch diff --git a/src/test/run_config2command_tests.pl b/src/test/run_config2command_tests.pl index 4c872d1c..c20f2377 100755 --- a/src/test/run_config2command_tests.pl +++ b/src/test/run_config2command_tests.pl @@ -253,9 +253,6 @@ $qemu_server_module->mock( kernel_has_vhost_net => sub { return 1; # TODO: make this per-test configurable? }, - get_host_arch => sub() { - return $current_test->{host_arch} // 'x86_64'; - }, get_iscsi_initiator_name => sub { return 'iqn.1993-08.org.debian:01:aabbccddeeff'; }, @@ -388,6 +385,9 @@ $pve_common_tools->mock( }, ); }, + get_host_arch => sub() { + return $current_test->{host_arch} // 'x86_64'; + }, ); my $pve_cpuconfig; -- 2.47.3