Beispiel #1
0
def remove_tag_inheritance(session, child_tag, parent_tag, check_mode):
    """
    Ensure that a tag inheritance rule does not exist.

    :param session: Koji client session
    :param str child_tag: Koji tag name
    :param str parent_tag: Koji tag name
    :param bool check_mode: don't make any changes
    :return: result (dict)
    """
    result = {'changed': False, 'stdout_lines': []}
    current_inheritance = session.getInheritanceData(child_tag)
    found_rule = {}
    for rule in current_inheritance:
        if rule['name'] == parent_tag:
            found_rule = rule.copy()
            # Mark this rule for deletion
            found_rule['delete link'] = True
    if not found_rule:
        return result
    result['stdout_lines'].append('remove inheritance link:')
    result['stdout_lines'].extend(
        common_koji.describe_inheritance_rule(found_rule))
    result['changed'] = True
    if not check_mode:
        common_koji.ensure_logged_in(session)
        session.setInheritanceData(child_tag, [found_rule])
    return result
Beispiel #2
0
 def test_simple(self):
     rule = {
         'child_id': 1234,
         'intransitive': False,
         'maxdepth': None,
         'name': 'rhel-8-build-base',
         'noconfig': False,
         'parent_id': 5678,
         'pkg_filter': '',
         'priority': 50,
     }
     result = describe_inheritance_rule(rule)
     assert result == ('  50   .... rhel-8-build-base', )
Beispiel #3
0
def add_tag_inheritance(session, child_tag, parent_tag, priority, maxdepth,
                        pkg_filter, intransitive, noconfig, check_mode):
    """
    Ensure that a tag inheritance rule exists.

    :param session: Koji client session
    :param str child_tag: Koji tag name
    :param str parent_tag: Koji tag name
    :param int priority: Priority of this parent for this child
    :param int maxdepth: Max depth of the inheritance
    :param str pkg_filter: Regular expression string of package names to include
    :param bool intransitive: Don't allow this inheritance link to be inherited
    :param bool noconfig: Prevent tag options ("extra") from being inherited
    :param bool check_mode: don't make any changes
    :return: result (dict)
    """
    result = {'changed': False, 'stdout_lines': []}
    data = get_ids_and_inheritance(session, child_tag, parent_tag)
    child_id, parent_id, current_inheritance = data
    if not child_id:
        msg = 'child tag %s not found' % child_tag
        if check_mode:
            result['stdout_lines'].append(msg)
        else:
            raise ValueError(msg)
    if not parent_id:
        msg = 'parent tag %s not found' % parent_tag
        if check_mode:
            result['stdout_lines'].append(msg)
        else:
            raise ValueError(msg)

    new_rule = generate_new_rule(child_id, parent_tag, parent_id, priority,
                                 maxdepth, pkg_filter, intransitive, noconfig)
    new_rules = [new_rule]
    for rule in current_inheritance:
        if rule == new_rule:
            return result
        if rule['priority'] == priority:
            # prefix taginfo-style inheritance strings with diff-like +/-
            result['stdout_lines'].append('dissimilar rules:')
            result['stdout_lines'].extend(
                map(lambda r: ' -' + r,
                    common_koji.describe_inheritance_rule(rule)))
            result['stdout_lines'].extend(
                map(lambda r: ' +' + r,
                    common_koji.describe_inheritance_rule(new_rule)))
            delete_rule = rule.copy()
            # Mark this rule for deletion
            delete_rule['delete link'] = True
            new_rules.insert(0, delete_rule)

    if len(new_rules) > 1:
        result['stdout_lines'].append('remove inheritance link:')
        result['stdout_lines'].extend(
            common_koji.describe_inheritance(new_rules[:-1]))
    result['stdout_lines'].append('add inheritance link:')
    result['stdout_lines'].extend(
        common_koji.describe_inheritance_rule(new_rule))
    result['changed'] = True
    if not check_mode:
        common_koji.ensure_logged_in(session)
        session.setInheritanceData(child_tag, new_rules)
    return result