def test_zero_device_no_examine_data(self): """ zero_device skips device if no examine metadata. """ device = '/wark/vda2' self.mock_examine.return_value = None mdadm.zero_device(device) self.mock_examine.assert_called_with(device, export=False) self.assertEqual(0, self.m_zero.call_count)
def test_zero_device_no_offsets(self): """ zero_device wipes at 0, and last 1MB for older metadata.""" device = '/wark/vda2' exdata = self._gen_examine("0.90", None, None) self.mock_examine.return_value = exdata mdadm.zero_device(device) expected_offsets = [0, -(1024 * 1024)] self.mock_examine.assert_called_with(device, export=False) self.m_zero.assert_called_with(device, expected_offsets, buflen=1024, count=1024, strict=True)
def test_zero_device(self): """ zero_device wipes at super and data offsets on device.""" device = '/wark/vda2' super_offset = 1024 data_offset = 2048 exdata = self._gen_examine("1.2", super_offset, data_offset) self.mock_examine.return_value = exdata mdadm.zero_device(device) expected_offsets = [offset * 512 for offset in [super_offset, data_offset]] self.mock_examine.assert_called_with(device, export=False) self.m_zero.assert_called_with(device, expected_offsets, buflen=1024, count=1024, strict=True)
def test_zero_device_no_sectors_uses_defaults(self): """ zero_device wipes at offsets on device no sector math.""" device = '/wark/vda2' super_offset = 1024 data_offset = 2048 exdata = self._gen_examine("1.1", super_offset, data_offset, sectors=False) self.mock_examine.return_value = exdata mdadm.zero_device(device) # if examine detail doesn't have 'sectors' in offset field # we use default offsets since we don't know what the value means. expected_offsets = [0, -(1024 * 1024)] self.mock_examine.assert_called_with(device, export=False) self.m_zero.assert_called_with(device, expected_offsets, buflen=1024, count=1024, strict=True)
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
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