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) # scan and activate for logical volumes lvm.lvm_scan() lvm.activate_volgroups() # 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')
def test_mdadm_assemble_exec_error(self): self.mock_util.ProcessExecutionError = util.ProcessExecutionError self.mock_util.subp.side_effect = raise_pexec_error with self.assertRaises(util.ProcessExecutionError): mdadm.mdadm_assemble(scan=True, ignore_errors=False) self.mock_util.subp.assert_called_with( ['mdadm', '--assemble', '--scan', '-v'], capture=True, rcs=[0, 1, 2])
def test_mdadm_assemble_scan(self): mdadm.mdadm_assemble(scan=True) assemble_calls = [ call(["mdadm", "--assemble", "--scan", "-v"], capture=True, rcs=[0, 1, 2]), call(["mdadm", "--detail", "--scan", "-v"], capture=True, rcs=[0, 1]), ] self.mock_util.subp.assert_has_calls(assemble_calls) self.assertTrue(self.mock_udev.udevadm_settle.called)
def test_mdadm_assemble_md_devname_devices(self): md_devname = "/dev/md0" devices = ["/dev/vdc1", "/dev/vdd1"] mdadm.mdadm_assemble(md_devname=md_devname, devices=devices) assemble_calls = [ call(["mdadm", "--assemble", md_devname, "--run"] + devices, capture=True, rcs=[0, 1, 2]), call(["mdadm", "--detail", "--scan", "-v"], capture=True, rcs=[0, 1]), ] self.mock_util.subp.assert_has_calls(assemble_calls) self.assertTrue(self.mock_udev.udevadm_settle.called)
def test_mdadm_assemble_md_devname_none(self): with self.assertRaises(ValueError): md_devname = None mdadm.mdadm_assemble(md_devname=md_devname)
def test_mdadm_assemble_md_devname_short(self): with self.assertRaises(ValueError): md_devname = "md0" mdadm.mdadm_assemble(md_devname=md_devname)
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) # scan and activate for logical volumes lvm.lvm_scan() lvm.activate_volgroups() # 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')