]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
cephadm: Fix get_cluster_count when data_dir is missing
authorJames Oakley <jfunk@funktronics.ca>
Sun, 15 Jun 2025 15:04:35 +0000 (12:04 -0300)
committerAdam King <adking@redhat.com>
Tue, 15 Jul 2025 13:40:47 +0000 (09:40 -0400)
It is possible for cephadm, if it fails to create a cluster, to direct
the user to delete the cluster even though the data_dir has not yet been
created. Running that command would fail during the cluster count check.

Signed-off-by: James Oakley <jfunk@funktronics.ca>
(cherry picked from commit 8e39f8911c4a485975d6adb04b04893e43128e67)

src/cephadm/cephadm.py
src/cephadm/tests/test_cephadm.py

index 5a6be98bcbd8d7e19b9bff9cee734c7878ddb2b1..f75aaa86dac6835a64ff70fa863089c2f2a68d22 100755 (executable)
@@ -3958,7 +3958,9 @@ def command_zap_osds(ctx: CephadmContext) -> None:
 
 
 def get_ceph_cluster_count(ctx: CephadmContext) -> int:
-    return len([c for c in os.listdir(ctx.data_dir) if is_fsid(c)])
+    if os.path.isdir(ctx.data_dir):
+        return len([c for c in os.listdir(ctx.data_dir) if is_fsid(c)])
+    return 0
 
 
 def command_rm_cluster(ctx: CephadmContext) -> None:
index 8af15c2e883be843e4ec482d118e01edea930aa3..ddb98c4205767231f2b3e98899cf62bc85c987f9 100644 (file)
@@ -1501,8 +1501,14 @@ ff792c06d8544b983.scope not found.: OCI runtime error"""
     ])
     def test_get_ceph_cluster_count(self, test_input, expected):
         ctx = _cephadm.CephadmContext()
-        with mock.patch('os.listdir', return_value=test_input):
-            assert _cephadm.get_ceph_cluster_count(ctx) == expected
+        with mock.patch('os.path.isdir', return_value=True):
+            with mock.patch('os.listdir', return_value=test_input):
+                assert _cephadm.get_ceph_cluster_count(ctx) == expected
+
+    def test_get_ceph_cluster_count_missing_datadir(self):
+        ctx = _cephadm.CephadmContext()
+        with mock.patch('os.path.isdir', return_value=False):
+            assert _cephadm.get_ceph_cluster_count(ctx) == 0
 
     def test_set_image_minimize_config(self):
         def throw_cmd(cmd):