ticket48226_test.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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 pytest
  10. from lib389.tasks import *
  11. from lib389.utils import *
  12. from lib389.topologies import topology_m2
  13. logging.getLogger(__name__).setLevel(logging.DEBUG)
  14. log = logging.getLogger(__name__)
  15. def test_ticket48226_set_purgedelay(topology_m2):
  16. args = {REPLICA_PURGE_DELAY: '5',
  17. REPLICA_PURGE_INTERVAL: '5'}
  18. try:
  19. topology_m2.ms["master1"].replica.setProperties(DEFAULT_SUFFIX, None, None, args)
  20. except:
  21. log.fatal('Failed to configure replica')
  22. assert False
  23. try:
  24. topology_m2.ms["master2"].replica.setProperties(DEFAULT_SUFFIX, None, None, args)
  25. except:
  26. log.fatal('Failed to configure replica')
  27. assert False
  28. topology_m2.ms["master1"].modify_s(DN_CONFIG, [(ldap.MOD_REPLACE, 'nsslapd-auditlog-logging-enabled', 'on')])
  29. topology_m2.ms["master2"].modify_s(DN_CONFIG, [(ldap.MOD_REPLACE, 'nsslapd-auditlog-logging-enabled', 'on')])
  30. topology_m2.ms["master1"].restart(30)
  31. topology_m2.ms["master2"].restart(30)
  32. def test_ticket48226_1(topology_m2):
  33. name = 'test_entry'
  34. dn = "cn=%s,%s" % (name, SUFFIX)
  35. topology_m2.ms["master1"].add_s(Entry((dn, {'objectclass': "top person".split(),
  36. 'sn': name,
  37. 'cn': name})))
  38. # First do an update that is replicated
  39. mods = [(ldap.MOD_ADD, 'description', '5')]
  40. topology_m2.ms["master1"].modify_s(dn, mods)
  41. nbtry = 0
  42. while (nbtry <= 10):
  43. try:
  44. ent = topology_m2.ms["master2"].getEntry(dn, ldap.SCOPE_BASE, "(objectclass=*)", ['description'])
  45. if ent.hasAttr('description') and ent.getValue('description') == '5':
  46. break
  47. except ldap.NO_SUCH_OBJECT:
  48. pass
  49. nbtry = nbtry + 1
  50. time.sleep(1)
  51. assert nbtry <= 10
  52. # Stop M2 so that it will not receive the next update
  53. topology_m2.ms["master2"].stop(10)
  54. # ADD a new value that is not replicated
  55. mods = [(ldap.MOD_DELETE, 'description', '5')]
  56. topology_m2.ms["master1"].modify_s(dn, mods)
  57. # Stop M1 so that it will keep del '5' that is unknown from master2
  58. topology_m2.ms["master1"].stop(10)
  59. # Get the sbin directory so we know where to replace 'ns-slapd'
  60. sbin_dir = topology_m2.ms["master2"].get_sbin_dir()
  61. # Enable valgrind
  62. if not topology_m2.ms["master2"].has_asan():
  63. valgrind_enable(sbin_dir)
  64. # start M2 to do the next updates
  65. topology_m2.ms["master2"].start()
  66. # ADD 'description' by '5'
  67. mods = [(ldap.MOD_DELETE, 'description', '5')]
  68. topology_m2.ms["master2"].modify_s(dn, mods)
  69. # DEL 'description' by '5'
  70. mods = [(ldap.MOD_ADD, 'description', '5')]
  71. topology_m2.ms["master2"].modify_s(dn, mods)
  72. # sleep of purge delay so that the next update will purge the CSN_7
  73. time.sleep(6)
  74. # ADD 'description' by '6' that purge the state info
  75. mods = [(ldap.MOD_ADD, 'description', '6')]
  76. topology_m2.ms["master2"].modify_s(dn, mods)
  77. # Restart master1
  78. # topology_m2.ms["master1"].start(30)
  79. if not topology_m2.ms["master2"].has_asan():
  80. results_file = valgrind_get_results_file(topology_m2.ms["master2"])
  81. # Stop master2
  82. topology_m2.ms["master2"].stop(30)
  83. # Check for leak
  84. if not topology_m2.ms["master2"].has_asan():
  85. if valgrind_check_file(results_file, VALGRIND_LEAK_STR, 'csnset_dup'):
  86. log.info('Valgrind reported leak in csnset_dup!')
  87. assert False
  88. else:
  89. log.info('Valgrind is happy!')
  90. # Check for invalid read/write
  91. if valgrind_check_file(results_file, VALGRIND_INVALID_STR, 'csnset_dup'):
  92. log.info('Valgrind reported invalid!')
  93. assert False
  94. else:
  95. log.info('Valgrind is happy!')
  96. # Check for invalid read/write
  97. if valgrind_check_file(results_file, VALGRIND_INVALID_STR, 'csnset_free'):
  98. log.info('Valgrind reported invalid!')
  99. assert False
  100. else:
  101. log.info('Valgrind is happy!')
  102. log.info('Testcase PASSED')
  103. if __name__ == '__main__':
  104. # Run isolated
  105. # -s for DEBUG mode
  106. CURRENT_FILE = os.path.realpath(__file__)
  107. pytest.main("-s %s" % CURRENT_FILE)