Skip to content

Commit c28d7b2

Browse files
authored
Merge pull request ceph#63952 from jimfunk/get_ceph_cluster_count_missing_data_dir
cephadm: Get ceph cluster count missing data dir Reviewed-by: Adam King <[email protected]>
2 parents e1c6a7d + 8e39f89 commit c28d7b2

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
@@ -3958,7 +3958,9 @@ def command_zap_osds(ctx: CephadmContext) -> None:
39583958

39593959

39603960
def get_ceph_cluster_count(ctx: CephadmContext) -> int:
3961-
return len([c for c in os.listdir(ctx.data_dir) if is_fsid(c)])
3961+
if os.path.isdir(ctx.data_dir):
3962+
return len([c for c in os.listdir(ctx.data_dir) if is_fsid(c)])
3963+
return 0
39623964

39633965

39643966
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)