예제 #1
0
파일: dna.py 프로젝트: edewata/389-ds-base
def dna_config_list(inst, basedn, log, args):
    log = log.getChild('dna_list')
    configs = DNAPluginSharedConfigs(inst, args.BASEDN)
    result = []
    result_json = []
    parent_config_entries = []

    parent_configs = DNAPluginConfigs(inst)
    for config in parent_configs.list():
        if config.present("dnaSharedCfgDN") and config.get_attr_val_utf8("dnaSharedCfgDN") == args.BASEDN:
            parent_config_entries.append(config.rdn)

    for config in configs.list():
        if args.json:
            result_json.append(config.get_all_attrs_json())
        else:
            result.append(config.rdn)
    if args.json:
        log.info(json.dumps({"type": "list", "items": result_json}))
    else:
        if len(result) > 0:
            for i in result:
                log.info(i)
            if parent_config_entries:
                log.info("DNA plugin configs which have the shared config entry set as a dnaSharedCfgDN attribute: " + " ".join(parent_config_entries))
            else:
                log.info("No DNA plugin configs have the shared config entry set as a dnaSharedCfgDN attribute.")
        else:
            log.info("No DNA shared configurations were found")
예제 #2
0
def dna_plugin(topology_st, request):
    inst = topology_st.standalone
    plugin = DNAPlugin(inst)
    ous = OrganizationalUnits(inst, DEFAULT_SUFFIX)
    ou_people = ous.get("People")

    log.info("Add dna plugin config entry...")
    configs = DNAPluginConfigs(inst, plugin.dn)
    dna_config = configs.create(
        properties={
            'cn': 'dna config',
            'dnaType': 'uidNumber',
            'dnaMaxValue': '1000',
            'dnaMagicRegen': '-1',
            'dnaFilter': '(objectclass=top)',
            'dnaScope': ou_people.dn,
            'dnaNextValue': '10',
            'dnaInterval': '10'
        })

    log.info("Enable the DNA plugin and restart...")
    plugin.enable()
    inst.restart()

    def fin():
        inst.stop()
        dse_ldif = DSEldif(inst)
        dse_ldif.delete_dn(f'cn=dna config,{plugin.dn}')
        inst.start()

    request.addfinalizer(fin)

    return dna_config
예제 #3
0
파일: dna.py 프로젝트: edewata/389-ds-base
def _get_shared_config_dn(inst, args):
    configs = DNAPluginConfigs(inst)
    config = configs.get(args.NAME)
    if config.present('dnaSharedCfgDN'):
        basedn = config.get_attr_val_utf8_l('dnaSharedCfgDN')
    else:
        raise ValueError('dnaSharedCfgDN should be set at the "%s" config entry' % args.NAME)

    decomposed_dn = [[('dnaHostname', args.HOSTNAME, 1),
                      ('dnaPortNum', args.PORT, 1)]] + ldap.dn.str2dn(basedn)
    return ldap.dn.dn2str(decomposed_dn)
예제 #4
0
파일: dna.py 프로젝트: edewata/389-ds-base
def dna_show(inst, basedn, log, args):
    log = log.getChild('dna_show')
    configs = DNAPluginConfigs(inst)
    config = configs.get(args.NAME)

    if not config.exists():
        raise ldap.NO_SUCH_OBJECT("Entry %s doesn't exists" % args.NAME)
    if args and args.json:
        o_str = config.get_all_attrs_json()
        log.info(o_str)
    else:
        log.info(config.display())
예제 #5
0
def _get_shared_config_dn(inst, args):
    configs = DNAPluginConfigs(inst)
    config = configs.get(args.NAME)
    if config.present('dnaSharedCfgDN'):
        basedn = config.get_attr_val_utf8_l('dnaSharedCfgDN')
    else:
        raise ValueError('dnaSharedCfgDN should be set at the "%s" config entry' % args.NAME)
    if ':' not in args.SHARED_CFG:
       raise ValueError("The shared config entry identifier must be HOSTNAME:PORT")
    (hostname, port) = args.SHARED_CFG.split(":", 1)
    decomposed_dn = [[('dnaHostname', hostname, 1),
                      ('dnaPortNum', port, 1)]] + ldap.dn.str2dn(basedn)
    return ldap.dn.dn2str(decomposed_dn)
예제 #6
0
파일: dna.py 프로젝트: edewata/389-ds-base
def dna_config_add(inst, basedn, log, args):
    log = log.getChild('dna_config_add')
    configs = DNAPluginConfigs(inst)
    config = configs.get(args.NAME)
    if config.present('dnaSharedCfgDN'):
        targetdn = config.get_attr_val_utf8_l('dnaSharedCfgDN')
    else:
        raise ValueError('dnaSharedCfgDN should be set at the "%s" config entry' % args.NAME)

    shared_configs = DNAPluginSharedConfigs(inst, targetdn)
    attrs = _args_to_attrs(args, arg_to_attr_config)
    props = {attr: value for (attr, value) in attrs.items() if value != ""}

    shared_config = shared_configs.create(properties=props)
    log.info("Successfully created the %s" % shared_config.dn)
예제 #7
0
파일: dna.py 프로젝트: edewata/389-ds-base
def dna_list(inst, basedn, log, args):
    log = log.getChild('dna_list')
    configs = DNAPluginConfigs(inst)
    result = []
    result_json = []
    for config in configs.list():
        if args.json:
            result_json.append(config.get_all_attrs_json())
        else:
            result.append(config.rdn)
    if args.json:
        log.info(json.dumps({"type": "list", "items": result_json}))
    else:
        if len(result) > 0:
            for i in result:
                log.info(i)
        else:
            log.info("No DNA configurations were found")
예제 #8
0
파일: dna.py 프로젝트: edewata/389-ds-base
def dna_edit(inst, basedn, log, args):
    log = log.getChild('dna_edit')
    configs = DNAPluginConfigs(inst)
    config = configs.get(args.NAME)
    generic_object_edit(config, log, args, arg_to_attr)
예제 #9
0
파일: dna.py 프로젝트: edewata/389-ds-base
def dna_del(inst, basedn, log, args):
    log = log.getChild('dna_del')
    configs = DNAPluginConfigs(inst)
    config = configs.get(args.NAME)
    config.delete()
    log.info("Successfully deleted the %s", config.dn)
예제 #10
0
def test_dnatype_only_valid(topology_st):
    """Test that DNA plugin only accepts valid attributes for "dnaType"

    :id: 0878ecff-5fdc-47d7-8c8f-edf4556f9746
    :setup: Standalone Instance
    :steps:
        1. Create a use entry
        2. Create DNA shared config entry container
        3. Create DNA shared config entry
        4. Add DNA plugin config entry
        5. Enable DNA plugin
        6. Restart the instance
        7. Replace dnaType with invalid value
    :expectedresults:
        1. Successful
        2. Successful
        3. Successful
        4. Successful
        5. Successful
        6. Successful
        7. Unwilling to perform exception should be raised
    """

    inst = topology_st.standalone
    plugin = DNAPlugin(inst)

    log.info("Creating an entry...")
    users = UserAccounts(inst, DEFAULT_SUFFIX)
    users.create_test_user(uid=1)

    log.info("Creating \"ou=ranges\"...")
    ous = OrganizationalUnits(inst, DEFAULT_SUFFIX)
    ou_ranges = ous.create(properties={'ou': 'ranges'})
    ou_people = ous.get("People")

    log.info("Creating DNA shared config entry...")
    shared_configs = DNAPluginSharedConfigs(inst, ou_ranges.dn)
    shared_configs.create(
        properties={
            'dnaHostname': str(inst.host),
            'dnaPortNum': str(inst.port),
            'dnaRemainingValues': '9501'
        })

    log.info("Add dna plugin config entry...")
    configs = DNAPluginConfigs(inst, plugin.dn)
    config = configs.create(
        properties={
            'cn': 'dna config',
            'dnaType': 'description',
            'dnaMaxValue': '10000',
            'dnaMagicRegen': '0',
            'dnaFilter': '(objectclass=top)',
            'dnaScope': ou_people.dn,
            'dnaNextValue': '500',
            'dnaSharedCfgDN': ou_ranges.dn
        })

    log.info("Enable the DNA plugin...")
    plugin.enable()

    log.info("Restarting the server...")
    inst.restart()

    log.info("Apply an invalid attribute to the DNA config(dnaType: foo)...")
    with pytest.raises(ldap.UNWILLING_TO_PERFORM):
        config.replace('dnaType', 'foo')