zrhoffman / rpms / 389-ds-base

Forked from rpms/389-ds-base 3 years ago
Clone
Blob Blame History Raw
From b36cdf27f313bba70f03b687ceef5bb5b3edd78b Mon Sep 17 00:00:00 2001
From: Noriko Hosoi <nhosoi@redhat.com>
Date: Thu, 2 Jul 2015 16:07:14 -0700
Subject: [PATCH 6/7] Ticket #48214 - CI test: added test cases for ticket
 48213

Description: ldapsearch on nsslapd-maxbersize returns 0 instead of
             current value

https://fedorahosted.org/389/ticket/48214
(cherry picked from commit b7b663c0e20c2f9bf8885bd7633570dc8d34f394)
(cherry picked from commit 7c73adc28c8877eb3b0d30a91f7fa8a964fb3fd2)
---
 dirsrvtests/tickets/ticket48214_test.py | 171 ++++++++++++++++++++++++++++++++
 1 file changed, 171 insertions(+)
 create mode 100644 dirsrvtests/tickets/ticket48214_test.py

diff --git a/dirsrvtests/tickets/ticket48214_test.py b/dirsrvtests/tickets/ticket48214_test.py
new file mode 100644
index 0000000..afbef22
--- /dev/null
+++ b/dirsrvtests/tickets/ticket48214_test.py
@@ -0,0 +1,171 @@
+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
+
+log = logging.getLogger(__name__)
+
+installation_prefix = None
+
+MYSUFFIX = 'dc=example,dc=com'
+MYSUFFIXBE = 'userRoot'
+
+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 getMaxBerSizeFromDseLdif(topology):
+    topology.standalone.log.info("		+++++ Get maxbersize from dse.ldif +++++\n")
+    dse_ldif = topology.standalone.confdir + '/dse.ldif'
+    grepMaxBerCMD = "egrep nsslapd-maxbersize " + dse_ldif
+    topology.standalone.log.info("		Run CMD: %s\n" % grepMaxBerCMD)
+    grepMaxBerOUT = os.popen(grepMaxBerCMD, "r")
+    running = True
+    maxbersize = -1
+    while running:
+        l = grepMaxBerOUT.readline()
+        if l == "":
+            topology.standalone.log.info("		Empty: %s\n" % l)
+            running = False
+        elif "nsslapd-maxbersize:" in l.lower():
+            running = False
+            fields = l.split()
+            if len(fields) >= 2:
+                maxbersize = fields[1]
+                topology.standalone.log.info("		Right format - %s %s\n" % (fields[0], fields[1]))
+            else:
+                topology.standalone.log.info("		Wrong format - %s\n" % l)
+        else:
+            topology.standalone.log.info("		Else?: %s\n" % l)
+    return maxbersize
+
+def checkMaxBerSize(topology):
+    topology.standalone.log.info("	+++++ Check Max Ber Size +++++\n")
+    maxbersizestr = getMaxBerSizeFromDseLdif(topology)
+    maxbersize = int(maxbersizestr)
+    isdefault = True
+    defaultvalue = 2097152
+    if maxbersize < 0:
+        topology.standalone.log.info("	No nsslapd-maxbersize found in dse.ldif\n")
+    elif maxbersize == 0:
+        topology.standalone.log.info("	nsslapd-maxbersize: %d\n" % maxbersize)
+    else:
+        isdefault = False
+        topology.standalone.log.info("	nsslapd-maxbersize: %d\n" % maxbersize)
+
+    try:
+        entry = topology.standalone.search_s('cn=config', ldap.SCOPE_BASE,
+                                             "(cn=*)",
+                                              ['nsslapd-maxbersize'])
+        if entry:
+            searchedsize = entry[0].getValue('nsslapd-maxbersize')
+            topology.standalone.log.info("	ldapsearch returned nsslapd-maxbersize: %s\n" % searchedsize)
+        else:
+            topology.standalone.log.fatal('ERROR: cn=config is not found?')
+            assert False
+    except ldap.LDAPError, e:
+        topology.standalone.log.error('ERROR: Failed to search for user entry: ' + e.message['desc'])
+        assert False
+
+    if isdefault:
+        topology.standalone.log.info("	Checking %d vs %d\n" % (int(searchedsize), defaultvalue))
+        assert int(searchedsize) == defaultvalue
+
+
+def test_ticket48214_run(topology):
+    """
+    Check ldapsearch returns the correct maxbersize when it is not explicitly set.
+    """
+    log.info('Testing Ticket 48214 - ldapsearch on nsslapd-maxbersize returns 0 instead of current value')
+
+    # 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######################### Out of Box ######################\n")
+    checkMaxBerSize(topology)
+
+    topology.standalone.log.info("\n\n######################### Add nsslapd-maxbersize: 0 ######################\n")
+    topology.standalone.modify_s('cn=config', [(ldap.MOD_REPLACE, 'nsslapd-maxbersize', '0')])
+    checkMaxBerSize(topology)
+
+    topology.standalone.log.info("\n\n######################### Add nsslapd-maxbersize: 10000 ######################\n")
+    topology.standalone.modify_s('cn=config', [(ldap.MOD_REPLACE, 'nsslapd-maxbersize', '10000')])
+    checkMaxBerSize(topology)
+
+    topology.standalone.log.info("ticket48214 was successfully verified.")
+
+
+def test_ticket48214_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_ticket48214_run(topo)
+
+    test_ticket48214_final(topo)
+
+
+if __name__ == '__main__':
+    run_isolated()
+
-- 
1.9.3