ticket48891_test.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 fnmatch
  10. import logging
  11. import pytest
  12. from lib389.tasks import *
  13. from lib389.topologies import topology_st
  14. from lib389._constants import DN_DM, PASSWORD, DEFAULT_SUFFIX, BACKEND_NAME, SUFFIX
  15. log = logging.getLogger(__name__)
  16. CONFIG_DN = 'cn=config'
  17. RDN_VAL_SUFFIX = 'ticket48891.org'
  18. MYSUFFIX = 'dc=%s' % RDN_VAL_SUFFIX
  19. MYSUFFIXBE = 'ticket48891'
  20. SEARCHFILTER = '(objectclass=person)'
  21. OTHER_NAME = 'other_entry'
  22. MAX_OTHERS = 10
  23. def test_ticket48891_setup(topology_st):
  24. """
  25. Check there is no core
  26. Create a second backend
  27. stop DS (that should trigger the core)
  28. check there is no core
  29. """
  30. log.info('Testing Ticket 48891 - ns-slapd crashes during the shutdown after adding attribute with a matching rule')
  31. # bind as directory manager
  32. topology_st.standalone.log.info("Bind as %s" % DN_DM)
  33. topology_st.standalone.simple_bind_s(DN_DM, PASSWORD)
  34. # check there is no core
  35. path = topology_st.standalone.config.get_attr_val_utf8('nsslapd-errorlog').replace('errors', '')
  36. log.debug('Looking for a core file in: ' + path)
  37. cores = fnmatch.filter(os.listdir(path), 'core.*')
  38. assert len(cores) == 0
  39. topology_st.standalone.log.info(
  40. "\n\n######################### SETUP SUFFIX o=ticket48891.org ######################\n")
  41. topology_st.standalone.backend.create(MYSUFFIX, {BACKEND_NAME: MYSUFFIXBE})
  42. topology_st.standalone.mappingtree.create(MYSUFFIX, bename=MYSUFFIXBE)
  43. topology_st.standalone.add_s(Entry((MYSUFFIX, {
  44. 'objectclass': "top domain".split(),
  45. 'dc': RDN_VAL_SUFFIX})))
  46. topology_st.standalone.log.info("\n\n######################### Generate Test data ######################\n")
  47. # add dummy entries on both backends
  48. for cpt in range(MAX_OTHERS):
  49. name = "%s%d" % (OTHER_NAME, cpt)
  50. topology_st.standalone.add_s(Entry(("cn=%s,%s" % (name, SUFFIX), {
  51. 'objectclass': "top person".split(),
  52. 'sn': name,
  53. 'cn': name})))
  54. for cpt in range(MAX_OTHERS):
  55. name = "%s%d" % (OTHER_NAME, cpt)
  56. topology_st.standalone.add_s(Entry(("cn=%s,%s" % (name, MYSUFFIX), {
  57. 'objectclass': "top person".split(),
  58. 'sn': name,
  59. 'cn': name})))
  60. topology_st.standalone.log.info("\n\n######################### SEARCH ALL ######################\n")
  61. topology_st.standalone.log.info("Bind as %s and add the READ/SEARCH SELFDN aci" % DN_DM)
  62. topology_st.standalone.simple_bind_s(DN_DM, PASSWORD)
  63. entries = topology_st.standalone.search_s(MYSUFFIX, ldap.SCOPE_SUBTREE, SEARCHFILTER)
  64. topology_st.standalone.log.info("Returned %d entries.\n", len(entries))
  65. assert MAX_OTHERS == len(entries)
  66. topology_st.standalone.log.info('%d person entries are successfully created under %s.' % (len(entries), MYSUFFIX))
  67. topology_st.standalone.stop(timeout=1)
  68. cores = fnmatch.filter(os.listdir(path), 'core.*')
  69. for core in cores:
  70. core = os.path.join(path, core)
  71. topology_st.standalone.log.info('cores are %s' % core)
  72. assert not os.path.isfile(core)
  73. log.info('Testcase PASSED')
  74. if __name__ == '__main__':
  75. # Run isolated
  76. # -s for DEBUG mode
  77. CURRENT_FILE = os.path.realpath(__file__)
  78. pytest.main("-s %s" % CURRENT_FILE)