Exemple #1
0
 def test_unblacklist_udev_rules_executes(self, mock_udev, mock_execute,
                                          mock_os, mock_open):
     utils.unblacklist_udev_rules('/etc/udev/rules.d', '.renamedrule')
     self.assertEqual([mock.call('udevadm', 'control', '--reload-rules',
                                 check_exit_code=[0]),
                       mock.call('udevadm', 'trigger',
                                 '--subsystem-match=block',
                                 check_exit_code=[0])],
                      mock_execute.call_args_list)
Exemple #2
0
 def test_unblacklist_udev_rules_executes(self, mock_udev, mock_execute, mock_os, mock_open):
     utils.unblacklist_udev_rules("/etc/udev/rules.d", ".renamedrule")
     self.assertEqual(
         [
             mock.call("udevadm", "control", "--reload-rules", check_exit_code=[0]),
             mock.call("udevadm", "trigger", "--subsystem-match=block", check_exit_code=[0]),
         ],
         mock_execute.call_args_list,
     )
Exemple #3
0
 def test_unblacklist_udev_rules_not_a_rule(self, mock_udev, mock_execute,
                                            mock_os, mock_open):
     mock_os.path.join.side_effect = self._fake_join
     mock_os.listdir.return_value = ['not_a_rule', 'dir']
     mock_os.path.isdir.side_effect = [False, True]
     utils.unblacklist_udev_rules('/etc/udev/rules.d', '.renamedrule')
     mock_os.listdir.assert_called_once_with('/etc/udev/rules.d')
     self.assertEqual([mock.call('/etc/udev/rules.d', 'not_a_rule'),
                       mock.call('/etc/udev/rules.d', 'dir')],
                      mock_os.path.join.call_args_list)
     self.assertEqual([mock.call('/etc/udev/rules.d/not_a_rule'),
                       mock.call('/etc/udev/rules.d/dir')],
                      mock_os.path.isdir.call_args_list)
     self.assertFalse(mock_os.path.exists.called)
     self.assertFalse(mock_os.remove.called)
     self.assertFalse(mock_os.rename.called)
     mock_udev.assert_called_once_with()
Exemple #4
0
 def test_unblacklist_udev_rules_remove(self, mock_udev, mock_execute, mock_os, mock_open):
     mock_os.path.join.side_effect = self._fake_join
     mock_os.listdir.return_value = ["fake.rules", "fake_err.rules"]
     mock_os.remove.side_effect = [None, OSError]
     mock_os.path.isdir.side_effect = 2 * [False]
     mock_os.path.islink.return_value = True
     utils.unblacklist_udev_rules("/etc/udev/rules.d", ".renamedrule")
     self.assertFalse(mock_os.path.exists.called)
     self.assertFalse(mock_os.rename.called)
     mock_os.listdir.assert_called_once_with("/etc/udev/rules.d")
     expected_rules_calls = [
         mock.call("/etc/udev/rules.d/fake.rules"),
         mock.call("/etc/udev/rules.d/fake_err.rules"),
     ]
     self.assertEqual(expected_rules_calls, mock_os.path.islink.call_args_list)
     self.assertEqual(expected_rules_calls, mock_os.remove.call_args_list)
     self.assertEqual(2 * [mock.call()], mock_udev.call_args_list)
Exemple #5
0
 def test_unblacklist_udev_rules_remove(self, mock_udev, mock_execute,
                                        mock_os, mock_open):
     mock_os.path.join.side_effect = self._fake_join
     mock_os.listdir.return_value = ['fake.rules', 'fake_err.rules']
     mock_os.remove.side_effect = [None, OSError]
     mock_os.path.isdir.side_effect = 2 * [False]
     mock_os.path.islink.return_value = True
     utils.unblacklist_udev_rules('/etc/udev/rules.d', '.renamedrule')
     self.assertFalse(mock_os.path.exists.called)
     self.assertFalse(mock_os.rename.called)
     mock_os.listdir.assert_called_once_with('/etc/udev/rules.d')
     expected_rules_calls = [mock.call('/etc/udev/rules.d/fake.rules'),
                             mock.call('/etc/udev/rules.d/fake_err.rules')]
     self.assertEqual(expected_rules_calls,
                      mock_os.path.islink.call_args_list)
     self.assertEqual(expected_rules_calls,
                      mock_os.remove.call_args_list)
     self.assertEqual(2 * [mock.call()], mock_udev.call_args_list)
Exemple #6
0
 def test_unblacklist_udev_rules_rename(self, mock_udev, mock_execute,
                                        mock_os, mock_open):
     mock_os.path.join.side_effect = self._fake_join
     mock_os.listdir.return_value = ['fake.renamedrule',
                                     'fake_err.renamedrule']
     mock_os.rename.side_effect = [None, OSError]
     mock_os.path.isdir.side_effect = 2 * [False]
     utils.unblacklist_udev_rules('/etc/udev/rules.d', '.renamedrule')
     self.assertFalse(mock_os.path.islink.called)
     self.assertFalse(mock_os.remove.called)
     mock_os.listdir.assert_called_once_with('/etc/udev/rules.d')
     self.assertEqual([mock.call('/etc/udev/rules.d/fake.renamedrule'),
                       mock.call('/etc/udev/rules.d/fake_err.renamedrule')],
                      mock_os.path.exists.call_args_list)
     self.assertEqual([mock.call('/etc/udev/rules.d/fake.renamedrule',
                                 '/etc/udev/rules.d/fake.rules'),
                       mock.call('/etc/udev/rules.d/fake_err.renamedrule',
                                 '/etc/udev/rules.d/fake_err.rules')],
                      mock_os.rename.call_args_list)
     self.assertEqual(2 * [mock.call()], mock_udev.call_args_list)
Exemple #7
0
    def do_partitioning(self):
        LOG.debug('--- Partitioning disks (do_partitioning) ---')

        if self.driver.partition_scheme.skip_partitioning:
            LOG.debug('Some of fs has keep_data flag, '
                      'partitioning is skiping')
            self.do_clean_filesystems()
            return

        # If disks are not wiped out at all, it is likely they contain lvm
        # and md metadata which will prevent re-creating a partition table
        # with 'device is busy' error.
        mu.mdclean_all()
        lu.lvremove_all()
        lu.vgremove_all()
        lu.pvremove_all()

        LOG.debug("Enabling udev's rules blacklisting")
        utils.blacklist_udev_rules(udev_rules_dir=CONF.udev_rules_dir,
                                   udev_rules_lib_dir=CONF.udev_rules_lib_dir,
                                   udev_rename_substr=CONF.udev_rename_substr,
                                   udev_empty_rule=CONF.udev_empty_rule)

        for parted in self.driver.partition_scheme.parteds:
            for prt in parted.partitions:
                # We wipe out the beginning of every new partition
                # right after creating it. It allows us to avoid possible
                # interactive dialog if some data (metadata or file system)
                # present on this new partition and it also allows udev not
                # hanging trying to parse this data.
                utils.execute('dd', 'if=/dev/zero', 'bs=1M',
                              'seek=%s' % max(prt.begin - 3, 0), 'count=5',
                              'of=%s' % prt.device, check_exit_code=[0])
                # Also wipe out the ending of every new partition.
                # Different versions of md stores metadata in different places.
                # Adding exit code 1 to be accepted as for handling situation
                # when 'no space left on device' occurs.
                utils.execute('dd', 'if=/dev/zero', 'bs=1M',
                              'seek=%s' % max(prt.end - 3, 0), 'count=5',
                              'of=%s' % prt.device, check_exit_code=[0, 1])

        for parted in self.driver.partition_scheme.parteds:
            pu.make_label(parted.name, parted.label)
            for prt in parted.partitions:
                pu.make_partition(prt.device, prt.begin, prt.end, prt.type)
                for flag in prt.flags:
                    pu.set_partition_flag(prt.device, prt.count, flag)
                if prt.guid:
                    pu.set_gpt_type(prt.device, prt.count, prt.guid)
                # If any partition to be created doesn't exist it's an error.
                # Probably it's again 'device or resource busy' issue.
                if not os.path.exists(prt.name):
                    raise errors.PartitionNotFoundError(
                        'Partition %s not found after creation' % prt.name)

        LOG.debug("Disabling udev's rules blacklisting")
        utils.unblacklist_udev_rules(
            udev_rules_dir=CONF.udev_rules_dir,
            udev_rename_substr=CONF.udev_rename_substr)

        # If one creates partitions with the same boundaries as last time,
        # there might be md and lvm metadata on those partitions. To prevent
        # failing of creating md and lvm devices we need to make sure
        # unused metadata are wiped out.
        mu.mdclean_all()
        lu.lvremove_all()
        lu.vgremove_all()
        lu.pvremove_all()

        # creating meta disks
        for md in self.driver.partition_scheme.mds:
            mu.mdcreate(md.name, md.level, md.devices, md.metadata)

        # creating physical volumes
        for pv in self.driver.partition_scheme.pvs:
            lu.pvcreate(pv.name, metadatasize=pv.metadatasize,
                        metadatacopies=pv.metadatacopies)

        # creating volume groups
        for vg in self.driver.partition_scheme.vgs:
            lu.vgcreate(vg.name, *vg.pvnames)

        # creating logical volumes
        for lv in self.driver.partition_scheme.lvs:
            lu.lvcreate(lv.vgname, lv.name, lv.size)

        # making file systems
        for fs in self.driver.partition_scheme.fss:
            found_images = [img for img in self.driver.image_scheme.images
                            if img.target_device == fs.device]
            if not found_images:
                fu.make_fs(fs.type, fs.options, fs.label, fs.device)
Exemple #8
0
    def do_partitioning(self):
        LOG.debug('--- Partitioning disks (do_partitioning) ---')

        if self.driver.partition_scheme.skip_partitioning:
            LOG.debug('Some of fs has keep_data flag, '
                      'partitioning is skiping')
            self.do_clean_filesystems()
            return

        # If disks are not wiped out at all, it is likely they contain lvm
        # and md metadata which will prevent re-creating a partition table
        # with 'device is busy' error.
        mu.mdclean_all(skip_containers=CONF.skip_md_containers)
        lu.lvremove_all()
        lu.vgremove_all()
        lu.pvremove_all()

        for parted in self.driver.partition_scheme.parteds:
            for prt in parted.partitions:
                # We wipe out the beginning of every new partition
                # right after creating it. It allows us to avoid possible
                # interactive dialog if some data (metadata or file system)
                # present on this new partition and it also allows udev not
                # hanging trying to parse this data.
                utils.execute('dd', 'if=/dev/zero', 'bs=1M',
                              'seek=%s' % max(prt.begin - 3, 0), 'count=5',
                              'of=%s' % prt.device, check_exit_code=[0])
                # Also wipe out the ending of every new partition.
                # Different versions of md stores metadata in different places.
                # Adding exit code 1 to be accepted as for handling situation
                # when 'no space left on device' occurs.
                utils.execute('dd', 'if=/dev/zero', 'bs=1M',
                              'seek=%s' % max(prt.end - 3, 0), 'count=5',
                              'of=%s' % prt.device, check_exit_code=[0, 1])

        parteds = []
        parteds_with_rules = []
        for parted in self.driver.partition_scheme.parteds:
            if hw.is_multipath_device(parted.name):
                parteds_with_rules.append(parted)
            else:
                parteds.append(parted)

        utils.blacklist_udev_rules(udev_rules_dir=CONF.udev_rules_dir,
                                   udev_rules_lib_dir=CONF.udev_rules_lib_dir,
                                   udev_rename_substr=CONF.udev_rename_substr,
                                   udev_empty_rule=CONF.udev_empty_rule)

        self._make_partitions(parteds)

        utils.unblacklist_udev_rules(
            udev_rules_dir=CONF.udev_rules_dir,
            udev_rename_substr=CONF.udev_rename_substr)

        self._make_partitions(parteds_with_rules)

        # If one creates partitions with the same boundaries as last time,
        # there might be md and lvm metadata on those partitions. To prevent
        # failing of creating md and lvm devices we need to make sure
        # unused metadata are wiped out.
        mu.mdclean_all(skip_containers=CONF.skip_md_containers)
        lu.lvremove_all()
        lu.vgremove_all()
        lu.pvremove_all()

        if parteds_with_rules:
            utils.refresh_multipath()

        # creating meta disks
        for md in self.driver.partition_scheme.mds:
            mu.mdcreate(md.name, md.level, md.devices, md.metadata)

        # creating physical volumes
        for pv in self.driver.partition_scheme.pvs:
            lu.pvcreate(pv.name, metadatasize=pv.metadatasize,
                        metadatacopies=pv.metadatacopies)

        # creating volume groups
        for vg in self.driver.partition_scheme.vgs:
            lu.vgcreate(vg.name, *vg.pvnames)

        # creating logical volumes
        for lv in self.driver.partition_scheme.lvs:
            lu.lvcreate(lv.vgname, lv.name, lv.size)

        # making file systems
        for fs in self.driver.partition_scheme.fss:
            found_images = [img for img in self.driver.image_scheme.images
                            if img.target_device == fs.device]
            if not found_images:
                fu.make_fs(fs.type, fs.options, fs.label, fs.device)