Skip to content

Commit 8e39f89

Browse files
committed
cephadm: Fix get_cluster_count when data_dir is missing
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 <[email protected]>
1 parent 1151a9a commit 8e39f89

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/cephadm/cephadm.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3960,7 +3960,9 @@ def command_zap_osds(ctx: CephadmContext) -> None:
39603960

39613961

39623962
def get_ceph_cluster_count(ctx: CephadmContext) -> int:
3963-
return len([c for c in os.listdir(ctx.data_dir) if is_fsid(c)])
3963+
if os.path.isdir(ctx.data_dir):
3964+
return len([c for c in os.listdir(ctx.data_dir) if is_fsid(c)])
3965+
return 0
39643966

39653967

39663968
def command_rm_cluster(ctx: CephadmContext) -> None:

src/cephadm/tests/test_cephadm.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1501,8 +1501,14 @@ def test_extract_uid_gid_fail(self, _call):
15011501
])
15021502
def test_get_ceph_cluster_count(self, test_input, expected):
15031503
ctx = _cephadm.CephadmContext()
1504-
with mock.patch('os.listdir', return_value=test_input):
1505-
assert _cephadm.get_ceph_cluster_count(ctx) == expected
1504+
with mock.patch('os.path.isdir', return_value=True):
1505+
with mock.patch('os.listdir', return_value=test_input):
1506+
assert _cephadm.get_ceph_cluster_count(ctx) == expected
1507+
1508+
def test_get_ceph_cluster_count_missing_datadir(self):
1509+
ctx = _cephadm.CephadmContext()
1510+
with mock.patch('os.path.isdir', return_value=False):
1511+
assert _cephadm.get_ceph_cluster_count(ctx) == 0
15061512

15071513
def test_set_image_minimize_config(self):
15081514
def throw_cmd(cmd):

0 commit comments

Comments
 (0)