ticket48212_test.py 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. import os
  2. import sys
  3. import time
  4. import ldap
  5. import logging
  6. import pytest
  7. from lib389 import DirSrv, Entry, tools, tasks
  8. from lib389.tools import DirSrvTools
  9. from lib389._constants import *
  10. from lib389.properties import *
  11. from lib389.tasks import *
  12. from lib389.utils import *
  13. from ldap.controls import SimplePagedResultsControl
  14. log = logging.getLogger(__name__)
  15. installation1_prefix = None
  16. MYSUFFIX = 'dc=example,dc=com'
  17. MYSUFFIXBE = 'userRoot'
  18. _MYLDIF = 'example1k_posix.ldif'
  19. UIDNUMBERDN = "cn=uidnumber,cn=index,cn=userroot,cn=ldbm database,cn=plugins,cn=config"
  20. class TopologyStandalone(object):
  21. def __init__(self, standalone):
  22. standalone.open()
  23. self.standalone = standalone
  24. @pytest.fixture(scope="module")
  25. def topology(request):
  26. global installation1_prefix
  27. if installation1_prefix:
  28. args_instance[SER_DEPLOYED_DIR] = installation1_prefix
  29. # Creating standalone instance ...
  30. standalone = DirSrv(verbose=False)
  31. args_instance[SER_HOST] = HOST_STANDALONE
  32. args_instance[SER_PORT] = PORT_STANDALONE
  33. args_instance[SER_SERVERID_PROP] = SERVERID_STANDALONE
  34. args_instance[SER_CREATION_SUFFIX] = DEFAULT_SUFFIX
  35. args_standalone = args_instance.copy()
  36. standalone.allocate(args_standalone)
  37. instance_standalone = standalone.exists()
  38. if instance_standalone:
  39. standalone.delete()
  40. standalone.create()
  41. standalone.open()
  42. # Delete each instance in the end
  43. def fin():
  44. standalone.delete()
  45. request.addfinalizer(fin)
  46. # Clear out the tmp dir
  47. standalone.clearTmpDir(__file__)
  48. return TopologyStandalone(standalone)
  49. def runDbVerify(topology):
  50. topology.standalone.log.info("\n\n +++++ dbverify +++++\n")
  51. sbin_dir = get_sbin_dir(prefix=topology.standalone.prefix)
  52. dbverifyCMD = sbin_dir + "/dbverify -Z " + topology.standalone.inst + " -V"
  53. dbverifyOUT = os.popen(dbverifyCMD, "r")
  54. topology.standalone.log.info("Running %s" % dbverifyCMD)
  55. running = True
  56. error = False
  57. while running:
  58. l = dbverifyOUT.readline()
  59. if l == "":
  60. running = False
  61. elif "libdb:" in l:
  62. running = False
  63. error = True
  64. topology.standalone.log.info("%s" % l)
  65. elif "verify failed" in l:
  66. error = True
  67. running = False
  68. topology.standalone.log.info("%s" % l)
  69. if error:
  70. topology.standalone.log.fatal("dbverify failed")
  71. assert False
  72. else:
  73. topology.standalone.log.info("dbverify passed")
  74. def reindexUidNumber(topology):
  75. topology.standalone.log.info("\n\n +++++ reindex uidnumber +++++\n")
  76. sbin_dir = get_sbin_dir(prefix=topology.standalone.prefix)
  77. indexCMD = sbin_dir + "/db2index.pl -Z " + topology.standalone.inst + " -D \"" + DN_DM + "\" -w \"" + PASSWORD + "\" -n " + MYSUFFIXBE + " -t uidnumber"
  78. indexOUT = os.popen(indexCMD, "r")
  79. topology.standalone.log.info("Running %s" % indexCMD)
  80. time.sleep(30)
  81. tailCMD = "tail -n 3 " + topology.standalone.errlog
  82. tailOUT = os.popen(tailCMD, "r")
  83. assert 'Finished indexing' in tailOUT.read()
  84. def test_ticket48212(topology):
  85. """
  86. Import posixAccount entries.
  87. Index uidNumber
  88. add nsMatchingRule: integerOrderingMatch
  89. run dbverify to see if it reports the db corruption or not
  90. delete nsMatchingRule: integerOrderingMatch
  91. run dbverify to see if it reports the db corruption or not
  92. if no corruption is reported, the bug fix was verified.
  93. """
  94. log.info('Testing Ticket 48212 - Dynamic nsMatchingRule changes had no effect on the attrinfo thus following reindexing, as well.')
  95. # bind as directory manager
  96. topology.standalone.log.info("Bind as %s" % DN_DM)
  97. topology.standalone.simple_bind_s(DN_DM, PASSWORD)
  98. data_dir_path = topology.standalone.getDir(__file__, DATA_DIR)
  99. ldif_file = data_dir_path + "ticket48212/" + _MYLDIF
  100. try:
  101. ldif_dir = topology.standalone.get_ldif_dir()
  102. shutil.copy(ldif_file, ldif_dir)
  103. ldif_file = ldif_dir + '/' + _MYLDIF
  104. except:
  105. log.fatal('Failed to copy ldif to instance ldif dir')
  106. assert False
  107. topology.standalone.log.info("\n\n######################### Import Test data (%s) ######################\n" % ldif_file)
  108. args = {TASK_WAIT: True}
  109. importTask = Tasks(topology.standalone)
  110. importTask.importLDIF(MYSUFFIX, MYSUFFIXBE, ldif_file, args)
  111. args = {TASK_WAIT: True}
  112. runDbVerify(topology)
  113. topology.standalone.log.info("\n\n######################### Add index by uidnumber ######################\n")
  114. try:
  115. topology.standalone.add_s(Entry((UIDNUMBERDN, {'objectclass': "top nsIndex".split(),
  116. 'cn': 'uidnumber',
  117. 'nsSystemIndex': 'false',
  118. 'nsIndexType': "pres eq".split()})))
  119. except ValueError:
  120. topology.standalone.log.fatal("add_s failed: %s", ValueError)
  121. topology.standalone.log.info("\n\n######################### reindexing... ######################\n")
  122. reindexUidNumber(topology)
  123. runDbVerify(topology)
  124. topology.standalone.log.info("\n\n######################### Add nsMatchingRule ######################\n")
  125. try:
  126. topology.standalone.modify_s(UIDNUMBERDN, [(ldap.MOD_ADD, 'nsMatchingRule', 'integerOrderingMatch')])
  127. except ValueError:
  128. topology.standalone.log.fatal("modify_s failed: %s", ValueError)
  129. topology.standalone.log.info("\n\n######################### reindexing... ######################\n")
  130. reindexUidNumber(topology)
  131. runDbVerify(topology)
  132. topology.standalone.log.info("\n\n######################### Delete nsMatchingRule ######################\n")
  133. try:
  134. topology.standalone.modify_s(UIDNUMBERDN, [(ldap.MOD_DELETE, 'nsMatchingRule', 'integerOrderingMatch')])
  135. except ValueError:
  136. topology.standalone.log.fatal("modify_s failed: %s", ValueError)
  137. reindexUidNumber(topology)
  138. runDbVerify(topology)
  139. log.info('Testcase PASSED')
  140. if __name__ == '__main__':
  141. # Run isolated
  142. # -s for DEBUG mode
  143. CURRENT_FILE = os.path.realpath(__file__)
  144. pytest.main("-s %s" % CURRENT_FILE)