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 8F43C1FF13B for ; Wed, 20 May 2026 12:23:39 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 63BD7CFD; Wed, 20 May 2026 12:23:30 +0200 (CEST) From: Shannon Sterz To: pve-devel@lists.proxmox.com Subject: [PATCH installer 2/2] post-hook: make post hook more failure tolerant Date: Wed, 20 May 2026 12:22:43 +0200 Message-ID: <20260520102243.129230-3-s.sterz@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260520102243.129230-1-s.sterz@proxmox.com> References: <20260520102243.129230-1-s.sterz@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1779272555036 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.113 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 Message-ID-Hash: ONEFUHHB2MTAH5XLUFMCHLMPAZ4LV57X X-Message-ID-Hash: ONEFUHHB2MTAH5XLUFMCHLMPAZ4LV57X X-MailFrom: s.sterz@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: by logging an error and providing an "unknown" or empty value where possible. this should avoid a single command failing from aborting the whole post hook by bubbling up an error. there are a couple of exceptions that will still bubble up: - if the low level installer config cannot be read or loaded - if the udev information cannot be read or parsed - if the product info cannot be gathered - if the file system details cannot be gathered the first two should always be present after a proper installation and something going wrong there points to a larger issue that should be fixed. the product info should also always be present, but we are lacking a sensible default we can return here instead, because the `ProxmoxProduct` enum does not have a "unknown" variant. so if an error is encountered we would report a potentially wrong product. file system details should also always be present and the `FilesystemType` enum also lacks a sensible "unknown" variant. Signed-off-by: Shannon Sterz --- proxmox-post-hook/src/main.rs | 70 +++++++++++++++++++++++++++++------ 1 file changed, 58 insertions(+), 12 deletions(-) diff --git a/proxmox-post-hook/src/main.rs b/proxmox-post-hook/src/main.rs index 97c36ef..2a36bbc 100644 --- a/proxmox-post-hook/src/main.rs +++ b/proxmox-post-hook/src/main.rs @@ -25,7 +25,7 @@ const POST_HOOK_SCHEMA_VERSION: &str = "1.2"; mod detail { use anyhow::{Context, Result, anyhow, bail}; use std::{ - collections::HashSet, + collections::{HashMap, HashSet}, ffi::CStr, fs::{self, File}, io::BufReader, @@ -39,7 +39,7 @@ mod detail { setup::{InstallConfig, RuntimeInfo, SetupInfo, load_installer_setup_files}, }; use proxmox_installer_types::{ - ProxmoxProduct, UdevInfo, + ProxmoxProduct, SystemDMI, UdevInfo, answer::{AutoInstallerConfig, FqdnConfig, FqdnFromDhcpConfig, FqdnSourceMode}, post_hook::{ BootInfo, CpuInfo, DiskInfo, KernelVersionInformation, NetworkInterfaceInfo, @@ -115,25 +115,71 @@ mod detail { schema: PostHookInfoSchema { version: super::POST_HOOK_SCHEMA_VERSION.to_owned(), }, - debian_version: read_file("/etc/debian_version")?, + debian_version: read_file("/etc/debian_version").unwrap_or_else(|e| { + eprintln!("could not gather debian version: {e:#}"); + "unknown".to_string() + }), product: gather_product_info(&setup_info, &run_cmd)?, iso: setup_info.iso_info, - kernel_version: gather_kernel_version(&run_cmd, &open_file)?, + kernel_version: gather_kernel_version(&run_cmd, &open_file).unwrap_or_else(|e| { + eprintln!("could not gather kernel version: {e:#}"); + KernelVersionInformation { + sysname: "unknown".to_string(), + release: "unknown".to_string(), + version: "unknown".to_string(), + machine: "unknown".to_string(), + } + }), boot_info: BootInfo { mode: run_env.boot_type, secureboot: run_env.secure_boot, }, - cpu_info: gather_cpu_info(&run_env)?, - dmi: proxmox_installer_common::dmi::get()?, + cpu_info: gather_cpu_info(&run_env).unwrap_or_else(|e| { + eprintln!("could not gather cpu info: {e:#}"); + CpuInfo { + cores: 0, + cpus: 0, + flags: "unknown".to_string(), + hvm: false, + model: "unknown".to_string(), + sockets: 0, + } + }), + dmi: proxmox_installer_common::dmi::get().unwrap_or_else(|e| { + eprintln!("could not gather dmi: {e:#}"); + SystemDMI { + baseboard: HashMap::new(), + chassis: HashMap::new(), + system: HashMap::new(), + } + }), filesystem: answer.disks.filesystem_details()?.to_type(), fqdn, - machine_id: read_file("/etc/machine-id")?, - disks: gather_disks(&config, &run_env, &udev)?, - network_interfaces: gather_nic(&config, &run_env, &udev)?, + machine_id: read_file("/etc/machine-id").unwrap_or_else(|e| { + eprintln!("could not gather machine-id: {e:#}"); + "unknown".to_string() + }), + disks: gather_disks(&config, &run_env, &udev).unwrap_or_else(|e| { + eprintln!("could not gather disks: {e:#}"); + Vec::new() + }), + network_interfaces: gather_nic(&config, &run_env, &udev).unwrap_or_else(|e| { + eprintln!("could not gather network interfaces: {e:#}"); + Vec::new() + }), ssh_public_host_keys: SshPublicHostKeys { - ecdsa: read_file("/etc/ssh/ssh_host_ecdsa_key.pub")?, - ed25519: read_file("/etc/ssh/ssh_host_ed25519_key.pub")?, - rsa: read_file("/etc/ssh/ssh_host_rsa_key.pub")?, + ecdsa: read_file("/etc/ssh/ssh_host_ecdsa_key.pub").unwrap_or_else(|e| { + eprintln!("could not gather ecdsa SSH key: {e:#}"); + "unknown".to_string() + }), + ed25519: read_file("/etc/ssh/ssh_host_ed25519_key.pub").unwrap_or_else(|e| { + eprintln!("could not gather ed25519 SSH key: {e:#}"); + "unknown".to_string() + }), + rsa: read_file("/etc/ssh/ssh_host_rsa_key.pub").unwrap_or_else(|e| { + eprintln!("could not gather rsa SSH key: {e:#}"); + "unknown".to_string() + }), }, reboot_mode: answer.global.reboot_mode, }) -- 2.47.3