ticket48005_test.py 13 KB

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