return command_exec
-def build_ceph_volume_cmd(action, container_image, cluster=None):
+def build_cmd(action, container_image, cluster='ceph', binary='ceph-volume'):
'''
Build the ceph-volume command
'''
+ _binary = binary
+
if container_image:
- binary = 'ceph-volume'
cmd = container_exec(
binary, container_image)
else:
- binary = ['ceph-volume']
+ binary = [binary]
cmd = binary
- if cluster:
+ if _binary == 'ceph-volume':
cmd.extend(['--cluster', cluster])
cmd.extend(action)
# Build the CLI
action = ['lvm', 'batch']
- cmd = build_ceph_volume_cmd(action, container_image, cluster)
+ cmd = build_cmd(action, container_image, cluster)
cmd.extend(['--%s' % objectstore])
cmd.append('--yes')
# Build the CLI
action = ['lvm', action]
- cmd = build_ceph_volume_cmd(action, container_image, cluster)
+ cmd = build_cmd(action, container_image, cluster)
cmd.extend(['--%s' % objectstore])
cmd.append('--data')
cmd.append(data)
# Build the CLI
action = ['lvm', 'list']
- cmd = build_ceph_volume_cmd(action, container_image, cluster)
+ cmd = build_cmd(action, container_image, cluster)
if data:
cmd.append(data)
cmd.append('--format=json')
'''
action = ['inventory']
- cmd = build_ceph_volume_cmd(action, container_image)
+ cmd = build_cmd(action, container_image)
cmd.append('--format=json')
return cmd
# build the CLI
action = ['lvm', 'activate']
container_image = None
- cmd = build_ceph_volume_cmd(action, container_image)
+ cmd = build_cmd(action, container_image)
cmd.append('--all')
return cmd
+def is_lv(module, vg, lv, container_image):
+ '''
+ Check if an LV exists
+ '''
+
+ args = [ '--noheadings', '--reportformat', 'json', '--select', 'lv_name={},vg_name={}'.format(lv, vg) ]
+
+ cmd = build_cmd(args, container_image, binary='lvs')
+
+ rc, cmd, out, err = exec_command(module, cmd)
+
+ result = json.loads(out)['report'][0]['lv']
+ if rc == 0 and len(result) > 0:
+ return True
+ else:
+ return False
+
+
def zap_devices(module, container_image):
'''
Will run 'ceph-volume lvm zap' on all devices, lvs and partitions
# build the CLI
action = ['lvm', 'zap']
- cmd = build_ceph_volume_cmd(action, container_image)
+ cmd = build_cmd(action, container_image)
if destroy:
cmd.append('--destroy')
elif action == 'zap':
# Zap the OSD
- rc, cmd, out, err = exec_command(
- module, zap_devices(module, container_image))
+ skip = []
+ for device_type in ['journal','data', 'db', 'wal']:
+ if module.params.get('{}_vg'.format(device_type), None) and module.params.get(device_type, None):
+ ret = is_lv(module, module.params['{}_vg'.format(device_type)], module.params[device_type], container_image)
+ skip.append(ret)
+ if not ret:
+ module.params['{}_vg'.format(device_type)] = False
+ module.params[device_type] = False
+ elif not module.params.get('{}_vg'.format(device_type), None) and module.params.get(device_type, None):
+ skip.append(True)
+
+ cmd = zap_devices(module, container_image)
+
+ if any(skip):
+ rc, cmd, out, err = exec_command(
+ module, cmd)
+ else:
+ out = 'Skipped, nothing to zap'
+ err = ''
+ changed = False
+ rc = 0
elif action == 'list':
# List Ceph LVM Metadata on a device
fake_module.params = {'data': '/dev/sda'}
fake_container_image = "docker.io/ceph/daemon:latest"
expected_command_list = container_cmd + [fake_container_image,
+ '--cluster',
+ 'ceph',
'lvm',
'zap',
'--destroy',
fake_module.params = {'data': '/dev/sda'}
fake_container_image = None
expected_command_list = ['ceph-volume',
+ '--cluster',
+ 'ceph',
'lvm',
'zap',
'--destroy',
fake_module.params = {'osd_fsid': 'a_uuid'}
fake_container_image = None
expected_command_list = ['ceph-volume',
+ '--cluster',
+ 'ceph',
'lvm',
'zap',
'--destroy',
def test_activate_osd(self):
expected_command_list = ['ceph-volume',
+ '--cluster',
+ 'ceph',
'lvm',
'activate',
'--all']
fake_module = MagicMock()
fake_container_image = None
expected_command_list = ['ceph-volume',
+ '--cluster',
+ 'ceph',
'inventory',
'--format=json',
]
fake_module = MagicMock()
fake_container_image = "docker.io/ceph/daemon:latest"
expected_command_list = container_cmd + [fake_container_image,
+ '--cluster',
+ 'ceph',
'inventory',
'--format=json']
result = ceph_volume.list_storage_inventory(fake_module, fake_container_image)