]> git.proxmox.com Git - pve-manager.git/commit
fix #5198: ceph: mon: fix mon existence check in mon removal assertion
authorMax Carrara <m.carrara@proxmox.com>
Thu, 14 Mar 2024 10:19:29 +0000 (11:19 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 21 Mar 2024 17:09:30 +0000 (18:09 +0100)
commitbacedc4e9bd1cd45e298c8b9c38c502aa2c40635
tree99f5e2b69b7a06d6609d97eb06f17963d0f4d9fc
parent6d336ba433061deb48375fe8bdb570f4a5805f7a
fix #5198: ceph: mon: fix mon existence check in mon removal assertion

The Ceph monitor removal assertion contains a condition that checks
whether the given mon ID actually exists and thus may be removed.

The first part of the condition checks whether the hash returned by
`get_services_info` [0] contains the key "mon.$monid". However, the
hash's keys are never prefixed with "mon.", which makes this check
incorrect.

This is fixed by just using "$monid" directly.

The second part checks whether the mon hashes returned by
Ceph contain the "name" key before comparing the key with the given
mon ID. This key existence check is also incorrect; in particular:
  * If the lookup `$_->{name}` evaluates to e.g. "foo", the check
    passes, because "foo" is truthy. [1]
  * If the lookup `$_->{name}` evaluates to "0", the check fails,
    because "0" is falsy (due to it being equivalent to the number 0,
    according to Perl [1]).

This is solved by using the inbuilt `defined()` instead of relying on
Perl's definition of truthiness.

[0]: https://git.proxmox.com/?p=pve-manager.git;a=blob;f=PVE/Ceph/Services.pm;h=e0f31e8eb6bc9b3777b3d0d548497276efaa5c41;hb=HEAD#l112
[1]: https://perldoc.perl.org/perldata#Scalar-values

Fixes: https://bugzilla.proxmox.com/show_bug.cgi?id=5198
Signed-off-by: Max Carrara <m.carrara@proxmox.com>
PVE/API2/Ceph/MON.pm