[pve-devel] [PATCH ha-manager v2 12/18] test: rules: add compiled config output to rules config test cases
Daniel Kral
d.kral at proxmox.com
Tue Sep 9 10:33:49 CEST 2025
Since there exists a compiled representation of the HA rules config now,
which is currently used by both the HA Manager and API endpoints, add
the compiled representation to the test cases to document and follow
changes through these test cases.
Signed-off-by: Daniel Kral <d.kral at proxmox.com>
Reviewed-by: Michael Köppl <m.koeppl at proxmox.com>
Tested-by: Michael Köppl <m.koeppl at proxmox.com>
---
no changes since v1
...efaults-for-node-affinity-rules.cfg.expect | 29 +++
...lts-for-resource-affinity-rules.cfg.expect | 15 ++
...nt-node-resource-affinity-rules.cfg.expect | 51 ++++++
...sistent-resource-affinity-rules.cfg.expect | 8 +
...egative-resource-affinity-rules.cfg.expect | 21 +++
...fective-resource-affinity-rules.cfg.expect | 8 +
...egative-resource-affinity-rules.cfg.expect | 88 +++++++++
...ositive-resource-affinity-rules.cfg.expect | 173 ++++++++++++++++++
...egative-resource-affinity-rules.cfg.expect | 44 +++++
...ositive-resource-affinity-rules.cfg.expect | 128 +++++++++++++
...ty-with-resource-affinity-rules.cfg.expect | 30 +++
...rce-refs-in-node-affinity-rules.cfg.expect | 84 +++++++++
src/test/test_rules_config.pl | 3 +
13 files changed, 682 insertions(+)
diff --git a/src/test/rules_cfgs/defaults-for-node-affinity-rules.cfg.expect b/src/test/rules_cfgs/defaults-for-node-affinity-rules.cfg.expect
index 8ea928f2..35d061bd 100644
--- a/src/test/rules_cfgs/defaults-for-node-affinity-rules.cfg.expect
+++ b/src/test/rules_cfgs/defaults-for-node-affinity-rules.cfg.expect
@@ -58,3 +58,32 @@
"node-affinity-strict" : 4
}
}
+--- Compiled Config ---
+{
+ "node-affinity" : {
+ "vm:101" : {
+ "nodes" : {
+ "node1" : {
+ "priority" : 0
+ },
+ "node2" : {
+ "priority" : -1
+ },
+ "node3" : {
+ "priority" : -1
+ }
+ }
+ },
+ "vm:104" : {
+ "nodes" : {
+ "node3" : {
+ "priority" : 0
+ }
+ }
+ }
+ },
+ "resource-affinity" : {
+ "negative" : {},
+ "positive" : {}
+ }
+}
diff --git a/src/test/rules_cfgs/defaults-for-resource-affinity-rules.cfg.expect b/src/test/rules_cfgs/defaults-for-resource-affinity-rules.cfg.expect
index 7af19a18..d6a1121e 100644
--- a/src/test/rules_cfgs/defaults-for-resource-affinity-rules.cfg.expect
+++ b/src/test/rules_cfgs/defaults-for-resource-affinity-rules.cfg.expect
@@ -36,3 +36,18 @@
"resource-affinity-disabled-explicit" : 3
}
}
+--- Compiled Config ---
+{
+ "node-affinity" : {},
+ "resource-affinity" : {
+ "negative" : {
+ "vm:101" : {
+ "vm:102" : 1
+ },
+ "vm:102" : {
+ "vm:101" : 1
+ }
+ },
+ "positive" : {}
+ }
+}
diff --git a/src/test/rules_cfgs/inconsistent-node-resource-affinity-rules.cfg.expect b/src/test/rules_cfgs/inconsistent-node-resource-affinity-rules.cfg.expect
index ad517077..4317292b 100644
--- a/src/test/rules_cfgs/inconsistent-node-resource-affinity-rules.cfg.expect
+++ b/src/test/rules_cfgs/inconsistent-node-resource-affinity-rules.cfg.expect
@@ -75,3 +75,54 @@ Drop rule 'vm503-must-be-on-node2', because at least one resource is in a positi
"vm202-must-be-on-node2" : 4
}
}
+--- Compiled Config ---
+{
+ "node-affinity" : {
+ "vm:101" : {
+ "nodes" : {
+ "node1" : {
+ "priority" : 0
+ }
+ }
+ },
+ "vm:102" : {
+ "nodes" : {
+ "node1" : {
+ "priority" : 0
+ }
+ }
+ },
+ "vm:201" : {
+ "nodes" : {
+ "node1" : {
+ "priority" : 0
+ }
+ }
+ },
+ "vm:202" : {
+ "nodes" : {
+ "node2" : {
+ "priority" : 0
+ }
+ }
+ }
+ },
+ "resource-affinity" : {
+ "negative" : {
+ "vm:201" : {
+ "vm:202" : 1
+ },
+ "vm:202" : {
+ "vm:201" : 1
+ }
+ },
+ "positive" : {
+ "vm:101" : {
+ "vm:102" : 1
+ },
+ "vm:102" : {
+ "vm:101" : 1
+ }
+ }
+ }
+}
diff --git a/src/test/rules_cfgs/inconsistent-resource-affinity-rules.cfg.expect b/src/test/rules_cfgs/inconsistent-resource-affinity-rules.cfg.expect
index f47828c6..70d51ffd 100644
--- a/src/test/rules_cfgs/inconsistent-resource-affinity-rules.cfg.expect
+++ b/src/test/rules_cfgs/inconsistent-resource-affinity-rules.cfg.expect
@@ -12,3 +12,11 @@ Drop rule 'stick-together1', because rule shares two or more resources with a ne
"ids" : {},
"order" : {}
}
+--- Compiled Config ---
+{
+ "node-affinity" : {},
+ "resource-affinity" : {
+ "negative" : {},
+ "positive" : {}
+ }
+}
diff --git a/src/test/rules_cfgs/ineffective-negative-resource-affinity-rules.cfg.expect b/src/test/rules_cfgs/ineffective-negative-resource-affinity-rules.cfg.expect
index e2c1ad11..42fa7d24 100644
--- a/src/test/rules_cfgs/ineffective-negative-resource-affinity-rules.cfg.expect
+++ b/src/test/rules_cfgs/ineffective-negative-resource-affinity-rules.cfg.expect
@@ -28,3 +28,24 @@ Drop rule 'remove-me2', because rule defines more resources than available nodes
"do-not-remove-me2" : 2
}
}
+--- Compiled Config ---
+{
+ "node-affinity" : {},
+ "resource-affinity" : {
+ "negative" : {
+ "vm:101" : {
+ "vm:102" : 1,
+ "vm:103" : 1
+ },
+ "vm:102" : {
+ "vm:101" : 1,
+ "vm:103" : 1
+ },
+ "vm:103" : {
+ "vm:101" : 1,
+ "vm:102" : 1
+ }
+ },
+ "positive" : {}
+ }
+}
diff --git a/src/test/rules_cfgs/ineffective-resource-affinity-rules.cfg.expect b/src/test/rules_cfgs/ineffective-resource-affinity-rules.cfg.expect
index 4bbc782a..9c61944f 100644
--- a/src/test/rules_cfgs/ineffective-resource-affinity-rules.cfg.expect
+++ b/src/test/rules_cfgs/ineffective-resource-affinity-rules.cfg.expect
@@ -7,3 +7,11 @@ Drop rule 'lonely-resource2', because rule is ineffective as there are less than
"ids" : {},
"order" : {}
}
+--- Compiled Config ---
+{
+ "node-affinity" : {},
+ "resource-affinity" : {
+ "negative" : {},
+ "positive" : {}
+ }
+}
diff --git a/src/test/rules_cfgs/infer-implicit-negative-resource-affinity-rules.cfg.expect b/src/test/rules_cfgs/infer-implicit-negative-resource-affinity-rules.cfg.expect
index d3f1c7c3..f863c9fa 100644
--- a/src/test/rules_cfgs/infer-implicit-negative-resource-affinity-rules.cfg.expect
+++ b/src/test/rules_cfgs/infer-implicit-negative-resource-affinity-rules.cfg.expect
@@ -129,3 +129,91 @@ Drop rule 'do-not-infer-inconsistent-positive1', because rule shares two or more
"infer-two-positive1" : 4
}
}
+--- Compiled Config ---
+{
+ "node-affinity" : {},
+ "resource-affinity" : {
+ "negative" : {
+ "vm:201" : {
+ "vm:204" : 1
+ },
+ "vm:202" : {
+ "vm:204" : 1
+ },
+ "vm:203" : {
+ "vm:204" : 1
+ },
+ "vm:204" : {
+ "vm:201" : 1,
+ "vm:202" : 1,
+ "vm:203" : 1
+ },
+ "vm:301" : {
+ "vm:304" : 1,
+ "vm:305" : 1
+ },
+ "vm:302" : {
+ "vm:304" : 1,
+ "vm:305" : 1
+ },
+ "vm:303" : {
+ "vm:304" : 1,
+ "vm:305" : 1
+ },
+ "vm:304" : {
+ "vm:301" : 1,
+ "vm:302" : 1,
+ "vm:303" : 1
+ },
+ "vm:305" : {
+ "vm:301" : 1,
+ "vm:302" : 1,
+ "vm:303" : 1
+ },
+ "vm:401" : {
+ "vm:404" : 1
+ },
+ "vm:404" : {
+ "vm:401" : 1
+ }
+ },
+ "positive" : {
+ "vm:101" : {
+ "vm:102" : 1,
+ "vm:103" : 1
+ },
+ "vm:102" : {
+ "vm:101" : 1,
+ "vm:103" : 1
+ },
+ "vm:103" : {
+ "vm:101" : 1,
+ "vm:102" : 1
+ },
+ "vm:201" : {
+ "vm:202" : 1,
+ "vm:203" : 1
+ },
+ "vm:202" : {
+ "vm:201" : 1,
+ "vm:203" : 1
+ },
+ "vm:203" : {
+ "vm:201" : 1,
+ "vm:202" : 1
+ },
+ "vm:301" : {
+ "vm:302" : 1,
+ "vm:303" : 1
+ },
+ "vm:302" : {
+ "vm:301" : 1,
+ "vm:303" : 1
+ },
+ "vm:303" : {
+ "vm:301" : 1,
+ "vm:302" : 1
+ }
+ }
+ }
+}
diff --git a/src/test/rules_cfgs/infer-node-affinity-for-positive-resource-affinity-rules.cfg.expect b/src/test/rules_cfgs/infer-node-affinity-for-positive-resource-affinity-rules.cfg.expect
index 3f5cd6d8..ed339777 100644
--- a/src/test/rules_cfgs/infer-node-affinity-for-positive-resource-affinity-rules.cfg.expect
+++ b/src/test/rules_cfgs/infer-node-affinity-for-positive-resource-affinity-rules.cfg.expect
@@ -109,3 +109,176 @@
"infer-single-resource2" : 6
}
}
+--- Compiled Config ---
+{
+ "node-affinity" : {
+ "vm:201" : {
+ "nodes" : {
+ "node1" : {
+ "priority" : -1
+ },
+ "node2" : {
+ "priority" : -1
+ },
+ "node3" : {
+ "priority" : 0
+ }
+ }
+ },
+ "vm:203" : {
+ "nodes" : {
+ "node1" : {
+ "priority" : 0
+ },
+ "node2" : {
+ "priority" : 0
+ }
+ }
+ },
+ "vm:301" : {
+ "nodes" : {
+ "node1" : {
+ "priority" : -1
+ },
+ "node2" : {
+ "priority" : -1
+ },
+ "node3" : {
+ "priority" : 0
+ }
+ }
+ },
+ "vm:302" : {
+ "nodes" : {
+ "node1" : {
+ "priority" : -1
+ },
+ "node2" : {
+ "priority" : -1
+ },
+ "node3" : {
+ "priority" : 0
+ }
+ }
+ },
+ "vm:303" : {
+ "nodes" : {
+ "node1" : {
+ "priority" : -1
+ },
+ "node2" : {
+ "priority" : -1
+ },
+ "node3" : {
+ "priority" : 0
+ }
+ }
+ },
+ "vm:401" : {
+ "nodes" : {
+ "node1" : {
+ "priority" : 0
+ },
+ "node3" : {
+ "priority" : 0
+ }
+ }
+ },
+ "vm:402" : {
+ "nodes" : {
+ "node1" : {
+ "priority" : 0
+ },
+ "node3" : {
+ "priority" : 0
+ }
+ }
+ },
+ "vm:403" : {
+ "nodes" : {
+ "node1" : {
+ "priority" : 0
+ },
+ "node3" : {
+ "priority" : 0
+ }
+ }
+ },
+ "vm:404" : {
+ "nodes" : {
+ "node1" : {
+ "priority" : 0
+ },
+ "node3" : {
+ "priority" : 0
+ }
+ }
+ },
+ "vm:405" : {
+ "nodes" : {
+ "node1" : {
+ "priority" : 0
+ },
+ "node3" : {
+ "priority" : 0
+ }
+ }
+ }
+ },
+ "resource-affinity" : {
+ "negative" : {
+ "vm:201" : {
+ "vm:203" : 1
+ },
+ "vm:203" : {
+ "vm:201" : 1
+ }
+ },
+ "positive" : {
+ "vm:101" : {
+ "vm:102" : 1,
+ "vm:103" : 1
+ },
+ "vm:102" : {
+ "vm:101" : 1,
+ "vm:103" : 1
+ },
+ "vm:103" : {
+ "vm:101" : 1,
+ "vm:102" : 1
+ },
+ "vm:301" : {
+ "vm:302" : 1,
+ "vm:303" : 1
+ },
+ "vm:302" : {
+ "vm:301" : 1,
+ "vm:303" : 1
+ },
+ "vm:303" : {
+ "vm:301" : 1,
+ "vm:302" : 1
+ },
+ "vm:401" : {
+ "vm:402" : 1,
+ "vm:403" : 1,
+ "vm:404" : 1
+ },
+ "vm:402" : {
+ "vm:401" : 1,
+ "vm:403" : 1,
+ "vm:404" : 1
+ },
+ "vm:403" : {
+ "vm:401" : 1,
+ "vm:402" : 1,
+ "vm:404" : 1
+ },
+ "vm:404" : {
+ "vm:401" : 1,
+ "vm:402" : 1,
+ "vm:403" : 1
+ }
+ }
+ }
+}
diff --git a/src/test/rules_cfgs/merge-and-infer-implicit-negative-resource-affinity-rules.cfg.expect b/src/test/rules_cfgs/merge-and-infer-implicit-negative-resource-affinity-rules.cfg.expect
index 0002dc2a..98c8079a 100644
--- a/src/test/rules_cfgs/merge-and-infer-implicit-negative-resource-affinity-rules.cfg.expect
+++ b/src/test/rules_cfgs/merge-and-infer-implicit-negative-resource-affinity-rules.cfg.expect
@@ -71,3 +71,47 @@
"infer-connected-negative2" : 4
}
}
+--- Compiled Config ---
+{
+ "node-affinity" : {},
+ "resource-affinity" : {
+ "negative" : {
+ "vm:101" : {
+ "vm:104" : 1,
+ "vm:105" : 1
+ },
+ "vm:102" : {
+ "vm:104" : 1,
+ "vm:105" : 1
+ },
+ "vm:103" : {
+ "vm:104" : 1,
+ "vm:105" : 1
+ },
+ "vm:104" : {
+ "vm:101" : 1,
+ "vm:102" : 1,
+ "vm:103" : 1
+ },
+ "vm:105" : {
+ "vm:101" : 1,
+ "vm:102" : 1,
+ "vm:103" : 1
+ }
+ },
+ "positive" : {
+ "vm:101" : {
+ "vm:102" : 1,
+ "vm:103" : 1
+ },
+ "vm:102" : {
+ "vm:101" : 1,
+ "vm:103" : 1
+ },
+ "vm:103" : {
+ "vm:101" : 1,
+ "vm:102" : 1
+ }
+ }
+ }
+}
diff --git a/src/test/rules_cfgs/merge-connected-positive-resource-affinity-rules.cfg.expect b/src/test/rules_cfgs/merge-connected-positive-resource-affinity-rules.cfg.expect
index 935a4f7c..07461626 100644
--- a/src/test/rules_cfgs/merge-connected-positive-resource-affinity-rules.cfg.expect
+++ b/src/test/rules_cfgs/merge-connected-positive-resource-affinity-rules.cfg.expect
@@ -68,3 +68,131 @@
"do-not-merge-positive2" : 5
}
}
+--- Compiled Config ---
+{
+ "node-affinity" : {},
+ "resource-affinity" : {
+ "negative" : {
+ "vm:101" : {
+ "vm:102" : 1
+ },
+ "vm:102" : {
+ "vm:101" : 1,
+ "vm:103" : 1
+ },
+ "vm:103" : {
+ "vm:102" : 1
+ },
+ "vm:104" : {
+ "vm:105" : 1
+ },
+ "vm:105" : {
+ "vm:104" : 1
+ }
+ },
+ "positive" : {
+ "vm:201" : {
+ "vm:202" : 1
+ },
+ "vm:202" : {
+ "vm:201" : 1
+ },
+ "vm:203" : {
+ "vm:204" : 1
+ },
+ "vm:204" : {
+ "vm:203" : 1
+ },
+ "vm:301" : {
+ "vm:302" : 1,
+ "vm:303" : 1,
+ "vm:304" : 1,
+ "vm:305" : 1,
+ "vm:306" : 1,
+ "vm:307" : 1,
+ "vm:308" : 1,
+ "vm:309" : 1
+ },
+ "vm:302" : {
+ "vm:301" : 1,
+ "vm:303" : 1,
+ "vm:304" : 1,
+ "vm:305" : 1,
+ "vm:306" : 1,
+ "vm:307" : 1,
+ "vm:308" : 1,
+ "vm:309" : 1
+ },
+ "vm:303" : {
+ "vm:301" : 1,
+ "vm:302" : 1,
+ "vm:304" : 1,
+ "vm:305" : 1,
+ "vm:306" : 1,
+ "vm:307" : 1,
+ "vm:308" : 1,
+ "vm:309" : 1
+ },
+ "vm:304" : {
+ "vm:301" : 1,
+ "vm:302" : 1,
+ "vm:303" : 1,
+ "vm:305" : 1,
+ "vm:306" : 1,
+ "vm:307" : 1,
+ "vm:308" : 1,
+ "vm:309" : 1
+ },
+ "vm:305" : {
+ "vm:301" : 1,
+ "vm:302" : 1,
+ "vm:303" : 1,
+ "vm:304" : 1,
+ "vm:306" : 1,
+ "vm:307" : 1,
+ "vm:308" : 1,
+ "vm:309" : 1
+ },
+ "vm:306" : {
+ "vm:301" : 1,
+ "vm:302" : 1,
+ "vm:303" : 1,
+ "vm:304" : 1,
+ "vm:305" : 1,
+ "vm:307" : 1,
+ "vm:308" : 1,
+ "vm:309" : 1
+ },
+ "vm:307" : {
+ "vm:301" : 1,
+ "vm:302" : 1,
+ "vm:303" : 1,
+ "vm:304" : 1,
+ "vm:305" : 1,
+ "vm:306" : 1,
+ "vm:308" : 1,
+ "vm:309" : 1
+ },
+ "vm:308" : {
+ "vm:301" : 1,
+ "vm:302" : 1,
+ "vm:303" : 1,
+ "vm:304" : 1,
+ "vm:305" : 1,
+ "vm:306" : 1,
+ "vm:307" : 1,
+ "vm:309" : 1
+ },
+ "vm:309" : {
+ "vm:301" : 1,
+ "vm:302" : 1,
+ "vm:303" : 1,
+ "vm:304" : 1,
+ "vm:305" : 1,
+ "vm:306" : 1,
+ "vm:307" : 1,
+ "vm:308" : 1
+ }
+ }
+ }
+}
diff --git a/src/test/rules_cfgs/multi-priority-node-affinity-with-resource-affinity-rules.cfg.expect b/src/test/rules_cfgs/multi-priority-node-affinity-with-resource-affinity-rules.cfg.expect
index e2d5ee00..68a2b75f 100644
--- a/src/test/rules_cfgs/multi-priority-node-affinity-with-resource-affinity-rules.cfg.expect
+++ b/src/test/rules_cfgs/multi-priority-node-affinity-with-resource-affinity-rules.cfg.expect
@@ -46,3 +46,33 @@ Drop rule 'vm201-vm202-must-be-on-node1-or-node2', because resources are in a re
"vm302-must-be-on-node2-with-prio-2" : 6
}
}
+--- Compiled Config ---
+{
+ "node-affinity" : {
+ "vm:301" : {
+ "nodes" : {
+ "node1" : {
+ "priority" : 1
+ }
+ }
+ },
+ "vm:302" : {
+ "nodes" : {
+ "node2" : {
+ "priority" : 2
+ }
+ }
+ }
+ },
+ "resource-affinity" : {
+ "negative" : {
+ "vm:301" : {
+ "vm:302" : 1
+ },
+ "vm:302" : {
+ "vm:301" : 1
+ }
+ },
+ "positive" : {}
+ }
+}
diff --git a/src/test/rules_cfgs/multiple-resource-refs-in-node-affinity-rules.cfg.expect b/src/test/rules_cfgs/multiple-resource-refs-in-node-affinity-rules.cfg.expect
index 30633d8c..425de2b1 100644
--- a/src/test/rules_cfgs/multiple-resource-refs-in-node-affinity-rules.cfg.expect
+++ b/src/test/rules_cfgs/multiple-resource-refs-in-node-affinity-rules.cfg.expect
@@ -61,3 +61,87 @@ Drop rule 'same-resource3', because resource 'vm:201' is already used in another
"no-same-resource3" : 3
}
}
+--- Compiled Config ---
+{
+ "node-affinity" : {
+ "vm:101" : {
+ "nodes" : {
+ "node1" : {
+ "priority" : 0
+ },
+ "node2" : {
+ "priority" : 2
+ },
+ "node3" : {
+ "priority" : -1
+ }
+ }
+ },
+ "vm:102" : {
+ "nodes" : {
+ "node1" : {
+ "priority" : 0
+ },
+ "node2" : {
+ "priority" : 2
+ },
+ "node3" : {
+ "priority" : -1
+ }
+ }
+ },
+ "vm:103" : {
+ "nodes" : {
+ "node1" : {
+ "priority" : 0
+ },
+ "node2" : {
+ "priority" : 2
+ },
+ "node3" : {
+ "priority" : -1
+ }
+ }
+ },
+ "vm:104" : {
+ "nodes" : {
+ "node1" : {
+ "priority" : 0
+ },
+ "node2" : {
+ "priority" : 2
+ },
+ "node3" : {
+ "priority" : -1
+ }
+ }
+ },
+ "vm:105" : {
+ "nodes" : {
+ "node1" : {
+ "priority" : 0
+ },
+ "node2" : {
+ "priority" : 2
+ },
+ "node3" : {
+ "priority" : -1
+ }
+ }
+ },
+ "vm:106" : {
+ "nodes" : {
+ "node1" : {
+ "priority" : 0
+ },
+ "node2" : {
+ "priority" : 2
+ }
+ }
+ }
+ },
+ "resource-affinity" : {
+ "negative" : {},
+ "positive" : {}
+ }
+}
diff --git a/src/test/test_rules_config.pl b/src/test/test_rules_config.pl
index edfcb3b7..f0792ff9 100755
--- a/src/test/test_rules_config.pl
+++ b/src/test/test_rules_config.pl
@@ -54,9 +54,12 @@ sub check_cfg {
my $cfg = PVE::HA::Rules->parse_config($cfg_fn, $raw);
PVE::HA::Rules->set_rule_defaults($_) for values %{ $cfg->{ids} };
my $messages = PVE::HA::Rules->transform($cfg, $nodes);
+ my $compiled_cfg = PVE::HA::Rules->compile($cfg, $nodes);
print $_ for @$messages;
print "--- Config ---\n";
print to_json($cfg, { canonical => 1, pretty => 1, utf8 => 1 });
+ print "--- Compiled Config ---\n";
+ print to_json($compiled_cfg, { canonical => 1, pretty => 1, utf8 => 1 });
select(STDOUT);
}
--
2.47.3
More information about the pve-devel
mailing list