cephadm: fix rm-cluster when /etc/ceph/ceph.conf is a directory
Fix IsADirectoryError in _rm_cluster() when /etc/ceph/ceph.conf exists
as a directory instead of a file.
The Error:
----------
During cluster cleanup, _rm_cluster() fails with:
Traceback (most recent call last):
File "/home/ubuntu/cephtest/cephadm", line 8634, in <module>
main()
File "/home/ubuntu/cephtest/cephadm", line 8622, in main
r = ctx.func(ctx)
File "/home/ubuntu/cephtest/cephadm", line 6538, in command_rm_cluster
with open(files[0]) as f:
IsADirectoryError: [Errno 21] Is a directory: '/etc/ceph/ceph.conf'
Docker/Podman has a quirk: when bind mounting to a destination that
doesn't exist, the container runtime creates the destination as a
DIRECTORY, not a file.
The Fix:
--------
Use early returns and guard clauses to handle different states of
/etc/ceph/ceph.conf:
1. If ceph.conf doesn't exist: return early (nothing to clean up)
2. If ceph.conf is an empty directory: remove it and return (leftover
bind mount point from container)
3. If ceph.conf exists but is not a file: return early (unexpected state)
4. If ceph.conf is a file: validate fsid and remove all config files
Also log a warning when the fsid in ceph.conf does not match the cluster
being removed, so the user knows why config files are not being deleted.