backup_test.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import logging
  2. import pytest
  3. import os
  4. from datetime import datetime
  5. from lib389._constants import DEFAULT_SUFFIX, INSTALL_LATEST_CONFIG
  6. from lib389.properties import BACKEND_SAMPLE_ENTRIES, TASK_WAIT
  7. from lib389.topologies import topology_st as topo
  8. from lib389.backend import Backend
  9. from lib389.tasks import BackupTask, RestoreTask
  10. DEBUGGING = os.getenv("DEBUGGING", default=False)
  11. if DEBUGGING:
  12. logging.getLogger(__name__).setLevel(logging.DEBUG)
  13. else:
  14. logging.getLogger(__name__).setLevel(logging.INFO)
  15. log = logging.getLogger(__name__)
  16. def test_missing_backend(topo):
  17. """Test that an error is returned when a restore is performed for a
  18. backend that is no longer present.
  19. :id: 889b8028-35cf-41d7-91f6-bc5193683646
  20. :setup: Standalone Instance
  21. :steps:
  22. 1. Create a second backend
  23. 2. Perform a back up
  24. 3. Remove one of the backends from the config
  25. 4. Perform a restore
  26. :expectedresults:
  27. 1. Success
  28. 2. Success
  29. 3. Success
  30. 4. Failure
  31. """
  32. # Create a new backend
  33. BE_NAME = 'backupRoot'
  34. BE_SUFFIX = 'dc=back,dc=up'
  35. props = {
  36. 'cn': BE_NAME,
  37. 'nsslapd-suffix': BE_SUFFIX,
  38. BACKEND_SAMPLE_ENTRIES: INSTALL_LATEST_CONFIG
  39. }
  40. be = Backend(topo.standalone)
  41. backend_entry = be.create(properties=props)
  42. # perform backup
  43. backup_dir_name = "backup-%s" % datetime.now().strftime("%Y_%m_%d_%H_%M_%S")
  44. archive = os.path.join(topo.standalone.ds_paths.backup_dir, backup_dir_name)
  45. backup_task = BackupTask(topo.standalone)
  46. task_properties = {'nsArchiveDir': archive}
  47. backup_task.create(properties=task_properties)
  48. backup_task.wait()
  49. assert backup_task.get_exit_code() == 0
  50. # Remove new backend
  51. backend_entry.delete()
  52. # Restore the backup - it should fail
  53. restore_task = RestoreTask(topo.standalone)
  54. task_properties = {'nsArchiveDir': archive}
  55. restore_task.create(properties=task_properties)
  56. restore_task.wait()
  57. assert restore_task.get_exit_code() != 0
  58. if __name__ == '__main__':
  59. # Run isolated
  60. # -s for DEBUG mode
  61. CURRENT_FILE = os.path.realpath(__file__)
  62. pytest.main(["-s", CURRENT_FILE])