export_test.py 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. # --- BEGIN COPYRIGHT BLOCK ---
  2. # Copyright (C) 2020 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. import os
  9. import pytest
  10. import subprocess
  11. from lib389.topologies import topology_st as topo
  12. from lib389._constants import DEFAULT_SUFFIX, DEFAULT_BENAME
  13. from lib389.utils import *
  14. from lib389.paths import Paths
  15. from lib389.cli_base import FakeArgs
  16. from lib389.cli_ctl.dbtasks import dbtasks_db2ldif
  17. pytestmark = pytest.mark.tier1
  18. def run_db2ldif_and_clear_logs(topology, instance, backend, ldif, output_msg, encrypt=False, repl=False):
  19. args = FakeArgs()
  20. args.instance = instance.serverid
  21. args.backend = backend
  22. args.encrypted = encrypt
  23. args.replication = repl
  24. args.ldif = ldif
  25. dbtasks_db2ldif(instance, topology.logcap.log, args)
  26. log.info('checking output msg')
  27. if not topology.logcap.contains(output_msg):
  28. log.error('The output message is not the expected one')
  29. assert False
  30. log.info('Clear the log')
  31. topology.logcap.flush()
  32. @pytest.mark.bz1806978
  33. @pytest.mark.ds51188
  34. @pytest.mark.skipif(ds_is_older("1.3.10", "1.4.2"), reason="Not implemented")
  35. def test_dbtasks_db2ldif_with_non_accessible_ldif_file_path(topo):
  36. """Export with dsctl db2ldif, giving a ldif file path which can't be accessed by the user (dirsrv by default)
  37. :id: ca91eda7-27b1-4750-a013-531a63d3f5b0
  38. :setup: Standalone Instance - entries imported in the db
  39. :steps:
  40. 1. Stop the server
  41. 2. Launch db2ldif with an non accessible ldif file path
  42. 3. Catch the reported error code
  43. 4. check the error reported in the errors log
  44. :expected results:
  45. 1. Operation successful
  46. 2. Operation properly fails, without crashing
  47. 3. An error code different from 139 (segmentation fault) should be reported
  48. 4. 'ERR - bdb_db2ldif - db2ldif: userRoot: can't open file' should be reported
  49. """
  50. export_ldif = '/tmp/nonexistent/export.ldif'
  51. log.info("Stopping the instance...")
  52. topo.standalone.stop()
  53. log.info("Performing an offline export to a non accessible ldif file path - should fail properly")
  54. expected_output="db2ldif failed"
  55. run_db2ldif_and_clear_logs(topo, topo.standalone, DEFAULT_BENAME, export_ldif, expected_output)
  56. log.info("parsing the errors log to search for the error reported")
  57. if ds_is_newer("1.3.10"):
  58. search_str = str(topo.standalone.ds_error_log.match(r".*ERR - bdb_db2ldif - db2ldif: userRoot: can't open*"))[1:-1]
  59. else:
  60. search_str = str(topo.standalone.ds_error_log.match(r".*ERR - ldbm_back_ldbm2ldif - db2ldif: can't open*"))[1:-1]
  61. assert len(search_str) > 0
  62. log.info("error string : %s" % search_str)
  63. log.info("Restarting the instance...")
  64. topo.standalone.start()
  65. @pytest.mark.bz1806978
  66. @pytest.mark.ds51188
  67. @pytest.mark.skipif(ds_is_older("1.4.3.8"), reason="bz1806978 not fixed")
  68. def test_db2ldif_cli_with_non_accessible_ldif_file_path(topo):
  69. """Export with ns-slapd db2ldif, giving a ldif file path which can't be accessed by the user (dirsrv by default)
  70. :id: ca91eda7-27b1-4750-a013-531a63d3f5b0
  71. :setup: Standalone Instance - entries imported in the db
  72. :steps:
  73. 1. Stop the server
  74. 2. Launch db2ldif with an non accessible ldif file path
  75. 3. Catch the reported error code
  76. 4. check the error reported in the errors log
  77. :expected results:
  78. 1. Operation successful
  79. 2. Operation properly fails, without crashing
  80. 3. An error code different from 139 (segmentation fault) should be reported
  81. 4. 'ERR - bdb_db2ldif - db2ldif: userRoot: can't open file' should be reported
  82. """
  83. export_ldif = '/tmp/nonexistent/export.ldif'
  84. db2ldif_cmd = os.path.join(topo.standalone.ds_paths.sbin_dir, 'dsctl')
  85. log.info("Stopping the instance...")
  86. topo.standalone.stop()
  87. log.info("Performing an offline export to a non accessible ldif file path - should fail properly")
  88. try:
  89. subprocess.check_call([db2ldif_cmd, topo.standalone.serverid, 'db2ldif', 'userroot', export_ldif])
  90. except subprocess.CalledProcessError as e:
  91. if format(e.returncode) == '139':
  92. log.error('db2ldif had a Segmentation fault (core dumped)')
  93. assert False
  94. else:
  95. log.info('db2ldif failed properly: error ({})'.format(e.returncode))
  96. assert True
  97. log.info("parsing the errors log to search for the error reported")
  98. search_str = str(topo.standalone.ds_error_log.match(r".*ERR - bdb_db2ldif - db2ldif: userRoot: can't open*"))[1:-1]
  99. assert len(search_str) > 0
  100. log.info("error string : %s" % search_str)
  101. log.info("Restarting the instance...")
  102. topo.standalone.start()
  103. @pytest.mark.bz1860291
  104. @pytest.mark.xfail(reason="bug 1860291")
  105. @pytest.mark.skipif(ds_is_older("1.3.10", "1.4.2"), reason="Not implemented")
  106. def test_dbtasks_db2ldif_with_non_accessible_ldif_file_path_output(topo):
  107. """Export with db2ldif, giving a ldif file path which can't be accessed by the user (dirsrv by default)
  108. :id: fcc63387-e650-40a7-b643-baa68c190037
  109. :setup: Standalone Instance - entries imported in the db
  110. :steps:
  111. 1. Stop the server
  112. 2. Launch db2ldif with a non accessible ldif file path
  113. 3. check the error reported in the command output
  114. :expected results:
  115. 1. Operation successful
  116. 2. Operation properly fails
  117. 3. An clear error message is reported as output of the cli
  118. """
  119. export_ldif = '/tmp/nonexistent/export.ldif'
  120. log.info("Stopping the instance...")
  121. topo.standalone.stop()
  122. log.info("Performing an offline export to a non accessible ldif file path - should fail and output a clear error message")
  123. expected_output="No such file or directory"
  124. run_db2ldif_and_clear_logs(topo, topo.standalone, DEFAULT_BENAME, export_ldif, expected_output)
  125. # This test will possibly have to be updated with the error message reported after bz1860291 fix
  126. log.info("Restarting the instance...")
  127. topo.standalone.start()