]> git.proxmox.com Git - pve-ha-manager.git/commitdiff
sim env: derive service usage from ID as fallback
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Mon, 20 Mar 2023 10:03:05 +0000 (11:03 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Mon, 20 Mar 2023 10:09:01 +0000 (11:09 +0100)
so that we don't need to specify all usage stats explicitly for
bigger tests.

Note, we explicitly use two digits for memory as with just one a lot
of services are exactly the same, which gives us flaky tests due to
rounding, or some flakiness in the rust code - so this is a bit of a
stop gap for that too and should be reduced to a single digit once
we fixed it in the future.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
src/PVE/HA/Sim/Resources.pm

index e6e1853cef85b0219709dde4c8858d4105eb11d5..f3517206e11a4b929a4fc76f035f74743fd2f1f7 100644 (file)
@@ -146,7 +146,15 @@ sub get_static_stats {
     my $hardware = $haenv->hardware();
 
     my $stats = $hardware->read_static_service_stats();
-    return $stats->{$sid};
+    if (my $service_stats = $stats->{$sid}) {
+       return $service_stats;
+    } elsif ($id =~ /^(\d)(\d\d)/) {
+       # auto assign usage calculated from ID for convenience
+       my ($maxcpu, $maxmeory) = (int($1) + 1, (int($2) + 1) * 1<<29);
+       return { maxcpu => $maxcpu, maxmem => $maxmeory };
+    } else {
+       return {};
+    }
 }
 
 1;