ticket48005_test.py 12 KB

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