From: John Mulligan Date: Sun, 19 Nov 2023 21:35:06 +0000 (-0500) Subject: cephadm: call functions instead of executing rm in rm_cluster X-Git-Tag: v19.3.0~284^2~5 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=08e7a56ead5d3a241cd626d0436dff24867d3445;p=ceph.git 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 --- diff --git a/src/cephadm/cephadm.py b/src/cephadm/cephadm.py index 23352651f27d..636c21615474 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