Ejemplo n.º 1
0
def _sync_memberof_attrs(topo, exp_memberof):
    """Check if expected entries are created or attributes are synced"""

    log.info('_sync_memberof_attrs: Check if expected memberOf attributes are synced/created')
    loop = 0
    start = time.time()
    entries = topo.standalone.search_s(SUFFIX, ldap.SCOPE_SUBTREE, FILTER, [MEMBEROF_ATTR])
    act_memberof = str(entries).count(MEMBEROF_ATTR)
    end = time.time()
    cmd_time = int(end - start)
    log.info('Loop-{}, expected memberOf attrs: {}, synced: {}, time for search-{} secs'.format(loop, exp_memberof,
                                                                                                act_memberof, cmd_time))
    while act_memberof != exp_memberof:
        loop = loop + 1
        time.sleep(30)
        start = time.time()
        entries = topo.standalone.search_s(SUFFIX, ldap.SCOPE_SUBTREE, FILTER, [MEMBEROF_ATTR])
        act_memberof = str(entries).count(MEMBEROF_ATTR)
        end = time.time()
        cmd_time = cmd_time + int(end - start)
        log.info('Loop-{}, expected memberOf attrs: {}, synced: {}, time for search-{} secs'.format(loop, exp_memberof,
                                                                                                    act_memberof,
                                                                                                    cmd_time))
        # Worst case scenario, exit the test after 10hrs of wait
        if loop > 1200:
            log.error('Either syncing memberOf attrs takes too long or some issue with the test itself')
            assert False
    sync_time = 1 + loop * 30
    log.info('Expected memberOf attrs: {}, Actual memberOf attrs: {}'.format(exp_memberof, act_memberof))
    assert act_memberof == exp_memberof
    return sync_time
Ejemplo n.º 2
0
def test_del_nestgrp(topo, memberof_setup, nof_users, nof_groups, grps_user,
                     ngrps_user, nof_depth):
    """Import bulk entries, delete nested groups at N depth and measure the time taken

    :ID: d3d82ac5-d968-4cd6-a268-d380fc9fd51b
    :feature: MemberOf Plugin
    :setup: Standalone instance, memberOf plugin enabled
    :steps: 1. Import bulk users and groups with nested level N.
            2. Run fixup memberOf task to create memberOf attributes
            3. Delete nested groups at nested level N
            4. Check memberOf attributes deleted for users and groups
            5. Compare the actual memberOf attributes with the expected
            6. Measure the time taken to sync memberOf attributes
    :expectedresults: MemberOf attributes should be deleted and synced
    """

    exp_memberof = (nof_users * grps_user) + ((nof_groups // grps_user) *
                                              (ngrps_user // nof_depth) *
                                              (nof_depth *
                                               (nof_depth + 1)) // 2)
    log.info('Create nested ldif file, import it and measure the time taken')
    import_time = _nested_import_add_ldif(topo, nof_users, nof_groups,
                                          grps_user, ngrps_user, nof_depth,
                                          True)
    log.info(
        'Run fixup memberOf task and measure the time to complete the task')
    fixup_time = _run_fixup_memberof(topo)
    sync_memberof = _sync_memberof_attrs(topo, exp_memberof)
    total_time = import_time + fixup_time + sync_memberof
    log.info(
        'Time taken to complete add users + memberOf sync: {} secs'.format(
            total_time))

    log.info('Delete {} groups from nested groups at depth level-{}'.format(
        nof_depth, nof_depth))
    start = time.time()
    for nos in range(nof_depth, nof_groups, grps_user):
        groupdn = 'cn=group{},ou=groups,{}'.format(nos, SUFFIX)
        try:
            topo.standalone.delete_s(groupdn)
        except ldap.LDAPError as e:
            log.error('Error-{}: Failed to delete group'.format(
                e.message['desc']))
            assert False
    end = time.time()
    cmd_time = int(end - start)

    exp_memberof = exp_memberof - (nof_users + (nof_depth *
                                                (nof_groups // grps_user)))
    log.info(
        'Check memberOf attributes after deleting groups at depth-{}'.format(
            nof_depth))
    sync_memberof = _sync_memberof_attrs(topo, exp_memberof)
    total_time = cmd_time + sync_memberof
    log.info(
        'Time taken to delete and sync memberOf attributes: {}secs'.format(
            total_time))
Ejemplo n.º 3
0
def test_mod_nestgrp(topo, memberof_setup, nof_users, nof_groups, grps_user, ngrps_user, nof_depth):
    """Import bulk entries, modify nested groups at N depth and measure the time taken

    :id: 4bf8e753-6ded-4177-8225-aaf6aef4d131
    :feature: MemberOf Plugin
    :setup: Standalone instance, memberOf plugin enabled
    :steps: 1. Import bulk entries with nested group and create memberOf attributes
            2. Modify nested groups by adding new members at each nested level
            3. Check new memberOf attributes created for users and groups
            4. Compare the actual memberOf attributes with the expected
            5. Measure the time taken to sync memberOf attributes
    :expectedresults: MemberOf attributes should be modified and synced
    """

    exp_memberof = (nof_users * grps_user) + (
        (nof_groups // grps_user) * (ngrps_user // nof_depth) * (nof_depth * (nof_depth + 1)) // 2)
    log.info('Create nested ldif file, import it and measure the time taken')
    import_time = _nested_import_add_ldif(topo, nof_users, nof_groups, grps_user, ngrps_user, nof_depth, True)
    log.info('Run fixup memberOf task and measure the time to complete the task')
    fixup_time = _run_fixup_memberof(topo)
    sync_memberof = _sync_memberof_attrs(topo, exp_memberof)
    total_time = import_time + fixup_time + sync_memberof
    log.info('Time for import-{}secs, fixup task-{}secs, total time for memberOf sync: {}secs'.format(import_time,
                                                                                                      fixup_time,
                                                                                                      total_time))

    log.info('Add {} users to existing nested groups at all depth level'.format(nof_groups))
    log.info('Add one user to each groups at different nest levels')
    start = time.time()
    for usr in range(nof_groups):
        usrrdn = 'newcliusr{}'.format(usr)
        userdn = 'uid={},ou=people,{}'.format(usrrdn, SUFFIX)
        groupdn = 'cn=group{},ou=groups,{}'.format(usr, SUFFIX)
        try:
            topo.standalone.add_s(Entry((userdn, {
                'objectclass': 'top person inetUser inetOrgperson'.split(),
                'cn': usrrdn,
                'sn': usrrdn,
                'userpassword': '******'})))
        except ldap.LDAPError as e:
            log.error('Failed to add {} user: error {}'.format(userdn, e.message['desc']))
            raise
        try:
            topo.standalone.modify_s(groupdn, [(ldap.MOD_ADD, 'member', userdn)])
        except ldap.LDAPError as e:
            log.error('Error-{}: Failed to add user to group'.format(e.message['desc']))
            assert False
    end = time.time()
    cmd_time = int(end - start)

    exp_memberof = (nof_users * grps_user) + nof_groups + (
        (nof_groups // grps_user) * (ngrps_user // nof_depth) * (nof_depth * (nof_depth + 1)))
    log.info('Check the total number of memberOf entries created for users and groups')
    sync_memberof = _sync_memberof_attrs(topo, exp_memberof)
    total_time = cmd_time + sync_memberof
    log.info('Time taken add new members to existing nested groups + memberOf sync: {} secs'.format(total_time))
Ejemplo n.º 4
0
def _run_fixup_memberof(topo):
    """Run fixup memberOf task and measure the time taken"""

    log.info('Running fixup memberOf task and measuring the time taken')
    start = time.time()
    try:
        topo.standalone.tasks.fixupMemberOf(suffix=SUFFIX, args={TASK_WAIT: True})
    except ValueError as e:
        log.error('Running fixup MemberOf task failed' + e.message('desc'))
        assert False
    end = time.time()
    cmd_time = int(end - start)
    return cmd_time
Ejemplo n.º 5
0
def _nested_import_add_ldif(topo, nof_users, nof_groups, grps_user, ngrps_user, nof_depth, is_import=False):
    """Create LDIF files for given nof users, groups and nested group levels"""

    log.info('Checking if the operation is Import or Ldapadd')
    if is_import:
        log.info('Import: Create base entry before adding users and groups')
        exp_entries = nof_users + nof_groups
        data_ldif = _create_base_ldif(topo, False)
        log.info('Create data LDIF file by appending users, groups and nested groups')
        with open(data_ldif, 'a') as file1:
            data = RHDSDataLDIF(stream=file1, users=nof_users, groups=nof_groups, grps_puser=grps_user,
                                nest_level=nof_depth, ngrps_puser=ngrps_user, basedn=SUFFIX)
            data.do_magic()
        start = time.time()
        log.info('Run importLDIF task to add entries to Server')
        try:
            topo.standalone.tasks.importLDIF(suffix=SUFFIX, input_file=data_ldif, args={TASK_WAIT: True})
        except ValueError as e:
            log.error('Online import failed' + e.message('desc'))
            assert False
        end = time.time()
        time_import = int(end - start)

        log.info('Check if number of entries created matches the expected entries')
        users_groups = topo.standalone.search_s(SUFFIX, ldap.SCOPE_SUBTREE, USER_FILTER, [DN_ATTR])
        act_entries = str(users_groups).count(DN_ATTR)
        log.info('Expected entries: {}, Actual entries: {}'.format(exp_entries, act_entries))
        assert act_entries == exp_entries
        return time_import
    else:
        log.info('Ldapadd: Create data LDIF file with users, groups and nested groups')
        ldif_dir = topo.standalone.get_ldif_dir()
        data_ldif = os.path.join(ldif_dir, '/perf_add.ldif')
        with open(data_ldif, 'w') as file1:
            data = RHDSDataLDIF(stream=file1, users=nof_users, groups=nof_groups, grps_puser=grps_user,
                                nest_level=nof_depth, ngrps_puser=ngrps_user, basedn=SUFFIX)
            data.do_magic()
        start = time.time()
        log.info('Run LDAPMODIFY to add entries to Server')
        try:
            subprocess.check_output(
                [LDAP_MOD, '-cx', '-D', DN_DM, '-w', PASSWORD, '-h', HOST_STANDALONE, '-p', str(PORT_STANDALONE), '-af',
                 data_ldif])
        except subprocess.CalledProcessError as e:
            log.error('LDAPMODIFY failed to add entries, error:{:s}'.format(str(e)))
            raise e
        end = time.time()
        cmd_time = int(end - start)
        log.info('Time taken to complete LDAPADD: {} secs'.format(cmd_time))
        return cmd_time