test_borgmatic.py 66 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626
  1. import logging
  2. import subprocess
  3. import time
  4. import pytest
  5. from flexmock import flexmock
  6. import borgmatic.hooks.command
  7. from borgmatic.commands import borgmatic as module
  8. @pytest.mark.parametrize(
  9. 'config,arguments,expected_actions',
  10. (
  11. ({}, {}, []),
  12. ({'skip_actions': []}, {}, []),
  13. ({'skip_actions': ['prune', 'check']}, {}, ['prune', 'check']),
  14. (
  15. {'skip_actions': ['prune', 'check']},
  16. {'check': flexmock(force=False)},
  17. ['prune', 'check'],
  18. ),
  19. ({'skip_actions': ['prune', 'check']}, {'check': flexmock(force=True)}, ['prune']),
  20. ),
  21. )
  22. def test_get_skip_actions_uses_config_and_arguments(config, arguments, expected_actions):
  23. assert module.get_skip_actions(config, arguments) == expected_actions
  24. def test_run_configuration_runs_actions_for_each_repository():
  25. flexmock(module).should_receive('verbosity_to_log_level').and_return(logging.INFO)
  26. flexmock(module).should_receive('get_skip_actions').and_return([])
  27. flexmock(module.borg_version).should_receive('local_borg_version').and_return(flexmock())
  28. expected_results = [flexmock(), flexmock()]
  29. flexmock(module).should_receive('Log_prefix').and_return(flexmock())
  30. flexmock(module).should_receive('run_actions').and_return(expected_results[:1]).and_return(
  31. expected_results[1:]
  32. )
  33. config = {'repositories': [{'path': 'foo'}, {'path': 'bar'}]}
  34. arguments = {'global': flexmock(monitoring_verbosity=1)}
  35. results = list(module.run_configuration('test.yaml', config, ['/tmp/test.yaml'], arguments))
  36. assert results == expected_results
  37. def test_run_configuration_with_skip_actions_does_not_raise():
  38. flexmock(module).should_receive('verbosity_to_log_level').and_return(logging.INFO)
  39. flexmock(module).should_receive('get_skip_actions').and_return(['compact'])
  40. flexmock(module.borg_version).should_receive('local_borg_version').and_return(flexmock())
  41. flexmock(module).should_receive('Log_prefix').and_return(flexmock())
  42. flexmock(module).should_receive('run_actions').and_return(flexmock()).and_return(flexmock())
  43. config = {'repositories': [{'path': 'foo'}, {'path': 'bar'}], 'skip_actions': ['compact']}
  44. arguments = {'global': flexmock(monitoring_verbosity=1)}
  45. list(module.run_configuration('test.yaml', config, ['/tmp/test.yaml'], arguments))
  46. def test_run_configuration_with_invalid_borg_version_errors():
  47. flexmock(module).should_receive('verbosity_to_log_level').and_return(logging.INFO)
  48. flexmock(module).should_receive('get_skip_actions').and_return([])
  49. flexmock(module.borg_version).should_receive('local_borg_version').and_raise(ValueError)
  50. flexmock(module.command).should_receive('execute_hook').never()
  51. flexmock(module.dispatch).should_receive('call_hooks').never()
  52. flexmock(module).should_receive('Log_prefix').and_return(flexmock())
  53. flexmock(module).should_receive('run_actions').never()
  54. config = {'repositories': [{'path': 'foo'}]}
  55. arguments = {'global': flexmock(monitoring_verbosity=1, dry_run=False), 'prune': flexmock()}
  56. list(module.run_configuration('test.yaml', config, ['/tmp/test.yaml'], arguments))
  57. def test_run_configuration_logs_monitor_start_error():
  58. flexmock(module).should_receive('verbosity_to_log_level').and_return(logging.INFO)
  59. flexmock(module).should_receive('get_skip_actions').and_return([])
  60. flexmock(module.borg_version).should_receive('local_borg_version').and_return(flexmock())
  61. flexmock(module.dispatch).should_receive('call_hooks').and_raise(OSError).and_return(
  62. None
  63. ).and_return(None).and_return(None)
  64. expected_results = [flexmock()]
  65. flexmock(module).should_receive('log_error_records').and_return(expected_results)
  66. flexmock(module).should_receive('Log_prefix').and_return(flexmock())
  67. flexmock(module).should_receive('run_actions').never()
  68. config = {'repositories': [{'path': 'foo'}]}
  69. arguments = {'global': flexmock(monitoring_verbosity=1, dry_run=False), 'create': flexmock()}
  70. results = list(module.run_configuration('test.yaml', config, ['/tmp/test.yaml'], arguments))
  71. assert results == expected_results
  72. def test_run_configuration_bails_for_monitor_start_soft_failure():
  73. flexmock(module).should_receive('verbosity_to_log_level').and_return(logging.INFO)
  74. flexmock(module).should_receive('get_skip_actions').and_return([])
  75. flexmock(module.borg_version).should_receive('local_borg_version').and_return(flexmock())
  76. error = subprocess.CalledProcessError(borgmatic.hooks.command.SOFT_FAIL_EXIT_CODE, 'try again')
  77. flexmock(module.dispatch).should_receive('call_hooks').and_raise(error).and_return(None)
  78. flexmock(module).should_receive('log_error_records').never()
  79. flexmock(module).should_receive('Log_prefix').and_return(flexmock())
  80. flexmock(module).should_receive('run_actions').never()
  81. config = {'repositories': [{'path': 'foo'}, {'path': 'bar'}]}
  82. arguments = {'global': flexmock(monitoring_verbosity=1, dry_run=False), 'create': flexmock()}
  83. results = list(module.run_configuration('test.yaml', config, ['/tmp/test.yaml'], arguments))
  84. assert results == []
  85. def test_run_configuration_logs_actions_error():
  86. flexmock(module).should_receive('verbosity_to_log_level').and_return(logging.INFO)
  87. flexmock(module).should_receive('get_skip_actions').and_return([])
  88. flexmock(module.borg_version).should_receive('local_borg_version').and_return(flexmock())
  89. flexmock(module.command).should_receive('execute_hook')
  90. flexmock(module.dispatch).should_receive('call_hooks')
  91. expected_results = [flexmock()]
  92. flexmock(module).should_receive('log_error_records').and_return(expected_results)
  93. flexmock(module).should_receive('Log_prefix').and_return(flexmock())
  94. flexmock(module).should_receive('run_actions').and_raise(OSError)
  95. config = {'repositories': [{'path': 'foo'}]}
  96. arguments = {'global': flexmock(monitoring_verbosity=1, dry_run=False)}
  97. results = list(module.run_configuration('test.yaml', config, ['/tmp/test.yaml'], arguments))
  98. assert results == expected_results
  99. def test_run_configuration_skips_remaining_actions_for_actions_soft_failure_but_still_runs_next_repository_actions():
  100. flexmock(module).should_receive('verbosity_to_log_level').and_return(logging.INFO)
  101. flexmock(module).should_receive('get_skip_actions').and_return([])
  102. flexmock(module.borg_version).should_receive('local_borg_version').and_return(flexmock())
  103. flexmock(module.dispatch).should_receive('call_hooks').times(5)
  104. error = subprocess.CalledProcessError(borgmatic.hooks.command.SOFT_FAIL_EXIT_CODE, 'try again')
  105. log = flexmock()
  106. flexmock(module).should_receive('Log_prefix').and_return(flexmock())
  107. flexmock(module).should_receive('run_actions').twice().and_raise(error).and_yield(log)
  108. flexmock(module).should_receive('log_error_records').never()
  109. flexmock(module.command).should_receive('considered_soft_failure').and_return(True)
  110. config = {'repositories': [{'path': 'foo'}, {'path': 'bar'}]}
  111. arguments = {'global': flexmock(monitoring_verbosity=1, dry_run=False), 'create': flexmock()}
  112. results = list(module.run_configuration('test.yaml', config, ['/tmp/test.yaml'], arguments))
  113. assert results == [log]
  114. def test_run_configuration_logs_monitor_log_error():
  115. flexmock(module).should_receive('verbosity_to_log_level').and_return(logging.INFO)
  116. flexmock(module).should_receive('get_skip_actions').and_return([])
  117. flexmock(module.borg_version).should_receive('local_borg_version').and_return(flexmock())
  118. flexmock(module.dispatch).should_receive('call_hooks').and_return(None).and_return(
  119. None
  120. ).and_raise(OSError)
  121. expected_results = [flexmock()]
  122. flexmock(module).should_receive('log_error_records').and_return(expected_results)
  123. flexmock(module).should_receive('Log_prefix').and_return(flexmock())
  124. flexmock(module).should_receive('run_actions').and_return([])
  125. config = {'repositories': [{'path': 'foo'}]}
  126. arguments = {'global': flexmock(monitoring_verbosity=1, dry_run=False), 'create': flexmock()}
  127. results = list(module.run_configuration('test.yaml', config, ['/tmp/test.yaml'], arguments))
  128. assert results == expected_results
  129. def test_run_configuration_still_pings_monitor_for_monitor_log_soft_failure():
  130. flexmock(module).should_receive('verbosity_to_log_level').and_return(logging.INFO)
  131. flexmock(module).should_receive('get_skip_actions').and_return([])
  132. flexmock(module.borg_version).should_receive('local_borg_version').and_return(flexmock())
  133. error = subprocess.CalledProcessError(borgmatic.hooks.command.SOFT_FAIL_EXIT_CODE, 'try again')
  134. flexmock(module.dispatch).should_receive('call_hooks').and_return(None).and_return(
  135. None
  136. ).and_raise(error).and_return(None).and_return(None).times(5)
  137. flexmock(module).should_receive('log_error_records').never()
  138. flexmock(module).should_receive('Log_prefix').and_return(flexmock())
  139. flexmock(module).should_receive('run_actions').and_return([])
  140. flexmock(module.command).should_receive('considered_soft_failure').and_return(True)
  141. config = {'repositories': [{'path': 'foo'}]}
  142. arguments = {'global': flexmock(monitoring_verbosity=1, dry_run=False), 'create': flexmock()}
  143. results = list(module.run_configuration('test.yaml', config, ['/tmp/test.yaml'], arguments))
  144. assert results == []
  145. def test_run_configuration_logs_monitor_finish_error():
  146. flexmock(module).should_receive('verbosity_to_log_level').and_return(logging.INFO)
  147. flexmock(module).should_receive('get_skip_actions').and_return([])
  148. flexmock(module.borg_version).should_receive('local_borg_version').and_return(flexmock())
  149. flexmock(module.dispatch).should_receive('call_hooks').and_return(None).and_return(
  150. None
  151. ).and_return(None).and_raise(OSError)
  152. expected_results = [flexmock()]
  153. flexmock(module).should_receive('log_error_records').and_return(expected_results)
  154. flexmock(module).should_receive('Log_prefix').and_return(flexmock())
  155. flexmock(module).should_receive('run_actions').and_return([])
  156. config = {'repositories': [{'path': 'foo'}]}
  157. arguments = {'global': flexmock(monitoring_verbosity=1, dry_run=False), 'create': flexmock()}
  158. results = list(module.run_configuration('test.yaml', config, ['/tmp/test.yaml'], arguments))
  159. assert results == expected_results
  160. def test_run_configuration_bails_for_monitor_finish_soft_failure():
  161. flexmock(module).should_receive('verbosity_to_log_level').and_return(logging.INFO)
  162. flexmock(module).should_receive('get_skip_actions').and_return([])
  163. flexmock(module.borg_version).should_receive('local_borg_version').and_return(flexmock())
  164. error = subprocess.CalledProcessError(borgmatic.hooks.command.SOFT_FAIL_EXIT_CODE, 'try again')
  165. flexmock(module.dispatch).should_receive('call_hooks').and_return(None).and_return(
  166. None
  167. ).and_raise(None).and_raise(error)
  168. flexmock(module).should_receive('log_error_records').never()
  169. flexmock(module).should_receive('Log_prefix').and_return(flexmock())
  170. flexmock(module).should_receive('run_actions').and_return([])
  171. flexmock(module.command).should_receive('considered_soft_failure').and_return(True)
  172. config = {'repositories': [{'path': 'foo'}]}
  173. arguments = {'global': flexmock(monitoring_verbosity=1, dry_run=False), 'create': flexmock()}
  174. results = list(module.run_configuration('test.yaml', config, ['/tmp/test.yaml'], arguments))
  175. assert results == []
  176. def test_run_configuration_does_not_call_monitoring_hooks_if_monitoring_hooks_are_disabled():
  177. flexmock(module).should_receive('verbosity_to_log_level').and_return(module.DISABLED)
  178. flexmock(module).should_receive('get_skip_actions').and_return([])
  179. flexmock(module.borg_version).should_receive('local_borg_version').and_return(flexmock())
  180. flexmock(module.dispatch).should_receive('call_hooks').never()
  181. flexmock(module).should_receive('Log_prefix').and_return(flexmock())
  182. flexmock(module).should_receive('run_actions').and_return([])
  183. config = {'repositories': [{'path': 'foo'}]}
  184. arguments = {'global': flexmock(monitoring_verbosity=-2, dry_run=False), 'create': flexmock()}
  185. results = list(module.run_configuration('test.yaml', config, ['/tmp/test.yaml'], arguments))
  186. assert results == []
  187. def test_run_configuration_logs_on_error_hook_error():
  188. flexmock(module).should_receive('verbosity_to_log_level').and_return(logging.INFO)
  189. flexmock(module).should_receive('get_skip_actions').and_return([])
  190. flexmock(module.borg_version).should_receive('local_borg_version').and_return(flexmock())
  191. flexmock(module.command).should_receive('execute_hook').and_raise(OSError)
  192. expected_results = [flexmock(), flexmock()]
  193. flexmock(module).should_receive('log_error_records').and_return(
  194. expected_results[:1]
  195. ).and_return(expected_results[1:])
  196. flexmock(module).should_receive('Log_prefix').and_return(flexmock())
  197. flexmock(module).should_receive('run_actions').and_raise(OSError)
  198. config = {'repositories': [{'path': 'foo'}]}
  199. arguments = {'global': flexmock(monitoring_verbosity=1, dry_run=False), 'create': flexmock()}
  200. results = list(module.run_configuration('test.yaml', config, ['/tmp/test.yaml'], arguments))
  201. assert results == expected_results
  202. def test_run_configuration_bails_for_on_error_hook_soft_failure():
  203. flexmock(module).should_receive('verbosity_to_log_level').and_return(logging.INFO)
  204. flexmock(module).should_receive('get_skip_actions').and_return([])
  205. flexmock(module.borg_version).should_receive('local_borg_version').and_return(flexmock())
  206. error = subprocess.CalledProcessError(borgmatic.hooks.command.SOFT_FAIL_EXIT_CODE, 'try again')
  207. flexmock(module.command).should_receive('execute_hook').and_raise(error)
  208. expected_results = [flexmock()]
  209. flexmock(module).should_receive('log_error_records').and_return(expected_results)
  210. flexmock(module).should_receive('Log_prefix').and_return(flexmock())
  211. flexmock(module).should_receive('run_actions').and_raise(OSError)
  212. config = {'repositories': [{'path': 'foo'}]}
  213. arguments = {'global': flexmock(monitoring_verbosity=1, dry_run=False), 'create': flexmock()}
  214. results = list(module.run_configuration('test.yaml', config, ['/tmp/test.yaml'], arguments))
  215. assert results == expected_results
  216. def test_run_configuration_retries_soft_error():
  217. # Run action first fails, second passes.
  218. flexmock(module).should_receive('verbosity_to_log_level').and_return(logging.INFO)
  219. flexmock(module).should_receive('get_skip_actions').and_return([])
  220. flexmock(module.borg_version).should_receive('local_borg_version').and_return(flexmock())
  221. flexmock(module.command).should_receive('execute_hook')
  222. flexmock(module).should_receive('Log_prefix').and_return(flexmock())
  223. flexmock(module).should_receive('run_actions').and_raise(OSError).and_return([])
  224. flexmock(module).should_receive('log_error_records').and_return([flexmock()]).once()
  225. config = {'repositories': [{'path': 'foo'}], 'retries': 1}
  226. arguments = {'global': flexmock(monitoring_verbosity=1, dry_run=False), 'create': flexmock()}
  227. results = list(module.run_configuration('test.yaml', config, ['/tmp/test.yaml'], arguments))
  228. assert results == []
  229. def test_run_configuration_retries_hard_error():
  230. # Run action fails twice.
  231. flexmock(module).should_receive('verbosity_to_log_level').and_return(logging.INFO)
  232. flexmock(module).should_receive('get_skip_actions').and_return([])
  233. flexmock(module.borg_version).should_receive('local_borg_version').and_return(flexmock())
  234. flexmock(module.command).should_receive('execute_hook')
  235. flexmock(module).should_receive('Log_prefix').and_return(flexmock())
  236. flexmock(module).should_receive('run_actions').and_raise(OSError).times(2)
  237. flexmock(module).should_receive('log_error_records').with_args(
  238. 'Error running actions for repository',
  239. OSError,
  240. levelno=logging.WARNING,
  241. log_command_error_output=True,
  242. ).and_return([flexmock()])
  243. error_logs = [flexmock()]
  244. flexmock(module).should_receive('log_error_records').with_args(
  245. 'Error running actions for repository',
  246. OSError,
  247. ).and_return(error_logs)
  248. config = {'repositories': [{'path': 'foo'}], 'retries': 1}
  249. arguments = {'global': flexmock(monitoring_verbosity=1, dry_run=False), 'create': flexmock()}
  250. results = list(module.run_configuration('test.yaml', config, ['/tmp/test.yaml'], arguments))
  251. assert results == error_logs
  252. def test_run_configuration_repos_ordered():
  253. flexmock(module).should_receive('verbosity_to_log_level').and_return(logging.INFO)
  254. flexmock(module).should_receive('get_skip_actions').and_return([])
  255. flexmock(module.borg_version).should_receive('local_borg_version').and_return(flexmock())
  256. flexmock(module.command).should_receive('execute_hook')
  257. flexmock(module).should_receive('Log_prefix').and_return(flexmock())
  258. flexmock(module).should_receive('run_actions').and_raise(OSError).times(2)
  259. expected_results = [flexmock(), flexmock()]
  260. flexmock(module).should_receive('log_error_records').with_args(
  261. 'Error running actions for repository', OSError
  262. ).and_return(expected_results[:1]).ordered()
  263. flexmock(module).should_receive('log_error_records').with_args(
  264. 'Error running actions for repository', OSError
  265. ).and_return(expected_results[1:]).ordered()
  266. config = {'repositories': [{'path': 'foo'}, {'path': 'bar'}]}
  267. arguments = {'global': flexmock(monitoring_verbosity=1, dry_run=False), 'create': flexmock()}
  268. results = list(module.run_configuration('test.yaml', config, ['/tmp/test.yaml'], arguments))
  269. assert results == expected_results
  270. def test_run_configuration_retries_round_robin():
  271. flexmock(module).should_receive('verbosity_to_log_level').and_return(logging.INFO)
  272. flexmock(module).should_receive('get_skip_actions').and_return([])
  273. flexmock(module.borg_version).should_receive('local_borg_version').and_return(flexmock())
  274. flexmock(module.command).should_receive('execute_hook')
  275. flexmock(module).should_receive('Log_prefix').and_return(flexmock())
  276. flexmock(module).should_receive('run_actions').and_raise(OSError).times(4)
  277. flexmock(module).should_receive('log_error_records').with_args(
  278. 'Error running actions for repository',
  279. OSError,
  280. levelno=logging.WARNING,
  281. log_command_error_output=True,
  282. ).and_return([flexmock()]).ordered()
  283. flexmock(module).should_receive('log_error_records').with_args(
  284. 'Error running actions for repository',
  285. OSError,
  286. levelno=logging.WARNING,
  287. log_command_error_output=True,
  288. ).and_return([flexmock()]).ordered()
  289. foo_error_logs = [flexmock()]
  290. flexmock(module).should_receive('log_error_records').with_args(
  291. 'Error running actions for repository', OSError
  292. ).and_return(foo_error_logs).ordered()
  293. bar_error_logs = [flexmock()]
  294. flexmock(module).should_receive('log_error_records').with_args(
  295. 'Error running actions for repository', OSError
  296. ).and_return(bar_error_logs).ordered()
  297. config = {
  298. 'repositories': [{'path': 'foo'}, {'path': 'bar'}],
  299. 'retries': 1,
  300. }
  301. arguments = {'global': flexmock(monitoring_verbosity=1, dry_run=False), 'create': flexmock()}
  302. results = list(module.run_configuration('test.yaml', config, ['/tmp/test.yaml'], arguments))
  303. assert results == foo_error_logs + bar_error_logs
  304. def test_run_configuration_retries_one_passes():
  305. flexmock(module).should_receive('verbosity_to_log_level').and_return(logging.INFO)
  306. flexmock(module).should_receive('get_skip_actions').and_return([])
  307. flexmock(module.borg_version).should_receive('local_borg_version').and_return(flexmock())
  308. flexmock(module.command).should_receive('execute_hook')
  309. flexmock(module).should_receive('Log_prefix').and_return(flexmock())
  310. flexmock(module).should_receive('run_actions').and_raise(OSError).and_raise(OSError).and_return(
  311. []
  312. ).and_raise(OSError).times(4)
  313. flexmock(module).should_receive('log_error_records').with_args(
  314. 'Error running actions for repository',
  315. OSError,
  316. levelno=logging.WARNING,
  317. log_command_error_output=True,
  318. ).and_return([flexmock()]).ordered()
  319. flexmock(module).should_receive('log_error_records').with_args(
  320. 'Error running actions for repository',
  321. OSError,
  322. levelno=logging.WARNING,
  323. log_command_error_output=True,
  324. ).and_return(flexmock()).ordered()
  325. error_logs = [flexmock()]
  326. flexmock(module).should_receive('log_error_records').with_args(
  327. 'Error running actions for repository', OSError
  328. ).and_return(error_logs).ordered()
  329. config = {
  330. 'repositories': [{'path': 'foo'}, {'path': 'bar'}],
  331. 'retries': 1,
  332. }
  333. arguments = {'global': flexmock(monitoring_verbosity=1, dry_run=False), 'create': flexmock()}
  334. results = list(module.run_configuration('test.yaml', config, ['/tmp/test.yaml'], arguments))
  335. assert results == error_logs
  336. def test_run_configuration_retry_wait():
  337. flexmock(module).should_receive('verbosity_to_log_level').and_return(logging.INFO)
  338. flexmock(module).should_receive('get_skip_actions').and_return([])
  339. flexmock(module.borg_version).should_receive('local_borg_version').and_return(flexmock())
  340. flexmock(module.command).should_receive('execute_hook')
  341. flexmock(module).should_receive('Log_prefix').and_return(flexmock())
  342. flexmock(module).should_receive('run_actions').and_raise(OSError).times(4)
  343. flexmock(module).should_receive('log_error_records').with_args(
  344. 'Error running actions for repository',
  345. OSError,
  346. levelno=logging.WARNING,
  347. log_command_error_output=True,
  348. ).and_return([flexmock()]).ordered()
  349. flexmock(time).should_receive('sleep').with_args(10).and_return().ordered()
  350. flexmock(module).should_receive('log_error_records').with_args(
  351. 'Error running actions for repository',
  352. OSError,
  353. levelno=logging.WARNING,
  354. log_command_error_output=True,
  355. ).and_return([flexmock()]).ordered()
  356. flexmock(time).should_receive('sleep').with_args(20).and_return().ordered()
  357. flexmock(module).should_receive('log_error_records').with_args(
  358. 'Error running actions for repository',
  359. OSError,
  360. levelno=logging.WARNING,
  361. log_command_error_output=True,
  362. ).and_return([flexmock()]).ordered()
  363. flexmock(time).should_receive('sleep').with_args(30).and_return().ordered()
  364. error_logs = [flexmock()]
  365. flexmock(module).should_receive('log_error_records').with_args(
  366. 'Error running actions for repository', OSError
  367. ).and_return(error_logs).ordered()
  368. config = {
  369. 'repositories': [{'path': 'foo'}],
  370. 'retries': 3,
  371. 'retry_wait': 10,
  372. }
  373. arguments = {'global': flexmock(monitoring_verbosity=1, dry_run=False), 'create': flexmock()}
  374. results = list(module.run_configuration('test.yaml', config, ['/tmp/test.yaml'], arguments))
  375. assert results == error_logs
  376. def test_run_configuration_retries_timeout_multiple_repos():
  377. flexmock(module).should_receive('verbosity_to_log_level').and_return(logging.INFO)
  378. flexmock(module).should_receive('get_skip_actions').and_return([])
  379. flexmock(module.borg_version).should_receive('local_borg_version').and_return(flexmock())
  380. flexmock(module.command).should_receive('execute_hook')
  381. flexmock(module).should_receive('Log_prefix').and_return(flexmock())
  382. flexmock(module).should_receive('run_actions').and_raise(OSError).and_raise(OSError).and_return(
  383. []
  384. ).and_raise(OSError).times(4)
  385. flexmock(module).should_receive('log_error_records').with_args(
  386. 'Error running actions for repository',
  387. OSError,
  388. levelno=logging.WARNING,
  389. log_command_error_output=True,
  390. ).and_return([flexmock()]).ordered()
  391. flexmock(module).should_receive('log_error_records').with_args(
  392. 'Error running actions for repository',
  393. OSError,
  394. levelno=logging.WARNING,
  395. log_command_error_output=True,
  396. ).and_return([flexmock()]).ordered()
  397. # Sleep before retrying foo (and passing)
  398. flexmock(time).should_receive('sleep').with_args(10).and_return().ordered()
  399. # Sleep before retrying bar (and failing)
  400. flexmock(time).should_receive('sleep').with_args(10).and_return().ordered()
  401. error_logs = [flexmock()]
  402. flexmock(module).should_receive('log_error_records').with_args(
  403. 'Error running actions for repository', OSError
  404. ).and_return(error_logs).ordered()
  405. config = {
  406. 'repositories': [{'path': 'foo'}, {'path': 'bar'}],
  407. 'retries': 1,
  408. 'retry_wait': 10,
  409. }
  410. arguments = {'global': flexmock(monitoring_verbosity=1, dry_run=False), 'create': flexmock()}
  411. results = list(module.run_configuration('test.yaml', config, ['/tmp/test.yaml'], arguments))
  412. assert results == error_logs
  413. def test_run_actions_runs_repo_create():
  414. flexmock(module).should_receive('add_custom_log_levels')
  415. flexmock(module).should_receive('get_skip_actions').and_return([])
  416. flexmock(module.command).should_receive('execute_hook')
  417. flexmock(borgmatic.actions.repo_create).should_receive('run_repo_create').once()
  418. tuple(
  419. module.run_actions(
  420. arguments={
  421. 'global': flexmock(dry_run=False, log_file='foo'),
  422. 'repo-create': flexmock(),
  423. },
  424. config_filename=flexmock(),
  425. config={'repositories': []},
  426. config_paths=[],
  427. local_path=flexmock(),
  428. remote_path=flexmock(),
  429. local_borg_version=flexmock(),
  430. repository={'path': 'repo'},
  431. )
  432. )
  433. def test_run_actions_adds_label_file_to_hook_context():
  434. flexmock(module).should_receive('add_custom_log_levels')
  435. flexmock(module).should_receive('get_skip_actions').and_return([])
  436. flexmock(module.command).should_receive('execute_hook')
  437. expected = flexmock()
  438. flexmock(borgmatic.actions.create).should_receive('run_create').with_args(
  439. config_filename=object,
  440. repository={'path': 'repo', 'label': 'my repo'},
  441. config={'repositories': []},
  442. config_paths=[],
  443. hook_context={
  444. 'repository_label': 'my repo',
  445. 'log_file': '',
  446. 'repositories': '',
  447. 'repository': 'repo',
  448. },
  449. local_borg_version=object,
  450. create_arguments=object,
  451. global_arguments=object,
  452. dry_run_label='',
  453. local_path=object,
  454. remote_path=object,
  455. ).once().and_return(expected)
  456. result = tuple(
  457. module.run_actions(
  458. arguments={'global': flexmock(dry_run=False, log_file=None), 'create': flexmock()},
  459. config_filename=flexmock(),
  460. config={'repositories': []},
  461. config_paths=[],
  462. local_path=flexmock(),
  463. remote_path=flexmock(),
  464. local_borg_version=flexmock(),
  465. repository={'path': 'repo', 'label': 'my repo'},
  466. )
  467. )
  468. assert result == (expected,)
  469. def test_run_actions_adds_log_file_to_hook_context():
  470. flexmock(module).should_receive('add_custom_log_levels')
  471. flexmock(module).should_receive('get_skip_actions').and_return([])
  472. flexmock(module.command).should_receive('execute_hook')
  473. expected = flexmock()
  474. flexmock(borgmatic.actions.create).should_receive('run_create').with_args(
  475. config_filename=object,
  476. repository={'path': 'repo'},
  477. config={'repositories': []},
  478. config_paths=[],
  479. hook_context={
  480. 'repository_label': '',
  481. 'log_file': 'foo',
  482. 'repositories': '',
  483. 'repository': 'repo',
  484. },
  485. local_borg_version=object,
  486. create_arguments=object,
  487. global_arguments=object,
  488. dry_run_label='',
  489. local_path=object,
  490. remote_path=object,
  491. ).once().and_return(expected)
  492. result = tuple(
  493. module.run_actions(
  494. arguments={'global': flexmock(dry_run=False, log_file='foo'), 'create': flexmock()},
  495. config_filename=flexmock(),
  496. config={'repositories': []},
  497. config_paths=[],
  498. local_path=flexmock(),
  499. remote_path=flexmock(),
  500. local_borg_version=flexmock(),
  501. repository={'path': 'repo'},
  502. )
  503. )
  504. assert result == (expected,)
  505. def test_run_actions_runs_transfer():
  506. flexmock(module).should_receive('add_custom_log_levels')
  507. flexmock(module).should_receive('get_skip_actions').and_return([])
  508. flexmock(module.command).should_receive('execute_hook')
  509. flexmock(borgmatic.actions.transfer).should_receive('run_transfer').once()
  510. tuple(
  511. module.run_actions(
  512. arguments={'global': flexmock(dry_run=False, log_file='foo'), 'transfer': flexmock()},
  513. config_filename=flexmock(),
  514. config={'repositories': []},
  515. config_paths=[],
  516. local_path=flexmock(),
  517. remote_path=flexmock(),
  518. local_borg_version=flexmock(),
  519. repository={'path': 'repo'},
  520. )
  521. )
  522. def test_run_actions_runs_create():
  523. flexmock(module).should_receive('add_custom_log_levels')
  524. flexmock(module).should_receive('get_skip_actions').and_return([])
  525. flexmock(module.command).should_receive('execute_hook')
  526. expected = flexmock()
  527. flexmock(borgmatic.actions.create).should_receive('run_create').and_yield(expected).once()
  528. result = tuple(
  529. module.run_actions(
  530. arguments={'global': flexmock(dry_run=False, log_file='foo'), 'create': flexmock()},
  531. config_filename=flexmock(),
  532. config={'repositories': []},
  533. config_paths=[],
  534. local_path=flexmock(),
  535. remote_path=flexmock(),
  536. local_borg_version=flexmock(),
  537. repository={'path': 'repo'},
  538. )
  539. )
  540. assert result == (expected,)
  541. def test_run_actions_with_skip_actions_skips_create():
  542. flexmock(module).should_receive('add_custom_log_levels')
  543. flexmock(module).should_receive('get_skip_actions').and_return(['create'])
  544. flexmock(module.command).should_receive('execute_hook')
  545. flexmock(borgmatic.actions.create).should_receive('run_create').never()
  546. tuple(
  547. module.run_actions(
  548. arguments={'global': flexmock(dry_run=False, log_file='foo'), 'create': flexmock()},
  549. config_filename=flexmock(),
  550. config={'repositories': [], 'skip_actions': ['create']},
  551. config_paths=[],
  552. local_path=flexmock(),
  553. remote_path=flexmock(),
  554. local_borg_version=flexmock(),
  555. repository={'path': 'repo'},
  556. )
  557. )
  558. def test_run_actions_runs_prune():
  559. flexmock(module).should_receive('add_custom_log_levels')
  560. flexmock(module).should_receive('get_skip_actions').and_return([])
  561. flexmock(module.command).should_receive('execute_hook')
  562. flexmock(borgmatic.actions.prune).should_receive('run_prune').once()
  563. tuple(
  564. module.run_actions(
  565. arguments={'global': flexmock(dry_run=False, log_file='foo'), 'prune': flexmock()},
  566. config_filename=flexmock(),
  567. config={'repositories': []},
  568. config_paths=[],
  569. local_path=flexmock(),
  570. remote_path=flexmock(),
  571. local_borg_version=flexmock(),
  572. repository={'path': 'repo'},
  573. )
  574. )
  575. def test_run_actions_with_skip_actions_skips_prune():
  576. flexmock(module).should_receive('add_custom_log_levels')
  577. flexmock(module).should_receive('get_skip_actions').and_return(['prune'])
  578. flexmock(module.command).should_receive('execute_hook')
  579. flexmock(borgmatic.actions.prune).should_receive('run_prune').never()
  580. tuple(
  581. module.run_actions(
  582. arguments={'global': flexmock(dry_run=False, log_file='foo'), 'prune': flexmock()},
  583. config_filename=flexmock(),
  584. config={'repositories': [], 'skip_actions': ['prune']},
  585. config_paths=[],
  586. local_path=flexmock(),
  587. remote_path=flexmock(),
  588. local_borg_version=flexmock(),
  589. repository={'path': 'repo'},
  590. )
  591. )
  592. def test_run_actions_runs_compact():
  593. flexmock(module).should_receive('add_custom_log_levels')
  594. flexmock(module).should_receive('get_skip_actions').and_return([])
  595. flexmock(module.command).should_receive('execute_hook')
  596. flexmock(borgmatic.actions.compact).should_receive('run_compact').once()
  597. tuple(
  598. module.run_actions(
  599. arguments={'global': flexmock(dry_run=False, log_file='foo'), 'compact': flexmock()},
  600. config_filename=flexmock(),
  601. config={'repositories': []},
  602. config_paths=[],
  603. local_path=flexmock(),
  604. remote_path=flexmock(),
  605. local_borg_version=flexmock(),
  606. repository={'path': 'repo'},
  607. )
  608. )
  609. def test_run_actions_with_skip_actions_skips_compact():
  610. flexmock(module).should_receive('add_custom_log_levels')
  611. flexmock(module).should_receive('get_skip_actions').and_return(['compact'])
  612. flexmock(module.command).should_receive('execute_hook')
  613. flexmock(borgmatic.actions.compact).should_receive('run_compact').never()
  614. tuple(
  615. module.run_actions(
  616. arguments={'global': flexmock(dry_run=False, log_file='foo'), 'compact': flexmock()},
  617. config_filename=flexmock(),
  618. config={'repositories': [], 'skip_actions': ['compact']},
  619. config_paths=[],
  620. local_path=flexmock(),
  621. remote_path=flexmock(),
  622. local_borg_version=flexmock(),
  623. repository={'path': 'repo'},
  624. )
  625. )
  626. def test_run_actions_runs_check_when_repository_enabled_for_checks():
  627. flexmock(module).should_receive('add_custom_log_levels')
  628. flexmock(module).should_receive('get_skip_actions').and_return([])
  629. flexmock(module.command).should_receive('execute_hook')
  630. flexmock(module.checks).should_receive('repository_enabled_for_checks').and_return(True)
  631. flexmock(borgmatic.actions.check).should_receive('run_check').once()
  632. tuple(
  633. module.run_actions(
  634. arguments={'global': flexmock(dry_run=False, log_file='foo'), 'check': flexmock()},
  635. config_filename=flexmock(),
  636. config={'repositories': []},
  637. config_paths=[],
  638. local_path=flexmock(),
  639. remote_path=flexmock(),
  640. local_borg_version=flexmock(),
  641. repository={'path': 'repo'},
  642. )
  643. )
  644. def test_run_actions_skips_check_when_repository_not_enabled_for_checks():
  645. flexmock(module).should_receive('add_custom_log_levels')
  646. flexmock(module).should_receive('get_skip_actions').and_return([])
  647. flexmock(module.command).should_receive('execute_hook')
  648. flexmock(module.checks).should_receive('repository_enabled_for_checks').and_return(False)
  649. flexmock(borgmatic.actions.check).should_receive('run_check').never()
  650. tuple(
  651. module.run_actions(
  652. arguments={'global': flexmock(dry_run=False, log_file='foo'), 'check': flexmock()},
  653. config_filename=flexmock(),
  654. config={'repositories': []},
  655. config_paths=[],
  656. local_path=flexmock(),
  657. remote_path=flexmock(),
  658. local_borg_version=flexmock(),
  659. repository={'path': 'repo'},
  660. )
  661. )
  662. def test_run_actions_with_skip_actions_skips_check():
  663. flexmock(module).should_receive('add_custom_log_levels')
  664. flexmock(module).should_receive('get_skip_actions').and_return(['check'])
  665. flexmock(module.command).should_receive('execute_hook')
  666. flexmock(module.checks).should_receive('repository_enabled_for_checks').and_return(True)
  667. flexmock(borgmatic.actions.check).should_receive('run_check').never()
  668. tuple(
  669. module.run_actions(
  670. arguments={'global': flexmock(dry_run=False, log_file='foo'), 'check': flexmock()},
  671. config_filename=flexmock(),
  672. config={'repositories': [], 'skip_actions': ['check']},
  673. config_paths=[],
  674. local_path=flexmock(),
  675. remote_path=flexmock(),
  676. local_borg_version=flexmock(),
  677. repository={'path': 'repo'},
  678. )
  679. )
  680. def test_run_actions_runs_extract():
  681. flexmock(module).should_receive('add_custom_log_levels')
  682. flexmock(module).should_receive('get_skip_actions').and_return([])
  683. flexmock(module.command).should_receive('execute_hook')
  684. flexmock(borgmatic.actions.extract).should_receive('run_extract').once()
  685. tuple(
  686. module.run_actions(
  687. arguments={'global': flexmock(dry_run=False, log_file='foo'), 'extract': flexmock()},
  688. config_filename=flexmock(),
  689. config={'repositories': []},
  690. config_paths=[],
  691. local_path=flexmock(),
  692. remote_path=flexmock(),
  693. local_borg_version=flexmock(),
  694. repository={'path': 'repo'},
  695. )
  696. )
  697. def test_run_actions_runs_export_tar():
  698. flexmock(module).should_receive('add_custom_log_levels')
  699. flexmock(module).should_receive('get_skip_actions').and_return([])
  700. flexmock(module.command).should_receive('execute_hook')
  701. flexmock(borgmatic.actions.export_tar).should_receive('run_export_tar').once()
  702. tuple(
  703. module.run_actions(
  704. arguments={'global': flexmock(dry_run=False, log_file='foo'), 'export-tar': flexmock()},
  705. config_filename=flexmock(),
  706. config={'repositories': []},
  707. config_paths=[],
  708. local_path=flexmock(),
  709. remote_path=flexmock(),
  710. local_borg_version=flexmock(),
  711. repository={'path': 'repo'},
  712. )
  713. )
  714. def test_run_actions_runs_mount():
  715. flexmock(module).should_receive('add_custom_log_levels')
  716. flexmock(module).should_receive('get_skip_actions').and_return([])
  717. flexmock(module.command).should_receive('execute_hook')
  718. flexmock(borgmatic.actions.mount).should_receive('run_mount').once()
  719. tuple(
  720. module.run_actions(
  721. arguments={'global': flexmock(dry_run=False, log_file='foo'), 'mount': flexmock()},
  722. config_filename=flexmock(),
  723. config={'repositories': []},
  724. config_paths=[],
  725. local_path=flexmock(),
  726. remote_path=flexmock(),
  727. local_borg_version=flexmock(),
  728. repository={'path': 'repo'},
  729. )
  730. )
  731. def test_run_actions_runs_restore():
  732. flexmock(module).should_receive('add_custom_log_levels')
  733. flexmock(module).should_receive('get_skip_actions').and_return([])
  734. flexmock(module.command).should_receive('execute_hook')
  735. flexmock(borgmatic.actions.restore).should_receive('run_restore').once()
  736. tuple(
  737. module.run_actions(
  738. arguments={'global': flexmock(dry_run=False, log_file='foo'), 'restore': flexmock()},
  739. config_filename=flexmock(),
  740. config={'repositories': []},
  741. config_paths=[],
  742. local_path=flexmock(),
  743. remote_path=flexmock(),
  744. local_borg_version=flexmock(),
  745. repository={'path': 'repo'},
  746. )
  747. )
  748. def test_run_actions_runs_repo_list():
  749. flexmock(module).should_receive('add_custom_log_levels')
  750. flexmock(module).should_receive('get_skip_actions').and_return([])
  751. flexmock(module.command).should_receive('execute_hook')
  752. expected = flexmock()
  753. flexmock(borgmatic.actions.repo_list).should_receive('run_repo_list').and_yield(expected).once()
  754. result = tuple(
  755. module.run_actions(
  756. arguments={'global': flexmock(dry_run=False, log_file='foo'), 'repo-list': flexmock()},
  757. config_filename=flexmock(),
  758. config={'repositories': []},
  759. config_paths=[],
  760. local_path=flexmock(),
  761. remote_path=flexmock(),
  762. local_borg_version=flexmock(),
  763. repository={'path': 'repo'},
  764. )
  765. )
  766. assert result == (expected,)
  767. def test_run_actions_runs_list():
  768. flexmock(module).should_receive('add_custom_log_levels')
  769. flexmock(module).should_receive('get_skip_actions').and_return([])
  770. flexmock(module.command).should_receive('execute_hook')
  771. expected = flexmock()
  772. flexmock(borgmatic.actions.list).should_receive('run_list').and_yield(expected).once()
  773. result = tuple(
  774. module.run_actions(
  775. arguments={'global': flexmock(dry_run=False, log_file='foo'), 'list': flexmock()},
  776. config_filename=flexmock(),
  777. config={'repositories': []},
  778. config_paths=[],
  779. local_path=flexmock(),
  780. remote_path=flexmock(),
  781. local_borg_version=flexmock(),
  782. repository={'path': 'repo'},
  783. )
  784. )
  785. assert result == (expected,)
  786. def test_run_actions_runs_repo_info():
  787. flexmock(module).should_receive('add_custom_log_levels')
  788. flexmock(module).should_receive('get_skip_actions').and_return([])
  789. flexmock(module.command).should_receive('execute_hook')
  790. expected = flexmock()
  791. flexmock(borgmatic.actions.repo_info).should_receive('run_repo_info').and_yield(expected).once()
  792. result = tuple(
  793. module.run_actions(
  794. arguments={'global': flexmock(dry_run=False, log_file='foo'), 'repo-info': flexmock()},
  795. config_filename=flexmock(),
  796. config={'repositories': []},
  797. config_paths=[],
  798. local_path=flexmock(),
  799. remote_path=flexmock(),
  800. local_borg_version=flexmock(),
  801. repository={'path': 'repo'},
  802. )
  803. )
  804. assert result == (expected,)
  805. def test_run_actions_runs_info():
  806. flexmock(module).should_receive('add_custom_log_levels')
  807. flexmock(module).should_receive('get_skip_actions').and_return([])
  808. flexmock(module.command).should_receive('execute_hook')
  809. expected = flexmock()
  810. flexmock(borgmatic.actions.info).should_receive('run_info').and_yield(expected).once()
  811. result = tuple(
  812. module.run_actions(
  813. arguments={'global': flexmock(dry_run=False, log_file='foo'), 'info': flexmock()},
  814. config_filename=flexmock(),
  815. config={'repositories': []},
  816. config_paths=[],
  817. local_path=flexmock(),
  818. remote_path=flexmock(),
  819. local_borg_version=flexmock(),
  820. repository={'path': 'repo'},
  821. )
  822. )
  823. assert result == (expected,)
  824. def test_run_actions_runs_break_lock():
  825. flexmock(module).should_receive('add_custom_log_levels')
  826. flexmock(module).should_receive('get_skip_actions').and_return([])
  827. flexmock(module.command).should_receive('execute_hook')
  828. flexmock(borgmatic.actions.break_lock).should_receive('run_break_lock').once()
  829. tuple(
  830. module.run_actions(
  831. arguments={'global': flexmock(dry_run=False, log_file='foo'), 'break-lock': flexmock()},
  832. config_filename=flexmock(),
  833. config={'repositories': []},
  834. config_paths=[],
  835. local_path=flexmock(),
  836. remote_path=flexmock(),
  837. local_borg_version=flexmock(),
  838. repository={'path': 'repo'},
  839. )
  840. )
  841. def test_run_actions_runs_export_key():
  842. flexmock(module).should_receive('add_custom_log_levels')
  843. flexmock(module).should_receive('get_skip_actions').and_return([])
  844. flexmock(module.command).should_receive('execute_hook')
  845. flexmock(borgmatic.actions.export_key).should_receive('run_export_key').once()
  846. tuple(
  847. module.run_actions(
  848. arguments={'global': flexmock(dry_run=False, log_file='foo'), 'export': flexmock()},
  849. config_filename=flexmock(),
  850. config={'repositories': []},
  851. config_paths=[],
  852. local_path=flexmock(),
  853. remote_path=flexmock(),
  854. local_borg_version=flexmock(),
  855. repository={'path': 'repo'},
  856. )
  857. )
  858. def test_run_actions_runs_change_passphrase():
  859. flexmock(module).should_receive('add_custom_log_levels')
  860. flexmock(module).should_receive('get_skip_actions').and_return([])
  861. flexmock(module.command).should_receive('execute_hook')
  862. flexmock(borgmatic.actions.change_passphrase).should_receive('run_change_passphrase').once()
  863. tuple(
  864. module.run_actions(
  865. arguments={
  866. 'global': flexmock(dry_run=False, log_file='foo'),
  867. 'change-passphrase': flexmock(),
  868. },
  869. config_filename=flexmock(),
  870. config={'repositories': []},
  871. config_paths=[],
  872. local_path=flexmock(),
  873. remote_path=flexmock(),
  874. local_borg_version=flexmock(),
  875. repository={'path': 'repo'},
  876. )
  877. )
  878. def test_run_actions_runs_delete():
  879. flexmock(module).should_receive('add_custom_log_levels')
  880. flexmock(module).should_receive('get_skip_actions').and_return([])
  881. flexmock(module.command).should_receive('execute_hook')
  882. flexmock(borgmatic.actions.delete).should_receive('run_delete').once()
  883. tuple(
  884. module.run_actions(
  885. arguments={'global': flexmock(dry_run=False, log_file='foo'), 'delete': flexmock()},
  886. config_filename=flexmock(),
  887. config={'repositories': []},
  888. config_paths=[],
  889. local_path=flexmock(),
  890. remote_path=flexmock(),
  891. local_borg_version=flexmock(),
  892. repository={'path': 'repo'},
  893. )
  894. )
  895. def test_run_actions_runs_repo_delete():
  896. flexmock(module).should_receive('add_custom_log_levels')
  897. flexmock(module).should_receive('get_skip_actions').and_return([])
  898. flexmock(module.command).should_receive('execute_hook')
  899. flexmock(borgmatic.actions.repo_delete).should_receive('run_repo_delete').once()
  900. tuple(
  901. module.run_actions(
  902. arguments={
  903. 'global': flexmock(dry_run=False, log_file='foo'),
  904. 'repo-delete': flexmock(),
  905. },
  906. config_filename=flexmock(),
  907. config={'repositories': []},
  908. config_paths=[],
  909. local_path=flexmock(),
  910. remote_path=flexmock(),
  911. local_borg_version=flexmock(),
  912. repository={'path': 'repo'},
  913. )
  914. )
  915. def test_run_actions_runs_borg():
  916. flexmock(module).should_receive('add_custom_log_levels')
  917. flexmock(module).should_receive('get_skip_actions').and_return([])
  918. flexmock(module.command).should_receive('execute_hook')
  919. flexmock(borgmatic.actions.borg).should_receive('run_borg').once()
  920. tuple(
  921. module.run_actions(
  922. arguments={'global': flexmock(dry_run=False, log_file='foo'), 'borg': flexmock()},
  923. config_filename=flexmock(),
  924. config={'repositories': []},
  925. config_paths=[],
  926. local_path=flexmock(),
  927. remote_path=flexmock(),
  928. local_borg_version=flexmock(),
  929. repository={'path': 'repo'},
  930. )
  931. )
  932. def test_run_actions_runs_multiple_actions_in_argument_order():
  933. flexmock(module).should_receive('add_custom_log_levels')
  934. flexmock(module).should_receive('get_skip_actions').and_return([])
  935. flexmock(module.command).should_receive('execute_hook')
  936. flexmock(borgmatic.actions.borg).should_receive('run_borg').once().ordered()
  937. flexmock(borgmatic.actions.restore).should_receive('run_restore').once().ordered()
  938. tuple(
  939. module.run_actions(
  940. arguments={
  941. 'global': flexmock(dry_run=False, log_file='foo'),
  942. 'borg': flexmock(),
  943. 'restore': flexmock(),
  944. },
  945. config_filename=flexmock(),
  946. config={'repositories': []},
  947. config_paths=[],
  948. local_path=flexmock(),
  949. remote_path=flexmock(),
  950. local_borg_version=flexmock(),
  951. repository={'path': 'repo'},
  952. )
  953. )
  954. @pytest.mark.parametrize(
  955. 'resolve_env',
  956. ((True, False),),
  957. )
  958. def test_load_configurations_collects_parsed_configurations_and_logs(resolve_env):
  959. configuration = flexmock()
  960. other_configuration = flexmock()
  961. test_expected_logs = [flexmock(), flexmock()]
  962. other_expected_logs = [flexmock(), flexmock()]
  963. flexmock(module.validate).should_receive('parse_configuration').and_return(
  964. configuration, ['/tmp/test.yaml'], test_expected_logs
  965. ).and_return(other_configuration, ['/tmp/other.yaml'], other_expected_logs)
  966. configs, config_paths, logs = tuple(
  967. module.load_configurations(
  968. ('test.yaml', 'other.yaml'),
  969. resolve_env=resolve_env,
  970. )
  971. )
  972. assert configs == {'test.yaml': configuration, 'other.yaml': other_configuration}
  973. assert config_paths == ['/tmp/other.yaml', '/tmp/test.yaml']
  974. assert set(logs) >= set(test_expected_logs + other_expected_logs)
  975. def test_load_configurations_logs_warning_for_permission_error():
  976. flexmock(module.validate).should_receive('parse_configuration').and_raise(PermissionError)
  977. configs, config_paths, logs = tuple(module.load_configurations(('test.yaml',)))
  978. assert configs == {}
  979. assert config_paths == []
  980. assert max(log.levelno for log in logs) == logging.WARNING
  981. def test_load_configurations_logs_critical_for_parse_error():
  982. flexmock(module.validate).should_receive('parse_configuration').and_raise(ValueError)
  983. configs, config_paths, logs = tuple(module.load_configurations(('test.yaml',)))
  984. assert configs == {}
  985. assert config_paths == []
  986. assert max(log.levelno for log in logs) == logging.CRITICAL
  987. def test_log_record_does_not_raise():
  988. module.log_record(levelno=1, foo='bar', baz='quux')
  989. def test_log_record_with_suppress_does_not_raise():
  990. module.log_record(levelno=1, foo='bar', baz='quux', suppress_log=True)
  991. def test_log_error_records_generates_output_logs_for_message_only():
  992. flexmock(module).should_receive('log_record').replace_with(dict).once()
  993. logs = tuple(module.log_error_records('Error'))
  994. assert {log['levelno'] for log in logs} == {logging.CRITICAL}
  995. def test_log_error_records_generates_output_logs_for_called_process_error_with_bytes_ouput():
  996. flexmock(module).should_receive('log_record').replace_with(dict).times(3)
  997. flexmock(module.logger).should_receive('getEffectiveLevel').and_return(logging.WARNING)
  998. logs = tuple(
  999. module.log_error_records('Error', subprocess.CalledProcessError(1, 'ls', b'error output'))
  1000. )
  1001. assert {log['levelno'] for log in logs} == {logging.CRITICAL}
  1002. assert any(log for log in logs if 'error output' in str(log))
  1003. def test_log_error_records_generates_output_logs_for_called_process_error_with_string_ouput():
  1004. flexmock(module).should_receive('log_record').replace_with(dict).times(3)
  1005. flexmock(module.logger).should_receive('getEffectiveLevel').and_return(logging.WARNING)
  1006. logs = tuple(
  1007. module.log_error_records('Error', subprocess.CalledProcessError(1, 'ls', 'error output'))
  1008. )
  1009. assert {log['levelno'] for log in logs} == {logging.CRITICAL}
  1010. assert any(log for log in logs if 'error output' in str(log))
  1011. def test_log_error_records_generates_work_around_output_logs_for_called_process_error_with_repository_access_aborted_exit_code():
  1012. flexmock(module).should_receive('log_record').replace_with(dict).times(4)
  1013. flexmock(module.logger).should_receive('getEffectiveLevel').and_return(logging.WARNING)
  1014. logs = tuple(
  1015. module.log_error_records(
  1016. 'Error',
  1017. subprocess.CalledProcessError(
  1018. module.BORG_REPOSITORY_ACCESS_ABORTED_EXIT_CODE, 'ls', 'error output'
  1019. ),
  1020. )
  1021. )
  1022. assert {log['levelno'] for log in logs} == {logging.CRITICAL}
  1023. assert any(log for log in logs if 'error output' in str(log))
  1024. assert any(log for log in logs if 'To work around this' in str(log))
  1025. def test_log_error_records_splits_called_process_error_with_multiline_ouput_into_multiple_logs():
  1026. flexmock(module).should_receive('log_record').replace_with(dict).times(4)
  1027. flexmock(module.logger).should_receive('getEffectiveLevel').and_return(logging.WARNING)
  1028. logs = tuple(
  1029. module.log_error_records(
  1030. 'Error', subprocess.CalledProcessError(1, 'ls', 'error output\nanother line')
  1031. )
  1032. )
  1033. assert {log['levelno'] for log in logs} == {logging.CRITICAL}
  1034. assert any(log for log in logs if 'error output' in str(log))
  1035. def test_log_error_records_generates_logs_for_value_error():
  1036. flexmock(module).should_receive('log_record').replace_with(dict).twice()
  1037. logs = tuple(module.log_error_records('Error', ValueError()))
  1038. assert {log['levelno'] for log in logs} == {logging.CRITICAL}
  1039. def test_log_error_records_generates_logs_for_os_error():
  1040. flexmock(module).should_receive('log_record').replace_with(dict).twice()
  1041. logs = tuple(module.log_error_records('Error', OSError()))
  1042. assert {log['levelno'] for log in logs} == {logging.CRITICAL}
  1043. def test_log_error_records_generates_nothing_for_other_error():
  1044. flexmock(module).should_receive('log_record').never()
  1045. logs = tuple(module.log_error_records('Error', KeyError()))
  1046. assert logs == ()
  1047. def test_get_local_path_uses_configuration_value():
  1048. assert module.get_local_path({'test.yaml': {'local_path': 'borg1'}}) == 'borg1'
  1049. def test_get_local_path_without_local_path_defaults_to_borg():
  1050. assert module.get_local_path({'test.yaml': {}}) == 'borg'
  1051. def test_collect_highlander_action_summary_logs_info_for_success_with_bootstrap():
  1052. flexmock(module.borg_version).should_receive('local_borg_version').and_return(flexmock())
  1053. flexmock(module.borgmatic.actions.config.bootstrap).should_receive('run_bootstrap')
  1054. arguments = {
  1055. 'bootstrap': flexmock(repository='repo', local_path='borg7'),
  1056. 'global': flexmock(dry_run=False),
  1057. }
  1058. logs = tuple(
  1059. module.collect_highlander_action_summary_logs(
  1060. {'test.yaml': {}}, arguments=arguments, configuration_parse_errors=False
  1061. )
  1062. )
  1063. assert {log.levelno for log in logs} == {logging.ANSWER}
  1064. def test_collect_highlander_action_summary_logs_error_on_bootstrap_failure():
  1065. flexmock(module.borg_version).should_receive('local_borg_version').and_return(flexmock())
  1066. flexmock(module.borgmatic.actions.config.bootstrap).should_receive('run_bootstrap').and_raise(
  1067. ValueError
  1068. )
  1069. arguments = {
  1070. 'bootstrap': flexmock(repository='repo', local_path='borg7'),
  1071. 'global': flexmock(dry_run=False),
  1072. }
  1073. logs = tuple(
  1074. module.collect_highlander_action_summary_logs(
  1075. {'test.yaml': {}}, arguments=arguments, configuration_parse_errors=False
  1076. )
  1077. )
  1078. assert {log.levelno for log in logs} == {logging.CRITICAL}
  1079. def test_collect_highlander_action_summary_logs_error_on_bootstrap_local_borg_version_failure():
  1080. flexmock(module.borg_version).should_receive('local_borg_version').and_raise(ValueError)
  1081. flexmock(module.borgmatic.actions.config.bootstrap).should_receive('run_bootstrap').never()
  1082. arguments = {
  1083. 'bootstrap': flexmock(repository='repo', local_path='borg7'),
  1084. 'global': flexmock(dry_run=False),
  1085. }
  1086. logs = tuple(
  1087. module.collect_highlander_action_summary_logs(
  1088. {'test.yaml': {}}, arguments=arguments, configuration_parse_errors=False
  1089. )
  1090. )
  1091. assert {log.levelno for log in logs} == {logging.CRITICAL}
  1092. def test_collect_highlander_action_summary_logs_info_for_success_with_generate():
  1093. flexmock(module.borgmatic.actions.config.generate).should_receive('run_generate')
  1094. arguments = {
  1095. 'generate': flexmock(destination='test.yaml'),
  1096. 'global': flexmock(dry_run=False),
  1097. }
  1098. logs = tuple(
  1099. module.collect_highlander_action_summary_logs(
  1100. {'test.yaml': {}}, arguments=arguments, configuration_parse_errors=False
  1101. )
  1102. )
  1103. assert {log.levelno for log in logs} == {logging.ANSWER}
  1104. def test_collect_highlander_action_summary_logs_error_on_generate_failure():
  1105. flexmock(module.borgmatic.actions.config.generate).should_receive('run_generate').and_raise(
  1106. ValueError
  1107. )
  1108. arguments = {
  1109. 'generate': flexmock(destination='test.yaml'),
  1110. 'global': flexmock(dry_run=False),
  1111. }
  1112. logs = tuple(
  1113. module.collect_highlander_action_summary_logs(
  1114. {'test.yaml': {}}, arguments=arguments, configuration_parse_errors=False
  1115. )
  1116. )
  1117. assert {log.levelno for log in logs} == {logging.CRITICAL}
  1118. def test_collect_highlander_action_summary_logs_info_for_success_with_validate():
  1119. flexmock(module.borgmatic.actions.config.validate).should_receive('run_validate')
  1120. arguments = {
  1121. 'validate': flexmock(),
  1122. 'global': flexmock(dry_run=False),
  1123. }
  1124. logs = tuple(
  1125. module.collect_highlander_action_summary_logs(
  1126. {'test.yaml': {}}, arguments=arguments, configuration_parse_errors=False
  1127. )
  1128. )
  1129. assert {log.levelno for log in logs} == {logging.ANSWER}
  1130. def test_collect_highlander_action_summary_logs_error_on_validate_parse_failure():
  1131. flexmock(module.borgmatic.actions.config.validate).should_receive('run_validate')
  1132. arguments = {
  1133. 'validate': flexmock(),
  1134. 'global': flexmock(dry_run=False),
  1135. }
  1136. logs = tuple(
  1137. module.collect_highlander_action_summary_logs(
  1138. {'test.yaml': {}}, arguments=arguments, configuration_parse_errors=True
  1139. )
  1140. )
  1141. assert {log.levelno for log in logs} == {logging.CRITICAL}
  1142. def test_collect_highlander_action_summary_logs_error_on_run_validate_failure():
  1143. flexmock(module.borgmatic.actions.config.validate).should_receive('run_validate').and_raise(
  1144. ValueError
  1145. )
  1146. arguments = {
  1147. 'validate': flexmock(),
  1148. 'global': flexmock(dry_run=False),
  1149. }
  1150. logs = tuple(
  1151. module.collect_highlander_action_summary_logs(
  1152. {'test.yaml': {}}, arguments=arguments, configuration_parse_errors=False
  1153. )
  1154. )
  1155. assert {log.levelno for log in logs} == {logging.CRITICAL}
  1156. def test_collect_configuration_run_summary_logs_info_for_success():
  1157. flexmock(module.command).should_receive('execute_hook').never()
  1158. flexmock(module.validate).should_receive('guard_configuration_contains_repository')
  1159. flexmock(module).should_receive('Log_prefix').and_return(flexmock())
  1160. flexmock(module).should_receive('run_configuration').and_return([])
  1161. arguments = {}
  1162. logs = tuple(
  1163. module.collect_configuration_run_summary_logs(
  1164. {'test.yaml': {}}, config_paths=['/tmp/test.yaml'], arguments=arguments
  1165. )
  1166. )
  1167. assert {log.levelno for log in logs} == {logging.INFO}
  1168. def test_collect_configuration_run_summary_executes_hooks_for_create():
  1169. flexmock(module.validate).should_receive('guard_configuration_contains_repository')
  1170. flexmock(module).should_receive('Log_prefix').and_return(flexmock())
  1171. flexmock(module).should_receive('run_configuration').and_return([])
  1172. arguments = {'create': flexmock(), 'global': flexmock(monitoring_verbosity=1, dry_run=False)}
  1173. logs = tuple(
  1174. module.collect_configuration_run_summary_logs(
  1175. {'test.yaml': {}}, config_paths=['/tmp/test.yaml'], arguments=arguments
  1176. )
  1177. )
  1178. assert {log.levelno for log in logs} == {logging.INFO}
  1179. def test_collect_configuration_run_summary_logs_info_for_success_with_extract():
  1180. flexmock(module.validate).should_receive('guard_configuration_contains_repository')
  1181. flexmock(module).should_receive('Log_prefix').and_return(flexmock())
  1182. flexmock(module).should_receive('run_configuration').and_return([])
  1183. arguments = {'extract': flexmock(repository='repo')}
  1184. logs = tuple(
  1185. module.collect_configuration_run_summary_logs(
  1186. {'test.yaml': {}}, config_paths=['/tmp/test.yaml'], arguments=arguments
  1187. )
  1188. )
  1189. assert {log.levelno for log in logs} == {logging.INFO}
  1190. def test_collect_configuration_run_summary_logs_extract_with_repository_error():
  1191. flexmock(module.validate).should_receive('guard_configuration_contains_repository').and_raise(
  1192. ValueError
  1193. )
  1194. expected_logs = (flexmock(),)
  1195. flexmock(module).should_receive('log_error_records').and_return(expected_logs)
  1196. arguments = {'extract': flexmock(repository='repo')}
  1197. logs = tuple(
  1198. module.collect_configuration_run_summary_logs(
  1199. {'test.yaml': {}}, config_paths=['/tmp/test.yaml'], arguments=arguments
  1200. )
  1201. )
  1202. assert logs == expected_logs
  1203. def test_collect_configuration_run_summary_logs_info_for_success_with_mount():
  1204. flexmock(module.validate).should_receive('guard_configuration_contains_repository')
  1205. flexmock(module).should_receive('Log_prefix').and_return(flexmock())
  1206. flexmock(module).should_receive('run_configuration').and_return([])
  1207. arguments = {'mount': flexmock(repository='repo')}
  1208. logs = tuple(
  1209. module.collect_configuration_run_summary_logs(
  1210. {'test.yaml': {}}, config_paths=['/tmp/test.yaml'], arguments=arguments
  1211. )
  1212. )
  1213. assert {log.levelno for log in logs} == {logging.INFO}
  1214. def test_collect_configuration_run_summary_logs_mount_with_repository_error():
  1215. flexmock(module.validate).should_receive('guard_configuration_contains_repository').and_raise(
  1216. ValueError
  1217. )
  1218. expected_logs = (flexmock(),)
  1219. flexmock(module).should_receive('log_error_records').and_return(expected_logs)
  1220. arguments = {'mount': flexmock(repository='repo')}
  1221. logs = tuple(
  1222. module.collect_configuration_run_summary_logs(
  1223. {'test.yaml': {}}, config_paths=['/tmp/test.yaml'], arguments=arguments
  1224. )
  1225. )
  1226. assert logs == expected_logs
  1227. def test_collect_configuration_run_summary_logs_missing_configs_error():
  1228. arguments = {'global': flexmock(config_paths=[])}
  1229. expected_logs = (flexmock(),)
  1230. flexmock(module).should_receive('log_error_records').and_return(expected_logs)
  1231. logs = tuple(
  1232. module.collect_configuration_run_summary_logs({}, config_paths=[], arguments=arguments)
  1233. )
  1234. assert logs == expected_logs
  1235. def test_collect_configuration_run_summary_logs_pre_hook_error():
  1236. flexmock(module.command).should_receive('execute_hook').and_raise(ValueError)
  1237. expected_logs = (flexmock(),)
  1238. flexmock(module).should_receive('log_error_records').and_return(expected_logs)
  1239. arguments = {'create': flexmock(), 'global': flexmock(monitoring_verbosity=1, dry_run=False)}
  1240. logs = tuple(
  1241. module.collect_configuration_run_summary_logs(
  1242. {'test.yaml': {}}, config_paths=['/tmp/test.yaml'], arguments=arguments
  1243. )
  1244. )
  1245. assert logs == expected_logs
  1246. def test_collect_configuration_run_summary_logs_post_hook_error():
  1247. flexmock(module.command).should_receive('execute_hook').and_return(None).and_raise(ValueError)
  1248. flexmock(module.validate).should_receive('guard_configuration_contains_repository')
  1249. flexmock(module).should_receive('Log_prefix').and_return(flexmock())
  1250. flexmock(module).should_receive('run_configuration').and_return([])
  1251. expected_logs = (flexmock(),)
  1252. flexmock(module).should_receive('log_error_records').and_return(expected_logs)
  1253. arguments = {'create': flexmock(), 'global': flexmock(monitoring_verbosity=1, dry_run=False)}
  1254. logs = tuple(
  1255. module.collect_configuration_run_summary_logs(
  1256. {'test.yaml': {}}, config_paths=['/tmp/test.yaml'], arguments=arguments
  1257. )
  1258. )
  1259. assert expected_logs[0] in logs
  1260. def test_collect_configuration_run_summary_logs_for_list_with_archive_and_repository_error():
  1261. flexmock(module.validate).should_receive('guard_configuration_contains_repository').and_raise(
  1262. ValueError
  1263. )
  1264. expected_logs = (flexmock(),)
  1265. flexmock(module).should_receive('log_error_records').and_return(expected_logs)
  1266. arguments = {'list': flexmock(repository='repo', archive='test')}
  1267. logs = tuple(
  1268. module.collect_configuration_run_summary_logs(
  1269. {'test.yaml': {}}, config_paths=['/tmp/test.yaml'], arguments=arguments
  1270. )
  1271. )
  1272. assert logs == expected_logs
  1273. def test_collect_configuration_run_summary_logs_info_for_success_with_list():
  1274. flexmock(module.validate).should_receive('guard_configuration_contains_repository')
  1275. flexmock(module).should_receive('Log_prefix').and_return(flexmock())
  1276. flexmock(module).should_receive('run_configuration').and_return([])
  1277. arguments = {'list': flexmock(repository='repo', archive=None)}
  1278. logs = tuple(
  1279. module.collect_configuration_run_summary_logs(
  1280. {'test.yaml': {}}, config_paths=['/tmp/test.yaml'], arguments=arguments
  1281. )
  1282. )
  1283. assert {log.levelno for log in logs} == {logging.INFO}
  1284. def test_collect_configuration_run_summary_logs_run_configuration_error():
  1285. flexmock(module.validate).should_receive('guard_configuration_contains_repository')
  1286. flexmock(module).should_receive('Log_prefix').and_return(flexmock())
  1287. flexmock(module).should_receive('run_configuration').and_return(
  1288. [logging.makeLogRecord(dict(levelno=logging.CRITICAL, levelname='CRITICAL', msg='Error'))]
  1289. )
  1290. flexmock(module).should_receive('log_error_records').and_return([])
  1291. arguments = {}
  1292. logs = tuple(
  1293. module.collect_configuration_run_summary_logs(
  1294. {'test.yaml': {}}, config_paths=['/tmp/test.yaml'], arguments=arguments
  1295. )
  1296. )
  1297. assert {log.levelno for log in logs} == {logging.CRITICAL}
  1298. def test_collect_configuration_run_summary_logs_run_umount_error():
  1299. flexmock(module.validate).should_receive('guard_configuration_contains_repository')
  1300. flexmock(module).should_receive('Log_prefix').and_return(flexmock())
  1301. flexmock(module).should_receive('run_configuration').and_return([])
  1302. flexmock(module.borg_umount).should_receive('unmount_archive').and_raise(OSError)
  1303. flexmock(module).should_receive('log_error_records').and_return(
  1304. [logging.makeLogRecord(dict(levelno=logging.CRITICAL, levelname='CRITICAL', msg='Error'))]
  1305. )
  1306. arguments = {'umount': flexmock(mount_point='/mnt')}
  1307. logs = tuple(
  1308. module.collect_configuration_run_summary_logs(
  1309. {'test.yaml': {}}, config_paths=['/tmp/test.yaml'], arguments=arguments
  1310. )
  1311. )
  1312. assert {log.levelno for log in logs} == {logging.INFO, logging.CRITICAL}
  1313. def test_collect_configuration_run_summary_logs_outputs_merged_json_results():
  1314. flexmock(module.validate).should_receive('guard_configuration_contains_repository')
  1315. flexmock(module).should_receive('Log_prefix').and_return(flexmock())
  1316. flexmock(module).should_receive('run_configuration').and_return(['foo', 'bar']).and_return(
  1317. ['baz']
  1318. )
  1319. stdout = flexmock()
  1320. stdout.should_receive('write').with_args('["foo", "bar", "baz"]').once()
  1321. flexmock(module.sys).stdout = stdout
  1322. arguments = {}
  1323. tuple(
  1324. module.collect_configuration_run_summary_logs(
  1325. {'test.yaml': {}, 'test2.yaml': {}},
  1326. config_paths=['/tmp/test.yaml', '/tmp/test2.yaml'],
  1327. arguments=arguments,
  1328. )
  1329. )