From 79b8f3a74da5b47a3cb9cb66bc089273ebc39d67 Mon Sep 17 00:00:00 2001 From: Guillaume Abrioux Date: Fri, 9 Jul 2021 11:07:08 +0200 Subject: [PATCH] lib/ceph-volume: support zapping by osd_id This commit adds the support for zapping an osd by osd_id in the ceph_volume module. Signed-off-by: Guillaume Abrioux (cherry picked from commit 70f1d6e2cd9ed4abb4db599f9faa816703430d80) --- library/ceph_volume.py | 20 ++++++++++++++++++-- tests/library/test_ceph_volume.py | 15 +++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/library/ceph_volume.py b/library/ceph_volume.py index 9bef51fe5..5e69b3d81 100644 --- a/library/ceph_volume.py +++ b/library/ceph_volume.py @@ -53,6 +53,10 @@ options: description: - The OSD FSID required: false + osd_id: + description: + - The OSD ID + required: false journal: description: - The logical volume name or partition to use as a filestore journal. @@ -493,6 +497,7 @@ def zap_devices(module, container_image): wal = module.params.get('wal', None) wal_vg = module.params.get('wal_vg', None) osd_fsid = module.params.get('osd_fsid', None) + osd_id = module.params.get('osd_id', None) destroy = module.params.get('destroy', True) # build the CLI @@ -504,6 +509,9 @@ def zap_devices(module, container_image): if osd_fsid: cmd.extend(['--osd-fsid', osd_fsid]) + if osd_id: + cmd.extend(['--osd-id', osd_id]) + if data: data = get_data(data, data_vg) cmd.append(data) @@ -549,12 +557,19 @@ def run_module(): wal_devices=dict(type='list', required=False, default=[]), report=dict(type='bool', required=False, default=False), osd_fsid=dict(type='str', required=False), + osd_id=dict(type='str', required=False), destroy=dict(type='bool', required=False, default=True), ) module = AnsibleModule( argument_spec=module_args, - supports_check_mode=True + supports_check_mode=True, + mutually_exclusive=[ + ('data', 'osd_fsid', 'osd_id'), + ], + required_if=[ + ('action', 'zap', ('data', 'osd_fsid', 'osd_id'), True) + ] ) result = dict( @@ -637,7 +652,8 @@ def run_module(): cmd = zap_devices(module, container_image) - if any(skip) or module.params.get('osd_fsid', None): + if any(skip) or module.params.get('osd_fsid', None) \ + or module.params.get('osd_id', None): rc, cmd, out, err = exec_command( module, cmd) for scan_cmd in ['vgscan', 'lvscan']: diff --git a/tests/library/test_ceph_volume.py b/tests/library/test_ceph_volume.py index 74d39197f..867128af3 100644 --- a/tests/library/test_ceph_volume.py +++ b/tests/library/test_ceph_volume.py @@ -119,6 +119,21 @@ class TestCephVolumeModule(object): result = ceph_volume.zap_devices(fake_module, fake_container_image) assert result == expected_command_list + def test_zap_osd_id(self): + fake_module = MagicMock() + fake_module.params = {'osd_id': '123'} + fake_container_image = None + expected_command_list = ['ceph-volume', + '--cluster', + 'ceph', + 'lvm', + 'zap', + '--destroy', + '--osd-id', + '123'] + result = ceph_volume.zap_devices(fake_module, fake_container_image) + assert result == expected_command_list + def test_activate_osd(self): expected_command_list = ['ceph-volume', '--cluster', -- 2.39.5