]> git.proxmox.com Git - pve-ha-manager.git/commitdiff
crs: avoid auto-vivification when adding node to service usage
authorFiona Ebner <f.ebner@proxmox.com>
Thu, 5 Oct 2023 14:05:46 +0000 (16:05 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 6 Oct 2023 10:27:04 +0000 (12:27 +0200)
Part of what caused bug #4984. Make the code future-proof and warn
when the node was never registered in the plugin, similar to what the
'static' usage plugin already does.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
 [ TL: rework commit message subject ]
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
src/PVE/HA/Usage/Basic.pm

index f066350a0000c12aab35638401e85823c5b5edcf..d6b3d6c69e8f890476c26c4dc31224fdf57cd006 100644 (file)
@@ -10,6 +10,7 @@ sub new {
 
     return bless {
        nodes => {},
+       haenv => $haenv,
     }, $class;
 }
 
@@ -40,7 +41,14 @@ sub contains_node {
 sub add_service_usage_to_node {
     my ($self, $nodename, $sid, $service_node, $migration_target) = @_;
 
-    $self->{nodes}->{$nodename}++;
+    if ($self->contains_node($nodename)) {
+       $self->{nodes}->{$nodename}++;
+    } else {
+       $self->{haenv}->log(
+           'warning',
+           "unable to add service '$sid' usage to node '$nodename' - node not in usage hash",
+       );
+    }
 }
 
 sub score_nodes_to_start_service {