]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: Fix get_cluster_count when data_dir is missing 63952/head
authorJames Oakley <jfunk@funktronics.ca>
Sun, 15 Jun 2025 15:04:35 +0000 (12:04 -0300)
committerJames Oakley <jfunk@funktronics.ca>
Mon, 16 Jun 2025 17:41:09 +0000 (14:41 -0300)
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>
src/cephadm/cephadm.py
src/cephadm/tests/test_cephadm.py

index ac5ab21e3a4af8626871963138f65398092a0ed5..b720d277e6a590af39ac25c3a53e96a187dc0c9f 100755 (executable)
@@ -3960,7 +3960,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):