From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id D829A1FF141 for ; Tue, 19 May 2026 16:06:31 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 633228680; Tue, 19 May 2026 16:06:28 +0200 (CEST) From: Arthur Bied-Charreton To: pve-devel@lists.proxmox.com Subject: [PATCH pve-manager 1/3] custom cpu models: make 'reported-model' required in POST Date: Tue, 19 May 2026 16:06:21 +0200 Message-ID: <20260519140623.594472-2-a.bied-charreton@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260519140623.594472-1-a.bied-charreton@proxmox.com> References: <20260519140623.594472-1-a.bied-charreton@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.134 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 KAM_LAZY_DOMAIN_SECURITY 1 Sending domain does not have any anti-forgery methods RDNS_NONE 0.793 Delivered to internal network by a host with no rDNS SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_NONE 0.001 SPF: sender does not publish an SPF Record Message-ID-Hash: UJ2YWPC7WWBWCREKRGXNIWPJTT3ZHJAD X-Message-ID-Hash: UJ2YWPC7WWBWCREKRGXNIWPJTT3ZHJAD X-MailFrom: abied-charreton@jett.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: The default reported-model is kvm64, which is a legacy CPU model with a very limited feature set that one should not really be using in practice. The UI already requires the reported-model, so this just brings the API in line. Signed-off-by: Arthur Bied-Charreton Suggested-by: Fiona Ebner --- PVE/API2/Cluster/Qemu/CustomCPUModels.pm | 4 ++++ test/CustomCPUModels_test.pl | 19 +++++++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/PVE/API2/Cluster/Qemu/CustomCPUModels.pm b/PVE/API2/Cluster/Qemu/CustomCPUModels.pm index 8628f20c..4ba04180 100644 --- a/PVE/API2/Cluster/Qemu/CustomCPUModels.pm +++ b/PVE/API2/Cluster/Qemu/CustomCPUModels.pm @@ -19,6 +19,9 @@ my $cputype_param = { description => "Name for the custom CPU model. The 'custom-' prefix is optional.", }; +my $reported_model_param = + { get_standard_option('pve-qm-custom-cpu-model')->{'reported-model'}->%*, optional => 0 }; + # privileges that grant any kind of visibility on a custom CPU model my $can_see_mapping_privs = ['Mapping.Modify', 'Mapping.Use', 'Mapping.Audit']; @@ -77,6 +80,7 @@ __PACKAGE__->register_method({ additionalProperties => 0, properties => PVE::QemuServer::CPUConfig::add_cpu_json_properties({ cputype => $cputype_param, + 'reported-model' => $reported_model_param, }), }, returns => { type => 'null' }, diff --git a/test/CustomCPUModels_test.pl b/test/CustomCPUModels_test.pl index b416b684..5511dbb7 100755 --- a/test/CustomCPUModels_test.pl +++ b/test/CustomCPUModels_test.pl @@ -49,27 +49,34 @@ like( 'POST without cputype rejected by schema', ); +eval { validate_params('POST', '', { cputype => 'name' }) }; +like( + $@, + qr/reported-model.*(?:missing|required|not optional)/i, + 'POST without reported-model rejected by schema', +); + # --- create: cputype must be a valid pve-configid (A1) --- -eval { validate_params('POST', '', { cputype => '4foo' }) }; +eval { validate_params('POST', '', { cputype => '4foo', 'reported-model' => 'qemu64' }) }; like( $@, qr/format/i, 'POST with cputype starting with digit rejected by schema', ); -eval { validate_params('POST', '', { cputype => 'bad name' }) }; +eval { validate_params('POST', '', { cputype => 'bad name', 'reported-model' => 'qemu64' }) }; like( $@, qr/format/i, 'POST with whitespace in cputype rejected by schema', ); -eval { validate_params('POST', '', { cputype => 'a' x 50 }) }; +eval { validate_params('POST', '', { cputype => 'a' x 50, 'reported-model' => 'qemu64' }) }; like( $@, qr/40 characters|maxLength|too long/i, 'POST with overly long cputype rejected by schema', ); # Valid cputype with optional 'custom-' prefix passes the schema. -eval { validate_params('POST', '', { cputype => 'custom-foo' }) }; +eval { validate_params('POST', '', { cputype => 'custom-foo', 'reported-model' => 'qemu64' }) }; is($@, '', 'POST with valid prefixed cputype accepted by schema'); -eval { validate_params('POST', '', { cputype => 'my_model' }) }; +eval { validate_params('POST', '', { cputype => 'my_model', 'reported-model' => 'qemu64' }) }; is($@, '', 'POST with valid unprefixed cputype accepted by schema'); # --- create: empty name after stripping 'custom-' is rejected by runtime check (A1) --- @@ -81,7 +88,7 @@ is($@, '', 'POST with valid unprefixed cputype accepted by schema'); $config_mock->mock( lock_custom_cpu_model_config => sub { fail('lock reached for empty stripped name'); }, ); - eval { invoke_method('POST', '', { cputype => 'custom-' }) }; + eval { invoke_method('POST', '', { cputype => 'custom-', 'reported-model' => 'qemu64' }) }; like($@, qr/configid|invalid/i, 'POST with cputype "custom-" rejected after stripping'); } -- 2.47.3