test_borgmatic.py 66 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633
  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,resolve_credentials',
  956. (
  957. (True, True),
  958. (False, True),
  959. (True, False),
  960. ),
  961. )
  962. def test_load_configurations_collects_parsed_configurations_and_logs(
  963. resolve_env, resolve_credentials
  964. ):
  965. configuration = flexmock()
  966. other_configuration = flexmock()
  967. test_expected_logs = [flexmock(), flexmock()]
  968. other_expected_logs = [flexmock(), flexmock()]
  969. flexmock(module.validate).should_receive('parse_configuration').and_return(
  970. configuration, ['/tmp/test.yaml'], test_expected_logs
  971. ).and_return(other_configuration, ['/tmp/other.yaml'], other_expected_logs)
  972. configs, config_paths, logs = tuple(
  973. module.load_configurations(
  974. ('test.yaml', 'other.yaml'),
  975. resolve_env=resolve_env,
  976. resolve_credentials=resolve_credentials,
  977. )
  978. )
  979. assert configs == {'test.yaml': configuration, 'other.yaml': other_configuration}
  980. assert config_paths == ['/tmp/other.yaml', '/tmp/test.yaml']
  981. assert set(logs) >= set(test_expected_logs + other_expected_logs)
  982. def test_load_configurations_logs_warning_for_permission_error():
  983. flexmock(module.validate).should_receive('parse_configuration').and_raise(PermissionError)
  984. configs, config_paths, logs = tuple(module.load_configurations(('test.yaml',)))
  985. assert configs == {}
  986. assert config_paths == []
  987. assert max(log.levelno for log in logs) == logging.WARNING
  988. def test_load_configurations_logs_critical_for_parse_error():
  989. flexmock(module.validate).should_receive('parse_configuration').and_raise(ValueError)
  990. configs, config_paths, logs = tuple(module.load_configurations(('test.yaml',)))
  991. assert configs == {}
  992. assert config_paths == []
  993. assert max(log.levelno for log in logs) == logging.CRITICAL
  994. def test_log_record_does_not_raise():
  995. module.log_record(levelno=1, foo='bar', baz='quux')
  996. def test_log_record_with_suppress_does_not_raise():
  997. module.log_record(levelno=1, foo='bar', baz='quux', suppress_log=True)
  998. def test_log_error_records_generates_output_logs_for_message_only():
  999. flexmock(module).should_receive('log_record').replace_with(dict).once()
  1000. logs = tuple(module.log_error_records('Error'))
  1001. assert {log['levelno'] for log in logs} == {logging.CRITICAL}
  1002. def test_log_error_records_generates_output_logs_for_called_process_error_with_bytes_ouput():
  1003. flexmock(module).should_receive('log_record').replace_with(dict).times(3)
  1004. flexmock(module.logger).should_receive('getEffectiveLevel').and_return(logging.WARNING)
  1005. logs = tuple(
  1006. module.log_error_records('Error', subprocess.CalledProcessError(1, 'ls', b'error output'))
  1007. )
  1008. assert {log['levelno'] for log in logs} == {logging.CRITICAL}
  1009. assert any(log for log in logs if 'error output' in str(log))
  1010. def test_log_error_records_generates_output_logs_for_called_process_error_with_string_ouput():
  1011. flexmock(module).should_receive('log_record').replace_with(dict).times(3)
  1012. flexmock(module.logger).should_receive('getEffectiveLevel').and_return(logging.WARNING)
  1013. logs = tuple(
  1014. module.log_error_records('Error', subprocess.CalledProcessError(1, 'ls', 'error output'))
  1015. )
  1016. assert {log['levelno'] for log in logs} == {logging.CRITICAL}
  1017. assert any(log for log in logs if 'error output' in str(log))
  1018. def test_log_error_records_generates_work_around_output_logs_for_called_process_error_with_repository_access_aborted_exit_code():
  1019. flexmock(module).should_receive('log_record').replace_with(dict).times(4)
  1020. flexmock(module.logger).should_receive('getEffectiveLevel').and_return(logging.WARNING)
  1021. logs = tuple(
  1022. module.log_error_records(
  1023. 'Error',
  1024. subprocess.CalledProcessError(
  1025. module.BORG_REPOSITORY_ACCESS_ABORTED_EXIT_CODE, 'ls', 'error output'
  1026. ),
  1027. )
  1028. )
  1029. assert {log['levelno'] for log in logs} == {logging.CRITICAL}
  1030. assert any(log for log in logs if 'error output' in str(log))
  1031. assert any(log for log in logs if 'To work around this' in str(log))
  1032. def test_log_error_records_splits_called_process_error_with_multiline_ouput_into_multiple_logs():
  1033. flexmock(module).should_receive('log_record').replace_with(dict).times(4)
  1034. flexmock(module.logger).should_receive('getEffectiveLevel').and_return(logging.WARNING)
  1035. logs = tuple(
  1036. module.log_error_records(
  1037. 'Error', subprocess.CalledProcessError(1, 'ls', 'error output\nanother line')
  1038. )
  1039. )
  1040. assert {log['levelno'] for log in logs} == {logging.CRITICAL}
  1041. assert any(log for log in logs if 'error output' in str(log))
  1042. def test_log_error_records_generates_logs_for_value_error():
  1043. flexmock(module).should_receive('log_record').replace_with(dict).twice()
  1044. logs = tuple(module.log_error_records('Error', ValueError()))
  1045. assert {log['levelno'] for log in logs} == {logging.CRITICAL}
  1046. def test_log_error_records_generates_logs_for_os_error():
  1047. flexmock(module).should_receive('log_record').replace_with(dict).twice()
  1048. logs = tuple(module.log_error_records('Error', OSError()))
  1049. assert {log['levelno'] for log in logs} == {logging.CRITICAL}
  1050. def test_log_error_records_generates_nothing_for_other_error():
  1051. flexmock(module).should_receive('log_record').never()
  1052. logs = tuple(module.log_error_records('Error', KeyError()))
  1053. assert logs == ()
  1054. def test_get_local_path_uses_configuration_value():
  1055. assert module.get_local_path({'test.yaml': {'local_path': 'borg1'}}) == 'borg1'
  1056. def test_get_local_path_without_local_path_defaults_to_borg():
  1057. assert module.get_local_path({'test.yaml': {}}) == 'borg'
  1058. def test_collect_highlander_action_summary_logs_info_for_success_with_bootstrap():
  1059. flexmock(module.borg_version).should_receive('local_borg_version').and_return(flexmock())
  1060. flexmock(module.borgmatic.actions.config.bootstrap).should_receive('run_bootstrap')
  1061. arguments = {
  1062. 'bootstrap': flexmock(repository='repo', local_path='borg7'),
  1063. 'global': flexmock(dry_run=False),
  1064. }
  1065. logs = tuple(
  1066. module.collect_highlander_action_summary_logs(
  1067. {'test.yaml': {}}, arguments=arguments, configuration_parse_errors=False
  1068. )
  1069. )
  1070. assert {log.levelno for log in logs} == {logging.ANSWER}
  1071. def test_collect_highlander_action_summary_logs_error_on_bootstrap_failure():
  1072. flexmock(module.borg_version).should_receive('local_borg_version').and_return(flexmock())
  1073. flexmock(module.borgmatic.actions.config.bootstrap).should_receive('run_bootstrap').and_raise(
  1074. ValueError
  1075. )
  1076. arguments = {
  1077. 'bootstrap': flexmock(repository='repo', local_path='borg7'),
  1078. 'global': flexmock(dry_run=False),
  1079. }
  1080. logs = tuple(
  1081. module.collect_highlander_action_summary_logs(
  1082. {'test.yaml': {}}, arguments=arguments, configuration_parse_errors=False
  1083. )
  1084. )
  1085. assert {log.levelno for log in logs} == {logging.CRITICAL}
  1086. def test_collect_highlander_action_summary_logs_error_on_bootstrap_local_borg_version_failure():
  1087. flexmock(module.borg_version).should_receive('local_borg_version').and_raise(ValueError)
  1088. flexmock(module.borgmatic.actions.config.bootstrap).should_receive('run_bootstrap').never()
  1089. arguments = {
  1090. 'bootstrap': flexmock(repository='repo', local_path='borg7'),
  1091. 'global': flexmock(dry_run=False),
  1092. }
  1093. logs = tuple(
  1094. module.collect_highlander_action_summary_logs(
  1095. {'test.yaml': {}}, arguments=arguments, configuration_parse_errors=False
  1096. )
  1097. )
  1098. assert {log.levelno for log in logs} == {logging.CRITICAL}
  1099. def test_collect_highlander_action_summary_logs_info_for_success_with_generate():
  1100. flexmock(module.borgmatic.actions.config.generate).should_receive('run_generate')
  1101. arguments = {
  1102. 'generate': flexmock(destination='test.yaml'),
  1103. 'global': flexmock(dry_run=False),
  1104. }
  1105. logs = tuple(
  1106. module.collect_highlander_action_summary_logs(
  1107. {'test.yaml': {}}, arguments=arguments, configuration_parse_errors=False
  1108. )
  1109. )
  1110. assert {log.levelno for log in logs} == {logging.ANSWER}
  1111. def test_collect_highlander_action_summary_logs_error_on_generate_failure():
  1112. flexmock(module.borgmatic.actions.config.generate).should_receive('run_generate').and_raise(
  1113. ValueError
  1114. )
  1115. arguments = {
  1116. 'generate': flexmock(destination='test.yaml'),
  1117. 'global': flexmock(dry_run=False),
  1118. }
  1119. logs = tuple(
  1120. module.collect_highlander_action_summary_logs(
  1121. {'test.yaml': {}}, arguments=arguments, configuration_parse_errors=False
  1122. )
  1123. )
  1124. assert {log.levelno for log in logs} == {logging.CRITICAL}
  1125. def test_collect_highlander_action_summary_logs_info_for_success_with_validate():
  1126. flexmock(module.borgmatic.actions.config.validate).should_receive('run_validate')
  1127. arguments = {
  1128. 'validate': flexmock(),
  1129. 'global': flexmock(dry_run=False),
  1130. }
  1131. logs = tuple(
  1132. module.collect_highlander_action_summary_logs(
  1133. {'test.yaml': {}}, arguments=arguments, configuration_parse_errors=False
  1134. )
  1135. )
  1136. assert {log.levelno for log in logs} == {logging.ANSWER}
  1137. def test_collect_highlander_action_summary_logs_error_on_validate_parse_failure():
  1138. flexmock(module.borgmatic.actions.config.validate).should_receive('run_validate')
  1139. arguments = {
  1140. 'validate': flexmock(),
  1141. 'global': flexmock(dry_run=False),
  1142. }
  1143. logs = tuple(
  1144. module.collect_highlander_action_summary_logs(
  1145. {'test.yaml': {}}, arguments=arguments, configuration_parse_errors=True
  1146. )
  1147. )
  1148. assert {log.levelno for log in logs} == {logging.CRITICAL}
  1149. def test_collect_highlander_action_summary_logs_error_on_run_validate_failure():
  1150. flexmock(module.borgmatic.actions.config.validate).should_receive('run_validate').and_raise(
  1151. ValueError
  1152. )
  1153. arguments = {
  1154. 'validate': flexmock(),
  1155. 'global': flexmock(dry_run=False),
  1156. }
  1157. logs = tuple(
  1158. module.collect_highlander_action_summary_logs(
  1159. {'test.yaml': {}}, arguments=arguments, configuration_parse_errors=False
  1160. )
  1161. )
  1162. assert {log.levelno for log in logs} == {logging.CRITICAL}
  1163. def test_collect_configuration_run_summary_logs_info_for_success():
  1164. flexmock(module.command).should_receive('execute_hook').never()
  1165. flexmock(module.validate).should_receive('guard_configuration_contains_repository')
  1166. flexmock(module).should_receive('Log_prefix').and_return(flexmock())
  1167. flexmock(module).should_receive('run_configuration').and_return([])
  1168. arguments = {}
  1169. logs = tuple(
  1170. module.collect_configuration_run_summary_logs(
  1171. {'test.yaml': {}}, config_paths=['/tmp/test.yaml'], arguments=arguments
  1172. )
  1173. )
  1174. assert {log.levelno for log in logs} == {logging.INFO}
  1175. def test_collect_configuration_run_summary_executes_hooks_for_create():
  1176. flexmock(module.validate).should_receive('guard_configuration_contains_repository')
  1177. flexmock(module).should_receive('Log_prefix').and_return(flexmock())
  1178. flexmock(module).should_receive('run_configuration').and_return([])
  1179. arguments = {'create': flexmock(), 'global': flexmock(monitoring_verbosity=1, dry_run=False)}
  1180. logs = tuple(
  1181. module.collect_configuration_run_summary_logs(
  1182. {'test.yaml': {}}, config_paths=['/tmp/test.yaml'], arguments=arguments
  1183. )
  1184. )
  1185. assert {log.levelno for log in logs} == {logging.INFO}
  1186. def test_collect_configuration_run_summary_logs_info_for_success_with_extract():
  1187. flexmock(module.validate).should_receive('guard_configuration_contains_repository')
  1188. flexmock(module).should_receive('Log_prefix').and_return(flexmock())
  1189. flexmock(module).should_receive('run_configuration').and_return([])
  1190. arguments = {'extract': flexmock(repository='repo')}
  1191. logs = tuple(
  1192. module.collect_configuration_run_summary_logs(
  1193. {'test.yaml': {}}, config_paths=['/tmp/test.yaml'], arguments=arguments
  1194. )
  1195. )
  1196. assert {log.levelno for log in logs} == {logging.INFO}
  1197. def test_collect_configuration_run_summary_logs_extract_with_repository_error():
  1198. flexmock(module.validate).should_receive('guard_configuration_contains_repository').and_raise(
  1199. ValueError
  1200. )
  1201. expected_logs = (flexmock(),)
  1202. flexmock(module).should_receive('log_error_records').and_return(expected_logs)
  1203. arguments = {'extract': flexmock(repository='repo')}
  1204. logs = tuple(
  1205. module.collect_configuration_run_summary_logs(
  1206. {'test.yaml': {}}, config_paths=['/tmp/test.yaml'], arguments=arguments
  1207. )
  1208. )
  1209. assert logs == expected_logs
  1210. def test_collect_configuration_run_summary_logs_info_for_success_with_mount():
  1211. flexmock(module.validate).should_receive('guard_configuration_contains_repository')
  1212. flexmock(module).should_receive('Log_prefix').and_return(flexmock())
  1213. flexmock(module).should_receive('run_configuration').and_return([])
  1214. arguments = {'mount': flexmock(repository='repo')}
  1215. logs = tuple(
  1216. module.collect_configuration_run_summary_logs(
  1217. {'test.yaml': {}}, config_paths=['/tmp/test.yaml'], arguments=arguments
  1218. )
  1219. )
  1220. assert {log.levelno for log in logs} == {logging.INFO}
  1221. def test_collect_configuration_run_summary_logs_mount_with_repository_error():
  1222. flexmock(module.validate).should_receive('guard_configuration_contains_repository').and_raise(
  1223. ValueError
  1224. )
  1225. expected_logs = (flexmock(),)
  1226. flexmock(module).should_receive('log_error_records').and_return(expected_logs)
  1227. arguments = {'mount': flexmock(repository='repo')}
  1228. logs = tuple(
  1229. module.collect_configuration_run_summary_logs(
  1230. {'test.yaml': {}}, config_paths=['/tmp/test.yaml'], arguments=arguments
  1231. )
  1232. )
  1233. assert logs == expected_logs
  1234. def test_collect_configuration_run_summary_logs_missing_configs_error():
  1235. arguments = {'global': flexmock(config_paths=[])}
  1236. expected_logs = (flexmock(),)
  1237. flexmock(module).should_receive('log_error_records').and_return(expected_logs)
  1238. logs = tuple(
  1239. module.collect_configuration_run_summary_logs({}, config_paths=[], arguments=arguments)
  1240. )
  1241. assert logs == expected_logs
  1242. def test_collect_configuration_run_summary_logs_pre_hook_error():
  1243. flexmock(module.command).should_receive('execute_hook').and_raise(ValueError)
  1244. expected_logs = (flexmock(),)
  1245. flexmock(module).should_receive('log_error_records').and_return(expected_logs)
  1246. arguments = {'create': flexmock(), 'global': flexmock(monitoring_verbosity=1, dry_run=False)}
  1247. logs = tuple(
  1248. module.collect_configuration_run_summary_logs(
  1249. {'test.yaml': {}}, config_paths=['/tmp/test.yaml'], arguments=arguments
  1250. )
  1251. )
  1252. assert logs == expected_logs
  1253. def test_collect_configuration_run_summary_logs_post_hook_error():
  1254. flexmock(module.command).should_receive('execute_hook').and_return(None).and_raise(ValueError)
  1255. flexmock(module.validate).should_receive('guard_configuration_contains_repository')
  1256. flexmock(module).should_receive('Log_prefix').and_return(flexmock())
  1257. flexmock(module).should_receive('run_configuration').and_return([])
  1258. expected_logs = (flexmock(),)
  1259. flexmock(module).should_receive('log_error_records').and_return(expected_logs)
  1260. arguments = {'create': flexmock(), 'global': flexmock(monitoring_verbosity=1, dry_run=False)}
  1261. logs = tuple(
  1262. module.collect_configuration_run_summary_logs(
  1263. {'test.yaml': {}}, config_paths=['/tmp/test.yaml'], arguments=arguments
  1264. )
  1265. )
  1266. assert expected_logs[0] in logs
  1267. def test_collect_configuration_run_summary_logs_for_list_with_archive_and_repository_error():
  1268. flexmock(module.validate).should_receive('guard_configuration_contains_repository').and_raise(
  1269. ValueError
  1270. )
  1271. expected_logs = (flexmock(),)
  1272. flexmock(module).should_receive('log_error_records').and_return(expected_logs)
  1273. arguments = {'list': flexmock(repository='repo', archive='test')}
  1274. logs = tuple(
  1275. module.collect_configuration_run_summary_logs(
  1276. {'test.yaml': {}}, config_paths=['/tmp/test.yaml'], arguments=arguments
  1277. )
  1278. )
  1279. assert logs == expected_logs
  1280. def test_collect_configuration_run_summary_logs_info_for_success_with_list():
  1281. flexmock(module.validate).should_receive('guard_configuration_contains_repository')
  1282. flexmock(module).should_receive('Log_prefix').and_return(flexmock())
  1283. flexmock(module).should_receive('run_configuration').and_return([])
  1284. arguments = {'list': flexmock(repository='repo', archive=None)}
  1285. logs = tuple(
  1286. module.collect_configuration_run_summary_logs(
  1287. {'test.yaml': {}}, config_paths=['/tmp/test.yaml'], arguments=arguments
  1288. )
  1289. )
  1290. assert {log.levelno for log in logs} == {logging.INFO}
  1291. def test_collect_configuration_run_summary_logs_run_configuration_error():
  1292. flexmock(module.validate).should_receive('guard_configuration_contains_repository')
  1293. flexmock(module).should_receive('Log_prefix').and_return(flexmock())
  1294. flexmock(module).should_receive('run_configuration').and_return(
  1295. [logging.makeLogRecord(dict(levelno=logging.CRITICAL, levelname='CRITICAL', msg='Error'))]
  1296. )
  1297. flexmock(module).should_receive('log_error_records').and_return([])
  1298. arguments = {}
  1299. logs = tuple(
  1300. module.collect_configuration_run_summary_logs(
  1301. {'test.yaml': {}}, config_paths=['/tmp/test.yaml'], arguments=arguments
  1302. )
  1303. )
  1304. assert {log.levelno for log in logs} == {logging.CRITICAL}
  1305. def test_collect_configuration_run_summary_logs_run_umount_error():
  1306. flexmock(module.validate).should_receive('guard_configuration_contains_repository')
  1307. flexmock(module).should_receive('Log_prefix').and_return(flexmock())
  1308. flexmock(module).should_receive('run_configuration').and_return([])
  1309. flexmock(module.borg_umount).should_receive('unmount_archive').and_raise(OSError)
  1310. flexmock(module).should_receive('log_error_records').and_return(
  1311. [logging.makeLogRecord(dict(levelno=logging.CRITICAL, levelname='CRITICAL', msg='Error'))]
  1312. )
  1313. arguments = {'umount': flexmock(mount_point='/mnt')}
  1314. logs = tuple(
  1315. module.collect_configuration_run_summary_logs(
  1316. {'test.yaml': {}}, config_paths=['/tmp/test.yaml'], arguments=arguments
  1317. )
  1318. )
  1319. assert {log.levelno for log in logs} == {logging.INFO, logging.CRITICAL}
  1320. def test_collect_configuration_run_summary_logs_outputs_merged_json_results():
  1321. flexmock(module.validate).should_receive('guard_configuration_contains_repository')
  1322. flexmock(module).should_receive('Log_prefix').and_return(flexmock())
  1323. flexmock(module).should_receive('run_configuration').and_return(['foo', 'bar']).and_return(
  1324. ['baz']
  1325. )
  1326. stdout = flexmock()
  1327. stdout.should_receive('write').with_args('["foo", "bar", "baz"]').once()
  1328. flexmock(module.sys).stdout = stdout
  1329. arguments = {}
  1330. tuple(
  1331. module.collect_configuration_run_summary_logs(
  1332. {'test.yaml': {}, 'test2.yaml': {}},
  1333. config_paths=['/tmp/test.yaml', '/tmp/test2.yaml'],
  1334. arguments=arguments,
  1335. )
  1336. )