pve-manager/PVE/API2/Ceph
Max Carrara bacedc4e9b 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>
2024-03-21 18:09:30 +01:00
..
Cfg.pm api: ceph: add endpoint to fetch config keys 2023-11-21 14:39:17 +01:00
FS.pm api: cephfs: add 'fs-name' for cephfs storage 2021-11-11 17:52:08 +01:00
Makefile api: ceph: remove deprecrated Pools path 2023-06-21 09:21:04 +02:00
MDS.pm fix #4808: ceph: mds create: use snake_case when setting options 2023-09-06 16:57:10 +02:00
MGR.pm ceph: make all service name regexes the same 2020-03-04 15:38:09 +01:00
MON.pm fix #5198: ceph: mon: fix mon existence check in mon removal assertion 2024-03-21 18:09:30 +01:00
OSD.pm api: osd: destroy: remove mclock max iops settings 2023-11-17 08:09:15 +01:00
Pool.pm api: ceph: deprecate pools in favor of pool 2023-03-20 15:31:04 +01:00