amoralej / rpms / 389-ds-base

Forked from rpms/389-ds-base 5 years ago
Clone

Blame SOURCES/0006-Ticket-48214-CI-test-added-test-cases-for-ticket-482.patch

a2f18f
From b36cdf27f313bba70f03b687ceef5bb5b3edd78b Mon Sep 17 00:00:00 2001
a2f18f
From: Noriko Hosoi <nhosoi@redhat.com>
a2f18f
Date: Thu, 2 Jul 2015 16:07:14 -0700
a2f18f
Subject: [PATCH 6/7] Ticket #48214 - CI test: added test cases for ticket
a2f18f
 48213
a2f18f
a2f18f
Description: ldapsearch on nsslapd-maxbersize returns 0 instead of
a2f18f
             current value
a2f18f
a2f18f
https://fedorahosted.org/389/ticket/48214
a2f18f
(cherry picked from commit b7b663c0e20c2f9bf8885bd7633570dc8d34f394)
a2f18f
(cherry picked from commit 7c73adc28c8877eb3b0d30a91f7fa8a964fb3fd2)
a2f18f
---
a2f18f
 dirsrvtests/tickets/ticket48214_test.py | 171 ++++++++++++++++++++++++++++++++
a2f18f
 1 file changed, 171 insertions(+)
a2f18f
 create mode 100644 dirsrvtests/tickets/ticket48214_test.py
a2f18f
a2f18f
diff --git a/dirsrvtests/tickets/ticket48214_test.py b/dirsrvtests/tickets/ticket48214_test.py
a2f18f
new file mode 100644
a2f18f
index 0000000..afbef22
a2f18f
--- /dev/null
a2f18f
+++ b/dirsrvtests/tickets/ticket48214_test.py
a2f18f
@@ -0,0 +1,171 @@
a2f18f
+import os
a2f18f
+import sys
a2f18f
+import time
a2f18f
+import ldap
a2f18f
+import logging
a2f18f
+import pytest
a2f18f
+from lib389 import DirSrv, Entry, tools, tasks
a2f18f
+from lib389.tools import DirSrvTools
a2f18f
+from lib389._constants import *
a2f18f
+from lib389.properties import *
a2f18f
+from lib389.tasks import *
a2f18f
+from ldap.controls import SimplePagedResultsControl
a2f18f
+
a2f18f
+log = logging.getLogger(__name__)
a2f18f
+
a2f18f
+installation_prefix = None
a2f18f
+
a2f18f
+MYSUFFIX = 'dc=example,dc=com'
a2f18f
+MYSUFFIXBE = 'userRoot'
a2f18f
+
a2f18f
+class TopologyStandalone(object):
a2f18f
+    def __init__(self, standalone):
a2f18f
+        standalone.open()
a2f18f
+        self.standalone = standalone
a2f18f
+
a2f18f
+
a2f18f
+@pytest.fixture(scope="module")
a2f18f
+def topology(request):
a2f18f
+    '''
a2f18f
+        This fixture is used to standalone topology for the 'module'.
a2f18f
+    '''
a2f18f
+    global installation_prefix
a2f18f
+
a2f18f
+    if installation_prefix:
a2f18f
+        args_instance[SER_DEPLOYED_DIR] = installation_prefix
a2f18f
+
a2f18f
+    standalone = DirSrv(verbose=False)
a2f18f
+
a2f18f
+    # Args for the standalone instance
a2f18f
+    args_instance[SER_HOST] = HOST_STANDALONE
a2f18f
+    args_instance[SER_PORT] = PORT_STANDALONE
a2f18f
+    args_instance[SER_SERVERID_PROP] = SERVERID_STANDALONE
a2f18f
+    args_standalone = args_instance.copy()
a2f18f
+    standalone.allocate(args_standalone)
a2f18f
+
a2f18f
+    # Get the status of the instance and restart it if it exists
a2f18f
+    instance_standalone = standalone.exists()
a2f18f
+
a2f18f
+    # Remove the instance
a2f18f
+    if instance_standalone:
a2f18f
+        standalone.delete()
a2f18f
+
a2f18f
+    # Create the instance
a2f18f
+    standalone.create()
a2f18f
+
a2f18f
+    # Used to retrieve configuration information (dbdir, confdir...)
a2f18f
+    standalone.open()
a2f18f
+
a2f18f
+    # clear the tmp directory
a2f18f
+    standalone.clearTmpDir(__file__)
a2f18f
+
a2f18f
+    # Here we have standalone instance up and running
a2f18f
+    return TopologyStandalone(standalone)
a2f18f
+
a2f18f
+def getMaxBerSizeFromDseLdif(topology):
a2f18f
+    topology.standalone.log.info("		+++++ Get maxbersize from dse.ldif +++++\n")
a2f18f
+    dse_ldif = topology.standalone.confdir + '/dse.ldif'
a2f18f
+    grepMaxBerCMD = "egrep nsslapd-maxbersize " + dse_ldif
a2f18f
+    topology.standalone.log.info("		Run CMD: %s\n" % grepMaxBerCMD)
a2f18f
+    grepMaxBerOUT = os.popen(grepMaxBerCMD, "r")
a2f18f
+    running = True
a2f18f
+    maxbersize = -1
a2f18f
+    while running:
a2f18f
+        l = grepMaxBerOUT.readline()
a2f18f
+        if l == "":
a2f18f
+            topology.standalone.log.info("		Empty: %s\n" % l)
a2f18f
+            running = False
a2f18f
+        elif "nsslapd-maxbersize:" in l.lower():
a2f18f
+            running = False
a2f18f
+            fields = l.split()
a2f18f
+            if len(fields) >= 2:
a2f18f
+                maxbersize = fields[1]
a2f18f
+                topology.standalone.log.info("		Right format - %s %s\n" % (fields[0], fields[1]))
a2f18f
+            else:
a2f18f
+                topology.standalone.log.info("		Wrong format - %s\n" % l)
a2f18f
+        else:
a2f18f
+            topology.standalone.log.info("		Else?: %s\n" % l)
a2f18f
+    return maxbersize
a2f18f
+
a2f18f
+def checkMaxBerSize(topology):
a2f18f
+    topology.standalone.log.info("	+++++ Check Max Ber Size +++++\n")
a2f18f
+    maxbersizestr = getMaxBerSizeFromDseLdif(topology)
a2f18f
+    maxbersize = int(maxbersizestr)
a2f18f
+    isdefault = True
a2f18f
+    defaultvalue = 2097152
a2f18f
+    if maxbersize < 0:
a2f18f
+        topology.standalone.log.info("	No nsslapd-maxbersize found in dse.ldif\n")
a2f18f
+    elif maxbersize == 0:
a2f18f
+        topology.standalone.log.info("	nsslapd-maxbersize: %d\n" % maxbersize)
a2f18f
+    else:
a2f18f
+        isdefault = False
a2f18f
+        topology.standalone.log.info("	nsslapd-maxbersize: %d\n" % maxbersize)
a2f18f
+
a2f18f
+    try:
a2f18f
+        entry = topology.standalone.search_s('cn=config', ldap.SCOPE_BASE,
a2f18f
+                                             "(cn=*)",
a2f18f
+                                              ['nsslapd-maxbersize'])
a2f18f
+        if entry:
a2f18f
+            searchedsize = entry[0].getValue('nsslapd-maxbersize')
a2f18f
+            topology.standalone.log.info("	ldapsearch returned nsslapd-maxbersize: %s\n" % searchedsize)
a2f18f
+        else:
a2f18f
+            topology.standalone.log.fatal('ERROR: cn=config is not found?')
a2f18f
+            assert False
a2f18f
+    except ldap.LDAPError, e:
a2f18f
+        topology.standalone.log.error('ERROR: Failed to search for user entry: ' + e.message['desc'])
a2f18f
+        assert False
a2f18f
+
a2f18f
+    if isdefault:
a2f18f
+        topology.standalone.log.info("	Checking %d vs %d\n" % (int(searchedsize), defaultvalue))
a2f18f
+        assert int(searchedsize) == defaultvalue
a2f18f
+
a2f18f
+
a2f18f
+def test_ticket48214_run(topology):
a2f18f
+    """
a2f18f
+    Check ldapsearch returns the correct maxbersize when it is not explicitly set.
a2f18f
+    """
a2f18f
+    log.info('Testing Ticket 48214 - ldapsearch on nsslapd-maxbersize returns 0 instead of current value')
a2f18f
+
a2f18f
+    # bind as directory manager
a2f18f
+    topology.standalone.log.info("Bind as %s" % DN_DM)
a2f18f
+    topology.standalone.simple_bind_s(DN_DM, PASSWORD)
a2f18f
+
a2f18f
+    topology.standalone.log.info("\n\n######################### Out of Box ######################\n")
a2f18f
+    checkMaxBerSize(topology)
a2f18f
+
a2f18f
+    topology.standalone.log.info("\n\n######################### Add nsslapd-maxbersize: 0 ######################\n")
a2f18f
+    topology.standalone.modify_s('cn=config', [(ldap.MOD_REPLACE, 'nsslapd-maxbersize', '0')])
a2f18f
+    checkMaxBerSize(topology)
a2f18f
+
a2f18f
+    topology.standalone.log.info("\n\n######################### Add nsslapd-maxbersize: 10000 ######################\n")
a2f18f
+    topology.standalone.modify_s('cn=config', [(ldap.MOD_REPLACE, 'nsslapd-maxbersize', '10000')])
a2f18f
+    checkMaxBerSize(topology)
a2f18f
+
a2f18f
+    topology.standalone.log.info("ticket48214 was successfully verified.")
a2f18f
+
a2f18f
+
a2f18f
+def test_ticket48214_final(topology):
a2f18f
+    topology.standalone.delete()
a2f18f
+    log.info('Testcase PASSED')
a2f18f
+
a2f18f
+
a2f18f
+def run_isolated():
a2f18f
+    '''
a2f18f
+        run_isolated is used to run these test cases independently of a test scheduler (xunit, py.test..)
a2f18f
+        To run isolated without py.test, you need to
a2f18f
+            - edit this file and comment '@pytest.fixture' line before 'topology' function.
a2f18f
+            - set the installation prefix
a2f18f
+            - run this program
a2f18f
+    '''
a2f18f
+    global installation_prefix
a2f18f
+    installation_prefix = None
a2f18f
+
a2f18f
+    topo = topology(True)
a2f18f
+    test_ticket48214_run(topo)
a2f18f
+
a2f18f
+    test_ticket48214_final(topo)
a2f18f
+
a2f18f
+
a2f18f
+if __name__ == '__main__':
a2f18f
+    run_isolated()
a2f18f
+
a2f18f
-- 
a2f18f
1.9.3
a2f18f