1
0

ticket48891_test.py 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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 time
  11. import ldap
  12. import logging
  13. import pytest
  14. from lib389 import DirSrv, Entry
  15. from lib389._constants import *
  16. from lib389.properties import *
  17. from lib389.tasks import *
  18. import fnmatch
  19. log = logging.getLogger(__name__)
  20. CONFIG_DN = 'cn=config'
  21. RDN_VAL_SUFFIX = 'ticket48891.org'
  22. MYSUFFIX = 'dc=%s' % RDN_VAL_SUFFIX
  23. MYSUFFIXBE = 'ticket48891'
  24. SEARCHFILTER = '(objectclass=person)'
  25. OTHER_NAME = 'other_entry'
  26. MAX_OTHERS = 10
  27. class TopologyStandalone(object):
  28. def __init__(self, standalone):
  29. standalone.open()
  30. self.standalone = standalone
  31. @pytest.fixture(scope="module")
  32. def topology(request):
  33. '''
  34. This fixture is used to standalone topology for the 'module'.
  35. '''
  36. standalone = DirSrv(verbose=False)
  37. # Args for the standalone instance
  38. args_instance[SER_HOST] = HOST_STANDALONE
  39. args_instance[SER_PORT] = PORT_STANDALONE
  40. args_instance[SER_SERVERID_PROP] = SERVERID_STANDALONE
  41. args_standalone = args_instance.copy()
  42. standalone.allocate(args_standalone)
  43. # Get the status of the instance and restart it if it exists
  44. instance_standalone = standalone.exists()
  45. # Remove the instance
  46. if instance_standalone:
  47. standalone.delete()
  48. # Create the instance
  49. standalone.create()
  50. # Used to retrieve configuration information (dbdir, confdir...)
  51. standalone.open()
  52. def fin():
  53. standalone.delete()
  54. request.addfinalizer(fin)
  55. # Here we have standalone instance up and running
  56. return TopologyStandalone(standalone)
  57. def test_ticket48891_setup(topology):
  58. """
  59. Check there is no core
  60. Create a second backend
  61. stop DS (that should trigger the core)
  62. check there is no core
  63. """
  64. log.info('Testing Ticket 48891 - ns-slapd crashes during the shutdown after adding attribute with a matching rule')
  65. # bind as directory manager
  66. topology.standalone.log.info("Bind as %s" % DN_DM)
  67. topology.standalone.simple_bind_s(DN_DM, PASSWORD)
  68. # check there is no core
  69. entry = topology.standalone.search_s(CONFIG_DN, ldap.SCOPE_BASE,
  70. "(cn=config)", ['nsslapd-errorlog'])
  71. assert entry
  72. path = entry[0].getValue('nsslapd-errorlog').replace('errors', '')
  73. log.debug('Looking for a core file in: ' + path)
  74. cores = fnmatch.filter(os.listdir(path), 'core.*')
  75. assert len(cores) == 0
  76. topology.standalone.log.info("\n\n######################### SETUP SUFFIX o=ticket48891.org ######################\n")
  77. topology.standalone.backend.create(MYSUFFIX, {BACKEND_NAME: MYSUFFIXBE})
  78. topology.standalone.mappingtree.create(MYSUFFIX, bename=MYSUFFIXBE)
  79. topology.standalone.add_s(Entry((MYSUFFIX, {
  80. 'objectclass': "top domain".split(),
  81. 'dc': RDN_VAL_SUFFIX})))
  82. topology.standalone.log.info("\n\n######################### Generate Test data ######################\n")
  83. # add dummy entries on both backends
  84. for cpt in range(MAX_OTHERS):
  85. name = "%s%d" % (OTHER_NAME, cpt)
  86. topology.standalone.add_s(Entry(("cn=%s,%s" % (name, SUFFIX), {
  87. 'objectclass': "top person".split(),
  88. 'sn': name,
  89. 'cn': name})))
  90. for cpt in range(MAX_OTHERS):
  91. name = "%s%d" % (OTHER_NAME, cpt)
  92. topology.standalone.add_s(Entry(("cn=%s,%s" % (name, MYSUFFIX), {
  93. 'objectclass': "top person".split(),
  94. 'sn': name,
  95. 'cn': name})))
  96. topology.standalone.log.info("\n\n######################### SEARCH ALL ######################\n")
  97. topology.standalone.log.info("Bind as %s and add the READ/SEARCH SELFDN aci" % DN_DM)
  98. topology.standalone.simple_bind_s(DN_DM, PASSWORD)
  99. entries = topology.standalone.search_s(MYSUFFIX, ldap.SCOPE_SUBTREE, SEARCHFILTER)
  100. topology.standalone.log.info("Returned %d entries.\n", len(entries))
  101. assert MAX_OTHERS == len(entries)
  102. topology.standalone.log.info('%d person entries are successfully created under %s.' % (len(entries), MYSUFFIX))
  103. topology.standalone.stop(timeout=1)
  104. cores = fnmatch.filter(os.listdir(path), 'core.*')
  105. for core in cores:
  106. core = os.path.join(path, core)
  107. topology.standalone.log.info('cores are %s' % core)
  108. assert not os.path.isfile(core)
  109. log.info('Testcase PASSED')
  110. if __name__ == '__main__':
  111. # Run isolated
  112. # -s for DEBUG mode
  113. CURRENT_FILE = os.path.realpath(__file__)
  114. pytest.main("-s %s" % CURRENT_FILE)