ticket48252_test.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 pytest
  11. from lib389.tasks import *
  12. from lib389.topologies import topology_st
  13. log = logging.getLogger(__name__)
  14. # Assuming DEFAULT_SUFFIX is "dc=example,dc=com", otherwise it does not work... :(
  15. USER_NUM = 10
  16. TEST_USER = "test_user"
  17. def test_ticket48252_setup(topology_st):
  18. """
  19. Enable USN plug-in for enabling tombstones
  20. Add test entries
  21. """
  22. log.info("Enable the USN plugin...")
  23. try:
  24. topology_st.standalone.plugins.enable(name=PLUGIN_USN)
  25. except e:
  26. log.error("Failed to enable USN Plugin: error " + e.message['desc'])
  27. assert False
  28. log.info("Adding test entries...")
  29. for id in range(USER_NUM):
  30. name = "%s%d" % (TEST_USER, id)
  31. topology_st.standalone.add_s(Entry(("cn=%s,%s" % (name, SUFFIX), {
  32. 'objectclass': "top person".split(),
  33. 'sn': name,
  34. 'cn': name})))
  35. def in_index_file(topology_st, id, index):
  36. key = "%s%s" % (TEST_USER, id)
  37. log.info(" dbscan - checking %s is in index file %s..." % (key, index))
  38. dbscanOut = topology_st.standalone.dbscan(DEFAULT_BENAME, index)
  39. if key in dbscanOut:
  40. found = True
  41. topology_st.standalone.log.info("Found key %s in dbscan output" % key)
  42. else:
  43. found = False
  44. topology_st.standalone.log.info("Did not found key %s in dbscan output" % key)
  45. return found
  46. def test_ticket48252_run_0(topology_st):
  47. """
  48. Delete an entry cn=test_entry0
  49. Check it is not in the 'cn' index file
  50. """
  51. log.info("Case 1 - Check deleted entry is not in the 'cn' index file")
  52. del_rdn = "cn=%s0" % TEST_USER
  53. del_entry = "%s,%s" % (del_rdn, SUFFIX)
  54. log.info(" Deleting a test entry %s..." % del_entry)
  55. topology_st.standalone.delete_s(del_entry)
  56. assert in_index_file(topology_st, 0, 'cn') == False
  57. log.info(" db2index - reindexing %s ..." % 'cn')
  58. assert topology_st.standalone.db2index(DEFAULT_BENAME, 'cn')
  59. assert in_index_file(topology_st, 0, 'cn') == False
  60. log.info(" entry %s is not in the cn index file after reindexed." % del_entry)
  61. log.info('Case 1 - PASSED')
  62. def test_ticket48252_run_1(topology_st):
  63. """
  64. Delete an entry cn=test_entry1
  65. Check it is in the 'objectclass' index file as a tombstone entry
  66. """
  67. log.info("Case 2 - Check deleted entry is in the 'objectclass' index file as a tombstone entry")
  68. del_rdn = "cn=%s1" % TEST_USER
  69. del_entry = "%s,%s" % (del_rdn, SUFFIX)
  70. log.info(" Deleting a test entry %s..." % del_entry)
  71. topology_st.standalone.delete_s(del_entry)
  72. entry = topology_st.standalone.search_s(SUFFIX, ldap.SCOPE_SUBTREE, '(&(objectclass=nstombstone)(%s))' % del_rdn)
  73. assert len(entry) == 1
  74. log.info(" entry %s is in the objectclass index file." % del_entry)
  75. log.info(" db2index - reindexing %s ..." % 'objectclass')
  76. assert topology_st.standalone.db2index(DEFAULT_BENAME, 'objectclass')
  77. entry = topology_st.standalone.search_s(SUFFIX, ldap.SCOPE_SUBTREE, '(&(objectclass=nstombstone)(%s))' % del_rdn)
  78. assert len(entry) == 1
  79. log.info(" entry %s is in the objectclass index file after reindexed." % del_entry)
  80. log.info('Case 2 - PASSED')
  81. if __name__ == '__main__':
  82. # Run isolated
  83. # -s for DEBUG mode
  84. CURRENT_FILE = os.path.realpath(__file__)
  85. pytest.main("-s %s" % CURRENT_FILE)