Ejemplo n.º 1
0
 def test_list_multipath(self):
     args = ceph_disk.parse_args(['list'])
     #
     # multipath data partition
     #
     partition_uuid = "56244cf5-83ef-4984-888a-2d8b8e0e04b2"
     disk = "Xda"
     partition = "Xda1"
     with patch.multiple(
             ceph_disk,
             list_all_partitions=lambda names: {disk: [partition]},
             get_partition_uuid=lambda dev: partition_uuid,
             get_partition_type=lambda dev: ceph_disk.MPATH_OSD_UUID,
             is_partition=lambda dev: True,
     ):
         expect = [{
             'path':
             '/dev/' + disk,
             'partitions': [{
                 'dmcrypt': {},
                 'fs_type': None,
                 'is_partition': True,
                 'mount': None,
                 'multipath': True,
                 'path': '/dev/' + partition,
                 'ptype': ceph_disk.MPATH_OSD_UUID,
                 'state': 'unprepared',
                 'type': 'data',
                 'uuid': partition_uuid,
             }]
         }]
         assert expect == ceph_disk.list_devices(args)
     #
     # multipath journal partition
     #
     journal_partition_uuid = "2cc40457-259e-4542-b029-785c7cc37871"
     with patch.multiple(
             ceph_disk,
             list_all_partitions=lambda names: {disk: [partition]},
             get_partition_uuid=lambda dev: journal_partition_uuid,
             get_partition_type=lambda dev: ceph_disk.MPATH_JOURNAL_UUID,
             is_partition=lambda dev: True,
     ):
         expect = [{
             'path':
             '/dev/' + disk,
             'partitions': [{
                 'dmcrypt': {},
                 'is_partition': True,
                 'multipath': True,
                 'path': '/dev/' + partition,
                 'ptype': ceph_disk.MPATH_JOURNAL_UUID,
                 'type': 'journal',
                 'uuid': journal_partition_uuid,
             }]
         }]
         assert expect == ceph_disk.list_devices(args)
Ejemplo n.º 2
0
 def test_list_multipath(self):
     args = ceph_disk.parse_args(['list'])
     #
     # multipath data partition
     #
     partition_uuid = "56244cf5-83ef-4984-888a-2d8b8e0e04b2"
     disk = "Xda"
     partition = "Xda1"
     with patch.multiple(
             ceph_disk,
             list_all_partitions=lambda names: { disk: [partition] },
             get_partition_uuid=lambda dev: partition_uuid,
             get_partition_type=lambda dev: ceph_disk.MPATH_OSD_UUID,
             is_partition=lambda dev: True,
             ):
         expect = [{'path': '/dev/' + disk,
                    'partitions': [{
                        'dmcrypt': {},
                        'fs_type': None,
                        'is_partition': True,
                        'mount': None,
                        'multipath': True,
                        'path': '/dev/' + partition,
                        'ptype': ceph_disk.MPATH_OSD_UUID,
                        'state': 'unprepared',
                        'type': 'data',
                        'uuid': partition_uuid,
                    }]}]
         assert expect == ceph_disk.list_devices(args)
     #
     # multipath journal partition
     #
     journal_partition_uuid = "2cc40457-259e-4542-b029-785c7cc37871"
     with patch.multiple(
             ceph_disk,
             list_all_partitions=lambda names: { disk: [partition] },
             get_partition_uuid=lambda dev: journal_partition_uuid,
             get_partition_type=lambda dev: ceph_disk.MPATH_JOURNAL_UUID,
             is_partition=lambda dev: True,
             ):
         expect = [{'path': '/dev/' + disk,
                    'partitions': [{
                        'dmcrypt': {},
                        'is_partition': True,
                        'multipath': True,
                        'path': '/dev/' + partition,
                        'ptype': ceph_disk.MPATH_JOURNAL_UUID,
                        'type': 'journal',
                        'uuid': journal_partition_uuid,
                    }]}]
         assert expect == ceph_disk.list_devices(args)
Ejemplo n.º 3
0
    def test_list_data(self):
        args = ceph_disk.parse_args(['list'])
        #
        # a data partition that fails to mount is silently
        # ignored
        #
        partition_uuid = "56244cf5-83ef-4984-888a-2d8b8e0e04b2"
        disk = "Xda"
        partition = "Xda1"
        fs_type = "ext4"

        with patch.multiple(
                ceph_disk,
                list_all_partitions=lambda names: { disk: [partition] },
                get_partition_uuid=lambda dev: partition_uuid,
                get_partition_type=lambda dev: ceph_disk.OSD_UUID,
                get_dev_fs=lambda dev: fs_type,
                mount=fail_to_mount,
                unmount=DEFAULT,
                is_partition=lambda dev: True,
                ):
            expect = [{'path': '/dev/' + disk,
                       'partitions': [{
                           'dmcrypt': {},
                           'fs_type': fs_type,
                           'is_partition': True,
                           'mount': None,
                           'path': '/dev/' + partition,
                           'ptype': ceph_disk.OSD_UUID,
                           'state': 'unprepared',
                           'type': 'data',
                           'uuid': partition_uuid,
                       }]}]
            assert expect == ceph_disk.list_devices(args)
Ejemplo n.º 4
0
    def test_list_other(self):
        args = ceph_disk.parse_args(['list'])
        #
        # not swap, unknown fs type, not mounted, with uuid
        #
        partition_uuid = "56244cf5-83ef-4984-888a-2d8b8e0e04b2"
        partition_type = "e51adfb9-e9fd-4718-9fc1-7a0cb03ea3f4"
        disk = "Xda"
        partition = "Xda1"
        with patch.multiple(
                ceph_disk,
                list_all_partitions=lambda names: { disk: [partition] },
                get_partition_uuid=lambda dev: partition_uuid,
                get_partition_type=lambda dev: partition_type,
                is_partition=lambda dev: True,
                ):
            expect = [{'path': '/dev/' + disk,
                       'partitions': [{'dmcrypt': {},
                                       'is_partition': True,
                                       'path': '/dev/' + partition,
                                       'ptype': partition_type,
                                       'type': 'other',
                                       'uuid': partition_uuid}]}]
            assert expect == ceph_disk.list_devices(args)
        #
        # not swap, mounted, ext4 fs type, with uuid
        #
        partition_uuid = "56244cf5-83ef-4984-888a-2d8b8e0e04b2"
        partition_type = "e51adfb9-e9fd-4718-9fc1-7a0cb03ea3f4"
        disk = "Xda"
        partition = "Xda1"
        mount_path = '/mount/path'
        fs_type = 'ext4'
        with patch.multiple(
                ceph_disk,
                list_all_partitions=lambda names: { disk: [partition] },
                get_dev_fs=lambda dev: fs_type,
                is_mounted=lambda dev: mount_path,
                get_partition_uuid=lambda dev: partition_uuid,
                get_partition_type=lambda dev: partition_type,
                is_partition=lambda dev: True,
                ):
            expect = [{'path': '/dev/' + disk,
                       'partitions': [{'dmcrypt': {},
                                       'is_partition': True,
                                       'mount': mount_path,
                                       'fs_type': fs_type,
                                       'path': '/dev/' + partition,
                                       'ptype': partition_type,
                                       'type': 'other',
                                       'uuid': partition_uuid,
                                   }]}]
            assert expect == ceph_disk.list_devices(args)

        #
        # swap, with uuid
        #
        partition_uuid = "56244cf5-83ef-4984-888a-2d8b8e0e04b2"
        partition_type = "e51adfb9-e9fd-4718-9fc1-7a0cb03ea3f4"
        disk = "Xda"
        partition = "Xda1"
        with patch.multiple(
                ceph_disk,
                list_all_partitions=lambda names: { disk: [partition] },
                is_swap=lambda dev: True,
                get_partition_uuid=lambda dev: partition_uuid,
                get_partition_type=lambda dev: partition_type,
                is_partition=lambda dev: True,
                ):
            expect = [{'path': '/dev/' + disk,
                       'partitions': [{'dmcrypt': {},
                                       'is_partition': True,
                                       'path': '/dev/' + partition,
                                       'ptype': partition_type,
                                       'type': 'swap',
                                       'uuid': partition_uuid}]}]
            assert expect == ceph_disk.list_devices(args)

        #
        # whole disk
        #
        partition_uuid = "56244cf5-83ef-4984-888a-2d8b8e0e04b2"
        disk = "Xda"
        partition = "Xda1"
        with patch.multiple(
                ceph_disk,
                list_all_partitions=lambda names: { disk: [] },
                is_partition=lambda dev: False,
                ):
            expect = [{'path': '/dev/' + disk,
                       'dmcrypt': {},
                       'is_partition': False,
                       'ptype': 'unknown',
                       'type': 'other'}]
            assert expect == ceph_disk.list_devices(args)
Ejemplo n.º 5
0
    def list(self, data_ptype, journal_ptype):
        args = ceph_disk.parse_args(['--verbose', 'list'])
        #
        # a single disk has a data partition and a journal
        # partition and the osd is active
        #
        data_uuid = "56244cf5-83ef-4984-888a-2d8b8e0e04b2"
        disk = "Xda"
        data = "Xda1"
        data_holder = "dm-0"
        journal = "Xda2"
        journal_holder = "dm-0"
        mount_path = '/mount/path'
        fs_type = 'ext4'
        journal_uuid = "7ad5e65a-0ca5-40e4-a896-62a74ca61c55"
        ceph_fsid = "60a2ef70-d99b-4b9b-a83c-8a86e5e60091"
        osd_id = '1234'
        def get_oneliner(path, what):
            if what == 'journal_uuid':
                return journal_uuid
            elif what == 'ceph_fsid':
                return ceph_fsid
            elif what == 'whoami':
                return osd_id
            else:
                raise Exception('unknown ' + what)
        def get_partition_uuid(dev):
            if dev == '/dev/' + data:
                return data_uuid
            elif dev == '/dev/' + journal:
                return journal_uuid
            else:
                raise Exception('unknown ' + dev)
        def get_partition_type(dev):
            if (dev == '/dev/' + data or
                dev == '/dev/' + data_holder):
                return data_ptype
            elif (dev == '/dev/' + journal or
                  dev == '/dev/' + journal_holder):
                return journal_ptype
            else:
                raise Exception('unknown ' + dev)
        cluster = 'ceph'
        if data_ptype == ceph_disk.OSD_UUID:
            data_dmcrypt = {}
        elif data_ptype == ceph_disk.DMCRYPT_OSD_UUID:
            data_dmcrypt = {
                'type': 'plain',
                'holders': [data_holder],
            }
        elif data_ptype == ceph_disk.DMCRYPT_LUKS_OSD_UUID:
            data_dmcrypt = {
                'type': 'LUKS',
                'holders': [data_holder],
            }
        else:
            raise Exception('unknown ' + data_ptype)

        if journal_ptype == ceph_disk.JOURNAL_UUID:
            journal_dmcrypt = {}
        elif journal_ptype == ceph_disk.DMCRYPT_JOURNAL_UUID:
            journal_dmcrypt = {
                'type': 'plain',
                'holders': [journal_holder],
            }
        elif journal_ptype == ceph_disk.DMCRYPT_LUKS_JOURNAL_UUID:
            journal_dmcrypt = {
                'type': 'LUKS',
                'holders': [journal_holder],
            }
        else:
            raise Exception('unknown ' + journal_ptype)

        if data_dmcrypt:
            def is_held(dev):
                if dev == '/dev/' + data:
                    return [data_holder]
                elif dev == '/dev/' + journal:
                    return [journal_holder]
                else:
                    raise Exception('unknown ' + dev)
        else:
            def is_held(dev):
                return []

        with patch.multiple(
                ceph_disk,
                list_all_partitions=lambda names: { disk: [data, journal] },
                get_dev_fs=lambda dev: fs_type,
                is_mounted=lambda dev: mount_path,
                get_partition_uuid=get_partition_uuid,
                get_partition_type=get_partition_type,
                find_cluster_by_uuid=lambda ceph_fsid: cluster,
                is_partition=lambda dev: True,
                mount=DEFAULT,
                unmount=DEFAULT,
                get_oneliner=get_oneliner,
                is_held=is_held,
                ):
            expect = [{'path': '/dev/' + disk,
                       'partitions': [{
                           'ceph_fsid': ceph_fsid,
                           'cluster': cluster,
                           'dmcrypt': data_dmcrypt,
                           'fs_type': fs_type,
                           'is_partition': True,
                           'journal_dev': '/dev/' + journal,
                           'journal_uuid': journal_uuid,
                           'mount': mount_path,
                           'path': '/dev/' + data,
                           'ptype': data_ptype,
                           'state': 'active',
                           'type': 'data',
                           'whoami': osd_id,
                           'uuid': data_uuid,
                       }, {
                           'dmcrypt': journal_dmcrypt,
                           'is_partition': True,
                           'journal_for': '/dev/' + data,
                           'path': '/dev/' + journal,
                           'ptype': journal_ptype,
                           'type': 'journal',
                           'uuid': journal_uuid,
                       },
                                  ]}]
            assert expect == ceph_disk.list_devices(args)
Ejemplo n.º 6
0
 def test_list_dmcrypt_data(self):
     args = ceph_disk.parse_args(['list'])
     partition_type2type = {
         ceph_disk.DMCRYPT_OSD_UUID: 'plain',
         ceph_disk.DMCRYPT_LUKS_OSD_UUID: 'LUKS',
     }
     for (partition_type, type) in partition_type2type.iteritems():
         #
         # dmcrypt data partition with one holder
         #
         partition_uuid = "56244cf5-83ef-4984-888a-2d8b8e0e04b2"
         disk = "Xda"
         partition = "Xda1"
         holders = ["dm-0"]
         with patch.multiple(
                 ceph_disk,
                 is_held=lambda dev: holders,
                 list_all_partitions=lambda names: { disk: [partition] },
                 get_partition_uuid=lambda dev: partition_uuid,
                 get_partition_type=lambda dev: partition_type,
                 is_partition=lambda dev: True,
                 ):
             expect = [{'path': '/dev/' + disk,
                        'partitions': [{
                            'dmcrypt': {
                                'holders': holders,
                                'type': type,
                            },
                            'fs_type': None,
                            'is_partition': True,
                            'mount': None,
                            'path': '/dev/' + partition,
                            'ptype': partition_type,
                            'state': 'unprepared',
                            'type': 'data',
                            'uuid': partition_uuid,
                        }]}]
             assert expect == ceph_disk.list_devices(args)
         #
         # dmcrypt data partition with two holders
         #
         partition_uuid = "56244cf5-83ef-4984-888a-2d8b8e0e04b2"
         disk = "Xda"
         partition = "Xda1"
         holders = ["dm-0","dm-1"]
         with patch.multiple(
                 ceph_disk,
                 is_held=lambda dev: holders,
                 list_all_partitions=lambda names: { disk: [partition] },
                 get_partition_uuid=lambda dev: partition_uuid,
                 get_partition_type=lambda dev: partition_type,
                 is_partition=lambda dev: True,
                 ):
             expect = [{'path': '/dev/' + disk,
                        'partitions': [{
                            'dmcrypt': {
                                'holders': holders,
                                'type': type,
                            },
                            'is_partition': True,
                            'path': '/dev/' + partition,
                            'ptype': partition_type,
                            'type': 'data',
                            'uuid': partition_uuid,
                        }]}]
             assert expect == ceph_disk.list_devices(args)