Thanks to visit codestin.com
Credit goes to github.com

Skip to content

cephadm: fix rm-cluster when /etc/ceph/ceph.conf is a directory#67621

Open
tchaikov wants to merge 1 commit intoceph:mainfrom
tchaikov:wip-cephadm-ceph.conf
Open

cephadm: fix rm-cluster when /etc/ceph/ceph.conf is a directory#67621
tchaikov wants to merge 1 commit intoceph:mainfrom
tchaikov:wip-cephadm-ceph.conf

Conversation

@tchaikov
Copy link
Contributor

@tchaikov tchaikov commented Mar 3, 2026

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'

This occurs when attempting to remove a cluster where /etc/ceph/ceph.conf is a directory instead of the expected file.

Root Cause:

Container services (iSCSI, NFS, NVMe-oF) create bind mounts like:

  mounts[os.path.join(data_dir, 'config')] = '/etc/ceph/ceph.conf:z'

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.

This occurs in test environments when:

  1. Test framework creates /etc/ceph/ directory
  2. Container service starts before bootstrap writes /etc/ceph/ceph.conf
  3. Container runtime creates /etc/ceph/ceph.conf as a directory for the bind mount
  4. Later, _rm_cluster() tries to open('/etc/ceph/ceph.conf') assuming it's a file, causing IsADirectoryError

Scenarios where /etc/ceph/ceph.conf may not exist as a file:

  • Bootstrap with custom --output-config location
  • Bootstrap failure/interruption before config write
  • Race condition: container service starts before bootstrap completes
  • Manual deletion of config file
  • Container-only deployment without host-level config

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

Fixes: https://tracker.ceph.com/issues/75275

Contribution Guidelines

  • To sign and title your commits, please refer to Submitting Patches to Ceph.

  • If you are submitting a fix for a stable branch (e.g. "quincy"), please refer to Submitting Patches to Ceph - Backports for the proper workflow.

  • When filling out the below checklist, you may click boxes directly in the GitHub web UI. When entering or editing the entire PR message in the GitHub web UI editor, you may also select a checklist item by adding an x between the brackets: [x]. Spaces and capitalization matter when checking off items this way.

Checklist

  • Tracker (select at least one)
    • References tracker ticket
    • Very recent bug; references commit where it was introduced
    • New feature (ticket optional)
    • Doc update (no ticket needed)
    • Code cleanup (no ticket needed)
  • Component impact
    • Affects Dashboard, opened tracker ticket
    • Affects Orchestrator, opened tracker ticket
    • No impact that needs to be tracked
  • Documentation (select at least one)
    • Updates relevant documentation
    • No doc update is appropriate
  • Tests (select at least one)
Show available Jenkins commands

You must only issue one Jenkins command per-comment. Jenkins does not understand
comments with more than one command.

@tchaikov tchaikov requested a review from a team as a code owner March 3, 2026 02:37
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'

This occurs when attempting to remove a cluster where /etc/ceph/ceph.conf
is a directory instead of the expected file.

Root Cause:
-----------
Container services (iSCSI, NFS, NVMe-oF) create bind mounts like:
  mounts[os.path.join(data_dir, 'config')] = '/etc/ceph/ceph.conf:z'

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.

This occurs in test environments when:
1. Test framework creates /etc/ceph/ directory
2. Container service starts before bootstrap writes /etc/ceph/ceph.conf
3. Container runtime creates /etc/ceph/ceph.conf as a directory for the
   bind mount
4. Later, _rm_cluster() tries to open('/etc/ceph/ceph.conf') assuming
   it's a file, causing IsADirectoryError

Scenarios where /etc/ceph/ceph.conf may not exist as a file:
- Bootstrap with custom --output-config location
- Bootstrap failure/interruption before config write
- Race condition: container service starts before bootstrap completes
- Manual deletion of config file
- Container-only deployment without host-level config

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

Signed-off-by: Kefu Chai <[email protected]>
@tchaikov tchaikov force-pushed the wip-cephadm-ceph.conf branch from 1899151 to 5bf13d6 Compare March 3, 2026 02:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant