backup_test.py 2.2 KB

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