def test_force_devmapper_symlinks(self, m_blkmap, m_islink, m_del_file): """ensure non-symlink for /dev/mapper/mpath* files are regenerated.""" m_blkmap.return_value = { 'mpatha': '/dev/dm-0', 'mpatha-part1': '/dev/dm-1', '1gb zero': '/dev/dm-2', } m_islink.side_effect = iter([ False, False, # mpatha, mpath-part1 are not links True, True, # mpatha, mpath-part1 are symlinks ]) multipath.force_devmapper_symlinks() udev = [ 'udevadm', 'trigger', '--subsystem-match=block', '--action=add' ] subp_expected_calls = [ mock.call(udev + ['/sys/class/block/dm-0']), mock.call(udev + ['/sys/class/block/dm-1']), ] # sorted for py27, whee! self.assertEqual(sorted(subp_expected_calls), sorted(self.m_subp.call_args_list)) islink_expected_calls = [ mock.call('/dev/mapper/mpatha'), mock.call('/dev/mapper/mpatha-part1'), mock.call('/dev/mapper/mpatha'), mock.call('/dev/mapper/mpatha-part1'), ] self.assertEqual(sorted(islink_expected_calls), sorted(m_islink.call_args_list)) del_file_expected_calls = [ mock.call('/dev/mapper/mpatha'), mock.call('/dev/mapper/mpatha-part1'), ] self.assertEqual(sorted(del_file_expected_calls), sorted(m_del_file.call_args_list))
def start_clear_holders_deps(): """ prepare system for clear holders to be able to scan old devices """ # a mdadm scan has to be started in case there is a md device that needs to # be detected. if the scan fails, it is either because there are no mdadm # devices on the system, or because there is a mdadm device in a damaged # state that could not be started. due to the nature of mdadm tools, it is # difficult to know which is the case. if any errors did occur, then ignore # them, since no action needs to be taken if there were no mdadm devices on # the system, and in the case where there is some mdadm metadata on a disk, # but there was not enough to start the array, the call to wipe_volume on # all disks and partitions should be sufficient to remove the mdadm # metadata mdadm.mdadm_assemble(scan=True, ignore_errors=True) # collect detail on any assembling arrays for md in [md for md in glob.glob('/dev/md*') if not os.path.isdir(md) and not identify_partition(md)]: mdstat = None if os.path.exists('/proc/mdstat'): mdstat = util.load_file('/proc/mdstat') LOG.debug("/proc/mdstat:\n%s", mdstat) found = [line for line in mdstat.splitlines() if os.path.basename(md) in line] # in some cases we have a /dev/md0 device node # but the kernel has already renamed the device /dev/md127 if len(found) == 0: LOG.debug('Ignoring md device %s, not present in mdstat', md) continue # give it a second poke to encourage running try: LOG.debug('Activating mdadm array %s', md) (out, err) = mdadm.mdadm_run(md) LOG.debug('MDADM run on %s stdout:\n%s\nstderr:\n%s', md, out, err) except util.ProcessExecutionError: LOG.debug('Non-fatal error when starting mdadm device %s', md) # extract details if we can try: (out, err) = mdadm.mdadm_query_detail(md, export=False, rawoutput=True) LOG.debug('MDADM detail on %s stdout:\n%s\nstderr:\n%s', md, out, err) except util.ProcessExecutionError: LOG.debug('Non-fatal error when querying mdadm detail on %s', md) mp_support = multipath.multipath_supported() if mp_support: LOG.debug('Detected multipath support, reload maps') multipath.reload() multipath.force_devmapper_symlinks() # scan and activate for logical volumes lvm.lvm_scan(multipath=mp_support) try: lvm.activate_volgroups(multipath=mp_support) except util.ProcessExecutionError: # partial vg may not come up due to missing members, that's OK pass udev.udevadm_settle() # the bcache module needs to be present to properly detect bcache devs # on some systems (precise without hwe kernel) it may not be possible to # lad the bcache module bcause it is not present in the kernel. if this # happens then there is no need to halt installation, as the bcache devices # will never appear and will never prevent the disk from being reformatted util.load_kernel_module('bcache') if not zfs.zfs_supported(): LOG.warning('zfs filesystem is not supported in this environment')