From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: <pve-devel-bounces@lists.proxmox.com> Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 89D611FF164 for <inbox@lore.proxmox.com>; Fri, 28 Mar 2025 18:23:17 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 9174BA16B; Fri, 28 Mar 2025 18:22:50 +0100 (CET) From: Gabriel Goller <g.goller@proxmox.com> To: pve-devel@lists.proxmox.com Date: Fri, 28 Mar 2025 18:13:06 +0100 Message-Id: <20250328171340.885413-19-g.goller@proxmox.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250328171340.885413-1-g.goller@proxmox.com> References: <20250328171340.885413-1-g.goller@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.074 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 PROLO_LEO1 0.1 Meta Catches all Leo drug variations so far SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pve-devel] [PATCH proxmox-ve-rs 17/17] ve-config: add integrations tests X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com> List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe> List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/> List-Post: <mailto:pve-devel@lists.proxmox.com> List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help> List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe> Reply-To: Proxmox VE development discussion <pve-devel@lists.proxmox.com> Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" <pve-devel-bounces@lists.proxmox.com> Add integration tests for the full cycle from section-config to FRR config file for both openfabric and ospf. Signed-off-by: Gabriel Goller <g.goller@proxmox.com> --- proxmox-ve-config/tests/fabric/helper.rs | 44 ++++++++++ proxmox-ve-config/tests/fabric/main.rs | 80 +++++++++++++++++++ .../resources/cfg/openfabric_default.cfg | 17 ++++ .../cfg/openfabric_verification_fail.cfg | 11 +++ .../fabric/resources/cfg/ospf_default.cfg | 10 +++ .../resources/cfg/ospf_verification_fail.cfg | 11 +++ .../resources/frr/openfabric_default.pve.frr | 32 ++++++++ .../resources/frr/openfabric_default.pve1.frr | 28 +++++++ .../fabric/resources/frr/ospf_default.pve.frr | 26 ++++++ .../resources/frr/ospf_default.pve1.frr | 21 +++++ 10 files changed, 280 insertions(+) create mode 100644 proxmox-ve-config/tests/fabric/helper.rs create mode 100644 proxmox-ve-config/tests/fabric/main.rs create mode 100644 proxmox-ve-config/tests/fabric/resources/cfg/openfabric_default.cfg create mode 100644 proxmox-ve-config/tests/fabric/resources/cfg/openfabric_verification_fail.cfg create mode 100644 proxmox-ve-config/tests/fabric/resources/cfg/ospf_default.cfg create mode 100644 proxmox-ve-config/tests/fabric/resources/cfg/ospf_verification_fail.cfg create mode 100644 proxmox-ve-config/tests/fabric/resources/frr/openfabric_default.pve.frr create mode 100644 proxmox-ve-config/tests/fabric/resources/frr/openfabric_default.pve1.frr create mode 100644 proxmox-ve-config/tests/fabric/resources/frr/ospf_default.pve.frr create mode 100644 proxmox-ve-config/tests/fabric/resources/frr/ospf_default.pve1.frr diff --git a/proxmox-ve-config/tests/fabric/helper.rs b/proxmox-ve-config/tests/fabric/helper.rs new file mode 100644 index 000000000000..3d878ac702a8 --- /dev/null +++ b/proxmox-ve-config/tests/fabric/helper.rs @@ -0,0 +1,44 @@ +#[allow(unused_macros)] +macro_rules! assert_frr_config { + ($node:expr, $output:expr) => {{ + fn f() {} + fn type_name_of<T>(_: T) -> &'static str { + std::any::type_name::<T>() + } + let mut name = type_name_of(f); + + // Find and cut the rest of the path + name = match &name[..name.len() - 3].rfind(':') { + Some(pos) => &name[pos + 1..name.len() - 3], + None => &name[..name.len() - 3], + }; + let real_filename = format!("tests/fabric/resources/frr/{name}.{}.frr", $node); + let reference = std::fs::read_to_string(real_filename).expect("cannot find reference file"); + similar_asserts::assert_eq!(reference, $output); + }}; +} + +#[allow(unused_macros)] +macro_rules! get_section_config { + () => {{ + fn f() {} + fn type_name_of<T>(_: T) -> &'static str { + std::any::type_name::<T>() + } + let mut name = type_name_of(f); + + // Find and cut the rest of the path + name = match &name[..name.len() - 3].rfind(':') { + Some(pos) => &name[pos + 1..name.len() - 3], + None => &name[..name.len() - 3], + }; + let real_filename = format!("tests/fabric/resources/cfg/{name}.cfg"); + std::fs::read_to_string(real_filename).expect("cannot find reference file") + }}; +} + +#[allow(unused_imports)] +pub(crate) use assert_frr_config; +#[allow(unused_imports)] +pub(crate) use get_section_config; +use proxmox_frr::{serializer::FrrConfigBlob, FrrConfig}; diff --git a/proxmox-ve-config/tests/fabric/main.rs b/proxmox-ve-config/tests/fabric/main.rs new file mode 100644 index 000000000000..9625ae7b8360 --- /dev/null +++ b/proxmox-ve-config/tests/fabric/main.rs @@ -0,0 +1,80 @@ +#![cfg(feature = "frr")] +use proxmox_frr::serializer::dump; +use proxmox_ve_config::sdn::fabric::openfabric::OpenFabricSectionConfig; +use proxmox_ve_config::sdn::fabric::ospf::OspfSectionConfig; +use proxmox_ve_config::sdn::fabric::{FabricConfig, FrrConfigBuilder, Valid}; + +mod helper; + +/* + * Use the macros helper::get_section_config!() to get the section config as a string. This uses + * the function name and checks for "/resources/cfg/{function name}.cfg" files. + * With the helper::assert_frr_config! macro (which takes the hostname for which you want to render + * the config and the actual output) you can check the output against the reference config, which + * can be found in "/resources/frr/{function name}.frr". + */ + +#[test] +fn openfabric_default() { + let openfabric = + <Valid<OpenFabricSectionConfig>>::parse_section_config("", &helper::get_section_config!()) + .unwrap(); + + let config = FabricConfig::with_openfabric(openfabric); + let mut frr_config = FrrConfigBuilder::default() + .add_fabrics(config.clone()) + .build("pve".to_owned().into()) + .expect("error building frr config"); + + let mut output = dump(&frr_config).expect("error dumping stuff"); + + helper::assert_frr_config!("pve", output); + + frr_config = FrrConfigBuilder::default() + .add_fabrics(config) + .build("pve1".to_owned().into()) + .expect("error building frr config"); + + output = dump(&frr_config).expect("error dumping stuff"); + + helper::assert_frr_config!("pve1", output); +} + +#[test] +fn ospf_default() { + let ospf = <Valid<OspfSectionConfig>>::parse_section_config("", &helper::get_section_config!()) + .unwrap(); + + let config = FabricConfig::with_ospf(ospf); + let mut frr_config = FrrConfigBuilder::default() + .add_fabrics(config.clone()) + .build("pve".to_owned().into()) + .expect("error building frr config"); + + let mut output = dump(&frr_config).expect("error dumping stuff"); + + helper::assert_frr_config!("pve", output); + + frr_config = FrrConfigBuilder::default() + .add_fabrics(config) + .build("pve1".to_owned().into()) + .expect("error building frr config"); + + output = dump(&frr_config).expect("error dumping stuff"); + + helper::assert_frr_config!("pve1", output); +} + +#[test] +fn openfabric_verification_fail() { + let result = + <Valid<OpenFabricSectionConfig>>::parse_section_config("", &helper::get_section_config!()); + assert!(result.is_err()); +} + +#[test] +fn ospf_verification_fail() { + let result = + <Valid<OspfSectionConfig>>::parse_section_config("", &helper::get_section_config!()); + assert!(result.is_err()); +} diff --git a/proxmox-ve-config/tests/fabric/resources/cfg/openfabric_default.cfg b/proxmox-ve-config/tests/fabric/resources/cfg/openfabric_default.cfg new file mode 100644 index 000000000000..3300ac12a1d9 --- /dev/null +++ b/proxmox-ve-config/tests/fabric/resources/cfg/openfabric_default.cfg @@ -0,0 +1,17 @@ +fabric: uwu + hello_interval 4 + +node: uwu_pve + interface name=ens20,passive=1,hello_interval=3,hello_multiplier=50 + interface name=ens19,passive=1,csnp_interval=100 + router_id 192.168.2.8 + +node: uwu_pve1 + interface name=ens19 + interface name=ens20 + router_id 192.168.2.9 + +node: uwu_pve2 + interface name=ens19 + interface name=ens20 + router_id 192.168.2.10 diff --git a/proxmox-ve-config/tests/fabric/resources/cfg/openfabric_verification_fail.cfg b/proxmox-ve-config/tests/fabric/resources/cfg/openfabric_verification_fail.cfg new file mode 100644 index 000000000000..0dd4d2199264 --- /dev/null +++ b/proxmox-ve-config/tests/fabric/resources/cfg/openfabric_verification_fail.cfg @@ -0,0 +1,11 @@ +fabric: uwu + +node: uwu1_pve + interface name=ens20,passive=1,hello_interval=3,hello_multiplier=50 + interface name=ens19,passive=1,csnp_interval=100 + router_id 192.168.2.8 + +node: uwu_pve1 + interface name=ens19 + interface name=ens20 + router_id 192.168.2.9 diff --git a/proxmox-ve-config/tests/fabric/resources/cfg/ospf_default.cfg b/proxmox-ve-config/tests/fabric/resources/cfg/ospf_default.cfg new file mode 100644 index 000000000000..778f04fc43fe --- /dev/null +++ b/proxmox-ve-config/tests/fabric/resources/cfg/ospf_default.cfg @@ -0,0 +1,10 @@ +fabric: 0 + +node: 0_pve + interface name=ens18,passive=false + interface name=ens19,passive=false,unnumbered=true + router_id 10.10.10.1 + +node: 0_pve1 + interface name=ens19,passive=false + router_id 10.10.10.2 diff --git a/proxmox-ve-config/tests/fabric/resources/cfg/ospf_verification_fail.cfg b/proxmox-ve-config/tests/fabric/resources/cfg/ospf_verification_fail.cfg new file mode 100644 index 000000000000..ae9ed03fdbc5 --- /dev/null +++ b/proxmox-ve-config/tests/fabric/resources/cfg/ospf_verification_fail.cfg @@ -0,0 +1,11 @@ +fabric: 0 + +node: 0_pve + interface name=dummy0,passive=true + interface name=ens18,passive=false + router_id 10.10.10.1 + +node: 1_pve1 + interface name=dummy0,passive=true + interface name=ens19,passive=false + router_id 10.10.10.2 diff --git a/proxmox-ve-config/tests/fabric/resources/frr/openfabric_default.pve.frr b/proxmox-ve-config/tests/fabric/resources/frr/openfabric_default.pve.frr new file mode 100644 index 000000000000..3eda4494f91b --- /dev/null +++ b/proxmox-ve-config/tests/fabric/resources/frr/openfabric_default.pve.frr @@ -0,0 +1,32 @@ +router openfabric uwu + net 49.0001.1921.6800.2008.00 +exit +! +interface dummy_uwu + ip router openfabric uwu + openfabric passive +exit +! +interface ens19 + ip router openfabric uwu + openfabric passive + openfabric hello-interval 4 + openfabric csnp-interval 100 +exit +! +interface ens20 + ip router openfabric uwu + openfabric passive + openfabric hello-interval 3 + openfabric hello-multiplier 50 +exit +! +access-list openfabric_uwu_ips permit 192.168.2.9/32 +access-list openfabric_uwu_ips permit 192.168.2.10/32 +! +route-map openfabric_uwu permit 10 + match ip address openfabric_uwu_ips + set src 192.168.2.8 +exit +! +ip protocol openfabric route-map openfabric_uwu diff --git a/proxmox-ve-config/tests/fabric/resources/frr/openfabric_default.pve1.frr b/proxmox-ve-config/tests/fabric/resources/frr/openfabric_default.pve1.frr new file mode 100644 index 000000000000..d291193b17b4 --- /dev/null +++ b/proxmox-ve-config/tests/fabric/resources/frr/openfabric_default.pve1.frr @@ -0,0 +1,28 @@ +router openfabric uwu + net 49.0001.1921.6800.2009.00 +exit +! +interface dummy_uwu + ip router openfabric uwu + openfabric passive +exit +! +interface ens19 + ip router openfabric uwu + openfabric hello-interval 4 +exit +! +interface ens20 + ip router openfabric uwu + openfabric hello-interval 4 +exit +! +access-list openfabric_uwu_ips permit 192.168.2.8/32 +access-list openfabric_uwu_ips permit 192.168.2.10/32 +! +route-map openfabric_uwu permit 10 + match ip address openfabric_uwu_ips + set src 192.168.2.9 +exit +! +ip protocol openfabric route-map openfabric_uwu diff --git a/proxmox-ve-config/tests/fabric/resources/frr/ospf_default.pve.frr b/proxmox-ve-config/tests/fabric/resources/frr/ospf_default.pve.frr new file mode 100644 index 000000000000..5ddb8c24be65 --- /dev/null +++ b/proxmox-ve-config/tests/fabric/resources/frr/ospf_default.pve.frr @@ -0,0 +1,26 @@ +router ospf + ospf router-id 10.10.10.1 +exit +! +interface dummy_0 + ip ospf area 0 + ip ospf passive +exit +! +interface ens18 + ip ospf area 0 +exit +! +interface ens19 + ip ospf area 0 + ip ospf network point-to-point +exit +! +access-list ospf_0_ips permit 10.10.10.2/32 +! +route-map ospf_0 permit 10 + match ip address ospf_0_ips + set src 10.10.10.1 +exit +! +ip protocol ospf route-map ospf_0 diff --git a/proxmox-ve-config/tests/fabric/resources/frr/ospf_default.pve1.frr b/proxmox-ve-config/tests/fabric/resources/frr/ospf_default.pve1.frr new file mode 100644 index 000000000000..da9cacb66b46 --- /dev/null +++ b/proxmox-ve-config/tests/fabric/resources/frr/ospf_default.pve1.frr @@ -0,0 +1,21 @@ +router ospf + ospf router-id 10.10.10.2 +exit +! +interface dummy_0 + ip ospf area 0 + ip ospf passive +exit +! +interface ens19 + ip ospf area 0 +exit +! +access-list ospf_0_ips permit 10.10.10.1/32 +! +route-map ospf_0 permit 10 + match ip address ospf_0_ips + set src 10.10.10.2 +exit +! +ip protocol ospf route-map ospf_0 -- 2.39.5 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel