예제 #1
0
def test_configs():
    tests = [
        (
            default_rhel7_conf,
            os.path.join(CUR_DIR, 'files/after/default_rhel7.conf'),
        ),
        (all_devs_conf, os.path.join(CUR_DIR, 'files/after/all_devs.conf')),
        (empty_conf, None),
        (default_rhel8_conf, None),
        (
            all_the_things_conf,
            os.path.join(CUR_DIR, 'files/after/all_the_things.conf'),
        ),
        (already_updated_conf, None),
        (ugly1_conf, os.path.join(CUR_DIR, 'files/after/ugly1.conf')),
        (ugly2_conf, os.path.join(CUR_DIR, 'files/after/ugly2.conf')),
        (
            just_checker_conf,
            os.path.join(CUR_DIR, 'files/after/just_checker.conf'),
        ),
        (
            just_detect_conf,
            os.path.join(CUR_DIR, 'files/after/just_detect.conf'),
        ),
        (
            just_reassign_conf,
            os.path.join(CUR_DIR, 'files/after/just_reassign.conf'),
        ),
        (
            just_exists_conf,
            os.path.join(CUR_DIR, 'files/after/just_exists.conf'),
        ),
        (
            just_all_devs_conf,
            os.path.join(CUR_DIR, 'files/after/just_all_devs.conf'),
        ),
    ]
    for config, expected_config in tests:
        config_lines = multipathconfupdate._update_config(config)
        if config_lines is None:
            assert expected_config is None
            continue
        expected_lines = multipathutil.read_config(expected_config)
        assert expected_lines is not None
        assert len(config_lines) == len(expected_lines)
        for config_line, expected_line in zip(config_lines, expected_lines):
            assert config_line == expected_line
def _update_config(config):
    if _nothing_to_do(config):
        return None
    contents = multipathutil.read_config(config.pathname)
    if contents is None:
        return None
    lines = contents.split('\n')
    section = None
    in_subsection = False
    in_all_devs = False
    subsection_start = None
    all_devs_ranges = []
    overrides_line = None
    qinp_info = None
    has_no_path_retry = False
    qinp_infos = []
    for i, line in enumerate(lines):
        try:
            data = multipathutil.LineData(line, section, in_subsection)
        except ValueError:
            continue
        if data.type == data.TYPE_SECTION_END:
            if qinp_info and not in_all_devs:
                qinp_info.has_no_path_retry = has_no_path_retry
                qinp_infos.append(qinp_info)
            qinp_info = None
            has_no_path_retry = False
            if in_subsection:
                in_subsection = False
                if in_all_devs:
                    all_devs_ranges.append((subsection_start, i + 1))
                in_all_devs = False
                subsection_start = None
            elif section is not None:
                section = None
        elif data.type == data.TYPE_SECTION_START:
            if section is None:
                section = data.section
                if section == 'overrides':
                    overrides_line = line
            elif not in_subsection:
                in_subsection = True
                subsection_start = i
        if data.type != data.TYPE_OPTION:
            continue
        if section == 'defaults':
            if (data.option
                    in ('path_checker', 'checker')) and data.value != 'tur':
                lines[i] = _comment_out_line(line)
                continue
            if data.option in _bool_options and \
                    _bool_options[data.option] != data.is_enabled():
                lines[i] = _comment_out_line(line)
                continue
        elif section == 'overrides' and data.option in _ovr_options:
            lines[i] = _comment_out_line(line)
            continue
        elif section == 'devices' and in_subsection and \
                data.option == 'all_devs' and data.is_enabled():
            in_all_devs = True
            continue
        if data.option in _exist_options:
            lines[i] = _comment_out_line(line)
        elif data.option == 'detect_path_checker':
            lines[i] = _convert_checker_line(line)
        elif data.option == 'no_path_retry' and _valid_npr(data.value):
            has_no_path_retry = True
        elif data.option == 'features' and 'queue_if_no_path' in data.value:
            qinp_info = _QueueIfNoPathInfo(line, data.value)

    if in_subsection:
        lines.append('\t} # line added by Leapp')
        if in_all_devs:
            all_devs_ranges.append((subsection_start, len(lines)))
        elif qinp_info:
            qinp_info.has_no_path_retry = has_no_path_retry
            qinp_infos.append(qinp_info)
            qinp_info = None
    if section is not None:
        lines.append('} # line added by Leapp')
        lines.append('')
        if qinp_info:
            qinp_info.has_no_path_retry = has_no_path_retry
            qinp_infos.append(qinp_info)
    _comment_out_ranges(lines, all_devs_ranges)
    if qinp_infos != []:
        _remove_qinp(lines, qinp_infos)
    if config.all_devs_options != []:
        if overrides_line:
            _update_overrides(lines, overrides_line, config.all_devs_options)
        else:
            _add_overrides(lines, config.all_devs_options)
    contents = '\n'.join(lines)
    return contents
예제 #3
0
def test_no_config():
    content = lib.read_config('/this/does/not/exist')
    assert content is None
예제 #4
0
def _parse_config(path):
    contents = multipathutil.read_config(path)
    if contents is None:
        return None
    conf = MultipathConfig(pathname=path)
    conf.all_devs_options = []
    section = None
    in_subsection = False
    device_options = []
    overrides_options = []
    in_all_devs = False
    for line in contents.split('\n'):
        try:
            data = multipathutil.LineData(line, section, in_subsection)
        except ValueError:
            continue
        if data.type == data.TYPE_BLANK:
            continue
        if data.type == data.TYPE_SECTION_END:
            if in_subsection:
                in_subsection = False
                if in_all_devs:
                    _add_options(conf.all_devs_options, device_options)
                in_all_devs = False
                device_options = []
            elif section:
                section = None
            continue
        if data.type == data.TYPE_SECTION_START:
            if not section:
                section = data.section
            elif not in_subsection:
                in_subsection = True
            continue
        if data.type != data.TYPE_OPTION:
            continue
        if section == 'defaults':
            if data.option == 'path_checker' or data.option == 'checker':
                conf.default_path_checker = data.value
            elif data.option == 'config_dir':
                conf.config_dir = data.value
            elif data.option == 'retain_attached_hw_handler':
                conf.default_retain_hwhandler = data.is_enabled()
            elif data.option == 'detect_prio':
                conf.default_detect_prio = data.is_enabled()
            elif data.option == 'detect_path_checker':
                conf.default_detect_checker = data.is_enabled()
            elif data.option == 'reassign_maps':
                conf.reassign_maps = data.is_enabled()
            elif data.option == 'hw_str_match':
                conf.hw_str_match_exists = True
            elif data.option == 'ignore_new_boot_devs':
                conf.ignore_new_boot_devs_exists = True
            elif data.option == 'new_bindings_in_boot':
                conf.new_bindings_in_boot_exists = True
        if section == 'devices' and in_subsection:
            if data.option == 'all_devs' and data.is_enabled():
                conf.all_devs_section_exists = True
                in_all_devs = True
            else:
                device_options.append((data.option, data.value))
        if section == 'overrides':
            if data.option == 'hardware_handler':
                conf.overrides_hwhandler_exists = True
            elif data.option == 'pg_timeout':
                conf.overrides_pg_timeout_exists = True
            else:
                overrides_options.append((data.option, data.value))
        if data.option == 'unpriv_sgio':
            conf.unpriv_sgio_exists = True
        if data.option == 'detect_path_checker':
            conf.detect_path_checker_exists = True
        if data.option == 'features' and 'queue_if_no_path' in data.value:
            conf.queue_if_no_path_exists = True

    if in_subsection and in_all_devs:
        _add_options(conf.all_devs_options, device_options)
    _fix_qinp_options(conf.all_devs_options)
    _filter_options(conf.all_devs_options, overrides_options)
    return conf