regression_test.py 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. # Copyright (C) 2017 Red Hat, Inc.
  2. # All rights reserved.
  3. #
  4. # License: GPL (version 3 or any later version).
  5. # See LICENSE for details.
  6. # --- END COPYRIGHT BLOCK ---
  7. #
  8. import pytest
  9. from lib389.backend import Backends
  10. from lib389.properties import TASK_WAIT
  11. from lib389.utils import time, ldap, os, logging
  12. from lib389.topologies import topology_st as topo
  13. from lib389.dbgen import dbgen
  14. pytestmark = pytest.mark.tier1
  15. DEBUGGING = os.getenv("DEBUGGING", default=False)
  16. if DEBUGGING:
  17. logging.getLogger(__name__).setLevel(logging.DEBUG)
  18. else:
  19. logging.getLogger(__name__).setLevel(logging.INFO)
  20. log = logging.getLogger(__name__)
  21. TEST_SUFFIX1 = "dc=importest1,dc=com"
  22. TEST_BACKEND1 = "importest1"
  23. TEST_SUFFIX2 = "dc=importest2,dc=com"
  24. TEST_BACKEND2 = "importest2"
  25. TEST_DEFAULT_SUFFIX = "dc=default,dc=com"
  26. TEST_DEFAULT_NAME = "default"
  27. def test_import_be_default(topo):
  28. """ Create a backend using the name "default". previously this name was
  29. used int
  30. :id: 8e507beb-e917-4330-8cac-1ff0eee10508
  31. :feature: Import
  32. :setup: Standalone instance
  33. :steps:
  34. 1. Create a test suffix using the be name of "default"
  35. 2. Create an ldif for the "default" backend
  36. 3. Import ldif
  37. 4. Verify all entries were imported
  38. :expectedresults:
  39. 1. Success
  40. 2. Success
  41. 3. Success
  42. 4. Success
  43. """
  44. log.info('Adding suffix:{} and backend: {}...'.format(TEST_DEFAULT_SUFFIX,
  45. TEST_DEFAULT_NAME))
  46. backends = Backends(topo.standalone)
  47. backends.create(properties={'nsslapd-suffix': TEST_DEFAULT_SUFFIX,
  48. 'name': TEST_DEFAULT_NAME})
  49. log.info('Create LDIF file and import it...')
  50. ldif_dir = topo.standalone.get_ldif_dir()
  51. ldif_file = os.path.join(ldif_dir, 'default.ldif')
  52. dbgen(topo.standalone, 5, ldif_file, TEST_DEFAULT_SUFFIX)
  53. log.info('Stopping the server and running offline import...')
  54. topo.standalone.stop()
  55. assert topo.standalone.ldif2db(TEST_DEFAULT_NAME, None, None,
  56. None, ldif_file)
  57. topo.standalone.start()
  58. log.info('Verifying entry count after import...')
  59. entries = topo.standalone.search_s(TEST_DEFAULT_SUFFIX,
  60. ldap.SCOPE_SUBTREE,
  61. "(objectclass=*)")
  62. assert len(entries) > 1
  63. log.info('Test PASSED')
  64. def test_del_suffix_import(topo):
  65. """Adding a database entry fails if the same database was deleted after an import
  66. :id: 652421ef-738b-47ed-80ec-2ceece6b5d77
  67. :feature: Import
  68. :setup: Standalone instance
  69. :steps: 1. Create a test suffix and add few entries
  70. 2. Stop the server and do offline import using ldif2db
  71. 3. Delete the suffix backend
  72. 4. Add a new suffix with the same database name
  73. 5. Check if adding the same database name is a success
  74. :expectedresults: Adding database with the same name should be successful
  75. """
  76. log.info('Adding suffix:{} and backend: {}'.format(TEST_SUFFIX1, TEST_BACKEND1))
  77. backends = Backends(topo.standalone)
  78. backend = backends.create(properties={'nsslapd-suffix': TEST_SUFFIX1,
  79. 'name': TEST_BACKEND1})
  80. log.info('Create LDIF file and import it')
  81. ldif_dir = topo.standalone.get_ldif_dir()
  82. ldif_file = os.path.join(ldif_dir, 'suffix_del1.ldif')
  83. dbgen(topo.standalone, 10, ldif_file, TEST_SUFFIX1)
  84. log.info('Stopping the server and running offline import')
  85. topo.standalone.stop()
  86. assert topo.standalone.ldif2db(TEST_BACKEND1, TEST_SUFFIX1, None, None, ldif_file)
  87. topo.standalone.start()
  88. log.info('Deleting suffix-{}'.format(TEST_SUFFIX2))
  89. backend.delete()
  90. log.info('Adding the same database-{} after deleting it'.format(TEST_BACKEND1))
  91. backends.create(properties={'nsslapd-suffix': TEST_SUFFIX1,
  92. 'name': TEST_BACKEND1})
  93. def test_del_suffix_backend(topo):
  94. """Adding a database entry fails if the same database was deleted after an import
  95. :id: ac702c35-74b6-434e-8e30-316433f3e91a
  96. :feature: Import
  97. :setup: Standalone instance
  98. :steps: 1. Create a test suffix and add entries
  99. 2. Stop the server and do online import using ldif2db
  100. 3. Delete the suffix backend
  101. 4. Add a new suffix with the same database name
  102. 5. Restart the server and check the status
  103. :expectedresults: Adding database with the same name should be successful and the server should not hang
  104. """
  105. log.info('Adding suffix:{} and backend: {}'.format(TEST_SUFFIX2, TEST_BACKEND2))
  106. backends = Backends(topo.standalone)
  107. backend = backends.create(properties={'nsslapd-suffix': TEST_SUFFIX2,
  108. 'name': TEST_BACKEND2})
  109. log.info('Create LDIF file and import it')
  110. ldif_dir = topo.standalone.get_ldif_dir()
  111. ldif_file = os.path.join(ldif_dir, 'suffix_del2.ldif')
  112. dbgen(topo.standalone, 10, ldif_file, TEST_SUFFIX2)
  113. topo.standalone.tasks.importLDIF(suffix=TEST_SUFFIX2, input_file=ldif_file, args={TASK_WAIT: True})
  114. log.info('Deleting suffix-{}'.format(TEST_SUFFIX2))
  115. backend.delete()
  116. log.info('Adding the same database-{} after deleting it'.format(TEST_BACKEND2))
  117. backends.create(properties={'nsslapd-suffix': TEST_SUFFIX2,
  118. 'name': TEST_BACKEND2})
  119. log.info('Checking if server can be restarted after re-adding the same database')
  120. topo.standalone.restart()
  121. assert not topo.standalone.detectDisorderlyShutdown()
  122. if __name__ == '__main__':
  123. # Run isolated
  124. # -s for DEBUG mode
  125. CURRENT_FILE = os.path.realpath(__file__)
  126. pytest.main("-s {}".format(CURRENT_FILE))