Пример #1
0
    def test_make_dname_lvm_partition(self, mock_util, mock_get_path,
                                      mock_log, mock_info):
        mock_util.load_command_environment.return_value = self.state

        # simple
        res_dname = 'vg1-lpartition1'
        mock_info.return_value = {'DM_NAME': res_dname}
        rule_identifiers = [('DM_NAME', res_dname)]
        block_meta.make_dname('lpart_id', self.storage_config)
        self.assertTrue(mock_log.debug.called)
        self.assertFalse(mock_log.warning.called)
        mock_util.write_file.assert_called_with(
            self.rule_file.format(res_dname),
            self._content(
                [self._formatted_rule(rule_identifiers, res_dname)]))

        # with invalid name
        res_dname = 'vg1-lvm-part-2'
        mock_info.return_value = {'DM_NAME': 'vg1-lvm part/2'}
        rule_identifiers = [('DM_NAME', 'vg1-lvm part/2')]
        block_meta.make_dname('lpart2_id', self.storage_config)
        self.assertTrue(mock_log.warning.called)
        mock_util.write_file.assert_called_with(
            self.rule_file.format(res_dname),
            self._content(
                [self._formatted_rule(rule_identifiers, res_dname)]))
Пример #2
0
    def test_make_dname_raid(self, mock_util, mock_get_path, mock_log,
                             mock_mdadm):
        md_uuid = str(uuid.uuid1())
        mock_mdadm.mdadm_query_detail.return_value = {'MD_UUID': md_uuid}
        mock_util.load_command_environment.return_value = self.state
        rule_identifiers = [('MD_UUID', md_uuid)]

        # simple
        res_dname = 'mdadm_name'
        block_meta.make_dname('md_id', self.storage_config)
        self.assertTrue(mock_log.debug.called)
        self.assertFalse(mock_log.warning.called)
        mock_util.write_file.assert_called_with(
            self.rule_file.format(res_dname),
            self._content(
                [self._formatted_rule(rule_identifiers, res_dname)]))

        # invalid name
        res_dname = 'mdadm-name'
        block_meta.make_dname('md_id2', self.storage_config)
        self.assertTrue(mock_log.warning.called)
        mock_util.write_file.assert_called_with(
            self.rule_file.format(res_dname),
            self._content(
                [self._formatted_rule(rule_identifiers, res_dname)]))
Пример #3
0
    def test_make_dname_disk(self, mock_util, mock_get_path, mock_log):
        disk_ptuuid = str(uuid.uuid1())
        mock_util.subp.side_effect = self._make_mock_subp_blkid(
            disk_ptuuid, self.disk_blkid)
        mock_util.load_command_environment.return_value = self.state
        rule_identifiers = [('DEVTYPE', 'disk'),
                            ('ID_PART_TABLE_UUID', disk_ptuuid)]

        # simple run
        res_dname = 'main_disk'
        block_meta.make_dname('disk1', self.storage_config)
        mock_util.ensure_dir.assert_called_with(self.rules_d)
        self.assertTrue(mock_log.debug.called)
        self.assertFalse(mock_log.warning.called)
        mock_util.write_file.assert_called_with(
            self.rule_file.format(res_dname),
            self._formatted_rule(rule_identifiers, res_dname))

        # run invalid dname
        res_dname = 'in_valid-name----------disk'
        block_meta.make_dname('disk2', self.storage_config)
        self.assertTrue(mock_log.warning.called)
        mock_util.write_file.assert_called_with(
            self.rule_file.format(res_dname),
            self._formatted_rule(rule_identifiers, res_dname))
Пример #4
0
    def test_make_dname_bcache(self, mock_util, mock_get_path, mock_bcache,
                               mock_log):
        """ check bcache dname uses backing device uuid to link dname """
        mock_get_path.return_value = '/my/dev/huge-storage'
        mock_bcache.superblock_asdict.return_value = self.bcache_super_show
        mock_util.load_command_environment.return_value = self.state

        res_dname = 'my-cached-data'
        backing_uuid = 'f36394c0-3cc0-4423-8d6f-ffac130f171a'
        rule_identifiers = [('CACHED_UUID', backing_uuid)]
        block_meta.make_dname('bcache1_id', self.storage_config)
        self.assertTrue(mock_log.debug.called)
        self.assertFalse(mock_log.warning.called)
        mock_util.write_file.assert_called_with(
            self.rule_file.format(res_dname),
            self._content([self._formatted_rule(rule_identifiers, res_dname)]))
Пример #5
0
    def test_make_dname_failures(self, mock_util, mock_get_path, mock_log):
        mock_util.subp.side_effect = self._make_mock_subp_blkid(
            '', self.trusty_blkid)
        mock_util.load_command_environment.return_value = self.state

        warning_msg = "Can't find a uuid for volume: {}. Skipping dname."

        # disk with no PT_UUID
        block_meta.make_dname('disk1', self.storage_config)
        mock_log.warning.assert_called_with(warning_msg.format('disk1'))
        self.assertFalse(mock_util.write_file.called)

        # partition with no PART_UUID
        block_meta.make_dname('disk1p1', self.storage_config)
        mock_log.warning.assert_called_with(warning_msg.format('disk1p1'))
        self.assertFalse(mock_util.write_file.called)
Пример #6
0
    def test_make_dname_partition(self, mock_util, mock_get_path, mock_log):
        part_uuid = str(uuid.uuid1())
        mock_util.subp.side_effect = self._make_mock_subp_blkid(
            part_uuid, self.part_blkid)
        mock_util.load_command_environment.return_value = self.state

        rule_identifiers = [
            ('DEVTYPE', 'partition'),
            ('ID_PART_ENTRY_UUID', part_uuid),
        ]

        # simple run
        res_dname = 'custom-partname'
        block_meta.make_dname('disk1p2', self.storage_config)
        mock_util.ensure_dir.assert_called_with(self.rules_d)
        self.assertTrue(mock_log.debug.called)
        self.assertFalse(mock_log.warning.called)
        mock_util.write_file.assert_called_with(
            self.rule_file.format(res_dname),
            self._content([self._formatted_rule(rule_identifiers, res_dname)]))
Пример #7
0
    def test_make_dname_disk(self, mock_util, mock_get_path, mock_log,
                             mock_udev):
        disk_ptuuid = str(uuid.uuid1())
        mock_util.subp.side_effect = self._make_mock_subp_blkid(
            disk_ptuuid, self.disk_blkid)
        mock_util.load_command_environment.return_value = self.state

        rule_identifiers = [('ID_PART_TABLE_UUID', disk_ptuuid)]
        id_rule_identifiers = [('ID_SERIAL', self.disk_serial)]
        wwn_rule_identifiers = [('ID_WWN_WITH_EXTENSION', self.disk_wwn)]

        def _drule(devtype, match):
            return [('DEVTYPE', devtype)] + [m for m in match]

        def drule(match):
            return _drule('disk', match)

        def prule(match):
            return _drule('partition', match)

        # simple run
        mock_udev.side_effect = (
            [{'DEVTYPE': 'disk', 'ID_SERIAL': self.disk_serial},
             {'DEVTYPE': 'disk', 'ID_WWN_WITH_EXTENSION': self.disk_wwn}])
        res_dname = 'main_disk'
        block_meta.make_dname('disk1', self.storage_config)
        mock_util.ensure_dir.assert_called_with(self.rules_d)
        self.assertTrue(mock_log.debug.called)
        self.assertFalse(mock_log.warning.called)
        mock_util.write_file.assert_called_with(
            self.rule_file.format(res_dname),
            self._content(
                [self._formatted_rule(drule(rule_identifiers),
                                      res_dname),
                 self._formatted_rule(drule(id_rule_identifiers),
                                      res_dname),
                 self._formatted_rule(prule(id_rule_identifiers),
                                      "%s-part%%n" % res_dname)]))

        # run invalid dname
        res_dname = 'in_valid-name----------disk'
        block_meta.make_dname('disk2', self.storage_config)
        self.assertTrue(mock_log.warning.called)
        mock_util.write_file.assert_called_with(
            self.rule_file.format(res_dname),
            self._content(
                [self._formatted_rule(drule(rule_identifiers),
                                      res_dname),
                 self._formatted_rule(drule(wwn_rule_identifiers),
                                      res_dname),
                 self._formatted_rule(prule(wwn_rule_identifiers),
                                      "%s-part%%n" % res_dname)]))

        # iscsi disk with no config, but info returns serial and wwn
        mock_udev.side_effect = (
            [{'DEVTYPE': 'disk', 'ID_SERIAL': self.disk_serial,
              'DEVTYPE': 'disk', 'ID_WWN_WITH_EXTENSION': self.disk_wwn}])
        res_dname = 'iscsi_disk1'
        block_meta.make_dname('iscsi1', self.storage_config)
        mock_util.ensure_dir.assert_called_with(self.rules_d)
        self.assertTrue(mock_log.debug.called)
        both_rules = (wwn_rule_identifiers + id_rule_identifiers)
        mock_util.write_file.assert_called_with(
            self.rule_file.format(res_dname),
            self._content(
                [self._formatted_rule(drule(rule_identifiers), res_dname),
                 self._formatted_rule(drule(both_rules), res_dname),
                 self._formatted_rule(prule(both_rules),
                                      "%s-part%%n" % res_dname)]))