ticket48252_test.py 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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 sys
  11. import time
  12. import ldap
  13. import logging
  14. import pytest
  15. from lib389 import DirSrv, Entry, tools, tasks
  16. from lib389.tools import DirSrvTools
  17. from lib389._constants import *
  18. from lib389.properties import *
  19. from lib389.tasks import *
  20. log = logging.getLogger(__name__)
  21. installation_prefix = None
  22. # Assuming DEFAULT_SUFFIX is "dc=example,dc=com", otherwise it does not work... :(
  23. USER_NUM = 10
  24. TEST_USER = "test_user"
  25. class TopologyStandalone(object):
  26. def __init__(self, standalone):
  27. standalone.open()
  28. self.standalone = standalone
  29. @pytest.fixture(scope="module")
  30. def topology(request):
  31. '''
  32. This fixture is used to standalone topology for the 'module'.
  33. '''
  34. global installation_prefix
  35. if installation_prefix:
  36. args_instance[SER_DEPLOYED_DIR] = installation_prefix
  37. standalone = DirSrv(verbose=False)
  38. # Args for the standalone instance
  39. args_instance[SER_HOST] = HOST_STANDALONE
  40. args_instance[SER_PORT] = PORT_STANDALONE
  41. args_instance[SER_SERVERID_PROP] = SERVERID_STANDALONE
  42. args_standalone = args_instance.copy()
  43. standalone.allocate(args_standalone)
  44. # Get the status of the instance and restart it if it exists
  45. instance_standalone = standalone.exists()
  46. # Remove the instance
  47. if instance_standalone:
  48. standalone.delete()
  49. # Create the instance
  50. standalone.create()
  51. # Used to retrieve configuration information (dbdir, confdir...)
  52. standalone.open()
  53. def fin():
  54. standalone.delete()
  55. request.addfinalizer(fin)
  56. # Here we have standalone instance up and running
  57. return TopologyStandalone(standalone)
  58. def test_ticket48252_setup(topology):
  59. """
  60. Enable USN plug-in for enabling tombstones
  61. Add test entries
  62. """
  63. log.info("Enable the USN plugin...")
  64. try:
  65. topology.standalone.plugins.enable(name=PLUGIN_USN)
  66. except e:
  67. log.error("Failed to enable USN Plugin: error " + e.message['desc'])
  68. assert False
  69. log.info("Adding test entries...")
  70. for id in range(USER_NUM):
  71. name = "%s%d" % (TEST_USER, id)
  72. topology.standalone.add_s(Entry(("cn=%s,%s" % (name, SUFFIX), {
  73. 'objectclass': "top person".split(),
  74. 'sn': name,
  75. 'cn': name})))
  76. def in_index_file(topology, id, index):
  77. key = "%s%s" % (TEST_USER, id)
  78. log.info(" dbscan - checking %s is in index file %s..." % (key, index))
  79. dbscanOut = topology.standalone.dbscan(DEFAULT_BENAME, index)
  80. if key in dbscanOut:
  81. found = True
  82. topology.standalone.log.info("Found key %s in dbscan output" % key)
  83. else:
  84. found = False
  85. topology.standalone.log.info("Did not found key %s in dbscan output" % key)
  86. return found
  87. def test_ticket48252_run_0(topology):
  88. """
  89. Delete an entry cn=test_entry0
  90. Check it is not in the 'cn' index file
  91. """
  92. log.info("Case 1 - Check deleted entry is not in the 'cn' index file")
  93. del_rdn = "cn=%s0" % TEST_USER
  94. del_entry = "%s,%s" % (del_rdn, SUFFIX)
  95. log.info(" Deleting a test entry %s..." % del_entry)
  96. topology.standalone.delete_s(del_entry)
  97. assert in_index_file(topology, 0, 'cn') == False
  98. log.info(" db2index - reindexing %s ..." % 'cn')
  99. assert topology.standalone.db2index(DEFAULT_BENAME, 'cn')
  100. assert in_index_file(topology, 0, 'cn') == False
  101. log.info(" entry %s is not in the cn index file after reindexed." % del_entry)
  102. log.info('Case 1 - PASSED')
  103. def test_ticket48252_run_1(topology):
  104. """
  105. Delete an entry cn=test_entry1
  106. Check it is in the 'objectclass' index file as a tombstone entry
  107. """
  108. log.info("Case 2 - Check deleted entry is in the 'objectclass' index file as a tombstone entry")
  109. del_rdn = "cn=%s1" % TEST_USER
  110. del_entry = "%s,%s" % (del_rdn, SUFFIX)
  111. log.info(" Deleting a test entry %s..." % del_entry)
  112. topology.standalone.delete_s(del_entry)
  113. entry = topology.standalone.search_s(SUFFIX, ldap.SCOPE_SUBTREE, '(&(objectclass=nstombstone)(%s))' % del_rdn)
  114. assert len(entry) == 1
  115. log.info(" entry %s is in the objectclass index file." % del_entry)
  116. log.info(" db2index - reindexing %s ..." % 'objectclass')
  117. assert topology.standalone.db2index(DEFAULT_BENAME, 'objectclass')
  118. entry = topology.standalone.search_s(SUFFIX, ldap.SCOPE_SUBTREE, '(&(objectclass=nstombstone)(%s))' % del_rdn)
  119. assert len(entry) == 1
  120. log.info(" entry %s is in the objectclass index file after reindexed." % del_entry)
  121. log.info('Case 2 - PASSED')
  122. if __name__ == '__main__':
  123. # Run isolated
  124. # -s for DEBUG mode
  125. CURRENT_FILE = os.path.realpath(__file__)
  126. pytest.main("-s %s" % CURRENT_FILE)