示例#1
0
    def test_md_present_no_proc_mdstat(self):
        mdname = 'md0'
        self.mock_util.side_effect = IOError

        md_is_present = mdadm.md_present(mdname)
        self.assertFalse(md_is_present)
        self.mock_util.load_file.assert_called_with('/proc/mdstat')
示例#2
0
    def test_md_present_none(self):
        mdname = ''
        self.mock_util.load_file.return_value = textwrap.dedent("""
        Personalities : [raid1] [linear] [multipath] [raid0] [raid6] [raid5]
        [raid4] [raid10]
        md0 : active raid1 vdc1[1] vda2[0]
              3143680 blocks super 1.2 [2/2] [UU]

        unused devices: <none>
        """)

        with self.assertRaises(ValueError):
            mdadm.md_present(mdname)

        # util.load_file should NOT have been called
        self.assertEqual([], self.mock_util.call_args_list)
示例#3
0
def shutdown_mdadm(device):
    """
    Shutdown specified mdadm device.
    """

    blockdev = block.sysfs_to_devpath(device)

    LOG.info('Wiping superblock on raid device: %s', device)
    _wipe_superblock(blockdev, exclusive=False)

    md_devs = (mdadm.md_get_devices_list(blockdev) +
               mdadm.md_get_spares_list(blockdev))
    mdadm.set_sync_action(blockdev, action="idle")
    mdadm.set_sync_action(blockdev, action="frozen")
    for mddev in md_devs:
        try:
            mdadm.fail_device(blockdev, mddev)
            mdadm.remove_device(blockdev, mddev)
        except util.ProcessExecutionError as e:
            LOG.debug('Non-fatal error clearing raid array: %s', e.stderr)
            pass

    LOG.debug('using mdadm.mdadm_stop on dev: %s', blockdev)
    mdadm.mdadm_stop(blockdev)

    for mddev in md_devs:
        mdadm.zero_device(mddev)

    # mdadm stop operation is asynchronous so we must wait for the kernel to
    # release resources. For more details see  LP: #1682456
    try:
        for wait in MDADM_RELEASE_RETRIES:
            if mdadm.md_present(block.path_to_kname(blockdev)):
                time.sleep(wait)
            else:
                LOG.debug('%s has been removed', blockdev)
                break

        if mdadm.md_present(block.path_to_kname(blockdev)):
            raise OSError('Timeout exceeded for removal of %s', blockdev)

    except OSError:
        LOG.critical('Failed to stop mdadm device %s', device)
        if os.path.exists('/proc/mdstat'):
            LOG.critical("/proc/mdstat:\n%s", util.load_file('/proc/mdstat'))
        raise
示例#4
0
    def test_md_present_with_dev_path(self):
        mdname = '/dev/md0'
        self.mock_util.load_file.return_value = textwrap.dedent("""
        Personalities : [raid1] [linear] [multipath] [raid0] [raid6] [raid5]
        [raid4] [raid10]
        md0 : active raid1 vdc1[1] vda2[0]
              3143680 blocks super 1.2 [2/2] [UU]

        unused devices: <none>
        """)

        md_is_present = mdadm.md_present(mdname)

        self.assertTrue(md_is_present)
        self.mock_util.load_file.assert_called_with('/proc/mdstat')
示例#5
0
    def test_md_present_not_found_check_matching(self):
        mdname = 'md1'
        found_mdname = 'md10'
        self.mock_util.load_file.return_value = textwrap.dedent("""
        Personalities : [raid1] [linear] [multipath] [raid0] [raid6] [raid5]
        [raid4] [raid10]
        md10 : active raid1 vdc1[1] vda2[0]
               3143680 blocks super 1.2 [2/2] [UU]

        unused devices: <none>
        """)

        md_is_present = mdadm.md_present(mdname)

        self.assertFalse(md_is_present,
                         "%s mistakenly matched %s" % (mdname, found_mdname))
        self.mock_util.load_file.assert_called_with('/proc/mdstat')
示例#6
0
def shutdown_mdadm(device):
    """
    Shutdown specified mdadm device.
    """

    blockdev = block.sysfs_to_devpath(device)

    LOG.info('Discovering raid devices and spares for %s', device)
    md_devs = (mdadm.md_get_devices_list(blockdev) +
               mdadm.md_get_spares_list(blockdev))
    mdadm.set_sync_action(blockdev, action="idle")
    mdadm.set_sync_action(blockdev, action="frozen")

    LOG.info('Wiping superblock on raid device: %s', device)
    try:
        _wipe_superblock(blockdev, exclusive=False)
    except ValueError as e:
        # if the array is not functional, writes to the device may fail
        # and _wipe_superblock will raise ValueError for short writes
        # which happens on inactive raid volumes.  In that case we
        # shouldn't give up yet as we still want to disassemble
        # array and wipe members.  Other errors such as IOError or OSError
        # are unwelcome and will stop deployment.
        LOG.debug(
            'Non-fatal error writing to array device %s, '
            'proceeding with shutdown: %s', blockdev, e)

    LOG.info('Removing raid array members: %s', md_devs)
    for mddev in md_devs:
        try:
            mdadm.fail_device(blockdev, mddev)
            mdadm.remove_device(blockdev, mddev)
        except util.ProcessExecutionError as e:
            LOG.debug('Non-fatal error clearing raid array: %s', e.stderr)
            pass

    LOG.debug('using mdadm.mdadm_stop on dev: %s', blockdev)
    mdadm.mdadm_stop(blockdev)

    LOG.debug('Wiping mdadm member devices: %s' % md_devs)
    for mddev in md_devs:
        mdadm.zero_device(mddev, force=True)

    # mdadm stop operation is asynchronous so we must wait for the kernel to
    # release resources. For more details see  LP: #1682456
    try:
        for wait in MDADM_RELEASE_RETRIES:
            if mdadm.md_present(block.path_to_kname(blockdev)):
                time.sleep(wait)
            else:
                LOG.debug('%s has been removed', blockdev)
                break

        if mdadm.md_present(block.path_to_kname(blockdev)):
            raise OSError('Timeout exceeded for removal of %s', blockdev)

    except OSError:
        LOG.critical('Failed to stop mdadm device %s', device)
        if os.path.exists('/proc/mdstat'):
            LOG.critical("/proc/mdstat:\n%s", util.load_file('/proc/mdstat'))
        raise