예제 #1
0
파일: dasd.py 프로젝트: tjjh89017/curtin
def dasdinfo(device_id):
    ''' Run dasdinfo command and return the exported values.

    :param: device_id:  string, device_id of the dasd device to query.
    :returns: dictionary of udev key=value pairs.
    :raises: ValueError on None-ish device_id.
    :raises: ProcessExecutionError if dasdinfo returns non-zero.

    e.g.

    % info = dasdinfo('0.0.1544')
    % pprint.pprint(info)
    {'ID_BUS': 'ccw',
     'ID_SERIAL': '0X1544',
     'ID_TYPE': 'disk',
     'ID_UID': 'IBM.750000000DXP71.1500.44',
     'ID_XUID': 'IBM.750000000DXP71.1500.44'}
    '''
    _valid_device_id(device_id)

    out, err = util.subp(
        ['dasdinfo', '--all', '--export', '--busid=%s' % device_id],
        capture=True)

    return util.load_shell_content(out)
예제 #2
0
    def test_dname_rules(self, disk_to_check=None):
        if self.target_distro != "ubuntu":
            raise SkipTest("dname not present in non-ubuntu releases")

        print('test_dname_rules: checking disks: %s', disk_to_check)
        self.output_files_exist(["udev_rules.d"])

        cfg = load_config(self.collect_path("root/curtin-install-cfg.yaml"))
        stgcfg = cfg.get("storage", {}).get("config", [])
        disks = [
            ent for ent in stgcfg
            if (ent.get('type') == 'disk' and 'name' in ent)
        ]
        for disk in disks:
            if not disk.get('name'):
                continue
            dname = sanitize_dname(disk.get('name'))
            dname_file = "%s.rules" % dname
            dm_dev = self._dname_to_kname(dname)
            info = util.load_shell_content(
                self.load_collect_file("udevadm_info_%s" % dm_dev))
            contents = self.load_collect_file("udev_rules.d/%s" % dname_file)

            present = [k for k in DNAME_BYID_KEYS if info.get(k)]
            # xenial and bionic do not have multipath in ephemeral environment
            # so dnames cannot use DM_UUID in rule files.
            if self.target_release in ['xenial', 'bionic', 'centos70']:
                present.remove('DM_UUID')
            if present:
                for id_key in present:
                    value = info[id_key]
                    if value:
                        self.assertIn(id_key, contents)
                        self.assertIn(value, contents)
예제 #3
0
 def test_info_returns_partial_dictionary(self):
     """dasdinfo returns partial dictionary on error."""
     device_id = random_device_id()
     self.m_subp.side_effect = (
         util.ProcessExecutionError(stdout=self.info_no_serial,
                                    stderr=self.random_string(),
                                    exit_code=random.randint(1, 255),
                                    cmd=self.random_string()))
     expected = util.load_shell_content(self.info_no_serial)
     self.assertDictEqual(expected, dasd.dasdinfo(device_id))
예제 #4
0
def _extract_mpath_data(cmd, show_verb):
    data, _err = util.subp(cmd, capture=True)
    result = []
    for line in data.splitlines():
        mp_dict = util.load_shell_content(line, add_empty=True)
        LOG.debug('Extracted multipath %s fields: %s', show_verb, mp_dict)
        if mp_dict:
            result.append(mp_dict)

    return result
예제 #5
0
    def test_proc_command_line_has_mp_device(self):
        cmdline = self.load_collect_file('proc_cmdline')
        root = [tok for tok in cmdline.split() if tok.startswith('root=')]
        self.assertEqual(len(root), 1)

        root = root.pop()
        root = root.split('root=')[1]
        if self.target_release in ['xenial', 'bionic']:
            self.assertEqual('/dev/mapper/mpath0-part1', root)
        elif self.target_release in ['centos70']:
            self.assertEqual('/dev/mapper/mpath0p1', root)
        else:
            dm_dev = self._dname_to_kname('mpath_a-part1')
            info = util.load_shell_content(
                self.load_collect_file("udevadm_info_%s" % dm_dev))
            dev_mapper = '/dev/mapper/' + info['DM_NAME']
            self.assertEqual(dev_mapper, root)
예제 #6
0
파일: dasd.py 프로젝트: jnavila/curtin
def dasdinfo(device_id, rawoutput=False, strict=False):
    ''' Run dasdinfo command and return the exported values.

    :param: device_id:  string, device_id of the dasd device to query.
    :returns: dictionary of udev key=value pairs.
    :raises: ValueError on None-ish device_id.
    :raises: ProcessExecutionError if dasdinfo returns non-zero.

    e.g.

    % info = dasdinfo('0.0.1544')
    % pprint.pprint(info)
    {'ID_BUS': 'ccw',
     'ID_SERIAL': '0X1544',
     'ID_TYPE': 'disk',
     'ID_UID': 'IBM.750000000DXP71.1500.44',
     'ID_XUID': 'IBM.750000000DXP71.1500.44'}
    '''
    _valid_device_id(device_id)

    try:
        out, err = util.subp(
            ['dasdinfo', '--all', '--export',
             '--busid=%s' % device_id],
            capture=True)
    except util.ProcessExecutionError as e:
        LOG.warning('dasdinfo result may be incomplete: %s', e)
        if strict:
            raise
        out = e.stdout
        err = e.stderr

    if rawoutput:
        return (out, err)

    return util.load_shell_content(out)
예제 #7
0
 def test_info_returns_dictionary(self):
     """dasdinfo returns dictionary of device info."""
     device_id = random_device_id()
     self.m_subp.return_value = (self.info, '')
     expected = util.load_shell_content(self.info)
     self.assertDictEqual(expected, dasd.dasdinfo(device_id))