1
0

ticket48252_test.py 4.7 KB

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