[prev in list] [next in list] [prev in thread] [next in thread] 

List:       fedora-directory-commits
Subject:    =?utf-8?q?=5B389-commits=5D?= dirsrvtests/tests
From:       Simon Pichugin <spichugi () fedoraproject ! org>
Date:       2016-07-19 5:55:34
Message-ID: 20160719055534.C113D61126 () fedorahosted ! org
[Download RAW message or body]

 dirsrvtests/tests/suites/paged_results/paged_results_test.py |  109 +++
 dirsrvtests/tests/tickets/ticket48191_test.py                |  323 -----------
 2 files changed, 109 insertions(+), 323 deletions(-)

New commits:
commit b9ab76af309b6914f6e12786dc147ef2b6fbc7dd
Author: Simon Pichugin <spichugi@redhat.com>
Date:   Mon Jul 18 13:54:41 2016 +0200

    Ticket 48191 - Move CI test to the pr suite and refactor
    
    Description: Test suite for a new config parameter -
    nsslapd-maxsimplepaged-per-conn. The parameter should resctrict
    asynchronous simple paged results requests that could add too much load
    the server can handle.
    
    It tests three cases:
    - If no value or value: -1 - all users should be found;
    - If the value is 0 - UNWILLING_TO_PERFORM should be throwned
    - If the value is positive, the value is the max simple paged results
      requests per connection.
    
    https://fedorahosted.org/389/ticket/48191
    
    Reviewed by: mreynolds (Thanks!)

diff --git a/dirsrvtests/tests/suites/paged_results/paged_results_test.py \
b/dirsrvtests/tests/suites/paged_results/paged_results_test.py index 7dbc8fa..6eef6c8 \
                100644
--- a/dirsrvtests/tests/suites/paged_results/paged_results_test.py
+++ b/dirsrvtests/tests/suites/paged_results/paged_results_test.py
@@ -1190,6 +1190,115 @@ def test_multi_suffix_search(topology, test_user, \
new_suffixes):  del_users(topology, users_list_2)
 
 
+@pytest.mark.parametrize('conf_attr_value', (None, '-1', '1000'))
+def test_maxsimplepaged_per_conn_success(topology, test_user, conf_attr_value):
+    """Verify that nsslapd-maxsimplepaged-per-conn acts according design
+
+    :Feature: Simple paged results
+
+    :Setup: Standalone instance, test user for binding,
+            20 users for the search base
+
+    :Steps: 1. Set nsslapd-maxsimplepaged-per-conn in cn=config
+               to the next values: no value, -1, some positive
+            2. Search through the added users with a simple paged control
+               using page size = 4
+
+    :Assert: If no value or value = -1 - all users should be found,
+             default behaviour;
+             If the value is positive, the value is the max simple paged
+             results requests per connection.
+    """
+
+    users_list = add_users(topology, 20, DEFAULT_SUFFIX)
+    search_flt = r'(uid=test*)'
+    searchreq_attrlist = ['dn', 'sn']
+    page_size = 4
+    if conf_attr_value:
+        max_per_con_bck = change_conf_attr(topology, DN_CONFIG,
+                                           'nsslapd-maxsimplepaged-per-conn',
+                                           conf_attr_value)
+
+    try:
+        log.info('Set user bind')
+        topology.standalone.simple_bind_s(TEST_USER_DN, TEST_USER_PWD)
+
+        log.info('Create simple paged results control instance')
+        req_ctrl = SimplePagedResultsControl(True, size=page_size, cookie='')
+
+        all_results = paged_search(topology, DEFAULT_SUFFIX, [req_ctrl],
+                                   search_flt, searchreq_attrlist)
+
+        log.info('{} results'.format(len(all_results)))
+        assert len(all_results) == len(users_list)
+    finally:
+        log.info('Remove added users')
+        topology.standalone.simple_bind_s(DN_DM, PASSWORD)
+        del_users(topology, users_list)
+        if conf_attr_value:
+            change_conf_attr(topology, DN_CONFIG,
+                             'nsslapd-maxsimplepaged-per-conn', max_per_con_bck)
+
+
+@pytest.mark.parametrize('conf_attr_value', ('0', '1'))
+def test_maxsimplepaged_per_conn_failure(topology, test_user, conf_attr_value):
+    """Verify that nsslapd-maxsimplepaged-per-conn acts according design
+
+    :Feature: Simple paged results
+
+    :Setup: Standalone instance, test user for binding,
+            20 users for the search base
+
+    :Steps: 1. Set nsslapd-maxsimplepaged-per-conn = 0 in cn=config
+            2. Search through the added users with a simple paged control
+               using page size = 4
+            3. Set nsslapd-maxsimplepaged-per-conn = 1 in cn=config
+            4. Search through the added users with a simple paged control
+               using page size = 4 two times, but don't close the connections
+
+    :Assert: During the searches UNWILLING_TO_PERFORM should be throwned
+    """
+
+    users_list = add_users(topology, 20, DEFAULT_SUFFIX)
+    search_flt = r'(uid=test*)'
+    searchreq_attrlist = ['dn', 'sn']
+    page_size = 4
+    max_per_con_bck = change_conf_attr(topology, DN_CONFIG,
+                                       'nsslapd-maxsimplepaged-per-conn',
+                                       conf_attr_value)
+
+    try:
+        log.info('Set user bind')
+        topology.standalone.simple_bind_s(TEST_USER_DN, TEST_USER_PWD)
+
+        log.info('Create simple paged results control instance')
+        req_ctrl = SimplePagedResultsControl(True, size=page_size, cookie='')
+
+        with pytest.raises(ldap.UNWILLING_TO_PERFORM):
+            msgid = topology.standalone.search_ext(DEFAULT_SUFFIX,
+                                                ldap.SCOPE_SUBTREE,
+                                                search_flt,
+                                                searchreq_attrlist,
+                                                serverctrls=[req_ctrl])
+            rtype, rdata, rmsgid, rctrls = topology.standalone.result3(msgid)
+
+            # If nsslapd-maxsimplepaged-per-conn = 1,
+            # it should pass this point, but failed on the next search
+            assert conf_attr_value == '1'
+            msgid = topology.standalone.search_ext(DEFAULT_SUFFIX,
+                                                ldap.SCOPE_SUBTREE,
+                                                search_flt,
+                                                searchreq_attrlist,
+                                                serverctrls=[req_ctrl])
+            rtype, rdata, rmsgid, rctrls = topology.standalone.result3(msgid)
+    finally:
+        log.info('Remove added users')
+        topology.standalone.simple_bind_s(DN_DM, PASSWORD)
+        del_users(topology, users_list)
+        change_conf_attr(topology, DN_CONFIG,
+                         'nsslapd-maxsimplepaged-per-conn', max_per_con_bck)
+
+
 if __name__ == '__main__':
     # Run isolated
     # -s for DEBUG mode
diff --git a/dirsrvtests/tests/tickets/ticket48191_test.py \
b/dirsrvtests/tests/tickets/ticket48191_test.py deleted file mode 100644
index 000975a..0000000
--- a/dirsrvtests/tests/tickets/ticket48191_test.py
+++ /dev/null
@@ -1,323 +0,0 @@
-# --- BEGIN COPYRIGHT BLOCK ---
-# Copyright (C) 2015 Red Hat, Inc.
-# All rights reserved.
-#
-# License: GPL (version 3 or any later version).
-# See LICENSE for details.
-# --- END COPYRIGHT BLOCK ---
-#
-import os
-import sys
-import time
-import ldap
-import logging
-import pytest
-from lib389 import DirSrv, Entry, tools, tasks
-from lib389.tools import DirSrvTools
-from lib389._constants import *
-from lib389.properties import *
-from lib389.tasks import *
-from ldap.controls import SimplePagedResultsControl
-from ldap.controls.simple import GetEffectiveRightsControl
-
-log = logging.getLogger(__name__)
-
-installation_prefix = None
-
-CONFIG_DN = 'cn=config'
-MYSUFFIX = 'o=ticket48191.org'
-MYSUFFIXBE = 'ticket48191'
-
-_MYLDIF = 'ticket48191.ldif'
-
-SEARCHFILTER = '(objectclass=*)'
-
-
-class TopologyStandalone(object):
-    def __init__(self, standalone):
-        standalone.open()
-        self.standalone = standalone
-
-
-@pytest.fixture(scope="module")
-def topology(request):
-    '''
-        This fixture is used to standalone topology for the 'module'.
-    '''
-    global installation_prefix
-
-    if installation_prefix:
-        args_instance[SER_DEPLOYED_DIR] = installation_prefix
-
-    standalone = DirSrv(verbose=False)
-
-    # Args for the standalone instance
-    args_instance[SER_HOST] = HOST_STANDALONE
-    args_instance[SER_PORT] = PORT_STANDALONE
-    args_instance[SER_SERVERID_PROP] = SERVERID_STANDALONE
-    args_standalone = args_instance.copy()
-    standalone.allocate(args_standalone)
-
-    # Get the status of the instance and restart it if it exists
-    instance_standalone = standalone.exists()
-
-    # Remove the instance
-    if instance_standalone:
-        standalone.delete()
-
-    # Create the instance
-    standalone.create()
-
-    # Used to retrieve configuration information (dbdir, confdir...)
-    standalone.open()
-
-    # clear the tmp directory
-    standalone.clearTmpDir(__file__)
-
-    # Here we have standalone instance up and running
-    return TopologyStandalone(standalone)
-
-
-def test_ticket48191_setup(topology):
-    """
-        Import 20 entries
-        Set nsslapd-maxsimplepaged-per-conn in cn=config
-        If the val is negative, no limit.
-        If the value is 0, the simple paged results is disabled.
-        If the value is positive, the value is the max simple paged results requests \
                per connection.
-        The setting has to be dynamic.
-    """
-    log.info('Testing Ticket 48191 - Config parameter \
                nsslapd-maxsimplepaged-per-conn')
-
-    # bind as directory manager
-    topology.standalone.log.info("Bind as %s" % DN_DM)
-    topology.standalone.simple_bind_s(DN_DM, PASSWORD)
-
-    topology.standalone.log.info("\n\n######################### SETUP SUFFIX \
                o=ticket48191.org ######################\n")
-
-    topology.standalone.backend.create(MYSUFFIX, {BACKEND_NAME: MYSUFFIXBE})
-    topology.standalone.mappingtree.create(MYSUFFIX, bename=MYSUFFIXBE)
-
-    topology.standalone.log.info("\n\n######################### Generate Test data \
                ######################\n")
-
-    # get tmp dir
-    mytmp = topology.standalone.getDir(__file__, TMP_DIR)
-    if mytmp is None:
-        mytmp = "/tmp"
-
-    MYLDIF = '%s%s' % (mytmp, _MYLDIF)
-    os.system('ls %s' % MYLDIF)
-    os.system('rm -f %s' % MYLDIF)
-    if hasattr(topology.standalone, 'prefix'):
-        prefix = topology.standalone.prefix
-    else:
-        prefix = None
-    dbgen_prog = prefix + '/bin/dbgen.pl'
-    topology.standalone.log.info('dbgen_prog: %s' % dbgen_prog)
-    os.system('%s -s %s -o %s -n 14' % (dbgen_prog, MYSUFFIX, MYLDIF))
-    cmdline = 'egrep dn: %s | wc -l' % MYLDIF
-    p = os.popen(cmdline, "r")
-    dnnumstr = p.readline()
-    global dnnum
-    dnnum = int(dnnumstr)
-    topology.standalone.log.info("We have %d entries.\n", dnnum)
-
-    topology.standalone.log.info("\n\n######################### Import Test data \
                ######################\n")
-
-    args = {TASK_WAIT: True}
-    importTask = Tasks(topology.standalone)
-    importTask.importLDIF(MYSUFFIX, MYSUFFIXBE, MYLDIF, args)
-
-    topology.standalone.log.info("\n\n######################### SEARCH ALL \
                ######################\n")
-    topology.standalone.log.info("Bind as %s and add the READ/SEARCH SELFDN aci" % \
                DN_DM)
-    topology.standalone.simple_bind_s(DN_DM, PASSWORD)
-
-    global entries
-    entries = topology.standalone.search_s(MYSUFFIX, ldap.SCOPE_SUBTREE, \
                SEARCHFILTER)
-    topology.standalone.log.info("Returned %d entries.\n", len(entries))
-
-    #print entries
-
-    assert dnnum == len(entries)
-
-    topology.standalone.log.info('%d entries are successfully imported.' % dnnum)
-
-
-def test_ticket48191_run_0(topology):
-    topology.standalone.log.info("\n\n######################### SEARCH WITH SIMPLE \
                PAGED RESULTS CONTROL (no nsslapd-maxsimplepaged-per-conn) \
                ######################\n")
-
-    page_size = 4
-    spr_req_ctrl = SimplePagedResultsControl(True, size=page_size, cookie='')
-
-    known_ldap_resp_ctrls = {
-        SimplePagedResultsControl.controlType: SimplePagedResultsControl,
-    }
-
-    topology.standalone.log.info("Calling search_ext...")
-    msgid = topology.standalone.search_ext(MYSUFFIX,
-                                           ldap.SCOPE_SUBTREE,
-                                           SEARCHFILTER,
-                                           ['cn'],
-                                           serverctrls=[spr_req_ctrl])
-    pageddncnt = 0
-    pages = 0
-    while True:
-        pages += 1
-
-        topology.standalone.log.info("Getting page %d" % pages)
-        rtype, rdata, rmsgid, responcectrls = topology.standalone.result3(msgid, \
                resp_ctrl_classes=known_ldap_resp_ctrls)
-        topology.standalone.log.info("%d results" % len(rdata))
-        pageddncnt += len(rdata)
-
-        topology.standalone.log.info("Results:")
-        for dn, attrs in rdata:
-            topology.standalone.log.info("dn: %s" % dn)
-
-        pctrls = [
-            c for c in responcectrls if c.controlType == \
                SimplePagedResultsControl.controlType
-        ]
-        if not pctrls:
-            topology.standalone.log.info('Warning: Server ignores RFC 2696 \
                control.')
-            break
-
-        if pctrls[0].cookie:
-            spr_req_ctrl.cookie = pctrls[0].cookie
-            topology.standalone.log.info("cookie: %s" % spr_req_ctrl.cookie)
-            msgid = topology.standalone.search_ext(MYSUFFIX,
-                                                   ldap.SCOPE_SUBTREE,
-                                                   SEARCHFILTER,
-                                                   ['cn'],
-                                                   serverctrls=[spr_req_ctrl])
-        else:
-            topology.standalone.log.info("No cookie")
-            break
-
-    topology.standalone.log.info("Paged result search returned %d entries in %d \
                pages.\n", pageddncnt, pages)
-
-    global dnnum
-    global entries
-    assert dnnum == len(entries)
-    assert pages == (dnnum / page_size)
-
-
-def test_ticket48191_run_1(topology):
-    topology.standalone.log.info("\n\n######################### SEARCH WITH SIMPLE \
                PAGED RESULTS CONTROL (nsslapd-maxsimplepaged-per-conn: 0) \
                ######################\n")
-
-    topology.standalone.modify_s(CONFIG_DN, [(ldap.MOD_REPLACE, \
                'nsslapd-maxsimplepaged-per-conn', '0')])
-
-    page_size = 4
-    spr_req_ctrl = SimplePagedResultsControl(True, size=page_size, cookie='')
-
-    known_ldap_resp_ctrls = {
-        SimplePagedResultsControl.controlType: SimplePagedResultsControl,
-    }
-
-    topology.standalone.log.info("Calling search_ext...")
-    msgid = topology.standalone.search_ext(MYSUFFIX,
-                                           ldap.SCOPE_SUBTREE,
-                                           SEARCHFILTER,
-                                           ['cn'],
-                                           serverctrls=[spr_req_ctrl])
-
-    topology.standalone.log.fatal('Unexpected success')
-    try:
-        rtype, rdata, rmsgid, responcectrls = topology.standalone.result3(msgid, \
                resp_ctrl_classes=known_ldap_resp_ctrls)
-    except ldap.UNWILLING_TO_PERFORM as e:
-        topology.standalone.log.info('Returned the expected RC \
                UNWILLING_TO_PERFORM')
-        return
-    except ldap.LDAPError as e:
-        topology.standalone.log.fatal('Unexpected error: ' + e.message['desc'])
-        assert False
-    topology.standalone.log.info("Type %d" % rtype)
-    topology.standalone.log.info("%d results" % len(rdata))
-    assert False
-
-
-def test_ticket48191_run_2(topology):
-    topology.standalone.log.info("\n\n######################### SEARCH WITH SIMPLE \
PAGED RESULTS CONTROL (nsslapd-maxsimplepaged-per-conn: 1000) \
                ######################\n")
-
-    topology.standalone.modify_s(CONFIG_DN, [(ldap.MOD_REPLACE, \
                'nsslapd-maxsimplepaged-per-conn', '1000')])
-
-    page_size = 4
-    spr_req_ctrl = SimplePagedResultsControl(True, size=page_size, cookie='')
-
-    known_ldap_resp_ctrls = {
-        SimplePagedResultsControl.controlType: SimplePagedResultsControl,
-    }
-
-    topology.standalone.log.info("Calling search_ext...")
-    msgid = topology.standalone.search_ext(MYSUFFIX,
-                                           ldap.SCOPE_SUBTREE,
-                                           SEARCHFILTER,
-                                           ['cn'],
-                                           serverctrls=[spr_req_ctrl])
-    pageddncnt = 0
-    pages = 0
-    while True:
-        pages += 1
-
-        topology.standalone.log.info("Getting page %d" % pages)
-        rtype, rdata, rmsgid, responcectrls = topology.standalone.result3(msgid, \
                resp_ctrl_classes=known_ldap_resp_ctrls)
-        topology.standalone.log.info("%d results" % len(rdata))
-        pageddncnt += len(rdata)
-
-        topology.standalone.log.info("Results:")
-        for dn, attrs in rdata:
-            topology.standalone.log.info("dn: %s" % dn)
-
-        pctrls = [
-            c for c in responcectrls if c.controlType == \
                SimplePagedResultsControl.controlType
-        ]
-        if not pctrls:
-            topology.standalone.log.info('Warning: Server ignores RFC 2696 \
                control.')
-            break
-
-        if pctrls[0].cookie:
-            spr_req_ctrl.cookie = pctrls[0].cookie
-            topology.standalone.log.info("cookie: %s" % spr_req_ctrl.cookie)
-            msgid = topology.standalone.search_ext(MYSUFFIX,
-                                                   ldap.SCOPE_SUBTREE,
-                                                   SEARCHFILTER,
-                                                   ['cn'],
-                                                   serverctrls=[spr_req_ctrl])
-        else:
-            topology.standalone.log.info("No cookie")
-            break
-
-    topology.standalone.log.info("Paged result search returned %d entries in %d \
                pages.\n", pageddncnt, pages)
-
-    global dnnum
-    global entries
-    assert dnnum == len(entries)
-    assert pages == (dnnum / page_size)
-
-    topology.standalone.log.info("ticket48191 was successfully verified.")
-
-
-def test_ticket48191_final(topology):
-    topology.standalone.delete()
-    log.info('Testcase PASSED')
-
-
-def run_isolated():
-    '''
-        run_isolated is used to run these test cases independently of a test \
                scheduler (xunit, py.test..)
-        To run isolated without py.test, you need to
-            - edit this file and comment '@pytest.fixture' line before 'topology' \
                function.
-            - set the installation prefix
-            - run this program
-    '''
-    global installation_prefix
-    installation_prefix = None
-
-    topo = topology(True)
-    test_ticket48191_setup(topo)
-    test_ticket48191_run_0(topo)
-    test_ticket48191_run_1(topo)
-    test_ticket48191_run_2(topo)
-    test_ticket48191_final(topo)
-
-
-if __name__ == '__main__':
-    run_isolated()
-

--
389-commits mailing list
389-commits@lists.fedoraproject.org
https://lists.fedoraproject.org/admin/lists/389-commits@lists.fedoraproject.org


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic