[pve-devel] [PATCH ha-manager 1/9] sim: add command to set static service stats

Maximiliano Sandoval m.sandoval at proxmox.com
Tue Oct 14 11:47:19 CEST 2025


This will allow testing different cluster resource schedulers.

Signed-off-by: Maximiliano Sandoval <m.sandoval at proxmox.com>
---
 src/PVE/HA/Sim/Hardware.pm | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/src/PVE/HA/Sim/Hardware.pm b/src/PVE/HA/Sim/Hardware.pm
index 9e8c799..4d84eeb 100644
--- a/src/PVE/HA/Sim/Hardware.pm
+++ b/src/PVE/HA/Sim/Hardware.pm
@@ -178,6 +178,25 @@ sub set_service_state {
     return $conf;
 }
 
+sub set_static_service_stats {
+    my ($self, $sid, $new_stats) = @_;
+
+    my $stats = $self->read_static_service_stats();
+    die "no such service '$sid'" if !$stats->{$sid};
+
+    if (my $memory = $new_stats->{maxmemory}) {
+        print "setting $sid memory to $memory\n" if $memory != $stats->{$sid}->{maxmemory};
+        $stats->{$sid}->{maxmemory} = $memory;
+    }
+
+    if (my $cpu = $new_stats->{maxcpu}) {
+        print "setting $sid memory to $cpu\n" if $cpu != $stats->{$sid}->{maxcpu};
+        $stats->{$sid}->{maxcpu} = $cpu;
+    }
+
+    $self->write_static_service_stats($stats);
+}
+
 sub add_service {
     my ($self, $sid, $opts, $running) = @_;
 
@@ -397,6 +416,14 @@ sub read_static_service_stats {
     return $stats;
 }
 
+sub write_static_service_stats {
+    my ($self, $stats) = @_;
+
+    my $filename = "$self->{statusdir}/static_service_stats";
+    eval { PVE::HA::Tools::write_json_to_file($filename, $stats) };
+    $self->log('error', "writing static service stats failed - $@") if $@;
+}
+
 sub new {
     my ($this, $testdir) = @_;
 
@@ -611,6 +638,7 @@ sub get_cfs_state {
 #   service <sid> stop <timeout>
 #   service <sid> lock/unlock [lockname]
 #   service <sid> add <node> [<request-state=started>] [<running=0>]
+#   service <sid> set-static-stats <maxcpu> <maxmemory>
 #   service <sid> delete
 sub sim_hardware_cmd {
     my ($self, $cmdstr, $logid) = @_;
@@ -760,6 +788,15 @@ sub sim_hardware_cmd {
                     $params[2] || 0,
                 );
 
+            } elsif ($action eq 'set-static-stats') {
+                die "sim_hardware_cmd: missing maxcpu for '$action' command" if !$params[0];
+                die "sim_hardware_cmd: missing maxmemory for '$action' command" if !$params[1];
+
+                $self->set_static_service_stats(
+                    $sid,
+                    { maxcpu => $params[0], maxmemory => $params[1] },
+                );
+
             } elsif ($action eq 'delete') {
 
                 $self->delete_service($sid);
-- 
2.47.3





More information about the pve-devel mailing list