ticket47973_test.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 logging
  10. import ldap.sasl
  11. import pytest
  12. from lib389.tasks import *
  13. from lib389.topologies import topology_st
  14. log = logging.getLogger(__name__)
  15. USER_DN = 'uid=user1,%s' % (DEFAULT_SUFFIX)
  16. SCHEMA_RELOAD_COUNT = 10
  17. def task_complete(conn, task_dn):
  18. finished = False
  19. try:
  20. task_entry = conn.search_s(task_dn, ldap.SCOPE_BASE, 'objectclass=*')
  21. if not task_entry:
  22. log.fatal('wait_for_task: Search failed to find task: ' + task_dn)
  23. assert False
  24. if task_entry[0].hasAttr('nstaskexitcode'):
  25. # task is done
  26. finished = True
  27. except ldap.LDAPError as e:
  28. log.fatal('wait_for_task: Search failed: ' + e.message['desc'])
  29. assert False
  30. return finished
  31. def test_ticket47973(topology_st):
  32. """
  33. During the schema reload task there is a small window where the new schema is not loaded
  34. into the asi hashtables - this results in searches not returning entries.
  35. """
  36. log.info('Testing Ticket 47973 - Test the searches still work as expected during schema reload tasks')
  37. #
  38. # Add a user
  39. #
  40. try:
  41. topology_st.standalone.add_s(Entry((USER_DN, {
  42. 'objectclass': 'top extensibleObject'.split(),
  43. 'uid': 'user1'
  44. })))
  45. except ldap.LDAPError as e:
  46. log.error('Failed to add user1: error ' + e.message['desc'])
  47. assert False
  48. #
  49. # Run a series of schema_reload tasks while searching for our user. Since
  50. # this is a race condition, run it several times.
  51. #
  52. task_count = 0
  53. while task_count < SCHEMA_RELOAD_COUNT:
  54. #
  55. # Add a schema reload task
  56. #
  57. TASK_DN = 'cn=task-' + str(task_count) + ',cn=schema reload task, cn=tasks, cn=config'
  58. try:
  59. topology_st.standalone.add_s(Entry((TASK_DN, {
  60. 'objectclass': 'top extensibleObject'.split(),
  61. 'cn': 'task-' + str(task_count)
  62. })))
  63. except ldap.LDAPError as e:
  64. log.error('Failed to add task entry: error ' + e.message['desc'])
  65. assert False
  66. #
  67. # While we wait for the task to complete keep searching for our user
  68. #
  69. search_count = 0
  70. while search_count < 100:
  71. #
  72. # Now check the user is still being returned
  73. #
  74. try:
  75. entries = topology_st.standalone.search_s(DEFAULT_SUFFIX,
  76. ldap.SCOPE_SUBTREE,
  77. '(uid=user1)')
  78. if not entries or not entries[0]:
  79. log.fatal('User was not returned from search!')
  80. assert False
  81. except ldap.LDAPError as e:
  82. log.fatal('Unable to search for entry %s: error %s' % (USER_DN, e.message['desc']))
  83. assert False
  84. #
  85. # Check if task is complete
  86. #
  87. if task_complete(topology_st.standalone, TASK_DN):
  88. break
  89. search_count += 1
  90. task_count += 1
  91. if __name__ == '__main__':
  92. # Run isolated
  93. # -s for DEBUG mode
  94. CURRENT_FILE = os.path.realpath(__file__)
  95. pytest.main("-s %s" % CURRENT_FILE)