Beispiel #1
0
    def test_init_filestore_dir(self):
        parser = argparse.ArgumentParser('ceph-disk')
        subparsers = parser.add_subparsers()
        main.Prepare.set_subparser(subparsers)

        data = tempfile.mkdtemp()
        main.setup_statedir(data)
        args = parser.parse_args([
            'prepare',
            data,
            '--filestore',
        ])

        def set_type(self):
            self.type = self.FILE
        with mock.patch.multiple(main.PrepareData,
                                 set_type=set_type):
            prepare = main.Prepare.factory(args)
        assert isinstance(prepare.data, main.PrepareFilestoreData)
        assert prepare.data.is_file()
        assert isinstance(prepare.journal, main.PrepareJournal)
        assert prepare.journal.is_none()
        prepare.prepare()
        assert os.path.exists(os.path.join(data, 'fsid'))
        shutil.rmtree(data)
Beispiel #2
0
 def test_main_list_plain(self, capsys):
     data = tempfile.mkdtemp()
     main.setup_statedir(data)
     args = main.parse_args(['list'])
     with patch.multiple(main, list_devices=lambda: {}):
         main.main_list(args)
         out, err = capsys.readouterr()
         assert '' == out
     shutil.rmtree(data)
Beispiel #3
0
 def test_main_list_plain(self, capsys):
     data = tempfile.mkdtemp()
     main.setup_statedir(data)
     args = main.parse_args(['list'])
     with patch.multiple(
             main,
             list_devices=lambda: {}):
         main.main_list(args)
         out, err = capsys.readouterr()
         assert '' == out
     shutil.rmtree(data)
Beispiel #4
0
    def test_main_list_json(self, capsys):
        if platform.system() == "FreeBSD":
            return

        data = tempfile.mkdtemp()
        main.setup_statedir(data)
        args = main.parse_args(['list', '--format', 'json'])
        with patch.multiple(main, list_devices=lambda: {}):
            main.main_list(args)
            out, err = capsys.readouterr()
            assert '{}\n' == out
        shutil.rmtree(data)
Beispiel #5
0
    def test_main_list_json(self, capsys):
        if platform.system() == "FreeBSD":
            return

        data = tempfile.mkdtemp()
        main.setup_statedir(data)
        args = main.parse_args(['list', '--format', 'json'])
        with patch.multiple(
                main,
                list_devices=lambda: {}):
            main.main_list(args)
            out, err = capsys.readouterr()
            assert '{}\n' == out
        shutil.rmtree(data)
    def test_init_default_dir(self, m_get_fsid):
        parser = argparse.ArgumentParser('ceph-disk')
        subparsers = parser.add_subparsers()
        main.Prepare.set_subparser(subparsers)

        data = tempfile.mkdtemp()
        main.setup_statedir(data)
        args = parser.parse_args([
            'prepare',
            data,
        ])

        def set_type(self):
            self.type = self.FILE

        m_get_fsid.return_value = '571bb920-6d85-44d7-9eca-1bc114d1cd75'
        with mock.patch.multiple(main.PrepareData, set_type=set_type):
            prepare = main.Prepare.factory(args)
        assert isinstance(prepare.data, main.PrepareBluestoreData)
        assert prepare.data.is_file()
        prepare.prepare()
        assert os.path.exists(os.path.join(data, 'fsid'))
        shutil.rmtree(data)
Beispiel #7
0
    def test_main_deactivate(self, mock_open):
        data = tempfile.mkdtemp()
        main.setup_statedir(data)
        DMCRYPT_LUKS_OSD_UUID = '4fbd7e29-9d25-41b8-afd0-35865ceff05d'
        part_uuid = '0ce28a16-6d5d-11e5-aec3-fa163e5c167b'
        disk = 'sdX'
        #
        # Can not find match device by osd-id
        #
        args = main.parse_args(['deactivate',
                                '--cluster', 'ceph',
                                '--deactivate-by-id', '5566'])
        fake_device = [{'path': '/dev/' + disk,
                        'partitions': [{
                            'path': '/dev/sdX1',
                            'whoami': '-1',
                        }]}]
        with patch.multiple(
                main,
                list_devices=lambda: fake_device,
        ):
            self.assertRaises(Exception, main.main_deactivate, args)

        #
        # find match device by osd-id, status: OSD_STATUS_IN_DOWN
        # with --mark-out option
        #
        args = main.parse_args(['deactivate',
                                '--cluster', 'ceph',
                                '--deactivate-by-id', '5566',
                                '--mark-out'])
        fake_device = [{'path': '/dev/' + disk,
                        'partitions': [{
                            'ptype': DMCRYPT_LUKS_OSD_UUID,
                            'path': '/dev/sdX1',
                            'whoami': '5566',
                            'mount': '/var/lib/ceph/osd/ceph-5566/',
                            'uuid': part_uuid,
                        }]}]
        with patch.multiple(
                main,
                list_devices=lambda: fake_device,
                _check_osd_status=lambda cluster, osd_id: 2,
                _mark_osd_out=lambda cluster, osd_id: True
        ):
            main.main_deactivate(args)

        #
        # find match device by device partition, status: OSD_STATUS_IN_DOWN
        #
        args = main.parse_args(['deactivate',
                                '--cluster', 'ceph',
                                '/dev/sdX1'])
        fake_device = [{'path': '/dev/' + disk,
                        'partitions': [{
                            'ptype': DMCRYPT_LUKS_OSD_UUID,
                            'path': '/dev/sdX1',
                            'whoami': '5566',
                            'mount': '/var/lib/ceph/osd/ceph-5566/',
                            'uuid': part_uuid,
                        }]}]
        with patch.multiple(
                main,
                list_devices=lambda: fake_device,
                _check_osd_status=lambda cluster, osd_id: 0,
        ):
            main.main_deactivate(args)

        #
        # find match device by device partition, status: OSD_STATUS_IN_UP
        # with --mark-out option
        #
        args = main.parse_args(['deactivate',
                                '--cluster', 'ceph',
                                '/dev/sdX1',
                                '--mark-out'])
        fake_device = [{'path': '/dev/' + disk,
                        'partitions': [{
                            'ptype': DMCRYPT_LUKS_OSD_UUID,
                            'path': '/dev/sdX1',
                            'whoami': '5566',
                            'mount': '/var/lib/ceph/osd/ceph-5566/',
                            'uuid': part_uuid,
                        }]}]

        # mock the file open.
        file_opened = io.StringIO()
        file_opened.write(u'deactive')
        mock_open.return_value = file_opened

        with patch.multiple(
                main,
                mock_open,
                list_devices=lambda: fake_device,
                _check_osd_status=lambda cluster, osd_id: 3,
                _mark_osd_out=lambda cluster, osd_id: True,
                stop_daemon=lambda cluster, osd_id: True,
                _remove_osd_directory_files=lambda path, cluster: True,
                path_set_context=lambda path: True,
                unmount=lambda path: True,
                dmcrypt_unmap=lambda part_uuid: True,
        ):
            main.main_deactivate(args)

        #
        # find match device by osd-id, status: OSD_STATUS_OUT_UP
        #
        args = main.parse_args(['deactivate',
                                '--cluster', 'ceph',
                                '--deactivate-by-id', '5566'])
        fake_device = [{'path': '/dev/' + disk,
                        'partitions': [{
                            'ptype': DMCRYPT_LUKS_OSD_UUID,
                            'path': '/dev/sdX1',
                            'whoami': '5566',
                            'mount': '/var/lib/ceph/osd/ceph-5566/',
                            'uuid': part_uuid,
                        }]}]

        # mock the file open.
        file_opened = io.StringIO()
        file_opened.write(u'deactive')
        mock_open.return_value = file_opened

        with patch.multiple(
                main,
                mock_open,
                list_devices=lambda: fake_device,
                _check_osd_status=lambda cluster, osd_id: 1,
                _mark_osd_out=lambda cluster, osd_id: True,
                stop_daemon=lambda cluster, osd_id: True,
                _remove_osd_directory_files=lambda path, cluster: True,
                path_set_context=lambda path: True,
                unmount=lambda path: True,
                dmcrypt_unmap=lambda part_uuid: True,
        ):
            main.main_deactivate(args)
        shutil.rmtree(data)
Beispiel #8
0
    def test_main_destroy(self):
        data = tempfile.mkdtemp()
        main.setup_statedir(data)
        OSD_UUID = '4fbd7e29-9d25-41b8-afd0-062c0ceff05d'
        MPATH_OSD_UUID = '4fbd7e29-8ae0-4982-bf9d-5a8d867af560'
        part_uuid = '0ce28a16-6d5d-11e5-aec3-fa163e5c167b'
        journal_uuid = "7ad5e65a-0ca5-40e4-a896-62a74ca61c55"
        mount_5566 = '/var/lib/ceph/osd/ceph-5566/'

        fake_devices_normal = [{'path': '/dev/sdY',
                                'partitions': [{
                                    'dmcrypt': {},
                                    'type': 'osd',
                                    'ptype': OSD_UUID,
                                    'path': '/dev/sdY1',
                                    'whoami': '5566',
                                    'mount': mount_5566,
                                    'uuid': part_uuid,
                                    'journal_uuid': journal_uuid}]},
                               {'path': '/dev/sdX',
                                'partitions': [{
                                    'dmcrypt': {},
                                    'type': 'osd',
                                    'ptype': MPATH_OSD_UUID,
                                    'path': '/dev/sdX1',
                                    'whoami': '7788',
                                    'mount': '/var/lib/ceph/osd/ceph-7788/',
                                    'uuid': part_uuid,
                                    'journal_uuid': journal_uuid}]}]

        def list_devices_return():
            return fake_devices_normal

        #
        # input device is not the device partition
        #
        args = main.parse_args(['destroy', '--cluster', 'ceph', '/dev/sdX'])
        with patch.multiple(
                main,
                is_partition=lambda path: False,
        ):
            self.assertRaises(Exception, main.main_destroy, args)

        #
        # skip the redundent devices and not found by dev
        #
        args = main.parse_args(['destroy', '--cluster', 'ceph', '/dev/sdZ1'])
        with patch.multiple(
                main,
                is_partition=lambda path: True,
                list_devices=list_devices_return,
        ):
            self.assertRaises(Exception, main.main_destroy, args)

        #
        # skip the redundent devices and not found by osd-id
        #
        args = main.parse_args(['destroy', '--cluster', 'ceph',
                                '--destroy-by-id', '1234'])
        with patch.multiple(
                main,
                is_partition=lambda path: True,
                list_devices=list_devices_return,
        ):
            self.assertRaises(Exception, main.main_destroy, args)

        #
        # skip the redundent devices and found by dev
        #
        args = main.parse_args(['destroy', '--cluster',
                                'ceph', '/dev/sdY1', '--zap'])
        with patch.multiple(
                main,
                is_partition=lambda path: True,
                list_devices=list_devices_return,
                get_partition_base=lambda dev_path: '/dev/sdY',
                _check_osd_status=lambda cluster, osd_id: 0,
                _remove_from_crush_map=lambda cluster, osd_id: True,
                _delete_osd_auth_key=lambda cluster, osd_id: True,
                _deallocate_osd_id=lambda cluster, osd_id: True,
                zap=lambda dev: True
        ):
            main.main_destroy(args)

        #
        # skip the redundent devices and found by osd-id
        # with active status and MPATH_OSD
        #
        args = main.parse_args(['destroy', '--cluster', 'ceph',
                                '--destroy-by-id', '7788'])
        with patch.multiple(
                main,
                is_partition=lambda path: True,
                list_devices=list_devices_return,
                get_partition_base_mpath=lambda dev_path: '/dev/sdX',
                _check_osd_status=lambda cluster, osd_id: 1,
        ):
            self.assertRaises(Exception, main.main_destroy, args)
        shutil.rmtree(data)
Beispiel #9
0
    def test_main_deactivate(self, mock_open):
        data = tempfile.mkdtemp()
        main.setup_statedir(data)
        DMCRYPT_LUKS_OSD_UUID = '4fbd7e29-9d25-41b8-afd0-35865ceff05d'
        part_uuid = '0ce28a16-6d5d-11e5-aec3-fa163e5c167b'
        disk = 'sdX'
        #
        # Can not find match device by osd-id
        #
        args = main.parse_args(
            ['deactivate', '--cluster', 'ceph', '--deactivate-by-id', '5566'])
        fake_device = [{
            'path': '/dev/' + disk,
            'partitions': [{
                'path': '/dev/sdX1',
                'whoami': '-1',
            }]
        }]
        with patch.multiple(
                main,
                list_devices=lambda: fake_device,
        ):
            self.assertRaises(Exception, main.main_deactivate, args)

        #
        # find match device by osd-id, status: OSD_STATUS_IN_DOWN
        # with --mark-out option
        #
        args = main.parse_args([
            'deactivate', '--cluster', 'ceph', '--deactivate-by-id', '5566',
            '--mark-out'
        ])
        fake_device = [{
            'path':
            '/dev/' + disk,
            'partitions': [{
                'ptype': DMCRYPT_LUKS_OSD_UUID,
                'path': '/dev/sdX1',
                'whoami': '5566',
                'mount': '/var/lib/ceph/osd/ceph-5566/',
                'uuid': part_uuid,
            }]
        }]
        with patch.multiple(main,
                            list_devices=lambda: fake_device,
                            _check_osd_status=lambda cluster, osd_id: 2,
                            _mark_osd_out=lambda cluster, osd_id: True):
            main.main_deactivate(args)

        #
        # find match device by device partition, status: OSD_STATUS_IN_DOWN
        #
        args = main.parse_args(
            ['deactivate', '--cluster', 'ceph', '/dev/sdX1'])
        fake_device = [{
            'path':
            '/dev/' + disk,
            'partitions': [{
                'ptype': DMCRYPT_LUKS_OSD_UUID,
                'path': '/dev/sdX1',
                'whoami': '5566',
                'mount': '/var/lib/ceph/osd/ceph-5566/',
                'uuid': part_uuid,
            }]
        }]
        with patch.multiple(
                main,
                list_devices=lambda: fake_device,
                _check_osd_status=lambda cluster, osd_id: 0,
        ):
            main.main_deactivate(args)

        #
        # find match device by device partition, status: OSD_STATUS_IN_UP
        # with --mark-out option
        #
        args = main.parse_args(
            ['deactivate', '--cluster', 'ceph', '/dev/sdX1', '--mark-out'])
        fake_device = [{
            'path':
            '/dev/' + disk,
            'partitions': [{
                'ptype': DMCRYPT_LUKS_OSD_UUID,
                'path': '/dev/sdX1',
                'whoami': '5566',
                'mount': '/var/lib/ceph/osd/ceph-5566/',
                'uuid': part_uuid,
            }]
        }]

        # mock the file open.
        file_opened = io.StringIO()
        file_opened.write(u'deactive')
        mock_open.return_value = file_opened

        with patch.multiple(
                main,
                mock_open,
                list_devices=lambda: fake_device,
                _check_osd_status=lambda cluster, osd_id: 3,
                _mark_osd_out=lambda cluster, osd_id: True,
                stop_daemon=lambda cluster, osd_id: True,
                _remove_osd_directory_files=lambda path, cluster: True,
                path_set_context=lambda path: True,
                unmount=lambda path: True,
                dmcrypt_unmap=lambda part_uuid: True,
        ):
            main.main_deactivate(args)

        #
        # find match device by osd-id, status: OSD_STATUS_OUT_UP
        #
        args = main.parse_args(
            ['deactivate', '--cluster', 'ceph', '--deactivate-by-id', '5566'])
        fake_device = [{
            'path':
            '/dev/' + disk,
            'partitions': [{
                'ptype': DMCRYPT_LUKS_OSD_UUID,
                'path': '/dev/sdX1',
                'whoami': '5566',
                'mount': '/var/lib/ceph/osd/ceph-5566/',
                'uuid': part_uuid,
            }]
        }]

        # mock the file open.
        file_opened = io.StringIO()
        file_opened.write(u'deactive')
        mock_open.return_value = file_opened

        with patch.multiple(
                main,
                mock_open,
                list_devices=lambda: fake_device,
                _check_osd_status=lambda cluster, osd_id: 1,
                _mark_osd_out=lambda cluster, osd_id: True,
                stop_daemon=lambda cluster, osd_id: True,
                _remove_osd_directory_files=lambda path, cluster: True,
                path_set_context=lambda path: True,
                unmount=lambda path: True,
                dmcrypt_unmap=lambda part_uuid: True,
        ):
            main.main_deactivate(args)
        shutil.rmtree(data)
Beispiel #10
0
    def test_main_destroy(self):
        data = tempfile.mkdtemp()
        main.setup_statedir(data)
        OSD_UUID = '4fbd7e29-9d25-41b8-afd0-062c0ceff05d'
        MPATH_OSD_UUID = '4fbd7e29-8ae0-4982-bf9d-5a8d867af560'
        part_uuid = '0ce28a16-6d5d-11e5-aec3-fa163e5c167b'
        journal_uuid = "7ad5e65a-0ca5-40e4-a896-62a74ca61c55"
        mount_5566 = '/var/lib/ceph/osd/ceph-5566/'

        fake_devices_normal = [{
            'path':
            '/dev/sdY',
            'partitions': [{
                'dmcrypt': {},
                'type': 'osd',
                'ptype': OSD_UUID,
                'path': '/dev/sdY1',
                'whoami': '5566',
                'mount': mount_5566,
                'uuid': part_uuid,
                'journal_uuid': journal_uuid
            }]
        }, {
            'path':
            '/dev/sdX',
            'partitions': [{
                'dmcrypt': {},
                'type': 'osd',
                'ptype': MPATH_OSD_UUID,
                'path': '/dev/sdX1',
                'whoami': '7788',
                'mount': '/var/lib/ceph/osd/ceph-7788/',
                'uuid': part_uuid,
                'journal_uuid': journal_uuid
            }]
        }]

        def list_devices_return():
            return fake_devices_normal

        #
        # input device is not the device partition
        #
        args = main.parse_args(['destroy', '--cluster', 'ceph', '/dev/sdX'])
        with patch.multiple(
                main,
                is_partition=lambda path: False,
        ):
            self.assertRaises(Exception, main.main_destroy, args)

        #
        # skip the redundent devices and not found by dev
        #
        args = main.parse_args(['destroy', '--cluster', 'ceph', '/dev/sdZ1'])
        with patch.multiple(
                main,
                is_partition=lambda path: True,
                list_devices=list_devices_return,
        ):
            self.assertRaises(Exception, main.main_destroy, args)

        #
        # skip the redundent devices and not found by osd-id
        #
        args = main.parse_args(
            ['destroy', '--cluster', 'ceph', '--destroy-by-id', '1234'])
        with patch.multiple(
                main,
                is_partition=lambda path: True,
                list_devices=list_devices_return,
        ):
            self.assertRaises(Exception, main.main_destroy, args)

        #
        # skip the redundent devices and found by dev
        #
        args = main.parse_args(
            ['destroy', '--cluster', 'ceph', '/dev/sdY1', '--zap'])
        with patch.multiple(
                main,
                is_partition=lambda path: True,
                list_devices=list_devices_return,
                get_partition_base=lambda dev_path: '/dev/sdY',
                _check_osd_status=lambda cluster, osd_id: 0,
                _remove_from_crush_map=lambda cluster, osd_id: True,
                _delete_osd_auth_key=lambda cluster, osd_id: True,
                _deallocate_osd_id=lambda cluster, osd_id: True,
                zap=lambda dev: True):
            main.main_destroy(args)

        #
        # skip the redundent devices and found by osd-id
        # with active status and MPATH_OSD
        #
        args = main.parse_args(
            ['destroy', '--cluster', 'ceph', '--destroy-by-id', '7788'])
        with patch.multiple(
                main,
                is_partition=lambda path: True,
                list_devices=list_devices_return,
                get_partition_base_mpath=lambda dev_path: '/dev/sdX',
                _check_osd_status=lambda cluster, osd_id: 1,
        ):
            self.assertRaises(Exception, main.main_destroy, args)
        shutil.rmtree(data)