ticket48005_test.py 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. import os
  2. import sys
  3. import time
  4. import ldap
  5. import logging
  6. import pytest
  7. import re
  8. from lib389 import DirSrv, Entry, tools, tasks
  9. from lib389.tools import DirSrvTools
  10. from lib389._constants import *
  11. from lib389.properties import *
  12. from lib389.tasks import *
  13. logging.getLogger(__name__).setLevel(logging.DEBUG)
  14. log = logging.getLogger(__name__)
  15. installation1_prefix = None
  16. class TopologyStandalone(object):
  17. def __init__(self, standalone):
  18. standalone.open()
  19. self.standalone = standalone
  20. @pytest.fixture(scope="module")
  21. def topology(request):
  22. global installation1_prefix
  23. if installation1_prefix:
  24. args_instance[SER_DEPLOYED_DIR] = installation1_prefix
  25. # Creating standalone instance ...
  26. standalone = DirSrv(verbose=False)
  27. args_instance[SER_HOST] = HOST_STANDALONE
  28. args_instance[SER_PORT] = PORT_STANDALONE
  29. args_instance[SER_SERVERID_PROP] = SERVERID_STANDALONE
  30. args_instance[SER_CREATION_SUFFIX] = DEFAULT_SUFFIX
  31. args_standalone = args_instance.copy()
  32. standalone.allocate(args_standalone)
  33. instance_standalone = standalone.exists()
  34. if instance_standalone:
  35. standalone.delete()
  36. standalone.create()
  37. standalone.open()
  38. # Clear out the tmp dir
  39. standalone.clearTmpDir(__file__)
  40. return TopologyStandalone(standalone)
  41. def test_ticket48005_setup(topology):
  42. '''
  43. allow dump core
  44. generate a test ldif file using dbgen.pl
  45. import the ldif
  46. '''
  47. log.info("Ticket 48005 setup...")
  48. if hasattr(topology.standalone, 'prefix'):
  49. prefix = topology.standalone.prefix
  50. else:
  51. prefix = None
  52. sysconfig_dirsrv = prefix + ENV_SYSCONFIG_DIR + "/dirsrv"
  53. cmdline = 'egrep "ulimit -c unlimited" %s' % sysconfig_dirsrv
  54. p = os.popen(cmdline, "r")
  55. ulimitc = p.readline()
  56. if ulimitc == "":
  57. log.info('No ulimit -c in %s' % sysconfig_dirsrv)
  58. log.info('Adding it')
  59. cmdline = 'echo "ulimit -c unlimited" >> %s' % sysconfig_dirsrv
  60. sysconfig_dirsrv_systemd = sysconfig_dirsrv + ".systemd"
  61. cmdline = 'egrep LimitCORE=infinity %s' % sysconfig_dirsrv_systemd
  62. p = os.popen(cmdline, "r")
  63. lcore = p.readline()
  64. if lcore == "":
  65. log.info('No LimitCORE in %s' % sysconfig_dirsrv_systemd)
  66. log.info('Adding it')
  67. cmdline = 'echo LimitCORE=infinity >> %s' % sysconfig_dirsrv_systemd
  68. topology.standalone.restart(timeout=10)
  69. ldif_file = topology.standalone.getDir(__file__, DATA_DIR) + "ticket48005.ldif"
  70. os.system('ls %s' % ldif_file)
  71. os.system('rm -f %s' % ldif_file)
  72. if hasattr(topology.standalone, 'prefix'):
  73. prefix = topology.standalone.prefix
  74. else:
  75. prefix = None
  76. dbgen_prog = prefix + '/bin/dbgen.pl'
  77. log.info('dbgen_prog: %s' % dbgen_prog)
  78. os.system('%s -s %s -o %s -u -n 10000' % (dbgen_prog, SUFFIX, ldif_file))
  79. cmdline = 'egrep dn: %s | wc -l' % ldif_file
  80. p = os.popen(cmdline, "r")
  81. dnnumstr = p.readline()
  82. num = int(dnnumstr)
  83. log.info("We have %d entries.\n", num)
  84. importTask = Tasks(topology.standalone)
  85. args = {TASK_WAIT: True}
  86. importTask.importLDIF(SUFFIX, None, ldif_file, args)
  87. log.info('Importing %s complete.' % ldif_file)
  88. def test_ticket48005_memberof(topology):
  89. '''
  90. Enable memberof and referint plugin
  91. Run fixmemberof task without waiting
  92. Shutdown the server
  93. Check if a core file was generated or not
  94. If no core was found, this test case was successful.
  95. '''
  96. log.info("Ticket 48005 memberof test...")
  97. topology.standalone.plugins.enable(name=PLUGIN_MEMBER_OF)
  98. topology.standalone.plugins.enable(name=PLUGIN_REFER_INTEGRITY)
  99. topology.standalone.restart(timeout=10)
  100. try:
  101. # run the fixup task
  102. topology.standalone.tasks.fixupMemberOf(suffix=SUFFIX, args={TASK_WAIT: False})
  103. except ValueError:
  104. log.error('Some problem occured with a value that was provided')
  105. assert False
  106. topology.standalone.stop(timeout=10)
  107. mytmp = topology.standalone.getDir(__file__, TMP_DIR)
  108. logdir = re.sub('errors', '', topology.standalone.errlog)
  109. cmdline = 'ls ' + logdir + 'core*'
  110. p = os.popen(cmdline, "r")
  111. lcore = p.readline()
  112. if lcore != "":
  113. s.system('mv %score* %s/core.ticket48005_memberof' % (logdir, mytmp))
  114. log.error('FixMemberof: Moved core file(s) to %s; Test failed' % mytmp)
  115. assert False
  116. log.info('No core files are found')
  117. topology.standalone.start(timeout=10)
  118. topology.standalone.plugins.disable(name=PLUGIN_REFER_INTEGRITY)
  119. topology.standalone.plugins.disable(name=PLUGIN_MEMBER_OF)
  120. topology.standalone.restart(timeout=10)
  121. log.info("Ticket 48005 memberof test complete")
  122. def test_ticket48005_automember(topology):
  123. '''
  124. Enable automember and referint plugin
  125. 1. Run automember rebuild membership task without waiting
  126. Shutdown the server
  127. Check if a core file was generated or not
  128. If no core was found, this test case was successful.
  129. 2. Run automember export updates task without waiting
  130. Shutdown the server
  131. Check if a core file was generated or not
  132. If no core was found, this test case was successful.
  133. 3. Run automember map updates task without waiting
  134. Shutdown the server
  135. Check if a core file was generated or not
  136. If no core was found, this test case was successful.
  137. '''
  138. log.info("Ticket 48005 automember test...")
  139. topology.standalone.plugins.enable(name=PLUGIN_AUTOMEMBER)
  140. topology.standalone.plugins.enable(name=PLUGIN_REFER_INTEGRITY)
  141. # configure automember config entry
  142. log.info('Adding automember config')
  143. try:
  144. topology.standalone.add_s(Entry(('cn=group cfg,cn=Auto Membership Plugin,cn=plugins,cn=config', {
  145. 'objectclass': 'top autoMemberDefinition'.split(),
  146. 'autoMemberScope': 'dc=example,dc=com',
  147. 'autoMemberFilter': 'objectclass=inetorgperson',
  148. 'autoMemberDefaultGroup': 'cn=group0,dc=example,dc=com',
  149. 'autoMemberGroupingAttr': 'uniquemember:dn',
  150. 'cn': 'group cfg'})))
  151. except ValueError:
  152. log.error('Failed to add automember config')
  153. assert False
  154. topology.standalone.restart(timeout=10)
  155. try:
  156. # run the automember rebuild task
  157. topology.standalone.tasks.automemberRebuild(suffix=SUFFIX, args={TASK_WAIT: False})
  158. except ValueError:
  159. log.error('Automember rebuild task failed.')
  160. assert False
  161. topology.standalone.stop(timeout=10)
  162. mytmp = topology.standalone.getDir(__file__, TMP_DIR)
  163. logdir = re.sub('errors', '', topology.standalone.errlog)
  164. cmdline = 'ls ' + logdir + 'core*'
  165. p = os.popen(cmdline, "r")
  166. lcore = p.readline()
  167. if lcore != "":
  168. s.system('mv %score* %s/core.ticket48005_automember_rebuild' % (logdir, mytmp))
  169. log.error('Automember_rebuld: Moved core file(s) to %s; Test failed' % mytmp)
  170. assert False
  171. log.info('No core files are found')
  172. topology.standalone.start(timeout=10)
  173. ldif_out_file = mytmp + "/ticket48005_automember_exported.ldif"
  174. try:
  175. # run the automember export task
  176. topology.standalone.tasks.automemberExport(suffix=SUFFIX, ldif_out=ldif_out_file, args={TASK_WAIT: False})
  177. except ValueError:
  178. log.error('Automember Export task failed.')
  179. assert False
  180. topology.standalone.stop(timeout=10)
  181. logdir = re.sub('errors', '', topology.standalone.errlog)
  182. cmdline = 'ls ' + logdir + 'core*'
  183. p = os.popen(cmdline, "r")
  184. lcore = p.readline()
  185. if lcore != "":
  186. s.system('mv %score* %s/core.ticket48005_automember_export' % (logdir, mytmp))
  187. log.error('Automember_export: Moved core file(s) to %s; Test failed' % mytmp)
  188. assert False
  189. log.info('No core files are found')
  190. topology.standalone.start(timeout=10)
  191. ldif_in_file = topology.standalone.getDir(__file__, DATA_DIR) + "ticket48005.ldif"
  192. ldif_out_file = mytmp + "/ticket48005_automember_map.ldif"
  193. try:
  194. # run the automember map task
  195. topology.standalone.tasks.automemberMap(ldif_in=ldif_in_file, ldif_out=ldif_out_file, args={TASK_WAIT: False})
  196. except ValueError:
  197. log.error('Automember Map task failed.')
  198. assert False
  199. topology.standalone.stop(timeout=10)
  200. logdir = re.sub('errors', '', topology.standalone.errlog)
  201. cmdline = 'ls ' + logdir + 'core*'
  202. p = os.popen(cmdline, "r")
  203. lcore = p.readline()
  204. if lcore != "":
  205. s.system('mv %score* %s/core.ticket48005_automember_map' % (logdir, mytmp))
  206. log.error('Automember_map: Moved core file(s) to %s; Test failed' % mytmp)
  207. assert False
  208. log.info('No core files are found')
  209. topology.standalone.start(timeout=10)
  210. topology.standalone.plugins.disable(name=PLUGIN_REFER_INTEGRITY)
  211. topology.standalone.plugins.enable(name=PLUGIN_AUTOMEMBER)
  212. topology.standalone.restart(timeout=10)
  213. log.info("Ticket 48005 automember test complete")
  214. def test_ticket48005_syntaxvalidate(topology):
  215. '''
  216. Run syntax validate task without waiting
  217. Shutdown the server
  218. Check if a core file was generated or not
  219. If no core was found, this test case was successful.
  220. '''
  221. log.info("Ticket 48005 syntax validate test...")
  222. try:
  223. # run the fixup task
  224. topology.standalone.tasks.syntaxValidate(suffix=SUFFIX, args={TASK_WAIT: False})
  225. except ValueError:
  226. log.error('Some problem occured with a value that was provided')
  227. assert False
  228. topology.standalone.stop(timeout=10)
  229. mytmp = topology.standalone.getDir(__file__, TMP_DIR)
  230. logdir = re.sub('errors', '', topology.standalone.errlog)
  231. cmdline = 'ls ' + logdir + 'core*'
  232. p = os.popen(cmdline, "r")
  233. lcore = p.readline()
  234. if lcore != "":
  235. s.system('mv %score* %s/core.ticket48005_syntaxvalidate' % (logdir, mytmp))
  236. log.error('SyntaxValidate: Moved core file(s) to %s; Test failed' % mytmp)
  237. assert False
  238. log.info('No core files are found')
  239. topology.standalone.start(timeout=10)
  240. log.info("Ticket 48005 syntax validate test complete")
  241. def test_ticket48005_usn(topology):
  242. '''
  243. Enable entryusn
  244. Delete all user entries.
  245. Run USN tombstone cleanup task
  246. Shutdown the server
  247. Check if a core file was generated or not
  248. If no core was found, this test case was successful.
  249. '''
  250. log.info("Ticket 48005 usn test...")
  251. topology.standalone.plugins.enable(name=PLUGIN_USN)
  252. topology.standalone.restart(timeout=10)
  253. try:
  254. entries = topology.standalone.search_s(SUFFIX, ldap.SCOPE_SUBTREE, "(objectclass=inetorgperson)")
  255. if len(entries) == 0:
  256. log.info("No user entries.")
  257. else:
  258. for i in range(len(entries)):
  259. # log.info('Deleting %s' % entries[i].dn)
  260. try:
  261. topology.standalone.delete_s(entries[i].dn)
  262. except ValueError:
  263. log.error('delete_s %s failed.' % entries[i].dn)
  264. assert False
  265. except ValueError:
  266. log.error('search_s failed.')
  267. assert False
  268. try:
  269. # run the usn tombstone cleanup
  270. topology.standalone.tasks.usnTombstoneCleanup(suffix=SUFFIX, bename="userRoot", args={TASK_WAIT: False})
  271. except ValueError:
  272. log.error('Some problem occured with a value that was provided')
  273. assert False
  274. topology.standalone.stop(timeout=10)
  275. mytmp = topology.standalone.getDir(__file__, TMP_DIR)
  276. logdir = re.sub('errors', '', topology.standalone.errlog)
  277. cmdline = 'ls ' + logdir + 'core*'
  278. p = os.popen(cmdline, "r")
  279. lcore = p.readline()
  280. if lcore != "":
  281. s.system('mv %score* %s/core.ticket48005_usn' % (logdir, mytmp))
  282. log.error('usnTombstoneCleanup: Moved core file(s) to %s; Test failed' % mytmp)
  283. assert False
  284. log.info('No core files are found')
  285. topology.standalone.start(timeout=10)
  286. topology.standalone.plugins.disable(name=PLUGIN_USN)
  287. topology.standalone.restart(timeout=10)
  288. log.info("Ticket 48005 usn test complete")
  289. def test_ticket48005_schemareload(topology):
  290. '''
  291. Run schema reload task without waiting
  292. Shutdown the server
  293. Check if a core file was generated or not
  294. If no core was found, this test case was successful.
  295. '''
  296. log.info("Ticket 48005 schema reload test...")
  297. try:
  298. # run the schema reload task
  299. topology.standalone.tasks.schemaReload(args={TASK_WAIT: False})
  300. except ValueError:
  301. log.error('Schema Reload task failed.')
  302. assert False
  303. topology.standalone.stop(timeout=10)
  304. logdir = re.sub('errors', '', topology.standalone.errlog)
  305. cmdline = 'ls ' + logdir + 'core*'
  306. p = os.popen(cmdline, "r")
  307. lcore = p.readline()
  308. if lcore != "":
  309. mytmp = topology.standalone.getDir(__file__, TMP_DIR)
  310. s.system('mv %score* %s/core.ticket48005_schema_reload' % (logdir, mytmp))
  311. log.error('Schema reload: Moved core file(s) to %s; Test failed' % mytmp)
  312. assert False
  313. log.info('No core files are found')
  314. topology.standalone.start(timeout=10)
  315. log.info("Ticket 48005 schema reload test complete")
  316. def test_ticket48005_final(topology):
  317. topology.standalone.delete()
  318. log.info('Testcase PASSED')
  319. def run_isolated():
  320. global installation1_prefix
  321. installation1_prefix = None
  322. topo = topology(True)
  323. test_ticket48005_setup(topo)
  324. test_ticket48005_memberof(topo)
  325. test_ticket48005_automember(topo)
  326. test_ticket48005_syntaxvalidate(topo)
  327. test_ticket48005_usn(topo)
  328. test_ticket48005_schemareload(topo)
  329. test_ticket48005_final(topo)
  330. if __name__ == '__main__':
  331. run_isolated()