2
0

test_create.py 67 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622
  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_map_directories_to_devices_gives_device_id_per_path():
  37. flexmock(module.os).should_receive('stat').with_args('/foo').and_return(flexmock(st_dev=55))
  38. flexmock(module.os).should_receive('stat').with_args('/bar').and_return(flexmock(st_dev=66))
  39. device_map = module.map_directories_to_devices(('/foo', '/bar'))
  40. assert device_map == {
  41. '/foo': 55,
  42. '/bar': 66,
  43. }
  44. def test_map_directories_to_devices_with_missing_path_does_not_error():
  45. flexmock(module.os).should_receive('stat').with_args('/foo').and_return(flexmock(st_dev=55))
  46. flexmock(module.os).should_receive('stat').with_args('/bar').and_raise(FileNotFoundError)
  47. device_map = module.map_directories_to_devices(('/foo', '/bar'))
  48. assert device_map == {
  49. '/foo': 55,
  50. '/bar': None,
  51. }
  52. @pytest.mark.parametrize(
  53. 'directories,expected_directories',
  54. (
  55. ({'/': 1, '/root': 1}, ('/',)),
  56. ({'/': 1, '/root/': 1}, ('/',)),
  57. ({'/': 1, '/root': 2}, ('/', '/root')),
  58. ({'/root': 1, '/': 1}, ('/',)),
  59. ({'/root': 1, '/root/foo': 1}, ('/root',)),
  60. ({'/root/': 1, '/root/foo': 1}, ('/root/',)),
  61. ({'/root': 1, '/root/foo/': 1}, ('/root',)),
  62. ({'/root': 1, '/root/foo': 2}, ('/root', '/root/foo')),
  63. ({'/root/foo': 1, '/root': 1}, ('/root',)),
  64. ({'/root': None, '/root/foo': None}, ('/root', '/root/foo')),
  65. ({'/root': 1, '/etc': 1, '/root/foo/bar': 1}, ('/etc', '/root')),
  66. ({'/root': 1, '/root/foo': 1, '/root/foo/bar': 1}, ('/root',)),
  67. ({'/dup': 1, '/dup': 1}, ('/dup',)),
  68. ({'/foo': 1, '/bar': 1}, ('/bar', '/foo')),
  69. ({'/foo': 1, '/bar': 2}, ('/bar', '/foo')),
  70. ),
  71. )
  72. def test_deduplicate_directories_removes_child_paths_on_the_same_filesystem(
  73. directories, expected_directories
  74. ):
  75. assert module.deduplicate_directories(directories) == expected_directories
  76. def test_write_pattern_file_does_not_raise():
  77. temporary_file = flexmock(name='filename', write=lambda mode: None, flush=lambda: None)
  78. flexmock(module.tempfile).should_receive('NamedTemporaryFile').and_return(temporary_file)
  79. module._write_pattern_file(['exclude'])
  80. def test_write_pattern_file_with_empty_exclude_patterns_does_not_raise():
  81. module._write_pattern_file([])
  82. def test_make_pattern_flags_includes_pattern_filename_when_given():
  83. pattern_flags = module._make_pattern_flags(
  84. location_config={'patterns': ['R /', '- /var']}, pattern_filename='/tmp/patterns'
  85. )
  86. assert pattern_flags == ('--patterns-from', '/tmp/patterns')
  87. def test_make_pattern_flags_includes_patterns_from_filenames_when_in_config():
  88. pattern_flags = module._make_pattern_flags(
  89. location_config={'patterns_from': ['patterns', 'other']}
  90. )
  91. assert pattern_flags == ('--patterns-from', 'patterns', '--patterns-from', 'other')
  92. def test_make_pattern_flags_includes_both_filenames_when_patterns_given_and_patterns_from_in_config():
  93. pattern_flags = module._make_pattern_flags(
  94. location_config={'patterns_from': ['patterns']}, pattern_filename='/tmp/patterns'
  95. )
  96. assert pattern_flags == ('--patterns-from', 'patterns', '--patterns-from', '/tmp/patterns')
  97. def test_make_pattern_flags_considers_none_patterns_from_filenames_as_empty():
  98. pattern_flags = module._make_pattern_flags(location_config={'patterns_from': None})
  99. assert pattern_flags == ()
  100. def test_make_exclude_flags_includes_exclude_patterns_filename_when_given():
  101. exclude_flags = module._make_exclude_flags(
  102. location_config={'exclude_patterns': ['*.pyc', '/var']}, exclude_filename='/tmp/excludes'
  103. )
  104. assert exclude_flags == ('--exclude-from', '/tmp/excludes')
  105. def test_make_exclude_flags_includes_exclude_from_filenames_when_in_config():
  106. exclude_flags = module._make_exclude_flags(
  107. location_config={'exclude_from': ['excludes', 'other']}
  108. )
  109. assert exclude_flags == ('--exclude-from', 'excludes', '--exclude-from', 'other')
  110. def test_make_exclude_flags_includes_both_filenames_when_patterns_given_and_exclude_from_in_config():
  111. exclude_flags = module._make_exclude_flags(
  112. location_config={'exclude_from': ['excludes']}, exclude_filename='/tmp/excludes'
  113. )
  114. assert exclude_flags == ('--exclude-from', 'excludes', '--exclude-from', '/tmp/excludes')
  115. def test_make_exclude_flags_considers_none_exclude_from_filenames_as_empty():
  116. exclude_flags = module._make_exclude_flags(location_config={'exclude_from': None})
  117. assert exclude_flags == ()
  118. def test_make_exclude_flags_includes_exclude_caches_when_true_in_config():
  119. exclude_flags = module._make_exclude_flags(location_config={'exclude_caches': True})
  120. assert exclude_flags == ('--exclude-caches',)
  121. def test_make_exclude_flags_does_not_include_exclude_caches_when_false_in_config():
  122. exclude_flags = module._make_exclude_flags(location_config={'exclude_caches': False})
  123. assert exclude_flags == ()
  124. def test_make_exclude_flags_includes_exclude_if_present_when_in_config():
  125. exclude_flags = module._make_exclude_flags(
  126. location_config={'exclude_if_present': ['exclude_me', 'also_me']}
  127. )
  128. assert exclude_flags == (
  129. '--exclude-if-present',
  130. 'exclude_me',
  131. '--exclude-if-present',
  132. 'also_me',
  133. )
  134. def test_make_exclude_flags_includes_keep_exclude_tags_when_true_in_config():
  135. exclude_flags = module._make_exclude_flags(location_config={'keep_exclude_tags': True})
  136. assert exclude_flags == ('--keep-exclude-tags',)
  137. def test_make_exclude_flags_does_not_include_keep_exclude_tags_when_false_in_config():
  138. exclude_flags = module._make_exclude_flags(location_config={'keep_exclude_tags': False})
  139. assert exclude_flags == ()
  140. def test_make_exclude_flags_includes_exclude_nodump_when_true_in_config():
  141. exclude_flags = module._make_exclude_flags(location_config={'exclude_nodump': True})
  142. assert exclude_flags == ('--exclude-nodump',)
  143. def test_make_exclude_flags_does_not_include_exclude_nodump_when_false_in_config():
  144. exclude_flags = module._make_exclude_flags(location_config={'exclude_nodump': False})
  145. assert exclude_flags == ()
  146. def test_make_exclude_flags_is_empty_when_config_has_no_excludes():
  147. exclude_flags = module._make_exclude_flags(location_config={})
  148. assert exclude_flags == ()
  149. def test_borgmatic_source_directories_set_when_directory_exists():
  150. flexmock(module.os.path).should_receive('exists').and_return(True)
  151. flexmock(module.os.path).should_receive('expanduser')
  152. assert module.borgmatic_source_directories('/tmp') == ['/tmp']
  153. def test_borgmatic_source_directories_empty_when_directory_does_not_exist():
  154. flexmock(module.os.path).should_receive('exists').and_return(False)
  155. flexmock(module.os.path).should_receive('expanduser')
  156. assert module.borgmatic_source_directories('/tmp') == []
  157. def test_borgmatic_source_directories_defaults_when_directory_not_given():
  158. flexmock(module.os.path).should_receive('exists').and_return(True)
  159. flexmock(module.os.path).should_receive('expanduser')
  160. assert module.borgmatic_source_directories(None) == [module.DEFAULT_BORGMATIC_SOURCE_DIRECTORY]
  161. DEFAULT_ARCHIVE_NAME = '{hostname}-{now:%Y-%m-%dT%H:%M:%S.%f}'
  162. ARCHIVE_WITH_PATHS = ('repo::{}'.format(DEFAULT_ARCHIVE_NAME), 'foo', 'bar')
  163. def test_create_archive_calls_borg_with_parameters():
  164. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  165. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  166. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  167. flexmock(module).should_receive('_expand_directories').and_return(())
  168. flexmock(module).should_receive('_expand_home_directories').and_return(())
  169. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  170. flexmock(module.feature).should_receive('available').and_return(True)
  171. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  172. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  173. flexmock(module).should_receive('execute_command').with_args(
  174. ('borg', 'create') + ARCHIVE_WITH_PATHS,
  175. output_log_level=logging.INFO,
  176. output_file=None,
  177. borg_local_path='borg',
  178. working_directory=None,
  179. )
  180. module.create_archive(
  181. dry_run=False,
  182. repository='repo',
  183. location_config={
  184. 'source_directories': ['foo', 'bar'],
  185. 'repositories': ['repo'],
  186. 'exclude_patterns': None,
  187. },
  188. storage_config={},
  189. local_borg_version='1.2.3',
  190. )
  191. def test_create_archive_with_patterns_calls_borg_with_patterns():
  192. pattern_flags = ('--patterns-from', 'patterns')
  193. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  194. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  195. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  196. flexmock(module).should_receive('_expand_directories').and_return(())
  197. flexmock(module).should_receive('_expand_home_directories').and_return(())
  198. flexmock(module).should_receive('_write_pattern_file').and_return(
  199. flexmock(name='/tmp/patterns')
  200. ).and_return(None)
  201. flexmock(module.feature).should_receive('available').and_return(True)
  202. flexmock(module).should_receive('_make_pattern_flags').and_return(pattern_flags)
  203. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  204. flexmock(module).should_receive('execute_command').with_args(
  205. ('borg', 'create') + pattern_flags + ARCHIVE_WITH_PATHS,
  206. output_log_level=logging.INFO,
  207. output_file=None,
  208. borg_local_path='borg',
  209. working_directory=None,
  210. )
  211. module.create_archive(
  212. dry_run=False,
  213. repository='repo',
  214. location_config={
  215. 'source_directories': ['foo', 'bar'],
  216. 'repositories': ['repo'],
  217. 'patterns': ['pattern'],
  218. },
  219. storage_config={},
  220. local_borg_version='1.2.3',
  221. )
  222. def test_create_archive_with_exclude_patterns_calls_borg_with_excludes():
  223. exclude_flags = ('--exclude-from', 'excludes')
  224. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  225. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  226. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  227. flexmock(module).should_receive('_expand_directories').and_return(())
  228. flexmock(module).should_receive('_expand_home_directories').and_return(('exclude',))
  229. flexmock(module).should_receive('_write_pattern_file').and_return(None).and_return(
  230. flexmock(name='/tmp/excludes')
  231. )
  232. flexmock(module.feature).should_receive('available').and_return(True)
  233. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  234. flexmock(module).should_receive('_make_exclude_flags').and_return(exclude_flags)
  235. flexmock(module).should_receive('execute_command').with_args(
  236. ('borg', 'create') + exclude_flags + ARCHIVE_WITH_PATHS,
  237. output_log_level=logging.INFO,
  238. output_file=None,
  239. borg_local_path='borg',
  240. working_directory=None,
  241. )
  242. module.create_archive(
  243. dry_run=False,
  244. repository='repo',
  245. location_config={
  246. 'source_directories': ['foo', 'bar'],
  247. 'repositories': ['repo'],
  248. 'exclude_patterns': ['exclude'],
  249. },
  250. storage_config={},
  251. local_borg_version='1.2.3',
  252. )
  253. def test_create_archive_with_log_info_calls_borg_with_info_parameter():
  254. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  255. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  256. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  257. flexmock(module).should_receive('_expand_directories').and_return(())
  258. flexmock(module).should_receive('_expand_home_directories').and_return(())
  259. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  260. flexmock(module.feature).should_receive('available').and_return(True)
  261. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  262. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  263. flexmock(module).should_receive('execute_command').with_args(
  264. ('borg', 'create', '--info') + ARCHIVE_WITH_PATHS,
  265. output_log_level=logging.INFO,
  266. output_file=None,
  267. borg_local_path='borg',
  268. working_directory=None,
  269. )
  270. insert_logging_mock(logging.INFO)
  271. module.create_archive(
  272. dry_run=False,
  273. repository='repo',
  274. location_config={
  275. 'source_directories': ['foo', 'bar'],
  276. 'repositories': ['repo'],
  277. 'exclude_patterns': None,
  278. },
  279. storage_config={},
  280. local_borg_version='1.2.3',
  281. )
  282. def test_create_archive_with_log_info_and_json_suppresses_most_borg_output():
  283. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  284. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  285. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  286. flexmock(module).should_receive('_expand_directories').and_return(())
  287. flexmock(module).should_receive('_expand_home_directories').and_return(())
  288. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  289. flexmock(module.feature).should_receive('available').and_return(True)
  290. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  291. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  292. flexmock(module).should_receive('execute_command').with_args(
  293. ('borg', 'create', '--json') + ARCHIVE_WITH_PATHS,
  294. output_log_level=None,
  295. output_file=None,
  296. borg_local_path='borg',
  297. working_directory=None,
  298. )
  299. insert_logging_mock(logging.INFO)
  300. module.create_archive(
  301. dry_run=False,
  302. repository='repo',
  303. location_config={
  304. 'source_directories': ['foo', 'bar'],
  305. 'repositories': ['repo'],
  306. 'exclude_patterns': None,
  307. },
  308. storage_config={},
  309. local_borg_version='1.2.3',
  310. json=True,
  311. )
  312. def test_create_archive_with_log_debug_calls_borg_with_debug_parameter():
  313. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  314. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  315. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  316. flexmock(module).should_receive('_expand_directories').and_return(())
  317. flexmock(module).should_receive('_expand_home_directories').and_return(())
  318. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  319. flexmock(module.feature).should_receive('available').and_return(True)
  320. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  321. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  322. flexmock(module).should_receive('execute_command').with_args(
  323. ('borg', 'create', '--debug', '--show-rc') + ARCHIVE_WITH_PATHS,
  324. output_log_level=logging.INFO,
  325. output_file=None,
  326. borg_local_path='borg',
  327. working_directory=None,
  328. )
  329. insert_logging_mock(logging.DEBUG)
  330. module.create_archive(
  331. dry_run=False,
  332. repository='repo',
  333. location_config={
  334. 'source_directories': ['foo', 'bar'],
  335. 'repositories': ['repo'],
  336. 'exclude_patterns': None,
  337. },
  338. storage_config={},
  339. local_borg_version='1.2.3',
  340. )
  341. def test_create_archive_with_log_debug_and_json_suppresses_most_borg_output():
  342. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  343. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  344. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  345. flexmock(module).should_receive('_expand_directories').and_return(())
  346. flexmock(module).should_receive('_expand_home_directories').and_return(())
  347. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  348. flexmock(module.feature).should_receive('available').and_return(True)
  349. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  350. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  351. flexmock(module).should_receive('execute_command').with_args(
  352. ('borg', 'create', '--json') + ARCHIVE_WITH_PATHS,
  353. output_log_level=None,
  354. output_file=None,
  355. borg_local_path='borg',
  356. working_directory=None,
  357. )
  358. insert_logging_mock(logging.DEBUG)
  359. module.create_archive(
  360. dry_run=False,
  361. repository='repo',
  362. location_config={
  363. 'source_directories': ['foo', 'bar'],
  364. 'repositories': ['repo'],
  365. 'exclude_patterns': None,
  366. },
  367. storage_config={},
  368. local_borg_version='1.2.3',
  369. json=True,
  370. )
  371. def test_create_archive_with_dry_run_calls_borg_with_dry_run_parameter():
  372. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  373. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  374. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  375. flexmock(module).should_receive('_expand_directories').and_return(())
  376. flexmock(module).should_receive('_expand_home_directories').and_return(())
  377. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  378. flexmock(module.feature).should_receive('available').and_return(True)
  379. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  380. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  381. flexmock(module).should_receive('execute_command').with_args(
  382. ('borg', 'create', '--dry-run') + ARCHIVE_WITH_PATHS,
  383. output_log_level=logging.INFO,
  384. output_file=None,
  385. borg_local_path='borg',
  386. working_directory=None,
  387. )
  388. module.create_archive(
  389. dry_run=True,
  390. repository='repo',
  391. location_config={
  392. 'source_directories': ['foo', 'bar'],
  393. 'repositories': ['repo'],
  394. 'exclude_patterns': None,
  395. },
  396. storage_config={},
  397. local_borg_version='1.2.3',
  398. )
  399. def test_create_archive_with_stats_and_dry_run_calls_borg_without_stats_parameter():
  400. # --dry-run and --stats are mutually exclusive, see:
  401. # https://borgbackup.readthedocs.io/en/stable/usage/create.html#description
  402. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  403. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  404. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  405. flexmock(module).should_receive('_expand_directories').and_return(())
  406. flexmock(module).should_receive('_expand_home_directories').and_return(())
  407. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  408. flexmock(module.feature).should_receive('available').and_return(True)
  409. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  410. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  411. flexmock(module).should_receive('execute_command').with_args(
  412. ('borg', 'create', '--info', '--dry-run') + ARCHIVE_WITH_PATHS,
  413. output_log_level=logging.INFO,
  414. output_file=None,
  415. borg_local_path='borg',
  416. working_directory=None,
  417. )
  418. insert_logging_mock(logging.INFO)
  419. module.create_archive(
  420. dry_run=True,
  421. repository='repo',
  422. location_config={
  423. 'source_directories': ['foo', 'bar'],
  424. 'repositories': ['repo'],
  425. 'exclude_patterns': None,
  426. },
  427. storage_config={},
  428. local_borg_version='1.2.3',
  429. stats=True,
  430. )
  431. def test_create_archive_with_checkpoint_interval_calls_borg_with_checkpoint_interval_parameters():
  432. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  433. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  434. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  435. flexmock(module).should_receive('_expand_directories').and_return(())
  436. flexmock(module).should_receive('_expand_home_directories').and_return(())
  437. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  438. flexmock(module.feature).should_receive('available').and_return(True)
  439. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  440. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  441. flexmock(module).should_receive('execute_command').with_args(
  442. ('borg', 'create', '--checkpoint-interval', '600') + ARCHIVE_WITH_PATHS,
  443. output_log_level=logging.INFO,
  444. output_file=None,
  445. borg_local_path='borg',
  446. working_directory=None,
  447. )
  448. module.create_archive(
  449. dry_run=False,
  450. repository='repo',
  451. location_config={
  452. 'source_directories': ['foo', 'bar'],
  453. 'repositories': ['repo'],
  454. 'exclude_patterns': None,
  455. },
  456. storage_config={'checkpoint_interval': 600},
  457. local_borg_version='1.2.3',
  458. )
  459. def test_create_archive_with_chunker_params_calls_borg_with_chunker_params_parameters():
  460. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  461. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  462. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  463. flexmock(module).should_receive('_expand_directories').and_return(())
  464. flexmock(module).should_receive('_expand_home_directories').and_return(())
  465. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  466. flexmock(module.feature).should_receive('available').and_return(True)
  467. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  468. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  469. flexmock(module).should_receive('execute_command').with_args(
  470. ('borg', 'create', '--chunker-params', '1,2,3,4') + ARCHIVE_WITH_PATHS,
  471. output_log_level=logging.INFO,
  472. output_file=None,
  473. borg_local_path='borg',
  474. working_directory=None,
  475. )
  476. module.create_archive(
  477. dry_run=False,
  478. repository='repo',
  479. location_config={
  480. 'source_directories': ['foo', 'bar'],
  481. 'repositories': ['repo'],
  482. 'exclude_patterns': None,
  483. },
  484. storage_config={'chunker_params': '1,2,3,4'},
  485. local_borg_version='1.2.3',
  486. )
  487. def test_create_archive_with_compression_calls_borg_with_compression_parameters():
  488. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  489. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  490. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  491. flexmock(module).should_receive('_expand_directories').and_return(())
  492. flexmock(module).should_receive('_expand_home_directories').and_return(())
  493. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  494. flexmock(module.feature).should_receive('available').and_return(True)
  495. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  496. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  497. flexmock(module).should_receive('execute_command').with_args(
  498. ('borg', 'create', '--compression', 'rle') + ARCHIVE_WITH_PATHS,
  499. output_log_level=logging.INFO,
  500. output_file=None,
  501. borg_local_path='borg',
  502. working_directory=None,
  503. )
  504. module.create_archive(
  505. dry_run=False,
  506. repository='repo',
  507. location_config={
  508. 'source_directories': ['foo', 'bar'],
  509. 'repositories': ['repo'],
  510. 'exclude_patterns': None,
  511. },
  512. storage_config={'compression': 'rle'},
  513. local_borg_version='1.2.3',
  514. )
  515. @pytest.mark.parametrize(
  516. 'feature_available,option_flag', ((True, '--upload-ratelimit'), (False, '--remote-ratelimit')),
  517. )
  518. def test_create_archive_with_remote_rate_limit_calls_borg_with_upload_ratelimit_parameters(
  519. feature_available, option_flag
  520. ):
  521. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  522. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  523. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  524. flexmock(module).should_receive('_expand_directories').and_return(())
  525. flexmock(module).should_receive('_expand_home_directories').and_return(())
  526. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  527. flexmock(module.feature).should_receive('available').and_return(feature_available)
  528. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  529. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  530. flexmock(module).should_receive('execute_command').with_args(
  531. ('borg', 'create', option_flag, '100') + ARCHIVE_WITH_PATHS,
  532. output_log_level=logging.INFO,
  533. output_file=None,
  534. borg_local_path='borg',
  535. working_directory=None,
  536. )
  537. module.create_archive(
  538. dry_run=False,
  539. repository='repo',
  540. location_config={
  541. 'source_directories': ['foo', 'bar'],
  542. 'repositories': ['repo'],
  543. 'exclude_patterns': None,
  544. },
  545. storage_config={'remote_rate_limit': 100},
  546. local_borg_version='1.2.3',
  547. )
  548. def test_create_archive_with_one_file_system_calls_borg_with_one_file_system_parameter():
  549. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  550. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  551. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  552. flexmock(module).should_receive('_expand_directories').and_return(())
  553. flexmock(module).should_receive('_expand_home_directories').and_return(())
  554. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  555. flexmock(module.feature).should_receive('available').and_return(True)
  556. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  557. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  558. flexmock(module).should_receive('execute_command').with_args(
  559. ('borg', 'create', '--one-file-system') + ARCHIVE_WITH_PATHS,
  560. output_log_level=logging.INFO,
  561. output_file=None,
  562. borg_local_path='borg',
  563. working_directory=None,
  564. )
  565. module.create_archive(
  566. dry_run=False,
  567. repository='repo',
  568. location_config={
  569. 'source_directories': ['foo', 'bar'],
  570. 'repositories': ['repo'],
  571. 'one_file_system': True,
  572. 'exclude_patterns': None,
  573. },
  574. storage_config={},
  575. local_borg_version='1.2.3',
  576. )
  577. @pytest.mark.parametrize(
  578. 'feature_available,option_flag', ((True, '--numeric-ids'), (False, '--numeric-owner')),
  579. )
  580. def test_create_archive_with_numeric_owner_calls_borg_with_numeric_ids_parameter(
  581. feature_available, option_flag
  582. ):
  583. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  584. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  585. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  586. flexmock(module).should_receive('_expand_directories').and_return(())
  587. flexmock(module).should_receive('_expand_home_directories').and_return(())
  588. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  589. flexmock(module.feature).should_receive('available').and_return(feature_available)
  590. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  591. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  592. flexmock(module).should_receive('execute_command').with_args(
  593. ('borg', 'create', option_flag) + ARCHIVE_WITH_PATHS,
  594. output_log_level=logging.INFO,
  595. output_file=None,
  596. borg_local_path='borg',
  597. working_directory=None,
  598. )
  599. module.create_archive(
  600. dry_run=False,
  601. repository='repo',
  602. location_config={
  603. 'source_directories': ['foo', 'bar'],
  604. 'repositories': ['repo'],
  605. 'numeric_owner': True,
  606. 'exclude_patterns': None,
  607. },
  608. storage_config={},
  609. local_borg_version='1.2.3',
  610. )
  611. def test_create_archive_with_read_special_calls_borg_with_read_special_parameter():
  612. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  613. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  614. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  615. flexmock(module).should_receive('_expand_directories').and_return(())
  616. flexmock(module).should_receive('_expand_home_directories').and_return(())
  617. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  618. flexmock(module.feature).should_receive('available').and_return(True)
  619. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  620. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  621. flexmock(module).should_receive('execute_command').with_args(
  622. ('borg', 'create', '--read-special') + ARCHIVE_WITH_PATHS,
  623. output_log_level=logging.INFO,
  624. output_file=None,
  625. borg_local_path='borg',
  626. working_directory=None,
  627. )
  628. module.create_archive(
  629. dry_run=False,
  630. repository='repo',
  631. location_config={
  632. 'source_directories': ['foo', 'bar'],
  633. 'repositories': ['repo'],
  634. 'read_special': True,
  635. 'exclude_patterns': None,
  636. },
  637. storage_config={},
  638. local_borg_version='1.2.3',
  639. )
  640. @pytest.mark.parametrize(
  641. 'option_name,option_value',
  642. (('ctime', True), ('ctime', False), ('birthtime', True), ('birthtime', False),),
  643. )
  644. def test_create_archive_with_basic_option_calls_borg_with_corresponding_parameter(
  645. option_name, option_value
  646. ):
  647. option_flag = '--no' + option_name.replace('_', '') if option_value is False else None
  648. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  649. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  650. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  651. flexmock(module).should_receive('_expand_directories').and_return(())
  652. flexmock(module).should_receive('_expand_home_directories').and_return(())
  653. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  654. flexmock(module.feature).should_receive('available').and_return(True)
  655. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  656. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  657. flexmock(module).should_receive('execute_command').with_args(
  658. ('borg', 'create') + ((option_flag,) if option_flag else ()) + ARCHIVE_WITH_PATHS,
  659. output_log_level=logging.INFO,
  660. output_file=None,
  661. borg_local_path='borg',
  662. )
  663. module.create_archive(
  664. dry_run=False,
  665. repository='repo',
  666. location_config={
  667. 'source_directories': ['foo', 'bar'],
  668. 'repositories': ['repo'],
  669. option_name: option_value,
  670. 'exclude_patterns': None,
  671. },
  672. storage_config={},
  673. local_borg_version='1.2.3',
  674. )
  675. @pytest.mark.parametrize(
  676. 'option_value,feature_available,option_flag',
  677. (
  678. (True, True, '--atime'),
  679. (True, False, None),
  680. (False, True, None),
  681. (False, False, '--noatime'),
  682. ),
  683. )
  684. def test_create_archive_with_atime_option_calls_borg_with_corresponding_parameter(
  685. option_value, feature_available, option_flag
  686. ):
  687. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  688. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  689. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  690. flexmock(module).should_receive('_expand_directories').and_return(())
  691. flexmock(module).should_receive('_expand_home_directories').and_return(())
  692. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  693. flexmock(module.feature).should_receive('available').and_return(feature_available)
  694. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  695. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  696. flexmock(module).should_receive('execute_command').with_args(
  697. ('borg', 'create') + ((option_flag,) if option_flag else ()) + ARCHIVE_WITH_PATHS,
  698. output_log_level=logging.INFO,
  699. output_file=None,
  700. borg_local_path='borg',
  701. working_directory=None,
  702. )
  703. module.create_archive(
  704. dry_run=False,
  705. repository='repo',
  706. location_config={
  707. 'source_directories': ['foo', 'bar'],
  708. 'repositories': ['repo'],
  709. 'atime': option_value,
  710. 'exclude_patterns': None,
  711. },
  712. storage_config={},
  713. local_borg_version='1.2.3',
  714. )
  715. @pytest.mark.parametrize(
  716. 'option_value,feature_available,option_flag',
  717. (
  718. (True, True, None),
  719. (True, False, None),
  720. (False, True, '--noflags'),
  721. (False, False, '--nobsdflags'),
  722. ),
  723. )
  724. def test_create_archive_with_bsd_flags_option_calls_borg_with_corresponding_parameter(
  725. option_value, feature_available, option_flag
  726. ):
  727. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  728. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  729. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  730. flexmock(module).should_receive('_expand_directories').and_return(())
  731. flexmock(module).should_receive('_expand_home_directories').and_return(())
  732. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  733. flexmock(module.feature).should_receive('available').and_return(feature_available)
  734. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  735. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  736. flexmock(module).should_receive('execute_command').with_args(
  737. ('borg', 'create') + ((option_flag,) if option_flag else ()) + ARCHIVE_WITH_PATHS,
  738. output_log_level=logging.INFO,
  739. output_file=None,
  740. borg_local_path='borg',
  741. working_directory=None,
  742. )
  743. module.create_archive(
  744. dry_run=False,
  745. repository='repo',
  746. location_config={
  747. 'source_directories': ['foo', 'bar'],
  748. 'repositories': ['repo'],
  749. 'bsd_flags': option_value,
  750. 'exclude_patterns': None,
  751. },
  752. storage_config={},
  753. local_borg_version='1.2.3',
  754. )
  755. def test_create_archive_with_files_cache_calls_borg_with_files_cache_parameters():
  756. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  757. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  758. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  759. flexmock(module).should_receive('_expand_directories').and_return(())
  760. flexmock(module).should_receive('_expand_home_directories').and_return(())
  761. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  762. flexmock(module.feature).should_receive('available').and_return(True)
  763. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  764. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  765. flexmock(module).should_receive('execute_command').with_args(
  766. ('borg', 'create', '--files-cache', 'ctime,size') + ARCHIVE_WITH_PATHS,
  767. output_log_level=logging.INFO,
  768. output_file=None,
  769. borg_local_path='borg',
  770. working_directory=None,
  771. )
  772. module.create_archive(
  773. dry_run=False,
  774. repository='repo',
  775. location_config={
  776. 'source_directories': ['foo', 'bar'],
  777. 'repositories': ['repo'],
  778. 'files_cache': 'ctime,size',
  779. 'exclude_patterns': None,
  780. },
  781. storage_config={},
  782. local_borg_version='1.2.3',
  783. )
  784. def test_create_archive_with_local_path_calls_borg_via_local_path():
  785. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  786. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  787. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  788. flexmock(module).should_receive('_expand_directories').and_return(())
  789. flexmock(module).should_receive('_expand_home_directories').and_return(())
  790. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  791. flexmock(module.feature).should_receive('available').and_return(True)
  792. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  793. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  794. flexmock(module).should_receive('execute_command').with_args(
  795. ('borg1', 'create') + ARCHIVE_WITH_PATHS,
  796. output_log_level=logging.INFO,
  797. output_file=None,
  798. borg_local_path='borg1',
  799. working_directory=None,
  800. )
  801. module.create_archive(
  802. dry_run=False,
  803. repository='repo',
  804. location_config={
  805. 'source_directories': ['foo', 'bar'],
  806. 'repositories': ['repo'],
  807. 'exclude_patterns': None,
  808. },
  809. storage_config={},
  810. local_borg_version='1.2.3',
  811. local_path='borg1',
  812. )
  813. def test_create_archive_with_remote_path_calls_borg_with_remote_path_parameters():
  814. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  815. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  816. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  817. flexmock(module).should_receive('_expand_directories').and_return(())
  818. flexmock(module).should_receive('_expand_home_directories').and_return(())
  819. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  820. flexmock(module.feature).should_receive('available').and_return(True)
  821. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  822. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  823. flexmock(module).should_receive('execute_command').with_args(
  824. ('borg', 'create', '--remote-path', 'borg1') + ARCHIVE_WITH_PATHS,
  825. output_log_level=logging.INFO,
  826. output_file=None,
  827. borg_local_path='borg',
  828. working_directory=None,
  829. )
  830. module.create_archive(
  831. dry_run=False,
  832. repository='repo',
  833. location_config={
  834. 'source_directories': ['foo', 'bar'],
  835. 'repositories': ['repo'],
  836. 'exclude_patterns': None,
  837. },
  838. storage_config={},
  839. local_borg_version='1.2.3',
  840. remote_path='borg1',
  841. )
  842. def test_create_archive_with_umask_calls_borg_with_umask_parameters():
  843. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  844. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  845. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  846. flexmock(module).should_receive('_expand_directories').and_return(())
  847. flexmock(module).should_receive('_expand_home_directories').and_return(())
  848. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  849. flexmock(module.feature).should_receive('available').and_return(True)
  850. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  851. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  852. flexmock(module).should_receive('execute_command').with_args(
  853. ('borg', 'create', '--umask', '740') + ARCHIVE_WITH_PATHS,
  854. output_log_level=logging.INFO,
  855. output_file=None,
  856. borg_local_path='borg',
  857. working_directory=None,
  858. )
  859. module.create_archive(
  860. dry_run=False,
  861. repository='repo',
  862. location_config={
  863. 'source_directories': ['foo', 'bar'],
  864. 'repositories': ['repo'],
  865. 'exclude_patterns': None,
  866. },
  867. storage_config={'umask': 740},
  868. local_borg_version='1.2.3',
  869. )
  870. def test_create_archive_with_lock_wait_calls_borg_with_lock_wait_parameters():
  871. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  872. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  873. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  874. flexmock(module).should_receive('_expand_directories').and_return(())
  875. flexmock(module).should_receive('_expand_home_directories').and_return(())
  876. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  877. flexmock(module.feature).should_receive('available').and_return(True)
  878. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  879. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  880. flexmock(module).should_receive('execute_command').with_args(
  881. ('borg', 'create', '--lock-wait', '5') + ARCHIVE_WITH_PATHS,
  882. output_log_level=logging.INFO,
  883. output_file=None,
  884. borg_local_path='borg',
  885. working_directory=None,
  886. )
  887. module.create_archive(
  888. dry_run=False,
  889. repository='repo',
  890. location_config={
  891. 'source_directories': ['foo', 'bar'],
  892. 'repositories': ['repo'],
  893. 'exclude_patterns': None,
  894. },
  895. storage_config={'lock_wait': 5},
  896. local_borg_version='1.2.3',
  897. )
  898. def test_create_archive_with_stats_calls_borg_with_stats_parameter_and_warning_output_log_level():
  899. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  900. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  901. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  902. flexmock(module).should_receive('_expand_directories').and_return(())
  903. flexmock(module).should_receive('_expand_home_directories').and_return(())
  904. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  905. flexmock(module.feature).should_receive('available').and_return(True)
  906. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  907. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  908. flexmock(module).should_receive('execute_command').with_args(
  909. ('borg', 'create', '--stats') + ARCHIVE_WITH_PATHS,
  910. output_log_level=logging.WARNING,
  911. output_file=None,
  912. borg_local_path='borg',
  913. working_directory=None,
  914. )
  915. module.create_archive(
  916. dry_run=False,
  917. repository='repo',
  918. location_config={
  919. 'source_directories': ['foo', 'bar'],
  920. 'repositories': ['repo'],
  921. 'exclude_patterns': None,
  922. },
  923. storage_config={},
  924. local_borg_version='1.2.3',
  925. stats=True,
  926. )
  927. def test_create_archive_with_stats_and_log_info_calls_borg_with_stats_parameter_and_info_output_log_level():
  928. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  929. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  930. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  931. flexmock(module).should_receive('_expand_directories').and_return(())
  932. flexmock(module).should_receive('_expand_home_directories').and_return(())
  933. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  934. flexmock(module.feature).should_receive('available').and_return(True)
  935. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  936. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  937. flexmock(module).should_receive('execute_command').with_args(
  938. ('borg', 'create', '--info', '--stats') + ARCHIVE_WITH_PATHS,
  939. output_log_level=logging.INFO,
  940. output_file=None,
  941. borg_local_path='borg',
  942. working_directory=None,
  943. )
  944. insert_logging_mock(logging.INFO)
  945. module.create_archive(
  946. dry_run=False,
  947. repository='repo',
  948. location_config={
  949. 'source_directories': ['foo', 'bar'],
  950. 'repositories': ['repo'],
  951. 'exclude_patterns': None,
  952. },
  953. storage_config={},
  954. local_borg_version='1.2.3',
  955. stats=True,
  956. )
  957. def test_create_archive_with_files_calls_borg_with_list_parameter_and_warning_output_log_level():
  958. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  959. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  960. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  961. flexmock(module).should_receive('_expand_directories').and_return(())
  962. flexmock(module).should_receive('_expand_home_directories').and_return(())
  963. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  964. flexmock(module.feature).should_receive('available').and_return(True)
  965. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  966. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  967. flexmock(module).should_receive('execute_command').with_args(
  968. ('borg', 'create', '--list', '--filter', 'AME-') + ARCHIVE_WITH_PATHS,
  969. output_log_level=logging.WARNING,
  970. output_file=None,
  971. borg_local_path='borg',
  972. working_directory=None,
  973. )
  974. module.create_archive(
  975. dry_run=False,
  976. repository='repo',
  977. location_config={
  978. 'source_directories': ['foo', 'bar'],
  979. 'repositories': ['repo'],
  980. 'exclude_patterns': None,
  981. },
  982. storage_config={},
  983. local_borg_version='1.2.3',
  984. files=True,
  985. )
  986. def test_create_archive_with_files_and_log_info_calls_borg_with_list_parameter_and_info_output_log_level():
  987. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  988. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  989. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  990. flexmock(module).should_receive('_expand_directories').and_return(())
  991. flexmock(module).should_receive('_expand_home_directories').and_return(())
  992. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  993. flexmock(module.feature).should_receive('available').and_return(True)
  994. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  995. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  996. flexmock(module).should_receive('execute_command').with_args(
  997. ('borg', 'create', '--list', '--filter', 'AME-', '--info') + ARCHIVE_WITH_PATHS,
  998. output_log_level=logging.INFO,
  999. output_file=None,
  1000. borg_local_path='borg',
  1001. working_directory=None,
  1002. )
  1003. insert_logging_mock(logging.INFO)
  1004. module.create_archive(
  1005. dry_run=False,
  1006. repository='repo',
  1007. location_config={
  1008. 'source_directories': ['foo', 'bar'],
  1009. 'repositories': ['repo'],
  1010. 'exclude_patterns': None,
  1011. },
  1012. storage_config={},
  1013. local_borg_version='1.2.3',
  1014. files=True,
  1015. )
  1016. def test_create_archive_with_progress_and_log_info_calls_borg_with_progress_parameter_and_no_list():
  1017. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  1018. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  1019. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  1020. flexmock(module).should_receive('_expand_directories').and_return(())
  1021. flexmock(module).should_receive('_expand_home_directories').and_return(())
  1022. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  1023. flexmock(module.feature).should_receive('available').and_return(True)
  1024. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  1025. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  1026. flexmock(module).should_receive('execute_command').with_args(
  1027. ('borg', 'create', '--info', '--progress') + ARCHIVE_WITH_PATHS,
  1028. output_log_level=logging.INFO,
  1029. output_file=module.DO_NOT_CAPTURE,
  1030. borg_local_path='borg',
  1031. working_directory=None,
  1032. )
  1033. insert_logging_mock(logging.INFO)
  1034. module.create_archive(
  1035. dry_run=False,
  1036. repository='repo',
  1037. location_config={
  1038. 'source_directories': ['foo', 'bar'],
  1039. 'repositories': ['repo'],
  1040. 'exclude_patterns': None,
  1041. },
  1042. storage_config={},
  1043. local_borg_version='1.2.3',
  1044. progress=True,
  1045. )
  1046. def test_create_archive_with_progress_calls_borg_with_progress_parameter():
  1047. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  1048. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  1049. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  1050. flexmock(module).should_receive('_expand_directories').and_return(())
  1051. flexmock(module).should_receive('_expand_home_directories').and_return(())
  1052. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  1053. flexmock(module.feature).should_receive('available').and_return(True)
  1054. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  1055. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  1056. flexmock(module).should_receive('execute_command').with_args(
  1057. ('borg', 'create', '--progress') + ARCHIVE_WITH_PATHS,
  1058. output_log_level=logging.INFO,
  1059. output_file=module.DO_NOT_CAPTURE,
  1060. borg_local_path='borg',
  1061. working_directory=None,
  1062. )
  1063. module.create_archive(
  1064. dry_run=False,
  1065. repository='repo',
  1066. location_config={
  1067. 'source_directories': ['foo', 'bar'],
  1068. 'repositories': ['repo'],
  1069. 'exclude_patterns': None,
  1070. },
  1071. storage_config={},
  1072. local_borg_version='1.2.3',
  1073. progress=True,
  1074. )
  1075. def test_create_archive_with_progress_and_stream_processes_calls_borg_with_progress_parameter():
  1076. processes = flexmock()
  1077. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  1078. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  1079. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  1080. flexmock(module).should_receive('_expand_directories').and_return(())
  1081. flexmock(module).should_receive('_expand_home_directories').and_return(())
  1082. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  1083. flexmock(module.feature).should_receive('available').and_return(True)
  1084. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  1085. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  1086. flexmock(module).should_receive('execute_command_with_processes').with_args(
  1087. ('borg', 'create', '--one-file-system', '--read-special', '--progress')
  1088. + ARCHIVE_WITH_PATHS,
  1089. processes=processes,
  1090. output_log_level=logging.INFO,
  1091. output_file=module.DO_NOT_CAPTURE,
  1092. borg_local_path='borg',
  1093. working_directory=None,
  1094. )
  1095. module.create_archive(
  1096. dry_run=False,
  1097. repository='repo',
  1098. location_config={
  1099. 'source_directories': ['foo', 'bar'],
  1100. 'repositories': ['repo'],
  1101. 'exclude_patterns': None,
  1102. },
  1103. storage_config={},
  1104. local_borg_version='1.2.3',
  1105. progress=True,
  1106. stream_processes=processes,
  1107. )
  1108. def test_create_archive_with_json_calls_borg_with_json_parameter():
  1109. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  1110. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  1111. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  1112. flexmock(module).should_receive('_expand_directories').and_return(())
  1113. flexmock(module).should_receive('_expand_home_directories').and_return(())
  1114. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  1115. flexmock(module.feature).should_receive('available').and_return(True)
  1116. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  1117. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  1118. flexmock(module).should_receive('execute_command').with_args(
  1119. ('borg', 'create', '--json') + ARCHIVE_WITH_PATHS,
  1120. output_log_level=None,
  1121. output_file=None,
  1122. borg_local_path='borg',
  1123. working_directory=None,
  1124. ).and_return('[]')
  1125. json_output = module.create_archive(
  1126. dry_run=False,
  1127. repository='repo',
  1128. location_config={
  1129. 'source_directories': ['foo', 'bar'],
  1130. 'repositories': ['repo'],
  1131. 'exclude_patterns': None,
  1132. },
  1133. storage_config={},
  1134. local_borg_version='1.2.3',
  1135. json=True,
  1136. )
  1137. assert json_output == '[]'
  1138. def test_create_archive_with_stats_and_json_calls_borg_without_stats_parameter():
  1139. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  1140. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  1141. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  1142. flexmock(module).should_receive('_expand_directories').and_return(())
  1143. flexmock(module).should_receive('_expand_home_directories').and_return(())
  1144. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  1145. flexmock(module.feature).should_receive('available').and_return(True)
  1146. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  1147. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  1148. flexmock(module).should_receive('execute_command').with_args(
  1149. ('borg', 'create', '--json') + ARCHIVE_WITH_PATHS,
  1150. output_log_level=None,
  1151. output_file=None,
  1152. borg_local_path='borg',
  1153. working_directory=None,
  1154. ).and_return('[]')
  1155. json_output = module.create_archive(
  1156. dry_run=False,
  1157. repository='repo',
  1158. location_config={
  1159. 'source_directories': ['foo', 'bar'],
  1160. 'repositories': ['repo'],
  1161. 'exclude_patterns': None,
  1162. },
  1163. storage_config={},
  1164. local_borg_version='1.2.3',
  1165. json=True,
  1166. stats=True,
  1167. )
  1168. assert json_output == '[]'
  1169. def test_create_archive_with_source_directories_glob_expands():
  1170. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  1171. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'food'))
  1172. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  1173. flexmock(module).should_receive('_expand_directories').and_return(())
  1174. flexmock(module).should_receive('_expand_home_directories').and_return(())
  1175. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  1176. flexmock(module.feature).should_receive('available').and_return(True)
  1177. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  1178. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  1179. flexmock(module).should_receive('execute_command').with_args(
  1180. ('borg', 'create', 'repo::{}'.format(DEFAULT_ARCHIVE_NAME), 'foo', 'food'),
  1181. output_log_level=logging.INFO,
  1182. output_file=None,
  1183. borg_local_path='borg',
  1184. working_directory=None,
  1185. )
  1186. flexmock(module.glob).should_receive('glob').with_args('foo*').and_return(['foo', 'food'])
  1187. module.create_archive(
  1188. dry_run=False,
  1189. repository='repo',
  1190. location_config={
  1191. 'source_directories': ['foo*'],
  1192. 'repositories': ['repo'],
  1193. 'exclude_patterns': None,
  1194. },
  1195. storage_config={},
  1196. local_borg_version='1.2.3',
  1197. )
  1198. def test_create_archive_with_non_matching_source_directories_glob_passes_through():
  1199. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  1200. flexmock(module).should_receive('deduplicate_directories').and_return(('foo*',))
  1201. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  1202. flexmock(module).should_receive('_expand_directories').and_return(())
  1203. flexmock(module).should_receive('_expand_home_directories').and_return(())
  1204. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  1205. flexmock(module.feature).should_receive('available').and_return(True)
  1206. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  1207. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  1208. flexmock(module).should_receive('execute_command').with_args(
  1209. ('borg', 'create', 'repo::{}'.format(DEFAULT_ARCHIVE_NAME), 'foo*'),
  1210. output_log_level=logging.INFO,
  1211. output_file=None,
  1212. borg_local_path='borg',
  1213. working_directory=None,
  1214. )
  1215. flexmock(module.glob).should_receive('glob').with_args('foo*').and_return([])
  1216. module.create_archive(
  1217. dry_run=False,
  1218. repository='repo',
  1219. location_config={
  1220. 'source_directories': ['foo*'],
  1221. 'repositories': ['repo'],
  1222. 'exclude_patterns': None,
  1223. },
  1224. storage_config={},
  1225. local_borg_version='1.2.3',
  1226. )
  1227. def test_create_archive_with_glob_calls_borg_with_expanded_directories():
  1228. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  1229. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'food'))
  1230. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  1231. flexmock(module).should_receive('_expand_directories').and_return(())
  1232. flexmock(module).should_receive('_expand_home_directories').and_return(())
  1233. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  1234. flexmock(module.feature).should_receive('available').and_return(True)
  1235. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  1236. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  1237. flexmock(module).should_receive('execute_command').with_args(
  1238. ('borg', 'create', 'repo::{}'.format(DEFAULT_ARCHIVE_NAME), 'foo', 'food'),
  1239. output_log_level=logging.INFO,
  1240. output_file=None,
  1241. borg_local_path='borg',
  1242. working_directory=None,
  1243. )
  1244. module.create_archive(
  1245. dry_run=False,
  1246. repository='repo',
  1247. location_config={
  1248. 'source_directories': ['foo*'],
  1249. 'repositories': ['repo'],
  1250. 'exclude_patterns': None,
  1251. },
  1252. storage_config={},
  1253. local_borg_version='1.2.3',
  1254. )
  1255. def test_create_archive_with_archive_name_format_calls_borg_with_archive_name():
  1256. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  1257. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  1258. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  1259. flexmock(module).should_receive('_expand_directories').and_return(())
  1260. flexmock(module).should_receive('_expand_home_directories').and_return(())
  1261. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  1262. flexmock(module.feature).should_receive('available').and_return(True)
  1263. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  1264. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  1265. flexmock(module).should_receive('execute_command').with_args(
  1266. ('borg', 'create', 'repo::ARCHIVE_NAME', 'foo', 'bar'),
  1267. output_log_level=logging.INFO,
  1268. output_file=None,
  1269. borg_local_path='borg',
  1270. working_directory=None,
  1271. )
  1272. module.create_archive(
  1273. dry_run=False,
  1274. repository='repo',
  1275. location_config={
  1276. 'source_directories': ['foo', 'bar'],
  1277. 'repositories': ['repo'],
  1278. 'exclude_patterns': None,
  1279. },
  1280. storage_config={'archive_name_format': 'ARCHIVE_NAME'},
  1281. local_borg_version='1.2.3',
  1282. )
  1283. def test_create_archive_with_archive_name_format_accepts_borg_placeholders():
  1284. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  1285. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  1286. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  1287. flexmock(module).should_receive('_expand_directories').and_return(())
  1288. flexmock(module).should_receive('_expand_home_directories').and_return(())
  1289. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  1290. flexmock(module.feature).should_receive('available').and_return(True)
  1291. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  1292. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  1293. flexmock(module).should_receive('execute_command').with_args(
  1294. ('borg', 'create', 'repo::Documents_{hostname}-{now}', 'foo', 'bar'),
  1295. output_log_level=logging.INFO,
  1296. output_file=None,
  1297. borg_local_path='borg',
  1298. working_directory=None,
  1299. )
  1300. module.create_archive(
  1301. dry_run=False,
  1302. repository='repo',
  1303. location_config={
  1304. 'source_directories': ['foo', 'bar'],
  1305. 'repositories': ['repo'],
  1306. 'exclude_patterns': None,
  1307. },
  1308. storage_config={'archive_name_format': 'Documents_{hostname}-{now}'},
  1309. local_borg_version='1.2.3',
  1310. )
  1311. def test_create_archive_with_repository_accepts_borg_placeholders():
  1312. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  1313. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  1314. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  1315. flexmock(module).should_receive('_expand_directories').and_return(())
  1316. flexmock(module).should_receive('_expand_home_directories').and_return(())
  1317. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  1318. flexmock(module.feature).should_receive('available').and_return(True)
  1319. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  1320. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  1321. flexmock(module).should_receive('execute_command').with_args(
  1322. ('borg', 'create', '{fqdn}::Documents_{hostname}-{now}', 'foo', 'bar'),
  1323. output_log_level=logging.INFO,
  1324. output_file=None,
  1325. borg_local_path='borg',
  1326. working_directory=None,
  1327. )
  1328. module.create_archive(
  1329. dry_run=False,
  1330. repository='{fqdn}',
  1331. location_config={
  1332. 'source_directories': ['foo', 'bar'],
  1333. 'repositories': ['{fqdn}'],
  1334. 'exclude_patterns': None,
  1335. },
  1336. storage_config={'archive_name_format': 'Documents_{hostname}-{now}'},
  1337. local_borg_version='1.2.3',
  1338. )
  1339. def test_create_archive_with_extra_borg_options_calls_borg_with_extra_options():
  1340. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  1341. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  1342. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  1343. flexmock(module).should_receive('_expand_directories').and_return(())
  1344. flexmock(module).should_receive('_expand_home_directories').and_return(())
  1345. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  1346. flexmock(module.feature).should_receive('available').and_return(True)
  1347. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  1348. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  1349. flexmock(module).should_receive('execute_command').with_args(
  1350. ('borg', 'create', '--extra', '--options') + ARCHIVE_WITH_PATHS,
  1351. output_log_level=logging.INFO,
  1352. output_file=None,
  1353. borg_local_path='borg',
  1354. working_directory=None,
  1355. )
  1356. module.create_archive(
  1357. dry_run=False,
  1358. repository='repo',
  1359. location_config={
  1360. 'source_directories': ['foo', 'bar'],
  1361. 'repositories': ['repo'],
  1362. 'exclude_patterns': None,
  1363. },
  1364. storage_config={'extra_borg_options': {'create': '--extra --options'}},
  1365. local_borg_version='1.2.3',
  1366. )
  1367. def test_create_archive_with_stream_processes_calls_borg_with_processes():
  1368. processes = flexmock()
  1369. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  1370. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  1371. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  1372. flexmock(module).should_receive('_expand_directories').and_return(())
  1373. flexmock(module).should_receive('_expand_home_directories').and_return(())
  1374. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  1375. flexmock(module.feature).should_receive('available').and_return(True)
  1376. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  1377. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  1378. flexmock(module).should_receive('execute_command_with_processes').with_args(
  1379. ('borg', 'create', '--one-file-system', '--read-special') + ARCHIVE_WITH_PATHS,
  1380. processes=processes,
  1381. output_log_level=logging.INFO,
  1382. output_file=None,
  1383. borg_local_path='borg',
  1384. working_directory=None,
  1385. )
  1386. module.create_archive(
  1387. dry_run=False,
  1388. repository='repo',
  1389. location_config={
  1390. 'source_directories': ['foo', 'bar'],
  1391. 'repositories': ['repo'],
  1392. 'exclude_patterns': None,
  1393. },
  1394. storage_config={},
  1395. local_borg_version='1.2.3',
  1396. stream_processes=processes,
  1397. )