crs: avoid auto-vivification when adding node to service usage

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>
This commit is contained in:
Fiona Ebner 2023-10-05 16:05:46 +02:00 committed by Thomas Lamprecht
parent c7843a315d
commit 1c61138341

View File

@ -10,6 +10,7 @@ sub new {
return bless { return bless {
nodes => {}, nodes => {},
haenv => $haenv,
}, $class; }, $class;
} }
@ -40,7 +41,14 @@ sub contains_node {
sub add_service_usage_to_node { sub add_service_usage_to_node {
my ($self, $nodename, $sid, $service_node, $migration_target) = @_; 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 { sub score_nodes_to_start_service {