ticket48226_test.py 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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. from lib389.utils import *
  21. logging.getLogger(__name__).setLevel(logging.DEBUG)
  22. log = logging.getLogger(__name__)
  23. installation1_prefix = None
  24. class TopologyReplication(object):
  25. def __init__(self, master1, master2):
  26. master1.open()
  27. self.master1 = master1
  28. master2.open()
  29. self.master2 = master2
  30. @pytest.fixture(scope="module")
  31. def topology(request):
  32. global installation1_prefix
  33. os.environ['USE_VALGRIND'] = '1'
  34. if installation1_prefix:
  35. args_instance[SER_DEPLOYED_DIR] = installation1_prefix
  36. # Creating master 1...
  37. master1 = DirSrv(verbose=False)
  38. if installation1_prefix:
  39. args_instance[SER_DEPLOYED_DIR] = installation1_prefix
  40. args_instance[SER_HOST] = HOST_MASTER_1
  41. args_instance[SER_PORT] = PORT_MASTER_1
  42. args_instance[SER_SERVERID_PROP] = SERVERID_MASTER_1
  43. args_instance[SER_CREATION_SUFFIX] = DEFAULT_SUFFIX
  44. args_master = args_instance.copy()
  45. master1.allocate(args_master)
  46. instance_master1 = master1.exists()
  47. if instance_master1:
  48. master1.delete()
  49. master1.create()
  50. master1.open()
  51. master1.replica.enableReplication(suffix=SUFFIX, role=REPLICAROLE_MASTER, replicaId=REPLICAID_MASTER_1)
  52. # Creating master 2...
  53. master2 = DirSrv(verbose=False)
  54. if installation1_prefix:
  55. args_instance[SER_DEPLOYED_DIR] = installation1_prefix
  56. args_instance[SER_HOST] = HOST_MASTER_2
  57. args_instance[SER_PORT] = PORT_MASTER_2
  58. args_instance[SER_SERVERID_PROP] = SERVERID_MASTER_2
  59. args_instance[SER_CREATION_SUFFIX] = DEFAULT_SUFFIX
  60. args_master = args_instance.copy()
  61. master2.allocate(args_master)
  62. instance_master2 = master2.exists()
  63. if instance_master2:
  64. master2.delete()
  65. master2.create()
  66. master2.open()
  67. master2.replica.enableReplication(suffix=SUFFIX, role=REPLICAROLE_MASTER, replicaId=REPLICAID_MASTER_2)
  68. #
  69. # Create all the agreements
  70. #
  71. # Creating agreement from master 1 to master 2
  72. properties = {RA_NAME: r'meTo_$host:$port',
  73. RA_BINDDN: defaultProperties[REPLICATION_BIND_DN],
  74. RA_BINDPW: defaultProperties[REPLICATION_BIND_PW],
  75. RA_METHOD: defaultProperties[REPLICATION_BIND_METHOD],
  76. RA_TRANSPORT_PROT: defaultProperties[REPLICATION_TRANSPORT]}
  77. m1_m2_agmt = master1.agreement.create(suffix=SUFFIX, host=master2.host, port=master2.port, properties=properties)
  78. if not m1_m2_agmt:
  79. log.fatal("Fail to create a master -> master replica agreement")
  80. sys.exit(1)
  81. log.debug("%s created" % m1_m2_agmt)
  82. # Creating agreement from master 2 to master 1
  83. properties = {RA_NAME: r'meTo_$host:$port',
  84. RA_BINDDN: defaultProperties[REPLICATION_BIND_DN],
  85. RA_BINDPW: defaultProperties[REPLICATION_BIND_PW],
  86. RA_METHOD: defaultProperties[REPLICATION_BIND_METHOD],
  87. RA_TRANSPORT_PROT: defaultProperties[REPLICATION_TRANSPORT]}
  88. m2_m1_agmt = master2.agreement.create(suffix=SUFFIX, host=master1.host, port=master1.port, properties=properties)
  89. if not m2_m1_agmt:
  90. log.fatal("Fail to create a master -> master replica agreement")
  91. sys.exit(1)
  92. log.debug("%s created" % m2_m1_agmt)
  93. # Allow the replicas to get situated with the new agreements...
  94. time.sleep(5)
  95. #
  96. # Initialize all the agreements
  97. #
  98. master1.agreement.init(SUFFIX, HOST_MASTER_2, PORT_MASTER_2)
  99. master1.waitForReplInit(m1_m2_agmt)
  100. # Check replication is working...
  101. if master1.testReplication(DEFAULT_SUFFIX, master2):
  102. log.info('Replication is working.')
  103. else:
  104. log.fatal('Replication is not working.')
  105. assert False
  106. # Clear out the tmp dir
  107. master1.clearTmpDir(__file__)
  108. return TopologyReplication(master1, master2)
  109. def test_ticket11111_set_purgedelay(topology):
  110. args = {REPLICA_PURGE_DELAY: '5',
  111. REPLICA_PURGE_INTERVAL: '5'}
  112. try:
  113. topology.master1.replica.setProperties(DEFAULT_SUFFIX, None, None, args)
  114. except:
  115. log.fatal('Failed to configure replica')
  116. assert False
  117. try:
  118. topology.master2.replica.setProperties(DEFAULT_SUFFIX, None, None, args)
  119. except:
  120. log.fatal('Failed to configure replica')
  121. assert False
  122. topology.master1.modify_s(DN_CONFIG, [(ldap.MOD_REPLACE, 'nsslapd-auditlog-logging-enabled', 'on')])
  123. topology.master2.modify_s(DN_CONFIG, [(ldap.MOD_REPLACE, 'nsslapd-auditlog-logging-enabled', 'on')])
  124. topology.master1.restart(10)
  125. topology.master2.restart(10)
  126. def test_ticket11111_1(topology):
  127. name = 'test_entry'
  128. dn = "cn=%s,%s" % (name, SUFFIX)
  129. topology.master1.add_s(Entry((dn , {
  130. 'objectclass': "top person".split(),
  131. 'sn': name,
  132. 'cn': name})))
  133. # First do an update that is replicated
  134. mods = [(ldap.MOD_ADD, 'description', '5')]
  135. topology.master1.modify_s(dn, mods)
  136. nbtry = 0
  137. while (nbtry <= 10):
  138. try:
  139. ent = topology.master2.getEntry(dn, ldap.SCOPE_BASE, "(objectclass=*)", ['description'])
  140. if ent.hasAttr('description') and ent.getValue('description') == '5':
  141. break
  142. except ldap.NO_SUCH_OBJECT:
  143. pass
  144. nbtry = nbtry + 1
  145. time.sleep(1)
  146. assert nbtry <= 10
  147. # Stop M2 so that it will not receive the next update
  148. topology.master2.stop(10)
  149. # ADD a new value that is not replicated
  150. mods = [(ldap.MOD_DELETE, 'description', '5')]
  151. topology.master1.modify_s(dn, mods)
  152. # Stop M1 so that it will keep del '5' that is unknown from master2
  153. topology.master1.stop(10)
  154. # Get the sbin directory so we know where to replace 'ns-slapd'
  155. sbin_dir = get_sbin_dir(prefix=topology.master2.prefix)
  156. # Enable valgrind
  157. valgrind_enable(sbin_dir)
  158. # start M2 to do the next updates
  159. topology.master2.start(10)
  160. # ADD 'description' by '5'
  161. mods = [(ldap.MOD_DELETE, 'description', '5')]
  162. topology.master2.modify_s(dn, mods)
  163. # DEL 'description' by '5'
  164. mods = [(ldap.MOD_ADD, 'description', '5')]
  165. topology.master2.modify_s(dn, mods)
  166. # sleep of purgedelay so that the next update will purge the CSN_7
  167. time.sleep(6)
  168. # ADD 'description' by '8' that purge the state info
  169. mods = [(ldap.MOD_ADD, 'description', '6')]
  170. topology.master2.modify_s(dn, mods)
  171. if valgrind_check_leak(topology.master2, 'csnset_dup'):
  172. log.error('test_csnset_dup: Memory leak is present!')
  173. else:
  174. log.info('test_csnset_dup: No leak is present!')
  175. if valgrind_check_leak(topology.master2, 'Invalid'):
  176. log.info('Valgrind reported invalid!')
  177. else:
  178. log.info('Valgrind is happy!')
  179. #log.info("You can attach yourself")
  180. #time.sleep(60)
  181. # Enable valgrind
  182. valgrind_disable(sbin_dir)
  183. topology.master1.start(10)
  184. def test_ticket11111_final(topology):
  185. topology.master1.delete()
  186. topology.master2.delete()
  187. log.info('Testcase PASSED')
  188. def run_isolated():
  189. global installation1_prefix
  190. installation1_prefix = None
  191. topo = topology(True)
  192. test_ticket11111_set_purgedelay(topo)
  193. test_ticket11111_1(topo)
  194. if __name__ == '__main__':
  195. run_isolated()