dirsrvtests/tickets/ticket48214_test.py | 171 ++++++++++++++++++++++++++++++++ ldap/servers/slapd/libglobs.c | 9 + 2 files changed, 178 insertions(+), 2 deletions(-)
New commits: commit 7c73adc28c8877eb3b0d30a91f7fa8a964fb3fd2 Author: Noriko Hosoi nhosoi@redhat.com Date: Thu Jul 2 16:07:14 2015 -0700
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)
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() +
commit b83c2554fad0bb2a08055c5105bcfa4c9d44af8f Author: Noriko Hosoi nhosoi@redhat.com Date: Thu Jul 2 16:44:09 2015 -0700
Ticket #48214 - ldapsearch on nsslapd-maxbersize returns 0 instead of current value
Description: If nsslapd-maxbersize is not explicitely set in cn=config or the value is 0, the default value is assigned. Internally, it was. But ldapsearch did not return the default value.
https://fedorahosted.org/389/ticket/48214
Reviewed by rmeggins@redhat.com (Thank you, Rich!)
(cherry picked from commit 7d0689aaadfa66a8f8a481b0c1bb70b2465c4986)
diff --git a/ldap/servers/slapd/libglobs.c b/ldap/servers/slapd/libglobs.c index 24de4f3..a3c4243 100644 --- a/ldap/servers/slapd/libglobs.c +++ b/ldap/servers/slapd/libglobs.c @@ -821,7 +821,7 @@ static struct config_get_and_set { {CONFIG_MAXBERSIZE_ATTRIBUTE, config_set_maxbersize, NULL, 0, (void**)&global_slapdFrontendConfig.maxbersize, - CONFIG_INT, NULL, DEFAULT_MAX_BERSIZE}, + CONFIG_INT, NULL, STRINGIFYDEFINE(DEFAULT_MAXBERSIZE)}, {CONFIG_MAXSASLIOSIZE_ATTRIBUTE, config_set_maxsasliosize, NULL, 0, (void**)&global_slapdFrontendConfig.maxsasliosize, @@ -1540,6 +1540,7 @@ FrontendConfig_init () { init_cn_uses_dn_syntax_in_dns = cfg->cn_uses_dn_syntax_in_dns = LDAP_OFF; init_global_backend_local = LDAP_OFF; cfg->maxsimplepaged_per_conn = DEFAULT_MAXSIMPLEPAGED_PER_CONN; + cfg->maxbersize = DEFAULT_MAXBERSIZE; #ifdef ENABLE_NUNC_STANS init_enable_nunc_stans = cfg->enable_nunc_stans = LDAP_OFF; #endif @@ -5713,6 +5714,9 @@ config_set_maxbersize( const char *attrname, char *value, char *errorbuf, int ap return retVal; }
+ if (size == 0) { + size = DEFAULT_MAXBERSIZE; + } CFG_LOCK_WRITE(slapdFrontendConfig);
slapdFrontendConfig->maxbersize = size; @@ -5728,8 +5732,9 @@ config_get_maxbersize() slapdFrontendConfig_t *slapdFrontendConfig = getFrontendConfig();
maxbersize = slapdFrontendConfig->maxbersize; - if(maxbersize==0) + if (maxbersize == 0) { maxbersize = DEFAULT_MAXBERSIZE; + }
return maxbersize; }
389-commits@lists.fedoraproject.org