test_borg.py 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. import logging
  2. from flexmock import flexmock
  3. from borgmatic.borg import borg as module
  4. from ..test_verbosity import insert_logging_mock
  5. def test_run_arbitrary_borg_calls_borg_with_parameters():
  6. flexmock(module.environment).should_receive('make_environment')
  7. flexmock(module).should_receive('execute_command').with_args(
  8. ('borg', 'break-lock', 'repo'),
  9. output_log_level=logging.WARNING,
  10. borg_local_path='borg',
  11. extra_environment=None,
  12. )
  13. module.run_arbitrary_borg(
  14. repository='repo', storage_config={}, options=['break-lock'],
  15. )
  16. def test_run_arbitrary_borg_with_log_info_calls_borg_with_info_parameter():
  17. flexmock(module.environment).should_receive('make_environment')
  18. flexmock(module).should_receive('execute_command').with_args(
  19. ('borg', 'break-lock', 'repo', '--info'),
  20. output_log_level=logging.WARNING,
  21. borg_local_path='borg',
  22. extra_environment=None,
  23. )
  24. insert_logging_mock(logging.INFO)
  25. module.run_arbitrary_borg(
  26. repository='repo', storage_config={}, options=['break-lock'],
  27. )
  28. def test_run_arbitrary_borg_with_log_debug_calls_borg_with_debug_parameter():
  29. flexmock(module.environment).should_receive('make_environment')
  30. flexmock(module).should_receive('execute_command').with_args(
  31. ('borg', 'break-lock', 'repo', '--debug', '--show-rc'),
  32. output_log_level=logging.WARNING,
  33. borg_local_path='borg',
  34. extra_environment=None,
  35. )
  36. insert_logging_mock(logging.DEBUG)
  37. module.run_arbitrary_borg(
  38. repository='repo', storage_config={}, options=['break-lock'],
  39. )
  40. def test_run_arbitrary_borg_with_lock_wait_calls_borg_with_lock_wait_parameters():
  41. storage_config = {'lock_wait': 5}
  42. flexmock(module.environment).should_receive('make_environment')
  43. flexmock(module).should_receive('execute_command').with_args(
  44. ('borg', 'break-lock', 'repo', '--lock-wait', '5'),
  45. output_log_level=logging.WARNING,
  46. borg_local_path='borg',
  47. extra_environment=None,
  48. )
  49. module.run_arbitrary_borg(
  50. repository='repo', storage_config=storage_config, options=['break-lock'],
  51. )
  52. def test_run_arbitrary_borg_with_archive_calls_borg_with_archive_parameter():
  53. storage_config = {}
  54. flexmock(module.environment).should_receive('make_environment')
  55. flexmock(module).should_receive('execute_command').with_args(
  56. ('borg', 'break-lock', 'repo::archive'),
  57. output_log_level=logging.WARNING,
  58. borg_local_path='borg',
  59. extra_environment=None,
  60. )
  61. module.run_arbitrary_borg(
  62. repository='repo', storage_config=storage_config, options=['break-lock'], archive='archive',
  63. )
  64. def test_run_arbitrary_borg_with_local_path_calls_borg_via_local_path():
  65. flexmock(module.environment).should_receive('make_environment')
  66. flexmock(module).should_receive('execute_command').with_args(
  67. ('borg1', 'break-lock', 'repo'),
  68. output_log_level=logging.WARNING,
  69. borg_local_path='borg1',
  70. extra_environment=None,
  71. )
  72. module.run_arbitrary_borg(
  73. repository='repo', storage_config={}, options=['break-lock'], local_path='borg1',
  74. )
  75. def test_run_arbitrary_borg_with_remote_path_calls_borg_with_remote_path_parameters():
  76. flexmock(module.environment).should_receive('make_environment')
  77. flexmock(module).should_receive('execute_command').with_args(
  78. ('borg', 'break-lock', 'repo', '--remote-path', 'borg1'),
  79. output_log_level=logging.WARNING,
  80. borg_local_path='borg',
  81. extra_environment=None,
  82. )
  83. module.run_arbitrary_borg(
  84. repository='repo', storage_config={}, options=['break-lock'], remote_path='borg1',
  85. )
  86. def test_run_arbitrary_borg_passes_borg_specific_parameters_to_borg():
  87. flexmock(module.environment).should_receive('make_environment')
  88. flexmock(module).should_receive('execute_command').with_args(
  89. ('borg', 'list', 'repo', '--progress'),
  90. output_log_level=logging.WARNING,
  91. borg_local_path='borg',
  92. extra_environment=None,
  93. )
  94. module.run_arbitrary_borg(
  95. repository='repo', storage_config={}, options=['list', '--progress'],
  96. )
  97. def test_run_arbitrary_borg_omits_dash_dash_in_parameters_passed_to_borg():
  98. flexmock(module.environment).should_receive('make_environment')
  99. flexmock(module).should_receive('execute_command').with_args(
  100. ('borg', 'break-lock', 'repo'),
  101. output_log_level=logging.WARNING,
  102. borg_local_path='borg',
  103. extra_environment=None,
  104. )
  105. module.run_arbitrary_borg(
  106. repository='repo', storage_config={}, options=['--', 'break-lock'],
  107. )
  108. def test_run_arbitrary_borg_without_borg_specific_parameters_does_not_raise():
  109. flexmock(module.environment).should_receive('make_environment')
  110. flexmock(module).should_receive('execute_command').with_args(
  111. ('borg',), output_log_level=logging.WARNING, borg_local_path='borg', extra_environment=None,
  112. )
  113. module.run_arbitrary_borg(
  114. repository='repo', storage_config={}, options=[],
  115. )
  116. def test_run_arbitrary_borg_passes_key_sub_command_to_borg_before_repository():
  117. flexmock(module.environment).should_receive('make_environment')
  118. flexmock(module).should_receive('execute_command').with_args(
  119. ('borg', 'key', 'export', 'repo'),
  120. output_log_level=logging.WARNING,
  121. borg_local_path='borg',
  122. extra_environment=None,
  123. )
  124. module.run_arbitrary_borg(
  125. repository='repo', storage_config={}, options=['key', 'export'],
  126. )
  127. def test_run_arbitrary_borg_passes_debug_sub_command_to_borg_before_repository():
  128. flexmock(module.environment).should_receive('make_environment')
  129. flexmock(module).should_receive('execute_command').with_args(
  130. ('borg', 'debug', 'dump-manifest', 'repo', 'path'),
  131. output_log_level=logging.WARNING,
  132. borg_local_path='borg',
  133. extra_environment=None,
  134. )
  135. module.run_arbitrary_borg(
  136. repository='repo', storage_config={}, options=['debug', 'dump-manifest', 'path'],
  137. )
  138. def test_run_arbitrary_borg_with_debug_info_command_does_not_pass_borg_repository():
  139. flexmock(module.environment).should_receive('make_environment')
  140. flexmock(module).should_receive('execute_command').with_args(
  141. ('borg', 'debug', 'info'),
  142. output_log_level=logging.WARNING,
  143. borg_local_path='borg',
  144. extra_environment=None,
  145. )
  146. module.run_arbitrary_borg(
  147. repository='repo', storage_config={}, options=['debug', 'info'],
  148. )
  149. def test_run_arbitrary_borg_with_debug_convert_profile_command_does_not_pass_borg_repository():
  150. flexmock(module.environment).should_receive('make_environment')
  151. flexmock(module).should_receive('execute_command').with_args(
  152. ('borg', 'debug', 'convert-profile', 'in', 'out'),
  153. output_log_level=logging.WARNING,
  154. borg_local_path='borg',
  155. extra_environment=None,
  156. )
  157. module.run_arbitrary_borg(
  158. repository='repo', storage_config={}, options=['debug', 'convert-profile', 'in', 'out'],
  159. )