[pve-devel] [PATCH proxmox-ve-rs 17/17] ve-config: add integrations tests

Gabriel Goller g.goller at proxmox.com
Fri Mar 28 18:13:06 CET 2025


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 at 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





More information about the pve-devel mailing list