ticket47536_test.py 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528
  1. # --- BEGIN COPYRIGHT BLOCK ---
  2. # Copyright (C) 2016 Red Hat, Inc.
  3. # All rights reserved.
  4. #
  5. # License: GPL (version 3 or any later version).
  6. # See LICENSE for details.
  7. # --- END COPYRIGHT BLOCK ---
  8. #
  9. import os
  10. import sys
  11. import time
  12. import shlex
  13. import subprocess
  14. import ldap
  15. import logging
  16. import pytest
  17. import base64
  18. from lib389 import DirSrv, Entry, tools, tasks
  19. from lib389.tools import DirSrvTools
  20. from lib389._constants import *
  21. from lib389.properties import *
  22. from lib389.tasks import *
  23. from lib389.utils import *
  24. logging.getLogger(__name__).setLevel(logging.DEBUG)
  25. log = logging.getLogger(__name__)
  26. installation1_prefix = None
  27. CONFIG_DN = 'cn=config'
  28. ENCRYPTION_DN = 'cn=encryption,%s' % CONFIG_DN
  29. RSA = 'RSA'
  30. RSA_DN = 'cn=%s,%s' % (RSA, ENCRYPTION_DN)
  31. ISSUER = 'cn=CAcert'
  32. CACERT = 'CAcertificate'
  33. M1SERVERCERT = 'Server-Cert1'
  34. M2SERVERCERT = 'Server-Cert2'
  35. M1LDAPSPORT = '41636'
  36. M2LDAPSPORT = '42636'
  37. class TopologyReplication(object):
  38. def __init__(self, master1, master2):
  39. master1.open()
  40. self.master1 = master1
  41. master2.open()
  42. self.master2 = master2
  43. @pytest.fixture(scope="module")
  44. def topology(request):
  45. global installation1_prefix
  46. if installation1_prefix:
  47. args_instance[SER_DEPLOYED_DIR] = installation1_prefix
  48. # Creating master 1...
  49. master1 = DirSrv(verbose=False)
  50. if installation1_prefix:
  51. args_instance[SER_DEPLOYED_DIR] = installation1_prefix
  52. args_instance[SER_HOST] = HOST_MASTER_1
  53. args_instance[SER_PORT] = PORT_MASTER_1
  54. args_instance[SER_SERVERID_PROP] = SERVERID_MASTER_1
  55. args_instance[SER_CREATION_SUFFIX] = DEFAULT_SUFFIX
  56. args_master = args_instance.copy()
  57. master1.allocate(args_master)
  58. instance_master1 = master1.exists()
  59. if instance_master1:
  60. master1.delete()
  61. master1.create()
  62. master1.open()
  63. master1.replica.enableReplication(suffix=SUFFIX, role=REPLICAROLE_MASTER, replicaId=REPLICAID_MASTER_1)
  64. # Creating master 2...
  65. master2 = DirSrv(verbose=True)
  66. if installation1_prefix:
  67. args_instance[SER_DEPLOYED_DIR] = installation1_prefix
  68. args_instance[SER_HOST] = HOST_MASTER_2
  69. args_instance[SER_PORT] = PORT_MASTER_2
  70. args_instance[SER_SERVERID_PROP] = SERVERID_MASTER_2
  71. args_instance[SER_CREATION_SUFFIX] = DEFAULT_SUFFIX
  72. args_master = args_instance.copy()
  73. master2.allocate(args_master)
  74. instance_master2 = master2.exists()
  75. if instance_master2:
  76. master2.delete()
  77. master2.create()
  78. master2.open()
  79. master2.replica.enableReplication(suffix=SUFFIX, role=REPLICAROLE_MASTER, replicaId=REPLICAID_MASTER_2)
  80. #
  81. # Create all the agreements
  82. #
  83. # Creating agreement from master 1 to master 2
  84. properties = {RA_NAME: r'meTo_%s:%s' % (master2.host, master2.port),
  85. RA_BINDDN: defaultProperties[REPLICATION_BIND_DN],
  86. RA_BINDPW: defaultProperties[REPLICATION_BIND_PW],
  87. RA_METHOD: defaultProperties[REPLICATION_BIND_METHOD],
  88. RA_TRANSPORT_PROT: defaultProperties[REPLICATION_TRANSPORT]}
  89. global m1_m2_agmt
  90. m1_m2_agmt = master1.agreement.create(suffix=SUFFIX, host=master2.host, port=master2.port, properties=properties)
  91. if not m1_m2_agmt:
  92. log.fatal("Fail to create a master -> master replica agreement")
  93. sys.exit(1)
  94. log.debug("%s created" % m1_m2_agmt)
  95. # Creating agreement from master 2 to master 1
  96. properties = {RA_NAME: r'meTo_%s:%s' % (master1.host, master1.port),
  97. RA_BINDDN: defaultProperties[REPLICATION_BIND_DN],
  98. RA_BINDPW: defaultProperties[REPLICATION_BIND_PW],
  99. RA_METHOD: defaultProperties[REPLICATION_BIND_METHOD],
  100. RA_TRANSPORT_PROT: defaultProperties[REPLICATION_TRANSPORT]}
  101. global m2_m1_agmt
  102. m2_m1_agmt = master2.agreement.create(suffix=SUFFIX, host=master1.host, port=master1.port, properties=properties)
  103. if not m2_m1_agmt:
  104. log.fatal("Fail to create a master -> master replica agreement")
  105. sys.exit(1)
  106. log.debug("%s created" % m2_m1_agmt)
  107. # Allow the replicas to get situated with the new agreements...
  108. time.sleep(2)
  109. global M1SUBJECT
  110. M1SUBJECT = 'CN=%s,OU=389 Directory Server' % (master1.host)
  111. global M2SUBJECT
  112. M2SUBJECT = 'CN=%s,OU=390 Directory Server' % (master2.host)
  113. #
  114. # Initialize all the agreements
  115. #
  116. master1.agreement.init(SUFFIX, HOST_MASTER_2, PORT_MASTER_2)
  117. master1.waitForReplInit(m1_m2_agmt)
  118. # Check replication is working...
  119. if master1.testReplication(DEFAULT_SUFFIX, master2):
  120. log.info('Replication is working.')
  121. else:
  122. log.fatal('Replication is not working.')
  123. assert False
  124. # Delete each instance in the end
  125. def fin():
  126. master1.delete()
  127. master2.delete()
  128. request.addfinalizer(fin)
  129. # Clear out the tmp dir
  130. master1.clearTmpDir(__file__)
  131. return TopologyReplication(master1, master2)
  132. @pytest.fixture(scope="module")
  133. def add_entry(server, name, rdntmpl, start, num):
  134. log.info("\n######################### Adding %d entries to %s ######################\n" % (num, name))
  135. for i in range(num):
  136. ii = start + i
  137. dn = '%s%d,%s' % (rdntmpl, ii, DEFAULT_SUFFIX)
  138. server.add_s(Entry((dn, {'objectclass': 'top person extensibleObject'.split(),
  139. 'uid': '%s%d' % (rdntmpl, ii),
  140. 'cn': '%s user%d' % (name, ii),
  141. 'sn': 'user%d' % (ii)})))
  142. def enable_ssl(server, ldapsport, mycert):
  143. log.info("\n######################### Enabling SSL LDAPSPORT %s ######################\n" % ldapsport)
  144. server.simple_bind_s(DN_DM, PASSWORD)
  145. server.modify_s(ENCRYPTION_DN, [(ldap.MOD_REPLACE, 'nsSSL3', 'off'),
  146. (ldap.MOD_REPLACE, 'nsTLS1', 'on'),
  147. (ldap.MOD_REPLACE, 'nsSSLClientAuth', 'allowed'),
  148. (ldap.MOD_REPLACE, 'nsSSL3Ciphers', '+all')])
  149. server.modify_s(CONFIG_DN, [(ldap.MOD_REPLACE, 'nsslapd-security', 'on'),
  150. (ldap.MOD_REPLACE, 'nsslapd-ssl-check-hostname', 'off'),
  151. (ldap.MOD_REPLACE, 'nsslapd-secureport', ldapsport)])
  152. server.add_s(Entry((RSA_DN, {'objectclass': "top nsEncryptionModule".split(),
  153. 'cn': RSA,
  154. 'nsSSLPersonalitySSL': mycert,
  155. 'nsSSLToken': 'internal (software)',
  156. 'nsSSLActivation': 'on'})))
  157. def check_pems(confdir, mycacert, myservercert, myserverkey, notexist):
  158. log.info("\n######################### Check PEM files (%s, %s, %s)%s in %s ######################\n"
  159. % (mycacert, myservercert, myserverkey, notexist, confdir))
  160. global cacert
  161. cacert = '%s/%s.pem' % (confdir, mycacert)
  162. if os.path.isfile(cacert):
  163. if notexist == "":
  164. log.info('%s is successfully generated.' % cacert)
  165. else:
  166. log.info('%s is incorrecly generated.' % cacert)
  167. assert False
  168. else:
  169. if notexist == "":
  170. log.fatal('%s is not generated.' % cacert)
  171. assert False
  172. else:
  173. log.info('%s is correctly not generated.' % cacert)
  174. servercert = '%s/%s.pem' % (confdir, myservercert)
  175. if os.path.isfile(servercert):
  176. if notexist == "":
  177. log.info('%s is successfully generated.' % servercert)
  178. else:
  179. log.info('%s is incorrecly generated.' % servercert)
  180. assert False
  181. else:
  182. if notexist == "":
  183. log.fatal('%s was not generated.' % servercert)
  184. assert False
  185. else:
  186. log.info('%s is correctly not generated.' % servercert)
  187. serverkey = '%s/%s.pem' % (confdir, myserverkey)
  188. if os.path.isfile(serverkey):
  189. if notexist == "":
  190. log.info('%s is successfully generated.' % serverkey)
  191. else:
  192. log.info('%s is incorrectly generated.' % serverkey)
  193. assert False
  194. else:
  195. if notexist == "":
  196. log.fatal('%s was not generated.' % serverkey)
  197. assert False
  198. else:
  199. log.info('%s is correctly not generated.' % serverkey)
  200. def doAndPrintIt(cmdline):
  201. proc = subprocess.Popen(cmdline, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  202. log.info(" OUT:")
  203. while True:
  204. l = proc.stdout.readline()
  205. if l == "":
  206. break
  207. log.info(" %s" % l)
  208. log.info(" ERR:")
  209. while True:
  210. l = proc.stderr.readline()
  211. if l == "" or l == "\n":
  212. break
  213. log.info(" <%s>" % l)
  214. assert False
  215. def create_keys_certs(topology):
  216. log.info("\n######################### Creating SSL Keys and Certs ######################\n")
  217. global m1confdir
  218. m1confdir = topology.master1.confdir
  219. global m2confdir
  220. m2confdir = topology.master2.confdir
  221. log.info("##### shutdown master1")
  222. topology.master1.stop(timeout=10)
  223. log.info("##### Creating a password file")
  224. pwdfile = '%s/pwdfile.txt' % (m1confdir)
  225. os.system('rm -f %s' % pwdfile)
  226. opasswd = os.popen("(ps -ef ; w ) | sha1sum | awk '{print $1}'", "r")
  227. passwd = opasswd.readline()
  228. pwdfd = open(pwdfile, "w")
  229. pwdfd.write(passwd)
  230. pwdfd.close()
  231. log.info("##### create the pin file")
  232. m1pinfile = '%s/pin.txt' % (m1confdir)
  233. m2pinfile = '%s/pin.txt' % (m2confdir)
  234. os.system('rm -f %s' % m1pinfile)
  235. os.system('rm -f %s' % m2pinfile)
  236. pintxt = 'Internal (Software) Token:%s' % passwd
  237. pinfd = open(m1pinfile, "w")
  238. pinfd.write(pintxt)
  239. pinfd.close()
  240. os.system('chmod 400 %s' % m1pinfile)
  241. log.info("##### Creating a noise file")
  242. noisefile = '%s/noise.txt' % (m1confdir)
  243. noise = os.popen("(w ; ps -ef ; date ) | sha1sum | awk '{print $1}'", "r")
  244. noisewdfd = open(noisefile, "w")
  245. noisewdfd.write(noise.readline())
  246. noisewdfd.close()
  247. cmdline = ['certutil', '-N', '-d', m1confdir, '-f', pwdfile]
  248. log.info("##### Create key3.db and cert8.db database (master1): %s" % cmdline)
  249. doAndPrintIt(cmdline)
  250. cmdline = ['certutil', '-G', '-d', m1confdir, '-z', noisefile, '-f', pwdfile]
  251. log.info("##### Creating encryption key for CA (master1): %s" % cmdline)
  252. #os.system('certutil -G -d %s -z %s -f %s' % (m1confdir, noisefile, pwdfile))
  253. doAndPrintIt(cmdline)
  254. time.sleep(2)
  255. log.info("##### Creating self-signed CA certificate (master1) -- nickname %s" % CACERT)
  256. os.system('( echo y ; echo ; echo y ) | certutil -S -n "%s" -s "%s" -x -t "CT,," -m 1000 -v 120 -d %s -z %s -f %s -2' % (CACERT, ISSUER, m1confdir, noisefile, pwdfile))
  257. global M1SUBJECT
  258. cmdline = ['certutil', '-S', '-n', M1SERVERCERT, '-s', M1SUBJECT, '-c', CACERT, '-t', ',,', '-m', '1001', '-v', '120', '-d', m1confdir, '-z', noisefile, '-f', pwdfile]
  259. log.info("##### Creating Server certificate -- nickname %s: %s" % (M1SERVERCERT, cmdline))
  260. doAndPrintIt(cmdline)
  261. time.sleep(2)
  262. global M2SUBJECT
  263. cmdline = ['certutil', '-S', '-n', M2SERVERCERT, '-s', M2SUBJECT, '-c', CACERT, '-t', ',,', '-m', '1002', '-v', '120', '-d', m1confdir, '-z', noisefile, '-f', pwdfile]
  264. log.info("##### Creating Server certificate -- nickname %s: %s" % (M2SERVERCERT, cmdline))
  265. doAndPrintIt(cmdline)
  266. time.sleep(2)
  267. log.info("##### start master1")
  268. topology.master1.start(timeout=10)
  269. log.info("##### enable SSL in master1 with all ciphers")
  270. enable_ssl(topology.master1, M1LDAPSPORT, M1SERVERCERT)
  271. cmdline = ['certutil', '-L', '-d', m1confdir]
  272. log.info("##### Check the cert db: %s" % cmdline)
  273. doAndPrintIt(cmdline)
  274. log.info("##### restart master1")
  275. topology.master1.restart(timeout=10)
  276. log.info("##### Check PEM files of master1 (before setting nsslapd-extract-pemfiles")
  277. check_pems(m1confdir, CACERT, M1SERVERCERT, M1SERVERCERT + '-Key', " not")
  278. log.info("##### Set on to nsslapd-extract-pemfiles")
  279. topology.master1.modify_s(CONFIG_DN, [(ldap.MOD_REPLACE, 'nsslapd-extract-pemfiles', 'on')])
  280. log.info("##### restart master1")
  281. topology.master1.restart(timeout=10)
  282. log.info("##### Check PEM files of master1 (after setting nsslapd-extract-pemfiles")
  283. check_pems(m1confdir, CACERT, M1SERVERCERT, M1SERVERCERT + '-Key', "")
  284. global mytmp
  285. mytmp = topology.master1.getDir(__file__, TMP_DIR)
  286. m2pk12file = '%s/%s.pk12' % (mytmp, M2SERVERCERT)
  287. cmd = 'pk12util -o %s -n "%s" -d %s -w %s -k %s' % (m2pk12file, M2SERVERCERT, m1confdir, pwdfile, pwdfile)
  288. log.info("##### Extract PK12 file for master2: %s" % cmd)
  289. os.system(cmd)
  290. log.info("##### Check PK12 files")
  291. if os.path.isfile(m2pk12file):
  292. log.info('%s is successfully extracted.' % m2pk12file)
  293. else:
  294. log.fatal('%s was not extracted.' % m2pk12file)
  295. assert False
  296. log.info("##### stop master2")
  297. topology.master2.stop(timeout=10)
  298. log.info("##### Initialize Cert DB for master2")
  299. cmdline = ['certutil', '-N', '-d', m2confdir, '-f', pwdfile]
  300. log.info("##### Create key3.db and cert8.db database (master2): %s" % cmdline)
  301. doAndPrintIt(cmdline)
  302. log.info("##### Import certs to master2")
  303. log.info('Importing %s' % CACERT)
  304. global cacert
  305. os.system('certutil -A -n "%s" -t "CT,," -f %s -d %s -a -i %s' % (CACERT, pwdfile, m2confdir, cacert))
  306. cmd = 'pk12util -i %s -n "%s" -d %s -w %s -k %s' % (m2pk12file, M2SERVERCERT, m2confdir, pwdfile, pwdfile)
  307. log.info('##### Importing %s to master2: %s' % (M2SERVERCERT, cmd))
  308. os.system(cmd)
  309. log.info('copy %s to %s' % (m1pinfile, m2pinfile))
  310. os.system('cp %s %s' % (m1pinfile, m2pinfile))
  311. os.system('chmod 400 %s' % m2pinfile)
  312. log.info("##### start master2")
  313. topology.master2.start(timeout=10)
  314. log.info("##### enable SSL in master2 with all ciphers")
  315. enable_ssl(topology.master2, M2LDAPSPORT, M2SERVERCERT)
  316. log.info("##### restart master2")
  317. topology.master2.restart(timeout=10)
  318. log.info("##### Check PEM files of master2 (before setting nsslapd-extract-pemfiles")
  319. check_pems(m2confdir, CACERT, M2SERVERCERT, M2SERVERCERT + '-Key', " not")
  320. log.info("##### Set on to nsslapd-extract-pemfiles")
  321. topology.master2.modify_s(CONFIG_DN, [(ldap.MOD_REPLACE, 'nsslapd-extract-pemfiles', 'on')])
  322. log.info("##### restart master2")
  323. topology.master2.restart(timeout=10)
  324. log.info("##### Check PEM files of master2 (after setting nsslapd-extract-pemfiles")
  325. check_pems(m2confdir, CACERT, M2SERVERCERT, M2SERVERCERT + '-Key', "")
  326. log.info("##### restart master1")
  327. topology.master1.restart(timeout=10)
  328. log.info("\n######################### Creating SSL Keys and Certs Done ######################\n")
  329. def config_tls_agreements(topology):
  330. log.info("######################### Configure SSL/TLS agreements ######################")
  331. log.info("######################## master1 -- startTLS -> master2 #####################")
  332. log.info("##################### master1 <- tls_clientAuth -- master2 ##################")
  333. log.info("##### Update the agreement of master1")
  334. global m1_m2_agmt
  335. topology.master1.modify_s(m1_m2_agmt, [(ldap.MOD_REPLACE, 'nsDS5ReplicaTransportInfo', 'TLS')])
  336. log.info("##### Add the cert to the repl manager on master1")
  337. global mytmp
  338. global m2confdir
  339. m2servercert = '%s/%s.pem' % (m2confdir, M2SERVERCERT)
  340. m2sc = open(m2servercert, "r")
  341. m2servercertstr = ''
  342. for l in m2sc.readlines():
  343. if ((l == "") or l.startswith('This file is auto-generated') or
  344. l.startswith('Do not edit') or l.startswith('Issuer:') or
  345. l.startswith('Subject:') or l.startswith('-----')):
  346. continue
  347. m2servercertstr = "%s%s" % (m2servercertstr, l.rstrip())
  348. m2sc.close()
  349. log.info('##### master2 Server Cert in base64 format: %s' % m2servercertstr)
  350. replmgr = defaultProperties[REPLICATION_BIND_DN]
  351. rentry = topology.master1.search_s(replmgr, ldap.SCOPE_BASE, 'objectclass=*')
  352. log.info('##### Replication manager on master1: %s' % replmgr)
  353. oc = 'ObjectClass'
  354. log.info(' %s:' % oc)
  355. if rentry:
  356. for val in rentry[0].getValues(oc):
  357. log.info(' : %s' % val)
  358. topology.master1.modify_s(replmgr, [(ldap.MOD_ADD, oc, 'extensibleObject')])
  359. global M2SUBJECT
  360. topology.master1.modify_s(replmgr, [(ldap.MOD_ADD, 'userCertificate;binary', base64.b64decode(m2servercertstr)),
  361. (ldap.MOD_ADD, 'description', M2SUBJECT)])
  362. log.info("##### Modify the certmap.conf on master1")
  363. m1certmap = '%s/certmap.conf' % (m1confdir)
  364. os.system('chmod 660 %s' % m1certmap)
  365. m1cm = open(m1certmap, "w")
  366. m1cm.write('certmap Example %s\n' % ISSUER)
  367. m1cm.write('Example:DNComps cn\n')
  368. m1cm.write('Example:FilterComps\n')
  369. m1cm.write('Example:verifycert on\n')
  370. m1cm.write('Example:CmapLdapAttr description')
  371. m1cm.close()
  372. os.system('chmod 440 %s' % m1certmap)
  373. log.info("##### Update the agreement of master2")
  374. global m2_m1_agmt
  375. topology.master2.modify_s(m2_m1_agmt, [(ldap.MOD_REPLACE, 'nsDS5ReplicaTransportInfo', 'TLS'),
  376. (ldap.MOD_REPLACE, 'nsDS5ReplicaBindMethod', 'SSLCLIENTAUTH')])
  377. topology.master1.stop(10)
  378. topology.master2.stop(10)
  379. topology.master1.start(10)
  380. topology.master2.start(10)
  381. log.info("\n######################### Configure SSL/TLS agreements Done ######################\n")
  382. def relocate_pem_files(topology):
  383. log.info("######################### Relocate PEM files on master1 ######################")
  384. mycacert = 'MyCA'
  385. topology.master1.modify_s(ENCRYPTION_DN, [(ldap.MOD_REPLACE, 'CACertExtractFile', mycacert)])
  386. myservercert = 'MyServerCert1'
  387. myserverkey = 'MyServerKey1'
  388. topology.master1.modify_s(RSA_DN, [(ldap.MOD_REPLACE, 'ServerCertExtractFile', myservercert),
  389. (ldap.MOD_REPLACE, 'ServerKeyExtractFile', myserverkey)])
  390. log.info("##### restart master1")
  391. topology.master1.restart(timeout=10)
  392. check_pems(m1confdir, mycacert, myservercert, myserverkey, "")
  393. def test_ticket47536(topology):
  394. """
  395. Set up 2way MMR:
  396. master_1 ----- startTLS -----> master_2
  397. master_1 <-- TLS_clientAuth -- master_2
  398. Check CA cert, Server-Cert and Key are retrieved as PEM from cert db
  399. when the server is started. First, the file names are not specified
  400. and the default names derived from the cert nicknames. Next, the
  401. file names are specified in the encryption config entries.
  402. Each time add 5 entries to master 1 and 2 and check they are replicated.
  403. """
  404. log.info("Ticket 47536 - Allow usage of OpenLDAP libraries that don't use NSS for crypto")
  405. create_keys_certs(topology)
  406. config_tls_agreements(topology)
  407. add_entry(topology.master1, 'master1', 'uid=m1user', 0, 5)
  408. add_entry(topology.master2, 'master2', 'uid=m2user', 0, 5)
  409. time.sleep(1)
  410. log.info('##### Searching for entries on master1...')
  411. entries = topology.master1.search_s(DEFAULT_SUFFIX, ldap.SCOPE_SUBTREE, '(uid=*)')
  412. assert 10 == len(entries)
  413. log.info('##### Searching for entries on master2...')
  414. entries = topology.master2.search_s(DEFAULT_SUFFIX, ldap.SCOPE_SUBTREE, '(uid=*)')
  415. assert 10 == len(entries)
  416. relocate_pem_files(topology)
  417. add_entry(topology.master1, 'master1', 'uid=m1user', 10, 5)
  418. add_entry(topology.master2, 'master2', 'uid=m2user', 10, 5)
  419. time.sleep(10)
  420. log.info('##### Searching for entries on master1...')
  421. entries = topology.master1.search_s(DEFAULT_SUFFIX, ldap.SCOPE_SUBTREE, '(uid=*)')
  422. assert 20 == len(entries)
  423. log.info('##### Searching for entries on master2...')
  424. entries = topology.master2.search_s(DEFAULT_SUFFIX, ldap.SCOPE_SUBTREE, '(uid=*)')
  425. assert 20 == len(entries)
  426. db2ldifpl = '%s/sbin/db2ldif.pl' % os.getenv('PREFIX')
  427. cmdline = [db2ldifpl, '-n', 'userRoot', '-Z', SERVERID_MASTER_1, '-D', DN_DM, '-w', PASSWORD]
  428. log.info("##### db2ldif.pl -- %s" % (cmdline))
  429. doAndPrintIt(cmdline)
  430. log.info("Ticket 47536 - PASSED")
  431. if __name__ == '__main__':
  432. # Run isolated
  433. # -s for DEBUG mode
  434. CURRENT_FILE = os.path.realpath(__file__)
  435. pytest.main("-s %s" % CURRENT_FILE)