test_create.py 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126
  1. import logging
  2. import pytest
  3. from flexmock import flexmock
  4. from borgmatic.borg import create as module
  5. from ..test_verbosity import insert_logging_mock
  6. def test_expand_directory_with_basic_path_passes_it_through():
  7. flexmock(module.os.path).should_receive('expanduser').and_return('foo')
  8. flexmock(module.glob).should_receive('glob').and_return([])
  9. paths = module._expand_directory('foo')
  10. assert paths == ['foo']
  11. def test_expand_directory_with_glob_expands():
  12. flexmock(module.os.path).should_receive('expanduser').and_return('foo*')
  13. flexmock(module.glob).should_receive('glob').and_return(['foo', 'food'])
  14. paths = module._expand_directory('foo*')
  15. assert paths == ['foo', 'food']
  16. def test_expand_directories_flattens_expanded_directories():
  17. flexmock(module).should_receive('_expand_directory').with_args('~/foo').and_return(
  18. ['/root/foo']
  19. )
  20. flexmock(module).should_receive('_expand_directory').with_args('bar*').and_return(
  21. ['bar', 'barf']
  22. )
  23. paths = module._expand_directories(('~/foo', 'bar*'))
  24. assert paths == ('/root/foo', 'bar', 'barf')
  25. def test_expand_directories_considers_none_as_no_directories():
  26. paths = module._expand_directories(None)
  27. assert paths == ()
  28. def test_expand_home_directories_expands_tildes():
  29. flexmock(module.os.path).should_receive('expanduser').with_args('~/bar').and_return('/foo/bar')
  30. flexmock(module.os.path).should_receive('expanduser').with_args('baz').and_return('baz')
  31. paths = module._expand_home_directories(('~/bar', 'baz'))
  32. assert paths == ('/foo/bar', 'baz')
  33. def test_expand_home_directories_considers_none_as_no_directories():
  34. paths = module._expand_home_directories(None)
  35. assert paths == ()
  36. def test_write_pattern_file_does_not_raise():
  37. temporary_file = flexmock(name='filename', write=lambda mode: None, flush=lambda: None)
  38. flexmock(module.tempfile).should_receive('NamedTemporaryFile').and_return(temporary_file)
  39. module._write_pattern_file(['exclude'])
  40. def test_write_pattern_file_with_empty_exclude_patterns_does_not_raise():
  41. module._write_pattern_file([])
  42. def test_make_pattern_flags_includes_pattern_filename_when_given():
  43. pattern_flags = module._make_pattern_flags(
  44. location_config={'patterns': ['R /', '- /var']}, pattern_filename='/tmp/patterns'
  45. )
  46. assert pattern_flags == ('--patterns-from', '/tmp/patterns')
  47. def test_make_pattern_flags_includes_patterns_from_filenames_when_in_config():
  48. pattern_flags = module._make_pattern_flags(
  49. location_config={'patterns_from': ['patterns', 'other']}
  50. )
  51. assert pattern_flags == ('--patterns-from', 'patterns', '--patterns-from', 'other')
  52. def test_make_pattern_flags_includes_both_filenames_when_patterns_given_and_patterns_from_in_config():
  53. pattern_flags = module._make_pattern_flags(
  54. location_config={'patterns_from': ['patterns']}, pattern_filename='/tmp/patterns'
  55. )
  56. assert pattern_flags == ('--patterns-from', 'patterns', '--patterns-from', '/tmp/patterns')
  57. def test_make_pattern_flags_considers_none_patterns_from_filenames_as_empty():
  58. pattern_flags = module._make_pattern_flags(location_config={'patterns_from': None})
  59. assert pattern_flags == ()
  60. def test_make_exclude_flags_includes_exclude_patterns_filename_when_given():
  61. exclude_flags = module._make_exclude_flags(
  62. location_config={'exclude_patterns': ['*.pyc', '/var']}, exclude_filename='/tmp/excludes'
  63. )
  64. assert exclude_flags == ('--exclude-from', '/tmp/excludes')
  65. def test_make_exclude_flags_includes_exclude_from_filenames_when_in_config():
  66. exclude_flags = module._make_exclude_flags(
  67. location_config={'exclude_from': ['excludes', 'other']}
  68. )
  69. assert exclude_flags == ('--exclude-from', 'excludes', '--exclude-from', 'other')
  70. def test_make_exclude_flags_includes_both_filenames_when_patterns_given_and_exclude_from_in_config():
  71. exclude_flags = module._make_exclude_flags(
  72. location_config={'exclude_from': ['excludes']}, exclude_filename='/tmp/excludes'
  73. )
  74. assert exclude_flags == ('--exclude-from', 'excludes', '--exclude-from', '/tmp/excludes')
  75. def test_make_exclude_flags_considers_none_exclude_from_filenames_as_empty():
  76. exclude_flags = module._make_exclude_flags(location_config={'exclude_from': None})
  77. assert exclude_flags == ()
  78. def test_make_exclude_flags_includes_exclude_caches_when_true_in_config():
  79. exclude_flags = module._make_exclude_flags(location_config={'exclude_caches': True})
  80. assert exclude_flags == ('--exclude-caches',)
  81. def test_make_exclude_flags_does_not_include_exclude_caches_when_false_in_config():
  82. exclude_flags = module._make_exclude_flags(location_config={'exclude_caches': False})
  83. assert exclude_flags == ()
  84. def test_make_exclude_flags_includes_exclude_if_present_when_in_config():
  85. exclude_flags = module._make_exclude_flags(location_config={'exclude_if_present': 'exclude_me'})
  86. assert exclude_flags == ('--exclude-if-present', 'exclude_me')
  87. def test_make_exclude_flags_includes_keep_exclude_tags_when_true_in_config():
  88. exclude_flags = module._make_exclude_flags(location_config={'keep_exclude_tags': True})
  89. assert exclude_flags == ('--keep-exclude-tags',)
  90. def test_make_exclude_flags_does_not_include_keep_exclude_tags_when_false_in_config():
  91. exclude_flags = module._make_exclude_flags(location_config={'keep_exclude_tags': False})
  92. assert exclude_flags == ()
  93. def test_make_exclude_flags_includes_exclude_nodump_when_true_in_config():
  94. exclude_flags = module._make_exclude_flags(location_config={'exclude_nodump': True})
  95. assert exclude_flags == ('--exclude-nodump',)
  96. def test_make_exclude_flags_does_not_include_exclude_nodump_when_false_in_config():
  97. exclude_flags = module._make_exclude_flags(location_config={'exclude_nodump': False})
  98. assert exclude_flags == ()
  99. def test_make_exclude_flags_is_empty_when_config_has_no_excludes():
  100. exclude_flags = module._make_exclude_flags(location_config={})
  101. assert exclude_flags == ()
  102. def test_borgmatic_source_directories_set_when_directory_exists():
  103. flexmock(module.os.path).should_receive('exists').and_return(True)
  104. flexmock(module.os.path).should_receive('expanduser')
  105. assert module.borgmatic_source_directories('/tmp') == ['/tmp']
  106. def test_borgmatic_source_directories_empty_when_directory_does_not_exist():
  107. flexmock(module.os.path).should_receive('exists').and_return(False)
  108. flexmock(module.os.path).should_receive('expanduser')
  109. assert module.borgmatic_source_directories('/tmp') == []
  110. def test_borgmatic_source_directories_defaults_when_directory_not_given():
  111. flexmock(module.os.path).should_receive('exists').and_return(True)
  112. flexmock(module.os.path).should_receive('expanduser')
  113. assert module.borgmatic_source_directories(None) == [module.DEFAULT_BORGMATIC_SOURCE_DIRECTORY]
  114. DEFAULT_ARCHIVE_NAME = '{hostname}-{now:%Y-%m-%dT%H:%M:%S.%f}'
  115. ARCHIVE_WITH_PATHS = ('repo::{}'.format(DEFAULT_ARCHIVE_NAME), 'foo', 'bar')
  116. def test_create_archive_calls_borg_with_parameters():
  117. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  118. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  119. flexmock(module).should_receive('_expand_home_directories').and_return(())
  120. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  121. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  122. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  123. flexmock(module).should_receive('execute_command').with_args(
  124. ('borg', 'create') + ARCHIVE_WITH_PATHS,
  125. output_log_level=logging.INFO,
  126. error_on_warnings=False,
  127. )
  128. module.create_archive(
  129. dry_run=False,
  130. repository='repo',
  131. location_config={
  132. 'source_directories': ['foo', 'bar'],
  133. 'repositories': ['repo'],
  134. 'exclude_patterns': None,
  135. },
  136. storage_config={},
  137. )
  138. def test_create_archive_with_patterns_calls_borg_with_patterns():
  139. pattern_flags = ('--patterns-from', 'patterns')
  140. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  141. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  142. flexmock(module).should_receive('_expand_home_directories').and_return(())
  143. flexmock(module).should_receive('_write_pattern_file').and_return(
  144. flexmock(name='/tmp/patterns')
  145. ).and_return(None)
  146. flexmock(module).should_receive('_make_pattern_flags').and_return(pattern_flags)
  147. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  148. flexmock(module).should_receive('execute_command').with_args(
  149. ('borg', 'create') + pattern_flags + ARCHIVE_WITH_PATHS,
  150. output_log_level=logging.INFO,
  151. error_on_warnings=False,
  152. )
  153. module.create_archive(
  154. dry_run=False,
  155. repository='repo',
  156. location_config={
  157. 'source_directories': ['foo', 'bar'],
  158. 'repositories': ['repo'],
  159. 'patterns': ['pattern'],
  160. },
  161. storage_config={},
  162. )
  163. def test_create_archive_with_exclude_patterns_calls_borg_with_excludes():
  164. exclude_flags = ('--exclude-from', 'excludes')
  165. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  166. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  167. flexmock(module).should_receive('_expand_home_directories').and_return(('exclude',))
  168. flexmock(module).should_receive('_write_pattern_file').and_return(None).and_return(
  169. flexmock(name='/tmp/excludes')
  170. )
  171. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  172. flexmock(module).should_receive('_make_exclude_flags').and_return(exclude_flags)
  173. flexmock(module).should_receive('execute_command').with_args(
  174. ('borg', 'create') + exclude_flags + ARCHIVE_WITH_PATHS,
  175. output_log_level=logging.INFO,
  176. error_on_warnings=False,
  177. )
  178. module.create_archive(
  179. dry_run=False,
  180. repository='repo',
  181. location_config={
  182. 'source_directories': ['foo', 'bar'],
  183. 'repositories': ['repo'],
  184. 'exclude_patterns': ['exclude'],
  185. },
  186. storage_config={},
  187. )
  188. def test_create_archive_with_log_info_calls_borg_with_info_parameter():
  189. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  190. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  191. flexmock(module).should_receive('_expand_home_directories').and_return(())
  192. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  193. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  194. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  195. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  196. flexmock(module).should_receive('execute_command').with_args(
  197. ('borg', 'create', '--list', '--filter', 'AME-', '--info', '--stats') + ARCHIVE_WITH_PATHS,
  198. output_log_level=logging.INFO,
  199. error_on_warnings=False,
  200. )
  201. insert_logging_mock(logging.INFO)
  202. module.create_archive(
  203. dry_run=False,
  204. repository='repo',
  205. location_config={
  206. 'source_directories': ['foo', 'bar'],
  207. 'repositories': ['repo'],
  208. 'exclude_patterns': None,
  209. },
  210. storage_config={},
  211. )
  212. def test_create_archive_with_log_info_and_json_suppresses_most_borg_output():
  213. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  214. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  215. flexmock(module).should_receive('_expand_home_directories').and_return(())
  216. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  217. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  218. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  219. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  220. flexmock(module).should_receive('execute_command').with_args(
  221. ('borg', 'create', '--json') + ARCHIVE_WITH_PATHS,
  222. output_log_level=None,
  223. error_on_warnings=False,
  224. )
  225. insert_logging_mock(logging.INFO)
  226. module.create_archive(
  227. dry_run=False,
  228. repository='repo',
  229. location_config={
  230. 'source_directories': ['foo', 'bar'],
  231. 'repositories': ['repo'],
  232. 'exclude_patterns': None,
  233. },
  234. storage_config={},
  235. json=True,
  236. )
  237. def test_create_archive_with_log_debug_calls_borg_with_debug_parameter():
  238. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  239. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  240. flexmock(module).should_receive('_expand_home_directories').and_return(())
  241. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  242. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  243. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  244. flexmock(module).should_receive('execute_command').with_args(
  245. ('borg', 'create', '--list', '--filter', 'AME-', '--stats', '--debug', '--show-rc')
  246. + ARCHIVE_WITH_PATHS,
  247. output_log_level=logging.INFO,
  248. error_on_warnings=False,
  249. )
  250. insert_logging_mock(logging.DEBUG)
  251. module.create_archive(
  252. dry_run=False,
  253. repository='repo',
  254. location_config={
  255. 'source_directories': ['foo', 'bar'],
  256. 'repositories': ['repo'],
  257. 'exclude_patterns': None,
  258. },
  259. storage_config={},
  260. )
  261. def test_create_archive_with_log_debug_and_json_suppresses_most_borg_output():
  262. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  263. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  264. flexmock(module).should_receive('_expand_home_directories').and_return(())
  265. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  266. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  267. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  268. flexmock(module).should_receive('execute_command').with_args(
  269. ('borg', 'create', '--json') + ARCHIVE_WITH_PATHS,
  270. output_log_level=None,
  271. error_on_warnings=False,
  272. )
  273. insert_logging_mock(logging.DEBUG)
  274. module.create_archive(
  275. dry_run=False,
  276. repository='repo',
  277. location_config={
  278. 'source_directories': ['foo', 'bar'],
  279. 'repositories': ['repo'],
  280. 'exclude_patterns': None,
  281. },
  282. storage_config={},
  283. json=True,
  284. )
  285. def test_create_archive_with_dry_run_calls_borg_with_dry_run_parameter():
  286. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  287. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  288. flexmock(module).should_receive('_expand_home_directories').and_return(())
  289. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  290. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  291. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  292. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  293. flexmock(module).should_receive('execute_command').with_args(
  294. ('borg', 'create', '--dry-run') + ARCHIVE_WITH_PATHS,
  295. output_log_level=logging.INFO,
  296. error_on_warnings=False,
  297. )
  298. module.create_archive(
  299. dry_run=True,
  300. repository='repo',
  301. location_config={
  302. 'source_directories': ['foo', 'bar'],
  303. 'repositories': ['repo'],
  304. 'exclude_patterns': None,
  305. },
  306. storage_config={},
  307. )
  308. def test_create_archive_with_dry_run_and_log_info_calls_borg_without_stats_parameter():
  309. # --dry-run and --stats are mutually exclusive, see:
  310. # https://borgbackup.readthedocs.io/en/stable/usage/create.html#description
  311. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  312. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  313. flexmock(module).should_receive('_expand_home_directories').and_return(())
  314. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  315. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  316. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  317. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  318. flexmock(module).should_receive('execute_command').with_args(
  319. ('borg', 'create', '--list', '--filter', 'AME-', '--info', '--dry-run')
  320. + ARCHIVE_WITH_PATHS,
  321. output_log_level=logging.INFO,
  322. error_on_warnings=False,
  323. )
  324. insert_logging_mock(logging.INFO)
  325. module.create_archive(
  326. dry_run=True,
  327. repository='repo',
  328. location_config={
  329. 'source_directories': ['foo', 'bar'],
  330. 'repositories': ['repo'],
  331. 'exclude_patterns': None,
  332. },
  333. storage_config={},
  334. )
  335. def test_create_archive_with_dry_run_and_log_debug_calls_borg_without_stats_parameter():
  336. # --dry-run and --stats are mutually exclusive, see:
  337. # https://borgbackup.readthedocs.io/en/stable/usage/create.html#description
  338. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  339. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  340. flexmock(module).should_receive('_expand_home_directories').and_return(())
  341. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  342. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  343. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  344. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  345. flexmock(module).should_receive('execute_command').with_args(
  346. ('borg', 'create', '--list', '--filter', 'AME-', '--debug', '--show-rc', '--dry-run')
  347. + ARCHIVE_WITH_PATHS,
  348. output_log_level=logging.INFO,
  349. error_on_warnings=False,
  350. )
  351. insert_logging_mock(logging.DEBUG)
  352. module.create_archive(
  353. dry_run=True,
  354. repository='repo',
  355. location_config={
  356. 'source_directories': ['foo', 'bar'],
  357. 'repositories': ['repo'],
  358. 'exclude_patterns': None,
  359. },
  360. storage_config={},
  361. )
  362. def test_create_archive_with_checkpoint_interval_calls_borg_with_checkpoint_interval_parameters():
  363. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  364. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  365. flexmock(module).should_receive('_expand_home_directories').and_return(())
  366. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  367. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  368. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  369. flexmock(module).should_receive('execute_command').with_args(
  370. ('borg', 'create', '--checkpoint-interval', '600') + ARCHIVE_WITH_PATHS,
  371. output_log_level=logging.INFO,
  372. error_on_warnings=False,
  373. )
  374. module.create_archive(
  375. dry_run=False,
  376. repository='repo',
  377. location_config={
  378. 'source_directories': ['foo', 'bar'],
  379. 'repositories': ['repo'],
  380. 'exclude_patterns': None,
  381. },
  382. storage_config={'checkpoint_interval': 600},
  383. )
  384. def test_create_archive_with_chunker_params_calls_borg_with_chunker_params_parameters():
  385. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  386. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  387. flexmock(module).should_receive('_expand_home_directories').and_return(())
  388. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  389. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  390. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  391. flexmock(module).should_receive('execute_command').with_args(
  392. ('borg', 'create', '--chunker-params', '1,2,3,4') + ARCHIVE_WITH_PATHS,
  393. output_log_level=logging.INFO,
  394. error_on_warnings=False,
  395. )
  396. module.create_archive(
  397. dry_run=False,
  398. repository='repo',
  399. location_config={
  400. 'source_directories': ['foo', 'bar'],
  401. 'repositories': ['repo'],
  402. 'exclude_patterns': None,
  403. },
  404. storage_config={'chunker_params': '1,2,3,4'},
  405. )
  406. def test_create_archive_with_compression_calls_borg_with_compression_parameters():
  407. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  408. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  409. flexmock(module).should_receive('_expand_home_directories').and_return(())
  410. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  411. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  412. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  413. flexmock(module).should_receive('execute_command').with_args(
  414. ('borg', 'create', '--compression', 'rle') + ARCHIVE_WITH_PATHS,
  415. output_log_level=logging.INFO,
  416. error_on_warnings=False,
  417. )
  418. module.create_archive(
  419. dry_run=False,
  420. repository='repo',
  421. location_config={
  422. 'source_directories': ['foo', 'bar'],
  423. 'repositories': ['repo'],
  424. 'exclude_patterns': None,
  425. },
  426. storage_config={'compression': 'rle'},
  427. )
  428. def test_create_archive_with_remote_rate_limit_calls_borg_with_remote_ratelimit_parameters():
  429. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  430. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  431. flexmock(module).should_receive('_expand_home_directories').and_return(())
  432. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  433. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  434. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  435. flexmock(module).should_receive('execute_command').with_args(
  436. ('borg', 'create', '--remote-ratelimit', '100') + ARCHIVE_WITH_PATHS,
  437. output_log_level=logging.INFO,
  438. error_on_warnings=False,
  439. )
  440. module.create_archive(
  441. dry_run=False,
  442. repository='repo',
  443. location_config={
  444. 'source_directories': ['foo', 'bar'],
  445. 'repositories': ['repo'],
  446. 'exclude_patterns': None,
  447. },
  448. storage_config={'remote_rate_limit': 100},
  449. )
  450. def test_create_archive_with_one_file_system_calls_borg_with_one_file_system_parameter():
  451. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  452. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  453. flexmock(module).should_receive('_expand_home_directories').and_return(())
  454. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  455. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  456. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  457. flexmock(module).should_receive('execute_command').with_args(
  458. ('borg', 'create', '--one-file-system') + ARCHIVE_WITH_PATHS,
  459. output_log_level=logging.INFO,
  460. error_on_warnings=False,
  461. )
  462. module.create_archive(
  463. dry_run=False,
  464. repository='repo',
  465. location_config={
  466. 'source_directories': ['foo', 'bar'],
  467. 'repositories': ['repo'],
  468. 'one_file_system': True,
  469. 'exclude_patterns': None,
  470. },
  471. storage_config={},
  472. )
  473. def test_create_archive_with_numeric_owner_calls_borg_with_numeric_owner_parameter():
  474. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  475. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  476. flexmock(module).should_receive('_expand_home_directories').and_return(())
  477. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  478. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  479. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  480. flexmock(module).should_receive('execute_command').with_args(
  481. ('borg', 'create', '--numeric-owner') + ARCHIVE_WITH_PATHS,
  482. output_log_level=logging.INFO,
  483. error_on_warnings=False,
  484. )
  485. module.create_archive(
  486. dry_run=False,
  487. repository='repo',
  488. location_config={
  489. 'source_directories': ['foo', 'bar'],
  490. 'repositories': ['repo'],
  491. 'numeric_owner': True,
  492. 'exclude_patterns': None,
  493. },
  494. storage_config={},
  495. )
  496. def test_create_archive_with_read_special_calls_borg_with_read_special_parameter():
  497. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  498. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  499. flexmock(module).should_receive('_expand_home_directories').and_return(())
  500. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  501. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  502. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  503. flexmock(module).should_receive('execute_command').with_args(
  504. ('borg', 'create', '--read-special') + ARCHIVE_WITH_PATHS,
  505. output_log_level=logging.INFO,
  506. error_on_warnings=False,
  507. )
  508. module.create_archive(
  509. dry_run=False,
  510. repository='repo',
  511. location_config={
  512. 'source_directories': ['foo', 'bar'],
  513. 'repositories': ['repo'],
  514. 'read_special': True,
  515. 'exclude_patterns': None,
  516. },
  517. storage_config={},
  518. )
  519. @pytest.mark.parametrize('option_name', ('atime', 'ctime', 'birthtime', 'bsd_flags'))
  520. def test_create_archive_with_option_true_calls_borg_without_corresponding_parameter(option_name):
  521. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  522. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  523. flexmock(module).should_receive('_expand_home_directories').and_return(())
  524. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  525. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  526. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  527. flexmock(module).should_receive('execute_command').with_args(
  528. ('borg', 'create') + ARCHIVE_WITH_PATHS,
  529. output_log_level=logging.INFO,
  530. error_on_warnings=False,
  531. )
  532. module.create_archive(
  533. dry_run=False,
  534. repository='repo',
  535. location_config={
  536. 'source_directories': ['foo', 'bar'],
  537. 'repositories': ['repo'],
  538. option_name: True,
  539. 'exclude_patterns': None,
  540. },
  541. storage_config={},
  542. )
  543. @pytest.mark.parametrize('option_name', ('atime', 'ctime', 'birthtime', 'bsd_flags'))
  544. def test_create_archive_with_option_false_calls_borg_with_corresponding_parameter(option_name):
  545. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  546. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  547. flexmock(module).should_receive('_expand_home_directories').and_return(())
  548. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  549. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  550. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  551. flexmock(module).should_receive('execute_command').with_args(
  552. ('borg', 'create', '--no' + option_name.replace('_', '')) + ARCHIVE_WITH_PATHS,
  553. output_log_level=logging.INFO,
  554. error_on_warnings=False,
  555. )
  556. module.create_archive(
  557. dry_run=False,
  558. repository='repo',
  559. location_config={
  560. 'source_directories': ['foo', 'bar'],
  561. 'repositories': ['repo'],
  562. option_name: False,
  563. 'exclude_patterns': None,
  564. },
  565. storage_config={},
  566. )
  567. def test_create_archive_with_files_cache_calls_borg_with_files_cache_parameters():
  568. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  569. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  570. flexmock(module).should_receive('_expand_home_directories').and_return(())
  571. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  572. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  573. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  574. flexmock(module).should_receive('execute_command').with_args(
  575. ('borg', 'create', '--files-cache', 'ctime,size') + ARCHIVE_WITH_PATHS,
  576. output_log_level=logging.INFO,
  577. error_on_warnings=False,
  578. )
  579. module.create_archive(
  580. dry_run=False,
  581. repository='repo',
  582. location_config={
  583. 'source_directories': ['foo', 'bar'],
  584. 'repositories': ['repo'],
  585. 'files_cache': 'ctime,size',
  586. 'exclude_patterns': None,
  587. },
  588. storage_config={},
  589. )
  590. def test_create_archive_with_local_path_calls_borg_via_local_path():
  591. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  592. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  593. flexmock(module).should_receive('_expand_home_directories').and_return(())
  594. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  595. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  596. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  597. flexmock(module).should_receive('execute_command').with_args(
  598. ('borg1', 'create') + ARCHIVE_WITH_PATHS,
  599. output_log_level=logging.INFO,
  600. error_on_warnings=False,
  601. )
  602. module.create_archive(
  603. dry_run=False,
  604. repository='repo',
  605. location_config={
  606. 'source_directories': ['foo', 'bar'],
  607. 'repositories': ['repo'],
  608. 'exclude_patterns': None,
  609. },
  610. storage_config={},
  611. local_path='borg1',
  612. )
  613. def test_create_archive_with_remote_path_calls_borg_with_remote_path_parameters():
  614. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  615. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  616. flexmock(module).should_receive('_expand_home_directories').and_return(())
  617. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  618. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  619. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  620. flexmock(module).should_receive('execute_command').with_args(
  621. ('borg', 'create', '--remote-path', 'borg1') + ARCHIVE_WITH_PATHS,
  622. output_log_level=logging.INFO,
  623. error_on_warnings=False,
  624. )
  625. module.create_archive(
  626. dry_run=False,
  627. repository='repo',
  628. location_config={
  629. 'source_directories': ['foo', 'bar'],
  630. 'repositories': ['repo'],
  631. 'exclude_patterns': None,
  632. },
  633. storage_config={},
  634. remote_path='borg1',
  635. )
  636. def test_create_archive_with_umask_calls_borg_with_umask_parameters():
  637. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  638. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  639. flexmock(module).should_receive('_expand_home_directories').and_return(())
  640. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  641. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  642. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  643. flexmock(module).should_receive('execute_command').with_args(
  644. ('borg', 'create', '--umask', '740') + ARCHIVE_WITH_PATHS,
  645. output_log_level=logging.INFO,
  646. error_on_warnings=False,
  647. )
  648. module.create_archive(
  649. dry_run=False,
  650. repository='repo',
  651. location_config={
  652. 'source_directories': ['foo', 'bar'],
  653. 'repositories': ['repo'],
  654. 'exclude_patterns': None,
  655. },
  656. storage_config={'umask': 740},
  657. )
  658. def test_create_archive_with_lock_wait_calls_borg_with_lock_wait_parameters():
  659. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  660. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  661. flexmock(module).should_receive('_expand_home_directories').and_return(())
  662. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  663. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  664. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  665. flexmock(module).should_receive('execute_command').with_args(
  666. ('borg', 'create', '--lock-wait', '5') + ARCHIVE_WITH_PATHS,
  667. output_log_level=logging.INFO,
  668. error_on_warnings=False,
  669. )
  670. module.create_archive(
  671. dry_run=False,
  672. repository='repo',
  673. location_config={
  674. 'source_directories': ['foo', 'bar'],
  675. 'repositories': ['repo'],
  676. 'exclude_patterns': None,
  677. },
  678. storage_config={'lock_wait': 5},
  679. )
  680. def test_create_archive_with_stats_calls_borg_with_stats_parameter():
  681. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  682. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  683. flexmock(module).should_receive('_expand_home_directories').and_return(())
  684. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  685. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  686. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  687. flexmock(module).should_receive('execute_command').with_args(
  688. ('borg', 'create', '--stats') + ARCHIVE_WITH_PATHS,
  689. output_log_level=logging.WARNING,
  690. error_on_warnings=False,
  691. )
  692. module.create_archive(
  693. dry_run=False,
  694. repository='repo',
  695. location_config={
  696. 'source_directories': ['foo', 'bar'],
  697. 'repositories': ['repo'],
  698. 'exclude_patterns': None,
  699. },
  700. storage_config={},
  701. stats=True,
  702. )
  703. def test_create_archive_with_progress_and_log_info_calls_borg_with_progress_parameter_and_no_list():
  704. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  705. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  706. flexmock(module).should_receive('_expand_home_directories').and_return(())
  707. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  708. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  709. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  710. flexmock(module).should_receive('execute_command_without_capture').with_args(
  711. ('borg', 'create', '--info', '--stats', '--progress') + ARCHIVE_WITH_PATHS,
  712. error_on_warnings=False,
  713. )
  714. insert_logging_mock(logging.INFO)
  715. module.create_archive(
  716. dry_run=False,
  717. repository='repo',
  718. location_config={
  719. 'source_directories': ['foo', 'bar'],
  720. 'repositories': ['repo'],
  721. 'exclude_patterns': None,
  722. },
  723. storage_config={},
  724. progress=True,
  725. )
  726. def test_create_archive_with_progress_calls_borg_with_progress_parameter():
  727. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  728. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  729. flexmock(module).should_receive('_expand_home_directories').and_return(())
  730. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  731. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  732. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  733. flexmock(module).should_receive('execute_command_without_capture').with_args(
  734. ('borg', 'create', '--progress') + ARCHIVE_WITH_PATHS, error_on_warnings=False
  735. )
  736. module.create_archive(
  737. dry_run=False,
  738. repository='repo',
  739. location_config={
  740. 'source_directories': ['foo', 'bar'],
  741. 'repositories': ['repo'],
  742. 'exclude_patterns': None,
  743. },
  744. storage_config={},
  745. progress=True,
  746. )
  747. def test_create_archive_with_json_calls_borg_with_json_parameter():
  748. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  749. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  750. flexmock(module).should_receive('_expand_home_directories').and_return(())
  751. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  752. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  753. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  754. flexmock(module).should_receive('execute_command').with_args(
  755. ('borg', 'create', '--json') + ARCHIVE_WITH_PATHS,
  756. output_log_level=None,
  757. error_on_warnings=False,
  758. ).and_return('[]')
  759. json_output = module.create_archive(
  760. dry_run=False,
  761. repository='repo',
  762. location_config={
  763. 'source_directories': ['foo', 'bar'],
  764. 'repositories': ['repo'],
  765. 'exclude_patterns': None,
  766. },
  767. storage_config={},
  768. json=True,
  769. )
  770. assert json_output == '[]'
  771. def test_create_archive_with_stats_and_json_calls_borg_without_stats_parameter():
  772. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  773. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  774. flexmock(module).should_receive('_expand_home_directories').and_return(())
  775. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  776. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  777. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  778. flexmock(module).should_receive('execute_command').with_args(
  779. ('borg', 'create', '--json') + ARCHIVE_WITH_PATHS,
  780. output_log_level=None,
  781. error_on_warnings=False,
  782. ).and_return('[]')
  783. json_output = module.create_archive(
  784. dry_run=False,
  785. repository='repo',
  786. location_config={
  787. 'source_directories': ['foo', 'bar'],
  788. 'repositories': ['repo'],
  789. 'exclude_patterns': None,
  790. },
  791. storage_config={},
  792. json=True,
  793. stats=True,
  794. )
  795. assert json_output == '[]'
  796. def test_create_archive_with_source_directories_glob_expands():
  797. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  798. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'food'))
  799. flexmock(module).should_receive('_expand_home_directories').and_return(())
  800. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  801. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  802. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  803. flexmock(module).should_receive('execute_command').with_args(
  804. ('borg', 'create', 'repo::{}'.format(DEFAULT_ARCHIVE_NAME), 'foo', 'food'),
  805. output_log_level=logging.INFO,
  806. error_on_warnings=False,
  807. )
  808. flexmock(module.glob).should_receive('glob').with_args('foo*').and_return(['foo', 'food'])
  809. module.create_archive(
  810. dry_run=False,
  811. repository='repo',
  812. location_config={
  813. 'source_directories': ['foo*'],
  814. 'repositories': ['repo'],
  815. 'exclude_patterns': None,
  816. },
  817. storage_config={},
  818. )
  819. def test_create_archive_with_non_matching_source_directories_glob_passes_through():
  820. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  821. flexmock(module).should_receive('_expand_directories').and_return(('foo*',))
  822. flexmock(module).should_receive('_expand_home_directories').and_return(())
  823. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  824. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  825. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  826. flexmock(module).should_receive('execute_command').with_args(
  827. ('borg', 'create', 'repo::{}'.format(DEFAULT_ARCHIVE_NAME), 'foo*'),
  828. output_log_level=logging.INFO,
  829. error_on_warnings=False,
  830. )
  831. flexmock(module.glob).should_receive('glob').with_args('foo*').and_return([])
  832. module.create_archive(
  833. dry_run=False,
  834. repository='repo',
  835. location_config={
  836. 'source_directories': ['foo*'],
  837. 'repositories': ['repo'],
  838. 'exclude_patterns': None,
  839. },
  840. storage_config={},
  841. )
  842. def test_create_archive_with_glob_calls_borg_with_expanded_directories():
  843. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  844. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'food'))
  845. flexmock(module).should_receive('_expand_home_directories').and_return(())
  846. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  847. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  848. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  849. flexmock(module).should_receive('execute_command').with_args(
  850. ('borg', 'create', 'repo::{}'.format(DEFAULT_ARCHIVE_NAME), 'foo', 'food'),
  851. output_log_level=logging.INFO,
  852. error_on_warnings=False,
  853. )
  854. module.create_archive(
  855. dry_run=False,
  856. repository='repo',
  857. location_config={
  858. 'source_directories': ['foo*'],
  859. 'repositories': ['repo'],
  860. 'exclude_patterns': None,
  861. },
  862. storage_config={},
  863. )
  864. def test_create_archive_with_archive_name_format_calls_borg_with_archive_name():
  865. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  866. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  867. flexmock(module).should_receive('_expand_home_directories').and_return(())
  868. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  869. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  870. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  871. flexmock(module).should_receive('execute_command').with_args(
  872. ('borg', 'create', 'repo::ARCHIVE_NAME', 'foo', 'bar'),
  873. output_log_level=logging.INFO,
  874. error_on_warnings=False,
  875. )
  876. module.create_archive(
  877. dry_run=False,
  878. repository='repo',
  879. location_config={
  880. 'source_directories': ['foo', 'bar'],
  881. 'repositories': ['repo'],
  882. 'exclude_patterns': None,
  883. },
  884. storage_config={'archive_name_format': 'ARCHIVE_NAME'},
  885. )
  886. def test_create_archive_with_archive_name_format_accepts_borg_placeholders():
  887. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  888. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  889. flexmock(module).should_receive('_expand_home_directories').and_return(())
  890. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  891. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  892. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  893. flexmock(module).should_receive('execute_command').with_args(
  894. ('borg', 'create', 'repo::Documents_{hostname}-{now}', 'foo', 'bar'),
  895. output_log_level=logging.INFO,
  896. error_on_warnings=False,
  897. )
  898. module.create_archive(
  899. dry_run=False,
  900. repository='repo',
  901. location_config={
  902. 'source_directories': ['foo', 'bar'],
  903. 'repositories': ['repo'],
  904. 'exclude_patterns': None,
  905. },
  906. storage_config={'archive_name_format': 'Documents_{hostname}-{now}'},
  907. )
  908. def test_create_archive_with_extra_borg_options_calls_borg_with_extra_options():
  909. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  910. flexmock(module).should_receive('_expand_directories').and_return(('foo', 'bar'))
  911. flexmock(module).should_receive('_expand_home_directories').and_return(())
  912. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  913. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  914. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  915. flexmock(module).should_receive('execute_command').with_args(
  916. ('borg', 'create', '--extra', '--options') + ARCHIVE_WITH_PATHS,
  917. output_log_level=logging.INFO,
  918. error_on_warnings=False,
  919. )
  920. module.create_archive(
  921. dry_run=False,
  922. repository='repo',
  923. location_config={
  924. 'source_directories': ['foo', 'bar'],
  925. 'repositories': ['repo'],
  926. 'exclude_patterns': None,
  927. },
  928. storage_config={'extra_borg_options': {'create': '--extra --options'}},
  929. )