Esempio n. 1
0
def test_addifnotset_action(config_filename):
    """Test if addifnotset action adds a comment about the modified conf.

    IPA doesn't want to break existing configuration, if a value already exists
    it adds a comment to the modified setting and a note about that on the line
    above.

    New settings will be added without any note.
    """
    ipa_conf = IPAChangeConf('IPA Installer Test')
    ipa_conf.setOptionAssignment(' ')

    opts = [
        {
            'action': 'addifnotset',
            'name': 'SOME_CONF',
            'type': 'option',
            'value': '/path/defined/by/ipa',
        },
        {
            'action': 'addifnotset',
            'name': 'NEW_CONF',
            'type': 'option',
            'value': '/path/to/somewhere',
        },
    ]

    ipa_conf.changeConf(str(config_filename), opts)

    assert config_filename.readlines() == [
        '# SOME_CONF modified by IPA\n',
        '#SOME_CONF /path/defined/by/ipa\n',
        'SOME_CONF /some/user/defined/path\n',
        'NEW_CONF /path/to/somewhere\n',
    ]
Esempio n. 2
0
def promote_openldap_conf(hostname, master):
    """
    Reset the URI directive in openldap-client configuration file to point to
    newly promoted replica. If this directive was set by third party, then
    replace the added comment with the one pointing to replica

    :param hostname: replica FQDN
    :param master: FQDN of remote master
    """

    ldap_conf = paths.OPENLDAP_LDAP_CONF

    ldap_change_conf = IPAChangeConf("IPA replica installer")
    ldap_change_conf.setOptionAssignment((" ", "\t"))

    new_opts = []

    with open(ldap_conf, 'r') as f:
        old_opts = ldap_change_conf.parse(f)

        for opt in old_opts:
            if opt['type'] == 'comment' and master in opt['value']:
                continue
            elif (opt['type'] == 'option' and opt['name'] == 'URI'
                  and master in opt['value']):
                continue
            new_opts.append(opt)

    change_opts = [{
        'action': 'addifnotset',
        'name': 'URI',
        'type': 'option',
        'value': 'ldaps://' + hostname
    }]

    try:
        ldap_change_conf.newConf(ldap_conf, new_opts)
        ldap_change_conf.changeConf(ldap_conf, change_opts)
    except Exception as e:
        logger.info("Failed to update %s: %s", ldap_conf, e)
Esempio n. 3
0
def promote_openldap_conf(hostname, master):
    """
    Reset the URI directive in openldap-client configuration file to point to
    newly promoted replica. If this directive was set by third party, then
    replace the added comment with the one pointing to replica

    :param hostname: replica FQDN
    :param master: FQDN of remote master
    """

    ldap_conf = paths.OPENLDAP_LDAP_CONF

    ldap_change_conf = IPAChangeConf("IPA replica installer")
    ldap_change_conf.setOptionAssignment((" ", "\t"))

    new_opts = []

    with open(ldap_conf, 'r') as f:
        old_opts = ldap_change_conf.parse(f)

        for opt in old_opts:
            if opt['type'] == 'comment' and master in opt['value']:
                continue
            elif (opt['type'] == 'option' and opt['name'] == 'URI' and
                    master in opt['value']):
                continue
            new_opts.append(opt)

    change_opts = [
        {'action': 'addifnotset',
         'name': 'URI',
         'type': 'option',
         'value': 'ldaps://' + hostname}
    ]

    try:
        ldap_change_conf.newConf(ldap_conf, new_opts)
        ldap_change_conf.changeConf(ldap_conf, change_opts)
    except Exception as e:
        logger.info("Failed to update %s: %s", ldap_conf, e)