From 08e7a56ead5d3a241cd626d0436dff24867d3445 Mon Sep 17 00:00:00 2001 From: John Mulligan Date: Sun, 19 Nov 2023 16:35:06 -0500 Subject: [PATCH] cephadm: call functions instead of executing rm in rm_cluster Convert a bunch of invocations of rm via a subprocess to function calls. This should make it easier (or possible?) to test the function in the unit test framework as well as possibly saving a few resources. Signed-off-by: John Mulligan --- src/cephadm/cephadm.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/cephadm/cephadm.py b/src/cephadm/cephadm.py index 23352651f27..636c2161547 100755 --- a/src/cephadm/cephadm.py +++ b/src/cephadm/cephadm.py @@ -4326,25 +4326,30 @@ def _rm_cluster(ctx: CephadmContext, keep_logs: bool, zap_osds: bool) -> None: shutil.rmtree(unit_dir / f'ceph-{ctx.fsid}.target.wants', ignore_errors=True) # rm data - call_throws(ctx, ['rm', '-rf', ctx.data_dir + '/' + ctx.fsid]) + shutil.rmtree(Path(ctx.data_dir) / ctx.fsid, ignore_errors=True) if not keep_logs: # rm logs - call_throws(ctx, ['rm', '-rf', ctx.log_dir + '/' + ctx.fsid]) + shutil.rmtree(Path(ctx.log_dir) / ctx.fsid, ignore_errors=True) # rm logrotate config - call_throws(ctx, ['rm', '-f', ctx.logrotate_dir + '/ceph-%s' % ctx.fsid]) + unlink_file( + Path(ctx.logrotate_dir) / ('ceph-%s' % ctx.fsid), ignore_errors=True + ) # if last cluster on host remove shared files if get_ceph_cluster_count(ctx) == 0: terminate_service(ctx, 'ceph.target') # rm shared ceph target files - call_throws(ctx, ['rm', '-f', ctx.unit_dir + '/multi-user.target.wants/ceph.target']) - call_throws(ctx, ['rm', '-f', ctx.unit_dir + '/ceph.target']) + unlink_file( + Path(ctx.unit_dir) / 'multi-user.target.wants/ceph.target', + ignore_errors=True + ) + unlink_file(Path(ctx.unit_dir) / 'ceph.target', ignore_errors=True) # rm cephadm logrotate config - call_throws(ctx, ['rm', '-f', ctx.logrotate_dir + '/cephadm']) + unlink_file(Path(ctx.logrotate_dir) / 'cephadm', ignore_errors=True) if not keep_logs: # remove all cephadm logs -- 2.39.5