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 CF79A1FF15C for ; Fri, 14 Nov 2025 11:30:31 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 8B8AFD951; Fri, 14 Nov 2025 11:31:25 +0100 (CET) From: Gabriel Goller To: pve-devel@lists.proxmox.com Date: Fri, 14 Nov 2025 11:30:09 +0100 Message-ID: <20251114103046.129669-1-g.goller@proxmox.com> X-Mailer: git-send-email 2.47.3 MIME-Version: 1.0 X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1763116225514 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.003 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 URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [status.rs, fabrics.rs] Subject: [pve-devel] [PATCH] pve-rs: fabrics: handle missing running-config and no fabrics 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: , Reply-To: Proxmox VE development discussion Cc: Thomas Lamprecht Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" Correctly handle if there is a missing `/etc/pve/sdn/.running-config` file. This happens, e.g. on a clean installation without any sdn "apply" activation. Also handle a config where there is no fabric configured. The `status()` functions gets called every few seconds to populate the network resources in pve, so don't return an error if there is no running-config or no fabric config. The other functions (neighbors, interfaces, routes) only get called by the api, so we can return an error on those. Reported-by: Thomas Lamprecht Reported-by: Stoiko Ivanov Signed-off-by: Gabriel Goller --- pve-rs/src/bindings/sdn/fabrics.rs | 36 ++++++++++++++++++++++++------ pve-rs/src/sdn/status.rs | 10 ++++++--- 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/pve-rs/src/bindings/sdn/fabrics.rs b/pve-rs/src/bindings/sdn/fabrics.rs index c9e5cf526c77..54606e7b6bb9 100644 --- a/pve-rs/src/bindings/sdn/fabrics.rs +++ b/pve-rs/src/bindings/sdn/fabrics.rs @@ -595,14 +595,21 @@ pub mod pve_rs_sdn_fabrics { /// Read and parse the running-config and get the fabrics section /// /// This will return a valid FabricConfig. Note that we read the file manually and not through - /// the cluster filesystem as with perl, so this will be slower. - fn get_fabrics_config() -> Result, anyhow::Error> { + /// the cluster filesystem as with perl, so this will be slower. If the running config exists, + /// but no fabric is configured, `Ok(None)` is returned. + fn get_fabrics_config() -> Result>, anyhow::Error> { let raw_config = std::fs::read_to_string("/etc/pve/sdn/.running-config")?; let running_config: RunningConfig = serde_json::from_str(&raw_config).with_context(|| "error parsing running-config")?; - let section_config = SectionConfigData::from_iter(running_config.fabrics.ids); - FabricConfig::from_section_config(section_config) - .with_context(|| "error converting section config to fabricconfig") + let Some(fabrics) = running_config.fabrics else { + return Ok(None); + }; + let section_config = SectionConfigData::from_iter(fabrics.ids); + Some( + FabricConfig::from_section_config(section_config) + .with_context(|| "error converting section config to fabricconfig"), + ) + .transpose() } /// Get the routes that have been learned and distributed by this specific fabric on this node. @@ -614,6 +621,9 @@ pub mod pve_rs_sdn_fabrics { fn routes(fabric_id: FabricId) -> Result, Error> { // Read fabric config to get protocol of fabric let config = get_fabrics_config()?; + let Some(config) = config else { + anyhow::bail!("no fabrics configured"); + }; let fabric = config.get_fabric(&fabric_id)?; match fabric { @@ -679,6 +689,9 @@ pub mod pve_rs_sdn_fabrics { fn neighbors(fabric_id: FabricId) -> Result { // Read fabric config to get protocol of fabric let config = get_fabrics_config()?; + let Some(config) = config else { + anyhow::bail!("no fabrics configured"); + }; let fabric = config.get_fabric(&fabric_id)?; @@ -734,6 +747,9 @@ pub mod pve_rs_sdn_fabrics { fn interfaces(fabric_id: FabricId) -> Result { // Read fabric config to get protocol of fabric let config = get_fabrics_config()?; + let Some(config) = config else { + anyhow::bail!("no fabrics configured"); + }; let fabric = config.get_fabric(&fabric_id)?; @@ -789,6 +805,14 @@ pub mod pve_rs_sdn_fabrics { /// config. If there are, show "ok" as status, otherwise "not ok". #[export] fn status() -> Result, Error> { + // This gets called every few seconds from pve to get the status of the fabrics into the + // network resources. It is possible that the .running-config doesn't exist or no fabric is + // configured -- in that case just return nothing. + let config = get_fabrics_config(); + let Ok(Some(config)) = config else { + return Ok(HashMap::new()); + }; + let openfabric_ipv4_routes_string = String::from_utf8( Command::new("sh") .args(["-c", "vtysh -c 'show ip route openfabric json'"]) @@ -831,8 +855,6 @@ pub mod pve_rs_sdn_fabrics { .with_context(|| "error parsing ospf routes")? }; - let config = get_fabrics_config()?; - let route_status = status::RoutesParsed { openfabric: openfabric_routes, ospf: ospf_routes, diff --git a/pve-rs/src/sdn/status.rs b/pve-rs/src/sdn/status.rs index 78b55502b837..e1e336297ac9 100644 --- a/pve-rs/src/sdn/status.rs +++ b/pve-rs/src/sdn/status.rs @@ -178,7 +178,7 @@ pub struct RoutesParsed { /// Config used to parse the fabric part of the running-config #[derive(Deserialize)] pub struct RunningConfig { - pub fabrics: FabricsRunningConfig, + pub fabrics: Option, } /// Map of ids for all the fabrics in the running-config @@ -647,7 +647,9 @@ mod tests { let running_config: RunningConfig = serde_json::from_str(raw_config).expect("error parsing running-config"); - let section_config = SectionConfigData::from_iter(running_config.fabrics.ids); + let section_config = SectionConfigData::from_iter( + running_config.fabrics.expect("no fabrics configured").ids, + ); FabricConfig::from_section_config(section_config) .expect("error converting section config to fabricconfig") } @@ -695,7 +697,9 @@ mod tests { "#; let running_config: RunningConfig = serde_json::from_str(raw_config).expect("error parsing running-config"); - let section_config = SectionConfigData::from_iter(running_config.fabrics.ids); + let section_config = SectionConfigData::from_iter( + running_config.fabrics.expect("no fabrics configured").ids, + ); FabricConfig::from_section_config(section_config) .expect("error converting section config to fabricconfig") } -- 2.47.3 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel