test_create.py 66 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577
  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. )
  179. module.create_archive(
  180. dry_run=False,
  181. repository='repo',
  182. location_config={
  183. 'source_directories': ['foo', 'bar'],
  184. 'repositories': ['repo'],
  185. 'exclude_patterns': None,
  186. },
  187. storage_config={},
  188. local_borg_version='1.2.3',
  189. )
  190. def test_create_archive_with_patterns_calls_borg_with_patterns():
  191. pattern_flags = ('--patterns-from', 'patterns')
  192. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  193. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  194. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  195. flexmock(module).should_receive('_expand_directories').and_return(())
  196. flexmock(module).should_receive('_expand_home_directories').and_return(())
  197. flexmock(module).should_receive('_write_pattern_file').and_return(
  198. flexmock(name='/tmp/patterns')
  199. ).and_return(None)
  200. flexmock(module.feature).should_receive('available').and_return(True)
  201. flexmock(module).should_receive('_make_pattern_flags').and_return(pattern_flags)
  202. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  203. flexmock(module).should_receive('execute_command').with_args(
  204. ('borg', 'create') + pattern_flags + ARCHIVE_WITH_PATHS,
  205. output_log_level=logging.INFO,
  206. output_file=None,
  207. borg_local_path='borg',
  208. )
  209. module.create_archive(
  210. dry_run=False,
  211. repository='repo',
  212. location_config={
  213. 'source_directories': ['foo', 'bar'],
  214. 'repositories': ['repo'],
  215. 'patterns': ['pattern'],
  216. },
  217. storage_config={},
  218. local_borg_version='1.2.3',
  219. )
  220. def test_create_archive_with_exclude_patterns_calls_borg_with_excludes():
  221. exclude_flags = ('--exclude-from', 'excludes')
  222. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  223. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  224. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  225. flexmock(module).should_receive('_expand_directories').and_return(())
  226. flexmock(module).should_receive('_expand_home_directories').and_return(('exclude',))
  227. flexmock(module).should_receive('_write_pattern_file').and_return(None).and_return(
  228. flexmock(name='/tmp/excludes')
  229. )
  230. flexmock(module.feature).should_receive('available').and_return(True)
  231. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  232. flexmock(module).should_receive('_make_exclude_flags').and_return(exclude_flags)
  233. flexmock(module).should_receive('execute_command').with_args(
  234. ('borg', 'create') + exclude_flags + ARCHIVE_WITH_PATHS,
  235. output_log_level=logging.INFO,
  236. output_file=None,
  237. borg_local_path='borg',
  238. )
  239. module.create_archive(
  240. dry_run=False,
  241. repository='repo',
  242. location_config={
  243. 'source_directories': ['foo', 'bar'],
  244. 'repositories': ['repo'],
  245. 'exclude_patterns': ['exclude'],
  246. },
  247. storage_config={},
  248. local_borg_version='1.2.3',
  249. )
  250. def test_create_archive_with_log_info_calls_borg_with_info_parameter():
  251. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  252. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  253. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  254. flexmock(module).should_receive('_expand_directories').and_return(())
  255. flexmock(module).should_receive('_expand_home_directories').and_return(())
  256. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  257. flexmock(module.feature).should_receive('available').and_return(True)
  258. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  259. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  260. flexmock(module).should_receive('execute_command').with_args(
  261. ('borg', 'create', '--info') + ARCHIVE_WITH_PATHS,
  262. output_log_level=logging.INFO,
  263. output_file=None,
  264. borg_local_path='borg',
  265. )
  266. insert_logging_mock(logging.INFO)
  267. module.create_archive(
  268. dry_run=False,
  269. repository='repo',
  270. location_config={
  271. 'source_directories': ['foo', 'bar'],
  272. 'repositories': ['repo'],
  273. 'exclude_patterns': None,
  274. },
  275. storage_config={},
  276. local_borg_version='1.2.3',
  277. )
  278. def test_create_archive_with_log_info_and_json_suppresses_most_borg_output():
  279. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  280. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  281. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  282. flexmock(module).should_receive('_expand_directories').and_return(())
  283. flexmock(module).should_receive('_expand_home_directories').and_return(())
  284. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  285. flexmock(module.feature).should_receive('available').and_return(True)
  286. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  287. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  288. flexmock(module).should_receive('execute_command').with_args(
  289. ('borg', 'create', '--json') + ARCHIVE_WITH_PATHS,
  290. output_log_level=None,
  291. output_file=None,
  292. borg_local_path='borg',
  293. )
  294. insert_logging_mock(logging.INFO)
  295. module.create_archive(
  296. dry_run=False,
  297. repository='repo',
  298. location_config={
  299. 'source_directories': ['foo', 'bar'],
  300. 'repositories': ['repo'],
  301. 'exclude_patterns': None,
  302. },
  303. storage_config={},
  304. local_borg_version='1.2.3',
  305. json=True,
  306. )
  307. def test_create_archive_with_log_debug_calls_borg_with_debug_parameter():
  308. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  309. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  310. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  311. flexmock(module).should_receive('_expand_directories').and_return(())
  312. flexmock(module).should_receive('_expand_home_directories').and_return(())
  313. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  314. flexmock(module.feature).should_receive('available').and_return(True)
  315. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  316. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  317. flexmock(module).should_receive('execute_command').with_args(
  318. ('borg', 'create', '--debug', '--show-rc') + ARCHIVE_WITH_PATHS,
  319. output_log_level=logging.INFO,
  320. output_file=None,
  321. borg_local_path='borg',
  322. )
  323. insert_logging_mock(logging.DEBUG)
  324. module.create_archive(
  325. dry_run=False,
  326. repository='repo',
  327. location_config={
  328. 'source_directories': ['foo', 'bar'],
  329. 'repositories': ['repo'],
  330. 'exclude_patterns': None,
  331. },
  332. storage_config={},
  333. local_borg_version='1.2.3',
  334. )
  335. def test_create_archive_with_log_debug_and_json_suppresses_most_borg_output():
  336. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  337. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  338. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  339. flexmock(module).should_receive('_expand_directories').and_return(())
  340. flexmock(module).should_receive('_expand_home_directories').and_return(())
  341. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  342. flexmock(module.feature).should_receive('available').and_return(True)
  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', '--json') + ARCHIVE_WITH_PATHS,
  347. output_log_level=None,
  348. output_file=None,
  349. borg_local_path='borg',
  350. )
  351. insert_logging_mock(logging.DEBUG)
  352. module.create_archive(
  353. dry_run=False,
  354. repository='repo',
  355. location_config={
  356. 'source_directories': ['foo', 'bar'],
  357. 'repositories': ['repo'],
  358. 'exclude_patterns': None,
  359. },
  360. storage_config={},
  361. local_borg_version='1.2.3',
  362. json=True,
  363. )
  364. def test_create_archive_with_dry_run_calls_borg_with_dry_run_parameter():
  365. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  366. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  367. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  368. flexmock(module).should_receive('_expand_directories').and_return(())
  369. flexmock(module).should_receive('_expand_home_directories').and_return(())
  370. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  371. flexmock(module.feature).should_receive('available').and_return(True)
  372. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  373. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  374. flexmock(module).should_receive('execute_command').with_args(
  375. ('borg', 'create', '--dry-run') + ARCHIVE_WITH_PATHS,
  376. output_log_level=logging.INFO,
  377. output_file=None,
  378. borg_local_path='borg',
  379. )
  380. module.create_archive(
  381. dry_run=True,
  382. repository='repo',
  383. location_config={
  384. 'source_directories': ['foo', 'bar'],
  385. 'repositories': ['repo'],
  386. 'exclude_patterns': None,
  387. },
  388. storage_config={},
  389. local_borg_version='1.2.3',
  390. )
  391. def test_create_archive_with_stats_and_dry_run_calls_borg_without_stats_parameter():
  392. # --dry-run and --stats are mutually exclusive, see:
  393. # https://borgbackup.readthedocs.io/en/stable/usage/create.html#description
  394. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  395. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  396. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  397. flexmock(module).should_receive('_expand_directories').and_return(())
  398. flexmock(module).should_receive('_expand_home_directories').and_return(())
  399. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  400. flexmock(module.feature).should_receive('available').and_return(True)
  401. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  402. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  403. flexmock(module).should_receive('execute_command').with_args(
  404. ('borg', 'create', '--info', '--dry-run') + ARCHIVE_WITH_PATHS,
  405. output_log_level=logging.INFO,
  406. output_file=None,
  407. borg_local_path='borg',
  408. )
  409. insert_logging_mock(logging.INFO)
  410. module.create_archive(
  411. dry_run=True,
  412. repository='repo',
  413. location_config={
  414. 'source_directories': ['foo', 'bar'],
  415. 'repositories': ['repo'],
  416. 'exclude_patterns': None,
  417. },
  418. storage_config={},
  419. local_borg_version='1.2.3',
  420. stats=True,
  421. )
  422. def test_create_archive_with_checkpoint_interval_calls_borg_with_checkpoint_interval_parameters():
  423. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  424. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  425. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  426. flexmock(module).should_receive('_expand_directories').and_return(())
  427. flexmock(module).should_receive('_expand_home_directories').and_return(())
  428. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  429. flexmock(module.feature).should_receive('available').and_return(True)
  430. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  431. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  432. flexmock(module).should_receive('execute_command').with_args(
  433. ('borg', 'create', '--checkpoint-interval', '600') + ARCHIVE_WITH_PATHS,
  434. output_log_level=logging.INFO,
  435. output_file=None,
  436. borg_local_path='borg',
  437. )
  438. module.create_archive(
  439. dry_run=False,
  440. repository='repo',
  441. location_config={
  442. 'source_directories': ['foo', 'bar'],
  443. 'repositories': ['repo'],
  444. 'exclude_patterns': None,
  445. },
  446. storage_config={'checkpoint_interval': 600},
  447. local_borg_version='1.2.3',
  448. )
  449. def test_create_archive_with_chunker_params_calls_borg_with_chunker_params_parameters():
  450. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  451. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  452. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  453. flexmock(module).should_receive('_expand_directories').and_return(())
  454. flexmock(module).should_receive('_expand_home_directories').and_return(())
  455. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  456. flexmock(module.feature).should_receive('available').and_return(True)
  457. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  458. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  459. flexmock(module).should_receive('execute_command').with_args(
  460. ('borg', 'create', '--chunker-params', '1,2,3,4') + ARCHIVE_WITH_PATHS,
  461. output_log_level=logging.INFO,
  462. output_file=None,
  463. borg_local_path='borg',
  464. )
  465. module.create_archive(
  466. dry_run=False,
  467. repository='repo',
  468. location_config={
  469. 'source_directories': ['foo', 'bar'],
  470. 'repositories': ['repo'],
  471. 'exclude_patterns': None,
  472. },
  473. storage_config={'chunker_params': '1,2,3,4'},
  474. local_borg_version='1.2.3',
  475. )
  476. def test_create_archive_with_compression_calls_borg_with_compression_parameters():
  477. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  478. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  479. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  480. flexmock(module).should_receive('_expand_directories').and_return(())
  481. flexmock(module).should_receive('_expand_home_directories').and_return(())
  482. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  483. flexmock(module.feature).should_receive('available').and_return(True)
  484. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  485. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  486. flexmock(module).should_receive('execute_command').with_args(
  487. ('borg', 'create', '--compression', 'rle') + ARCHIVE_WITH_PATHS,
  488. output_log_level=logging.INFO,
  489. output_file=None,
  490. borg_local_path='borg',
  491. )
  492. module.create_archive(
  493. dry_run=False,
  494. repository='repo',
  495. location_config={
  496. 'source_directories': ['foo', 'bar'],
  497. 'repositories': ['repo'],
  498. 'exclude_patterns': None,
  499. },
  500. storage_config={'compression': 'rle'},
  501. local_borg_version='1.2.3',
  502. )
  503. def test_create_archive_with_remote_rate_limit_calls_borg_with_remote_ratelimit_parameters():
  504. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  505. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  506. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  507. flexmock(module).should_receive('_expand_directories').and_return(())
  508. flexmock(module).should_receive('_expand_home_directories').and_return(())
  509. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  510. flexmock(module.feature).should_receive('available').and_return(True)
  511. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  512. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  513. flexmock(module).should_receive('execute_command').with_args(
  514. ('borg', 'create', '--remote-ratelimit', '100') + ARCHIVE_WITH_PATHS,
  515. output_log_level=logging.INFO,
  516. output_file=None,
  517. borg_local_path='borg',
  518. )
  519. module.create_archive(
  520. dry_run=False,
  521. repository='repo',
  522. location_config={
  523. 'source_directories': ['foo', 'bar'],
  524. 'repositories': ['repo'],
  525. 'exclude_patterns': None,
  526. },
  527. storage_config={'remote_rate_limit': 100},
  528. local_borg_version='1.2.3',
  529. )
  530. def test_create_archive_with_one_file_system_calls_borg_with_one_file_system_parameter():
  531. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  532. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  533. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  534. flexmock(module).should_receive('_expand_directories').and_return(())
  535. flexmock(module).should_receive('_expand_home_directories').and_return(())
  536. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  537. flexmock(module.feature).should_receive('available').and_return(True)
  538. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  539. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  540. flexmock(module).should_receive('execute_command').with_args(
  541. ('borg', 'create', '--one-file-system') + ARCHIVE_WITH_PATHS,
  542. output_log_level=logging.INFO,
  543. output_file=None,
  544. borg_local_path='borg',
  545. )
  546. module.create_archive(
  547. dry_run=False,
  548. repository='repo',
  549. location_config={
  550. 'source_directories': ['foo', 'bar'],
  551. 'repositories': ['repo'],
  552. 'one_file_system': True,
  553. 'exclude_patterns': None,
  554. },
  555. storage_config={},
  556. local_borg_version='1.2.3',
  557. )
  558. @pytest.mark.parametrize(
  559. 'feature_available,option_flag', ((True, '--numeric-ids'), (False, '--numeric-owner'),),
  560. )
  561. def test_create_archive_with_numeric_owner_calls_borg_with_numeric_ids_parameter(
  562. feature_available, option_flag
  563. ):
  564. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  565. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  566. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  567. flexmock(module).should_receive('_expand_directories').and_return(())
  568. flexmock(module).should_receive('_expand_home_directories').and_return(())
  569. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  570. flexmock(module.feature).should_receive('available').and_return(feature_available)
  571. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  572. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  573. flexmock(module).should_receive('execute_command').with_args(
  574. ('borg', 'create') + ((option_flag,) if option_flag else ()) + ARCHIVE_WITH_PATHS,
  575. output_log_level=logging.INFO,
  576. output_file=None,
  577. borg_local_path='borg',
  578. )
  579. module.create_archive(
  580. dry_run=False,
  581. repository='repo',
  582. location_config={
  583. 'source_directories': ['foo', 'bar'],
  584. 'repositories': ['repo'],
  585. 'numeric_owner': True,
  586. 'exclude_patterns': None,
  587. },
  588. storage_config={},
  589. local_borg_version='1.2.3',
  590. )
  591. def test_create_archive_with_read_special_calls_borg_with_read_special_parameter():
  592. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  593. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  594. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  595. flexmock(module).should_receive('_expand_directories').and_return(())
  596. flexmock(module).should_receive('_expand_home_directories').and_return(())
  597. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  598. flexmock(module.feature).should_receive('available').and_return(True)
  599. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  600. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  601. flexmock(module).should_receive('execute_command').with_args(
  602. ('borg', 'create', '--read-special') + ARCHIVE_WITH_PATHS,
  603. output_log_level=logging.INFO,
  604. output_file=None,
  605. borg_local_path='borg',
  606. )
  607. module.create_archive(
  608. dry_run=False,
  609. repository='repo',
  610. location_config={
  611. 'source_directories': ['foo', 'bar'],
  612. 'repositories': ['repo'],
  613. 'read_special': True,
  614. 'exclude_patterns': None,
  615. },
  616. storage_config={},
  617. local_borg_version='1.2.3',
  618. )
  619. @pytest.mark.parametrize(
  620. 'option_name,option_value',
  621. (('ctime', True), ('ctime', False), ('birthtime', True), ('birthtime', False),),
  622. )
  623. def test_create_archive_with_basic_option_calls_borg_with_corresponding_parameter(
  624. option_name, option_value
  625. ):
  626. option_flag = '--no' + option_name.replace('_', '') if option_value is False else None
  627. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  628. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  629. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  630. flexmock(module).should_receive('_expand_directories').and_return(())
  631. flexmock(module).should_receive('_expand_home_directories').and_return(())
  632. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  633. flexmock(module.feature).should_receive('available').and_return(True)
  634. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  635. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  636. flexmock(module).should_receive('execute_command').with_args(
  637. ('borg', 'create') + ((option_flag,) if option_flag else ()) + ARCHIVE_WITH_PATHS,
  638. output_log_level=logging.INFO,
  639. output_file=None,
  640. borg_local_path='borg',
  641. )
  642. module.create_archive(
  643. dry_run=False,
  644. repository='repo',
  645. location_config={
  646. 'source_directories': ['foo', 'bar'],
  647. 'repositories': ['repo'],
  648. option_name: option_value,
  649. 'exclude_patterns': None,
  650. },
  651. storage_config={},
  652. local_borg_version='1.2.3',
  653. )
  654. @pytest.mark.parametrize(
  655. 'option_value,feature_available,option_flag',
  656. (
  657. (True, True, '--atime'),
  658. (True, False, None),
  659. (False, True, None),
  660. (False, False, '--noatime'),
  661. ),
  662. )
  663. def test_create_archive_with_atime_option_calls_borg_with_corresponding_parameter(
  664. option_value, feature_available, option_flag
  665. ):
  666. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  667. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  668. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  669. flexmock(module).should_receive('_expand_directories').and_return(())
  670. flexmock(module).should_receive('_expand_home_directories').and_return(())
  671. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  672. flexmock(module.feature).should_receive('available').and_return(feature_available)
  673. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  674. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  675. flexmock(module).should_receive('execute_command').with_args(
  676. ('borg', 'create') + ((option_flag,) if option_flag else ()) + ARCHIVE_WITH_PATHS,
  677. output_log_level=logging.INFO,
  678. output_file=None,
  679. borg_local_path='borg',
  680. )
  681. module.create_archive(
  682. dry_run=False,
  683. repository='repo',
  684. location_config={
  685. 'source_directories': ['foo', 'bar'],
  686. 'repositories': ['repo'],
  687. 'atime': option_value,
  688. 'exclude_patterns': None,
  689. },
  690. storage_config={},
  691. local_borg_version='1.2.3',
  692. )
  693. @pytest.mark.parametrize(
  694. 'option_value,feature_available,option_flag',
  695. (
  696. (True, True, None),
  697. (True, False, None),
  698. (False, True, '--noflags'),
  699. (False, False, '--nobsdflags'),
  700. ),
  701. )
  702. def test_create_archive_with_bsd_flags_option_calls_borg_with_corresponding_parameter(
  703. option_value, feature_available, option_flag
  704. ):
  705. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  706. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  707. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  708. flexmock(module).should_receive('_expand_directories').and_return(())
  709. flexmock(module).should_receive('_expand_home_directories').and_return(())
  710. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  711. flexmock(module.feature).should_receive('available').and_return(feature_available)
  712. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  713. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  714. flexmock(module).should_receive('execute_command').with_args(
  715. ('borg', 'create') + ((option_flag,) if option_flag else ()) + ARCHIVE_WITH_PATHS,
  716. output_log_level=logging.INFO,
  717. output_file=None,
  718. borg_local_path='borg',
  719. )
  720. module.create_archive(
  721. dry_run=False,
  722. repository='repo',
  723. location_config={
  724. 'source_directories': ['foo', 'bar'],
  725. 'repositories': ['repo'],
  726. 'bsd_flags': option_value,
  727. 'exclude_patterns': None,
  728. },
  729. storage_config={},
  730. local_borg_version='1.2.3',
  731. )
  732. def test_create_archive_with_files_cache_calls_borg_with_files_cache_parameters():
  733. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  734. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  735. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  736. flexmock(module).should_receive('_expand_directories').and_return(())
  737. flexmock(module).should_receive('_expand_home_directories').and_return(())
  738. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  739. flexmock(module.feature).should_receive('available').and_return(True)
  740. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  741. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  742. flexmock(module).should_receive('execute_command').with_args(
  743. ('borg', 'create', '--files-cache', 'ctime,size') + ARCHIVE_WITH_PATHS,
  744. output_log_level=logging.INFO,
  745. output_file=None,
  746. borg_local_path='borg',
  747. )
  748. module.create_archive(
  749. dry_run=False,
  750. repository='repo',
  751. location_config={
  752. 'source_directories': ['foo', 'bar'],
  753. 'repositories': ['repo'],
  754. 'files_cache': 'ctime,size',
  755. 'exclude_patterns': None,
  756. },
  757. storage_config={},
  758. local_borg_version='1.2.3',
  759. )
  760. def test_create_archive_with_local_path_calls_borg_via_local_path():
  761. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  762. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  763. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  764. flexmock(module).should_receive('_expand_directories').and_return(())
  765. flexmock(module).should_receive('_expand_home_directories').and_return(())
  766. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  767. flexmock(module.feature).should_receive('available').and_return(True)
  768. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  769. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  770. flexmock(module).should_receive('execute_command').with_args(
  771. ('borg1', 'create') + ARCHIVE_WITH_PATHS,
  772. output_log_level=logging.INFO,
  773. output_file=None,
  774. borg_local_path='borg1',
  775. )
  776. module.create_archive(
  777. dry_run=False,
  778. repository='repo',
  779. location_config={
  780. 'source_directories': ['foo', 'bar'],
  781. 'repositories': ['repo'],
  782. 'exclude_patterns': None,
  783. },
  784. storage_config={},
  785. local_borg_version='1.2.3',
  786. local_path='borg1',
  787. )
  788. def test_create_archive_with_remote_path_calls_borg_with_remote_path_parameters():
  789. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  790. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  791. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  792. flexmock(module).should_receive('_expand_directories').and_return(())
  793. flexmock(module).should_receive('_expand_home_directories').and_return(())
  794. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  795. flexmock(module.feature).should_receive('available').and_return(True)
  796. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  797. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  798. flexmock(module).should_receive('execute_command').with_args(
  799. ('borg', 'create', '--remote-path', 'borg1') + ARCHIVE_WITH_PATHS,
  800. output_log_level=logging.INFO,
  801. output_file=None,
  802. borg_local_path='borg',
  803. )
  804. module.create_archive(
  805. dry_run=False,
  806. repository='repo',
  807. location_config={
  808. 'source_directories': ['foo', 'bar'],
  809. 'repositories': ['repo'],
  810. 'exclude_patterns': None,
  811. },
  812. storage_config={},
  813. local_borg_version='1.2.3',
  814. remote_path='borg1',
  815. )
  816. def test_create_archive_with_umask_calls_borg_with_umask_parameters():
  817. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  818. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  819. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  820. flexmock(module).should_receive('_expand_directories').and_return(())
  821. flexmock(module).should_receive('_expand_home_directories').and_return(())
  822. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  823. flexmock(module.feature).should_receive('available').and_return(True)
  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', '--umask', '740') + ARCHIVE_WITH_PATHS,
  828. output_log_level=logging.INFO,
  829. output_file=None,
  830. borg_local_path='borg',
  831. )
  832. module.create_archive(
  833. dry_run=False,
  834. repository='repo',
  835. location_config={
  836. 'source_directories': ['foo', 'bar'],
  837. 'repositories': ['repo'],
  838. 'exclude_patterns': None,
  839. },
  840. storage_config={'umask': 740},
  841. local_borg_version='1.2.3',
  842. )
  843. def test_create_archive_with_lock_wait_calls_borg_with_lock_wait_parameters():
  844. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  845. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  846. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  847. flexmock(module).should_receive('_expand_directories').and_return(())
  848. flexmock(module).should_receive('_expand_home_directories').and_return(())
  849. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  850. flexmock(module.feature).should_receive('available').and_return(True)
  851. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  852. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  853. flexmock(module).should_receive('execute_command').with_args(
  854. ('borg', 'create', '--lock-wait', '5') + ARCHIVE_WITH_PATHS,
  855. output_log_level=logging.INFO,
  856. output_file=None,
  857. borg_local_path='borg',
  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={'lock_wait': 5},
  868. local_borg_version='1.2.3',
  869. )
  870. def test_create_archive_with_stats_calls_borg_with_stats_parameter_and_warning_output_log_level():
  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', '--stats') + ARCHIVE_WITH_PATHS,
  882. output_log_level=logging.WARNING,
  883. output_file=None,
  884. borg_local_path='borg',
  885. )
  886. module.create_archive(
  887. dry_run=False,
  888. repository='repo',
  889. location_config={
  890. 'source_directories': ['foo', 'bar'],
  891. 'repositories': ['repo'],
  892. 'exclude_patterns': None,
  893. },
  894. storage_config={},
  895. local_borg_version='1.2.3',
  896. stats=True,
  897. )
  898. def test_create_archive_with_stats_and_log_info_calls_borg_with_stats_parameter_and_info_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', '--info', '--stats') + ARCHIVE_WITH_PATHS,
  910. output_log_level=logging.INFO,
  911. output_file=None,
  912. borg_local_path='borg',
  913. )
  914. insert_logging_mock(logging.INFO)
  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_files_calls_borg_with_list_parameter_and_warning_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', '--list', '--filter', 'AME-') + ARCHIVE_WITH_PATHS,
  939. output_log_level=logging.WARNING,
  940. output_file=None,
  941. borg_local_path='borg',
  942. )
  943. module.create_archive(
  944. dry_run=False,
  945. repository='repo',
  946. location_config={
  947. 'source_directories': ['foo', 'bar'],
  948. 'repositories': ['repo'],
  949. 'exclude_patterns': None,
  950. },
  951. storage_config={},
  952. local_borg_version='1.2.3',
  953. files=True,
  954. )
  955. def test_create_archive_with_files_and_log_info_calls_borg_with_list_parameter_and_info_output_log_level():
  956. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  957. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  958. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  959. flexmock(module).should_receive('_expand_directories').and_return(())
  960. flexmock(module).should_receive('_expand_home_directories').and_return(())
  961. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  962. flexmock(module.feature).should_receive('available').and_return(True)
  963. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  964. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  965. flexmock(module).should_receive('execute_command').with_args(
  966. ('borg', 'create', '--list', '--filter', 'AME-', '--info') + ARCHIVE_WITH_PATHS,
  967. output_log_level=logging.INFO,
  968. output_file=None,
  969. borg_local_path='borg',
  970. )
  971. insert_logging_mock(logging.INFO)
  972. module.create_archive(
  973. dry_run=False,
  974. repository='repo',
  975. location_config={
  976. 'source_directories': ['foo', 'bar'],
  977. 'repositories': ['repo'],
  978. 'exclude_patterns': None,
  979. },
  980. storage_config={},
  981. local_borg_version='1.2.3',
  982. files=True,
  983. )
  984. def test_create_archive_with_progress_and_log_info_calls_borg_with_progress_parameter_and_no_list():
  985. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  986. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  987. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  988. flexmock(module).should_receive('_expand_directories').and_return(())
  989. flexmock(module).should_receive('_expand_home_directories').and_return(())
  990. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  991. flexmock(module.feature).should_receive('available').and_return(True)
  992. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  993. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  994. flexmock(module).should_receive('execute_command').with_args(
  995. ('borg', 'create', '--info', '--progress') + ARCHIVE_WITH_PATHS,
  996. output_log_level=logging.INFO,
  997. output_file=module.DO_NOT_CAPTURE,
  998. borg_local_path='borg',
  999. )
  1000. insert_logging_mock(logging.INFO)
  1001. module.create_archive(
  1002. dry_run=False,
  1003. repository='repo',
  1004. location_config={
  1005. 'source_directories': ['foo', 'bar'],
  1006. 'repositories': ['repo'],
  1007. 'exclude_patterns': None,
  1008. },
  1009. storage_config={},
  1010. local_borg_version='1.2.3',
  1011. progress=True,
  1012. )
  1013. def test_create_archive_with_progress_calls_borg_with_progress_parameter():
  1014. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  1015. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  1016. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  1017. flexmock(module).should_receive('_expand_directories').and_return(())
  1018. flexmock(module).should_receive('_expand_home_directories').and_return(())
  1019. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  1020. flexmock(module.feature).should_receive('available').and_return(True)
  1021. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  1022. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  1023. flexmock(module).should_receive('execute_command').with_args(
  1024. ('borg', 'create', '--progress') + ARCHIVE_WITH_PATHS,
  1025. output_log_level=logging.INFO,
  1026. output_file=module.DO_NOT_CAPTURE,
  1027. borg_local_path='borg',
  1028. )
  1029. module.create_archive(
  1030. dry_run=False,
  1031. repository='repo',
  1032. location_config={
  1033. 'source_directories': ['foo', 'bar'],
  1034. 'repositories': ['repo'],
  1035. 'exclude_patterns': None,
  1036. },
  1037. storage_config={},
  1038. local_borg_version='1.2.3',
  1039. progress=True,
  1040. )
  1041. def test_create_archive_with_progress_and_stream_processes_calls_borg_with_progress_parameter():
  1042. processes = flexmock()
  1043. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  1044. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  1045. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  1046. flexmock(module).should_receive('_expand_directories').and_return(())
  1047. flexmock(module).should_receive('_expand_home_directories').and_return(())
  1048. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  1049. flexmock(module.feature).should_receive('available').and_return(True)
  1050. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  1051. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  1052. flexmock(module).should_receive('execute_command_with_processes').with_args(
  1053. ('borg', 'create', '--one-file-system', '--read-special', '--progress')
  1054. + ARCHIVE_WITH_PATHS,
  1055. processes=processes,
  1056. output_log_level=logging.INFO,
  1057. output_file=module.DO_NOT_CAPTURE,
  1058. borg_local_path='borg',
  1059. )
  1060. module.create_archive(
  1061. dry_run=False,
  1062. repository='repo',
  1063. location_config={
  1064. 'source_directories': ['foo', 'bar'],
  1065. 'repositories': ['repo'],
  1066. 'exclude_patterns': None,
  1067. },
  1068. storage_config={},
  1069. local_borg_version='1.2.3',
  1070. progress=True,
  1071. stream_processes=processes,
  1072. )
  1073. def test_create_archive_with_json_calls_borg_with_json_parameter():
  1074. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  1075. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  1076. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  1077. flexmock(module).should_receive('_expand_directories').and_return(())
  1078. flexmock(module).should_receive('_expand_home_directories').and_return(())
  1079. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  1080. flexmock(module.feature).should_receive('available').and_return(True)
  1081. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  1082. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  1083. flexmock(module).should_receive('execute_command').with_args(
  1084. ('borg', 'create', '--json') + ARCHIVE_WITH_PATHS,
  1085. output_log_level=None,
  1086. output_file=None,
  1087. borg_local_path='borg',
  1088. ).and_return('[]')
  1089. json_output = module.create_archive(
  1090. dry_run=False,
  1091. repository='repo',
  1092. location_config={
  1093. 'source_directories': ['foo', 'bar'],
  1094. 'repositories': ['repo'],
  1095. 'exclude_patterns': None,
  1096. },
  1097. storage_config={},
  1098. local_borg_version='1.2.3',
  1099. json=True,
  1100. )
  1101. assert json_output == '[]'
  1102. def test_create_archive_with_stats_and_json_calls_borg_without_stats_parameter():
  1103. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  1104. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  1105. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  1106. flexmock(module).should_receive('_expand_directories').and_return(())
  1107. flexmock(module).should_receive('_expand_home_directories').and_return(())
  1108. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  1109. flexmock(module.feature).should_receive('available').and_return(True)
  1110. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  1111. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  1112. flexmock(module).should_receive('execute_command').with_args(
  1113. ('borg', 'create', '--json') + ARCHIVE_WITH_PATHS,
  1114. output_log_level=None,
  1115. output_file=None,
  1116. borg_local_path='borg',
  1117. ).and_return('[]')
  1118. json_output = module.create_archive(
  1119. dry_run=False,
  1120. repository='repo',
  1121. location_config={
  1122. 'source_directories': ['foo', 'bar'],
  1123. 'repositories': ['repo'],
  1124. 'exclude_patterns': None,
  1125. },
  1126. storage_config={},
  1127. local_borg_version='1.2.3',
  1128. json=True,
  1129. stats=True,
  1130. )
  1131. assert json_output == '[]'
  1132. def test_create_archive_with_source_directories_glob_expands():
  1133. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  1134. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'food'))
  1135. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  1136. flexmock(module).should_receive('_expand_directories').and_return(())
  1137. flexmock(module).should_receive('_expand_home_directories').and_return(())
  1138. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  1139. flexmock(module.feature).should_receive('available').and_return(True)
  1140. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  1141. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  1142. flexmock(module).should_receive('execute_command').with_args(
  1143. ('borg', 'create', 'repo::{}'.format(DEFAULT_ARCHIVE_NAME), 'foo', 'food'),
  1144. output_log_level=logging.INFO,
  1145. output_file=None,
  1146. borg_local_path='borg',
  1147. )
  1148. flexmock(module.glob).should_receive('glob').with_args('foo*').and_return(['foo', 'food'])
  1149. module.create_archive(
  1150. dry_run=False,
  1151. repository='repo',
  1152. location_config={
  1153. 'source_directories': ['foo*'],
  1154. 'repositories': ['repo'],
  1155. 'exclude_patterns': None,
  1156. },
  1157. storage_config={},
  1158. local_borg_version='1.2.3',
  1159. )
  1160. def test_create_archive_with_non_matching_source_directories_glob_passes_through():
  1161. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  1162. flexmock(module).should_receive('deduplicate_directories').and_return(('foo*',))
  1163. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  1164. flexmock(module).should_receive('_expand_directories').and_return(())
  1165. flexmock(module).should_receive('_expand_home_directories').and_return(())
  1166. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  1167. flexmock(module.feature).should_receive('available').and_return(True)
  1168. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  1169. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  1170. flexmock(module).should_receive('execute_command').with_args(
  1171. ('borg', 'create', 'repo::{}'.format(DEFAULT_ARCHIVE_NAME), 'foo*'),
  1172. output_log_level=logging.INFO,
  1173. output_file=None,
  1174. borg_local_path='borg',
  1175. )
  1176. flexmock(module.glob).should_receive('glob').with_args('foo*').and_return([])
  1177. module.create_archive(
  1178. dry_run=False,
  1179. repository='repo',
  1180. location_config={
  1181. 'source_directories': ['foo*'],
  1182. 'repositories': ['repo'],
  1183. 'exclude_patterns': None,
  1184. },
  1185. storage_config={},
  1186. local_borg_version='1.2.3',
  1187. )
  1188. def test_create_archive_with_glob_calls_borg_with_expanded_directories():
  1189. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  1190. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'food'))
  1191. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  1192. flexmock(module).should_receive('_expand_directories').and_return(())
  1193. flexmock(module).should_receive('_expand_home_directories').and_return(())
  1194. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  1195. flexmock(module.feature).should_receive('available').and_return(True)
  1196. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  1197. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  1198. flexmock(module).should_receive('execute_command').with_args(
  1199. ('borg', 'create', 'repo::{}'.format(DEFAULT_ARCHIVE_NAME), 'foo', 'food'),
  1200. output_log_level=logging.INFO,
  1201. output_file=None,
  1202. borg_local_path='borg',
  1203. )
  1204. module.create_archive(
  1205. dry_run=False,
  1206. repository='repo',
  1207. location_config={
  1208. 'source_directories': ['foo*'],
  1209. 'repositories': ['repo'],
  1210. 'exclude_patterns': None,
  1211. },
  1212. storage_config={},
  1213. local_borg_version='1.2.3',
  1214. )
  1215. def test_create_archive_with_archive_name_format_calls_borg_with_archive_name():
  1216. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  1217. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  1218. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  1219. flexmock(module).should_receive('_expand_directories').and_return(())
  1220. flexmock(module).should_receive('_expand_home_directories').and_return(())
  1221. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  1222. flexmock(module.feature).should_receive('available').and_return(True)
  1223. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  1224. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  1225. flexmock(module).should_receive('execute_command').with_args(
  1226. ('borg', 'create', 'repo::ARCHIVE_NAME', 'foo', 'bar'),
  1227. output_log_level=logging.INFO,
  1228. output_file=None,
  1229. borg_local_path='borg',
  1230. )
  1231. module.create_archive(
  1232. dry_run=False,
  1233. repository='repo',
  1234. location_config={
  1235. 'source_directories': ['foo', 'bar'],
  1236. 'repositories': ['repo'],
  1237. 'exclude_patterns': None,
  1238. },
  1239. storage_config={'archive_name_format': 'ARCHIVE_NAME'},
  1240. local_borg_version='1.2.3',
  1241. )
  1242. def test_create_archive_with_archive_name_format_accepts_borg_placeholders():
  1243. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  1244. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  1245. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  1246. flexmock(module).should_receive('_expand_directories').and_return(())
  1247. flexmock(module).should_receive('_expand_home_directories').and_return(())
  1248. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  1249. flexmock(module.feature).should_receive('available').and_return(True)
  1250. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  1251. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  1252. flexmock(module).should_receive('execute_command').with_args(
  1253. ('borg', 'create', 'repo::Documents_{hostname}-{now}', 'foo', 'bar'),
  1254. output_log_level=logging.INFO,
  1255. output_file=None,
  1256. borg_local_path='borg',
  1257. )
  1258. module.create_archive(
  1259. dry_run=False,
  1260. repository='repo',
  1261. location_config={
  1262. 'source_directories': ['foo', 'bar'],
  1263. 'repositories': ['repo'],
  1264. 'exclude_patterns': None,
  1265. },
  1266. storage_config={'archive_name_format': 'Documents_{hostname}-{now}'},
  1267. local_borg_version='1.2.3',
  1268. )
  1269. def test_create_archive_with_repository_accepts_borg_placeholders():
  1270. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  1271. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  1272. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  1273. flexmock(module).should_receive('_expand_directories').and_return(())
  1274. flexmock(module).should_receive('_expand_home_directories').and_return(())
  1275. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  1276. flexmock(module.feature).should_receive('available').and_return(True)
  1277. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  1278. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  1279. flexmock(module).should_receive('execute_command').with_args(
  1280. ('borg', 'create', '{fqdn}::Documents_{hostname}-{now}', 'foo', 'bar'),
  1281. output_log_level=logging.INFO,
  1282. output_file=None,
  1283. borg_local_path='borg',
  1284. )
  1285. module.create_archive(
  1286. dry_run=False,
  1287. repository='{fqdn}',
  1288. location_config={
  1289. 'source_directories': ['foo', 'bar'],
  1290. 'repositories': ['{fqdn}'],
  1291. 'exclude_patterns': None,
  1292. },
  1293. storage_config={'archive_name_format': 'Documents_{hostname}-{now}'},
  1294. local_borg_version='1.2.3',
  1295. )
  1296. def test_create_archive_with_extra_borg_options_calls_borg_with_extra_options():
  1297. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  1298. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  1299. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  1300. flexmock(module).should_receive('_expand_directories').and_return(())
  1301. flexmock(module).should_receive('_expand_home_directories').and_return(())
  1302. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  1303. flexmock(module.feature).should_receive('available').and_return(True)
  1304. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  1305. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  1306. flexmock(module).should_receive('execute_command').with_args(
  1307. ('borg', 'create', '--extra', '--options') + ARCHIVE_WITH_PATHS,
  1308. output_log_level=logging.INFO,
  1309. output_file=None,
  1310. borg_local_path='borg',
  1311. )
  1312. module.create_archive(
  1313. dry_run=False,
  1314. repository='repo',
  1315. location_config={
  1316. 'source_directories': ['foo', 'bar'],
  1317. 'repositories': ['repo'],
  1318. 'exclude_patterns': None,
  1319. },
  1320. storage_config={'extra_borg_options': {'create': '--extra --options'}},
  1321. local_borg_version='1.2.3',
  1322. )
  1323. def test_create_archive_with_stream_processes_calls_borg_with_processes():
  1324. processes = flexmock()
  1325. flexmock(module).should_receive('borgmatic_source_directories').and_return([])
  1326. flexmock(module).should_receive('deduplicate_directories').and_return(('foo', 'bar'))
  1327. flexmock(module).should_receive('map_directories_to_devices').and_return({})
  1328. flexmock(module).should_receive('_expand_directories').and_return(())
  1329. flexmock(module).should_receive('_expand_home_directories').and_return(())
  1330. flexmock(module).should_receive('_write_pattern_file').and_return(None)
  1331. flexmock(module.feature).should_receive('available').and_return(True)
  1332. flexmock(module).should_receive('_make_pattern_flags').and_return(())
  1333. flexmock(module).should_receive('_make_exclude_flags').and_return(())
  1334. flexmock(module).should_receive('execute_command_with_processes').with_args(
  1335. ('borg', 'create', '--one-file-system', '--read-special') + ARCHIVE_WITH_PATHS,
  1336. processes=processes,
  1337. output_log_level=logging.INFO,
  1338. output_file=None,
  1339. borg_local_path='borg',
  1340. )
  1341. module.create_archive(
  1342. dry_run=False,
  1343. repository='repo',
  1344. location_config={
  1345. 'source_directories': ['foo', 'bar'],
  1346. 'repositories': ['repo'],
  1347. 'exclude_patterns': None,
  1348. },
  1349. storage_config={},
  1350. local_borg_version='1.2.3',
  1351. stream_processes=processes,
  1352. )