def main(self): sub_command_help = dedent(""" Scan running OSDs, an OSD directory (or data device) for files and configurations that will allow to take over the management of the OSD. Scanned OSDs will get their configurations stored in /etc/ceph/osd/<id>-<fsid>.json For an OSD ID of 0 with fsid of ``a9d50838-e823-43d6-b01f-2f8d0a77afc2`` that could mean a scan command that looks like:: ceph-volume lvm scan /var/lib/ceph/osd/ceph-0 Which would store the metadata in a JSON file at:: /etc/ceph/osd/0-a9d50838-e823-43d6-b01f-2f8d0a77afc2.json To scan all running OSDs: ceph-volume simple scan To a scan a specific running OSD: ceph-volume simple scan /var/lib/ceph/osd/{cluster}-{osd id} And to scan a device (mounted or unmounted) that has OSD data in it, for example /dev/sda1 ceph-volume simple scan /dev/sda1 Scanning a device or directory that belongs to an OSD not created by ceph-disk will be ingored. """) parser = argparse.ArgumentParser( prog='ceph-volume simple scan', formatter_class=argparse.RawDescriptionHelpFormatter, description=sub_command_help, ) parser.add_argument( '-f', '--force', action='store_true', help='If OSD has already been scanned, the JSON file will be overwritten' ) parser.add_argument( '--stdout', action='store_true', help='Do not save to a file, output metadata to stdout' ) parser.add_argument( 'osd_path', metavar='OSD_PATH', type=arg_validators.OSDPath(), nargs='?', default=None, help='Path to an existing OSD directory or OSD data partition' ) args = parser.parse_args(self.argv) paths = [] if args.osd_path: paths.append(args.osd_path) else: osd_ids = systemctl.get_running_osd_ids() for osd_id in osd_ids: paths.append("/var/lib/ceph/osd/{}-{}".format( conf.cluster, osd_id, )) # Capture some environment status, so that it can be reused all over self.device_mounts = system.get_mounts(devices=True) self.path_mounts = system.get_mounts(paths=True) for path in paths: args.osd_path = path device = Device(args.osd_path) if device.is_partition: if device.ceph_disk.type != 'data': label = device.ceph_disk.partlabel msg = 'Device must be the ceph data partition, but PARTLABEL reported: "%s"' % label raise RuntimeError(msg) self.encryption_metadata = encryption.legacy_encrypted(args.osd_path) self.is_encrypted = self.encryption_metadata['encrypted'] device = Device(self.encryption_metadata['device']) if not device.is_ceph_disk_member: terminal.warning("Ignoring %s because it's not a ceph-disk created osd." % path) else: self.scan(args)
def test_returns_empty_list_on_nonzero_return_code(self, stub_call): stdout = ['[email protected]', '', '[email protected]'] stub_call((stdout, [], 1)) osd_ids = systemctl.get_running_osd_ids() assert osd_ids == []
def test_get_running_osd_ids(self, stub_call, stdout, expected): stub_call((stdout, [], 0)) osd_ids = systemctl.get_running_osd_ids() assert osd_ids == expected