示例#1
0
 def test_files_are_missing(self, is_root, tmpdir, monkeypatch):
     tmppath = str(tmpdir)
     monkeypatch.setattr(arg_validators.disk, 'is_partition', lambda x: False)
     validator = arg_validators.OSDPath()
     with pytest.raises(argparse.ArgumentError) as error:
         validator(tmppath)
     assert 'Required file (ceph_fsid) was not found in OSD' in str(error)
示例#2
0
    def main(self):
        sub_command_help = dedent("""
        Scan an OSD directory 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 a scan an existing, 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
        """)
        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='?',
            help='Path to an existing OSD directory or OSD data partition')

        if len(self.argv) == 0:
            print(sub_command_help)
            return
        args = parser.parse_args(self.argv)
        self.scan(args)
示例#3
0
 def test_path_is_not_a_directory(self, is_root, tmpfile, monkeypatch):
     monkeypatch.setattr(arg_validators.disk, 'is_partition', lambda x: False)
     validator = arg_validators.OSDPath()
     with pytest.raises(argparse.ArgumentError):
         validator(tmpfile())
示例#4
0
 def setup(self):
     self.validator = arg_validators.OSDPath()
示例#5
0
    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 main(self):
        sub_command_help = dedent("""
        Scan 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 a scan an existing, 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
        """)
        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='?',
            help='Path to an existing OSD directory or OSD data partition')

        if len(self.argv) == 0:
            print(sub_command_help)
            return

        args = parser.parse_args(self.argv)
        if disk.is_partition(args.osd_path):
            label = disk.lsblk(args.osd_path)['PARTLABEL']
            if 'data' not in label:
                raise RuntimeError(
                    'Device must be the data partition, but got: %s' % label)

        # 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)
        self.encryption_metadata = encryption.legacy_encrypted(args.osd_path)
        self.is_encrypted = self.encryption_metadata['encrypted']

        self.scan(args)