1
0

ticket47781_test.py 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. 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. '''
  29. This fixture is used to standalone topology for the 'module'.
  30. '''
  31. global installation_prefix
  32. if installation_prefix:
  33. args_instance[SER_DEPLOYED_DIR] = installation_prefix
  34. standalone = DirSrv(verbose=False)
  35. # Args for the standalone instance
  36. args_instance[SER_HOST] = HOST_STANDALONE
  37. args_instance[SER_PORT] = PORT_STANDALONE
  38. args_instance[SER_SERVERID_PROP] = SERVERID_STANDALONE
  39. args_standalone = args_instance.copy()
  40. standalone.allocate(args_standalone)
  41. # Get the status of the instance and restart it if it exists
  42. instance_standalone = standalone.exists()
  43. # Remove the instance
  44. if instance_standalone:
  45. standalone.delete()
  46. # Create the instance
  47. standalone.create()
  48. # Used to retrieve configuration information (dbdir, confdir...)
  49. standalone.open()
  50. # clear the tmp directory
  51. standalone.clearTmpDir(__file__)
  52. # Here we have standalone instance up and running
  53. return TopologyStandalone(standalone)
  54. def test_ticket47781(topology):
  55. """
  56. Testing for a deadlock after doing an online import of an LDIF with
  57. replication data. The replication agreement should be invalid.
  58. """
  59. log.info('Testing Ticket 47781 - Testing for deadlock after importing LDIF with replication data')
  60. #
  61. # Setup Replication
  62. #
  63. log.info('Setting up replication...')
  64. topology.standalone.replica.enableReplication(suffix=DEFAULT_SUFFIX, role=REPLICAROLE_MASTER,
  65. replicaId=REPLICAID_MASTER_1)
  66. properties = {RA_NAME: r'meTo_$host:$port',
  67. RA_BINDDN: defaultProperties[REPLICATION_BIND_DN],
  68. RA_BINDPW: defaultProperties[REPLICATION_BIND_PW],
  69. RA_METHOD: defaultProperties[REPLICATION_BIND_METHOD],
  70. RA_TRANSPORT_PROT: defaultProperties[REPLICATION_TRANSPORT]}
  71. # The agreement should point to a server that does NOT exist (invalid port)
  72. repl_agreement = topology.standalone.agreement.create(suffix=DEFAULT_SUFFIX,
  73. host=topology.standalone.host,
  74. port=5555,
  75. properties=properties)
  76. #
  77. # add two entries
  78. #
  79. log.info('Adding two entries...')
  80. try:
  81. topology.standalone.add_s(Entry(('cn=entry1,dc=example,dc=com', {
  82. 'objectclass': 'top person'.split(),
  83. 'sn': 'user',
  84. 'cn': 'entry1'})))
  85. except ldap.LDAPError as e:
  86. log.error('Failed to add entry 1: ' + e.message['desc'])
  87. assert False
  88. try:
  89. topology.standalone.add_s(Entry(('cn=entry2,dc=example,dc=com', {
  90. 'objectclass': 'top person'.split(),
  91. 'sn': 'user',
  92. 'cn': 'entry2'})))
  93. except ldap.LDAPError as e:
  94. log.error('Failed to add entry 2: ' + e.message['desc'])
  95. assert False
  96. #
  97. # export the replication ldif
  98. #
  99. log.info('Exporting replication ldif...')
  100. args = {EXPORT_REPL_INFO: True}
  101. exportTask = Tasks(topology.standalone)
  102. try:
  103. exportTask.exportLDIF(DEFAULT_SUFFIX, None, "/tmp/export.ldif", args)
  104. except ValueError:
  105. assert False
  106. #
  107. # Restart the server
  108. #
  109. log.info('Restarting server...')
  110. topology.standalone.stop(timeout=5)
  111. topology.standalone.start(timeout=5)
  112. #
  113. # Import the ldif
  114. #
  115. log.info('Import replication LDIF file...')
  116. importTask = Tasks(topology.standalone)
  117. args = {TASK_WAIT: True}
  118. try:
  119. importTask.importLDIF(DEFAULT_SUFFIX, None, "/tmp/export.ldif", args)
  120. os.remove("/tmp/export.ldif")
  121. except ValueError:
  122. os.remove("/tmp/export.ldif")
  123. assert False
  124. #
  125. # Search for tombstones - we should not hang/timeout
  126. #
  127. log.info('Search for tombstone entries(should find one and not hang)...')
  128. topology.standalone.set_option(ldap.OPT_NETWORK_TIMEOUT, 5)
  129. topology.standalone.set_option(ldap.OPT_TIMEOUT, 5)
  130. try:
  131. entries = topology.standalone.search_s(DEFAULT_SUFFIX, ldap.SCOPE_SUBTREE, 'objectclass=nsTombstone')
  132. if not entries:
  133. log.fatal('Search failed to find any entries.')
  134. assert PR_False
  135. except ldap.LDAPError as e:
  136. log.fatal('Search failed: ' + e.message['desc'])
  137. assert PR_False
  138. def test_ticket47781_final(topology):
  139. topology.standalone.delete()
  140. log.info('Testcase PASSED')
  141. def run_isolated():
  142. '''
  143. run_isolated is used to run these test cases independently of a test scheduler (xunit, py.test..)
  144. To run isolated without py.test, you need to
  145. - edit this file and comment '@pytest.fixture' line before 'topology' function.
  146. - set the installation prefix
  147. - run this program
  148. '''
  149. global installation_prefix
  150. installation_prefix = None
  151. topo = topology(True)
  152. test_ticket47781(topo)
  153. test_ticket47781_final(topo)
  154. if __name__ == '__main__':
  155. run_isolated()