def default_test(): host = 'localhost' port = 10200 binddn = "cn=directory manager" bindpw = "password" suffix = 'dc=example,dc=com' basedn = DN_CONFIG scope = ldap.SCOPE_BASE filt = "(objectclass=*)" instance_name = ['m1', 'm2'] instance_config = { 'cfgdshost': host, 'cfgdsport': port, 'cfgdsuser': '******', 'cfgdspwd': 'admin', 'newrootpw': 'password', 'newhost': host, 'newport': port, 'newinstance': instance_name[0], 'newsuffix': suffix, 'setup_admin': True, } try: m1 = DSAdmin(host, port, binddn, bindpw) except: m1 = DSAdminTools.createInstance(instance_config, verbose=1) added_instances.append(instance_config['newinstance']) # filename = "%s/slapd-%s/ldif/Example.ldif" % (m1.sroot, m1.inst) # m1.importLDIF(filename, "dc=example,dc=com", None, True) # m1.exportLDIF('/tmp/ldif', "dc=example,dc=com", False, True) print m1.sroot, m1.inst, m1.errlog ent = m1.getEntry(basedn, scope, filt, None) if ent: print ent.passwordmaxage instance_config.update({ 'newinstance': instance_name[1], 'newport': port + 10, }) m1 = DSAdminTools.createInstance(instance_config, verbose=1) added_instances.append(instance_config['newinstance']) # m1.stop(True) # m1.start(True) cn = m1.setupBackend("dc=example2,dc=com") rc = m1.setupSuffix("dc=example2,dc=com", cn) entry = m1.getEntry(DN_CONFIG, ldap.SCOPE_SUBTREE, "(cn=" + cn + ")") print "new backend entry is:" print entry print entry.getValues('objectclass') print entry.OBJECTCLASS results = m1.search_s("cn=monitor", ldap.SCOPE_SUBTREE) print results results = m1.getBackendsForSuffix("dc=example,dc=com") print results print "done"
def stop_start_test(): # dunno why DSAdmin.start|stop writes to dirsrv error-log conn.errlog = "/tmp/dsadmin-errlog" open(conn.errlog, "w").close() DSAdminTools.stop(conn) log.info("server stopped") DSAdminTools.start(conn) log.info("server start") time.sleep(5) # save and restore conn settings after restart tmp = conn.added_backends, conn.added_entries setup() conn.added_backends, conn.added_entries = tmp assert conn.search_s( *utils.searches['NAMINGCONTEXTS']), "Missing namingcontexts"
def setupSSL_test(): ssl_args = { 'secport': 636, 'sourcedir': None, 'secargs': {'nsSSLPersonalitySSL': 'localhost'}, } cert_dir = conn.getDseAttr('nsslapd-certdir') assert cert_dir, "Cannot retrieve cert dir" log.info("Initialize the cert store with an empty password: %r", cert_dir) fd_null = open('/dev/null', 'w') open('%s/pin.txt' % cert_dir, 'w').close() cmd_initialize = 'certutil -d %s -N -f %s/pin.txt' % (cert_dir, cert_dir) Popen(cmd_initialize.split(), stderr=fd_null) log.info("Creating a self-signed cert for the server in %r" % cert_dir) cmd_mkcert = 'certutil -d %s -S -n localhost -t CTu,Cu,Cu -s cn=localhost -x' % cert_dir Popen(cmd_mkcert.split(), stdin=open("/dev/urandom"), stderr=fd_null) log.info("Testing ssl configuration") ssl_args.update({'dsadmin': conn}) DSAdminTools.setupSSL(**ssl_args)
def setupSSL_test(): ssl_args = { 'secport': 636, 'sourcedir': None, 'secargs': { 'nsSSLPersonalitySSL': 'localhost' }, } cert_dir = conn.getDseAttr('nsslapd-certdir') assert cert_dir, "Cannot retrieve cert dir" log.info("Initialize the cert store with an empty password: %r", cert_dir) fd_null = open('/dev/null', 'w') open('%s/pin.txt' % cert_dir, 'w').close() cmd_initialize = 'certutil -d %s -N -f %s/pin.txt' % (cert_dir, cert_dir) Popen(cmd_initialize.split(), stderr=fd_null) log.info("Creating a self-signed cert for the server in %r" % cert_dir) cmd_mkcert = 'certutil -d %s -S -n localhost -t CTu,Cu,Cu -s cn=localhost -x' % cert_dir Popen(cmd_mkcert.split(), stdin=open("/dev/urandom"), stderr=fd_null) log.info("Testing ssl configuration") ssl_args.update({'dsadmin': conn}) DSAdminTools.setupSSL(**ssl_args)
def setupSSL(self, secport, sourcedir=os.environ['SECDIR'], secargs=None): """Bug scripts requires SECDIR.""" return DSAdminTools.setupSSL(self, secport, sourcedir, secargs)
def createInstance(args): # eventually set prefix args.setdefault(SER_DEPLOYED_DIR, os.environ.get('PREFIX', None)) args.setdefault('sroot', os.environ.get('SERVER_ROOT', None)) DSAdminTools.createInstance(args)
nsslapd-threadnumber: 16 """) cfgfd.close() os.chmod(cfgfd.name, 0644) createargs['ConfigFile'] = [cfgfd.name] createargs['InstallLdifFile'] = 'none' os.environ['USE_VALGRIND'] = "1" #os.environ['USE_CALLGRIND'] = "1" print "create and setup m1" createargs['newhost'] = host1 createargs['newport'] = port1 createargs['newinst'] = 'm1' m1 = DSAdminTools.createInstance(createargs) #del os.environ['USE_CALLGRIND'] #del os.environ['USE_DBX'] createargs['newhost'] = host2 createargs['newport'] = port2 createargs['newinst'] = 'm2' #os.environ['USE_GDB'] = "1" print "create and setup m2" m2 = DSAdminTools.createInstance(createargs) #del os.environ['USE_GDB'] os.unlink(cfgfd.name) print "add entries to each suffix" for suf in suflist: