regression_test.py 5.6 KB

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