test_mariadb.py 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751
  1. import logging
  2. import pytest
  3. from flexmock import flexmock
  4. from borgmatic.hooks.data_source import mariadb as module
  5. def test_database_names_to_dump_passes_through_name():
  6. extra_environment = flexmock()
  7. names = module.database_names_to_dump({'name': 'foo'}, extra_environment, dry_run=False)
  8. assert names == ('foo',)
  9. def test_database_names_to_dump_bails_for_dry_run():
  10. extra_environment = flexmock()
  11. flexmock(module).should_receive('execute_command_and_capture_output').never()
  12. names = module.database_names_to_dump({'name': 'all'}, extra_environment, dry_run=True)
  13. assert names == ()
  14. def test_database_names_to_dump_queries_mariadb_for_database_names():
  15. extra_environment = flexmock()
  16. flexmock(module).should_receive('execute_command_and_capture_output').with_args(
  17. ('mariadb', '--skip-column-names', '--batch', '--execute', 'show schemas'),
  18. extra_environment=extra_environment,
  19. ).and_return('foo\nbar\nmysql\n').once()
  20. names = module.database_names_to_dump({'name': 'all'}, extra_environment, dry_run=False)
  21. assert names == ('foo', 'bar')
  22. def test_use_streaming_true_for_any_databases():
  23. assert module.use_streaming(
  24. databases=[flexmock(), flexmock()],
  25. config=flexmock(),
  26. )
  27. def test_use_streaming_false_for_no_databases():
  28. assert not module.use_streaming(databases=[], config=flexmock())
  29. def test_dump_data_sources_dumps_each_database():
  30. databases = [{'name': 'foo'}, {'name': 'bar'}]
  31. processes = [flexmock(), flexmock()]
  32. flexmock(module).should_receive('make_dump_path').and_return('')
  33. flexmock(module).should_receive('database_names_to_dump').and_return(('foo',)).and_return(
  34. ('bar',)
  35. )
  36. for name, process in zip(('foo', 'bar'), processes):
  37. flexmock(module).should_receive('execute_dump_command').with_args(
  38. database={'name': name},
  39. dump_path=object,
  40. database_names=(name,),
  41. extra_environment=object,
  42. dry_run=object,
  43. dry_run_label=object,
  44. ).and_return(process).once()
  45. assert (
  46. module.dump_data_sources(
  47. databases,
  48. {},
  49. config_paths=('test.yaml',),
  50. borgmatic_runtime_directory='/run/borgmatic',
  51. patterns=[],
  52. dry_run=False,
  53. )
  54. == processes
  55. )
  56. def test_dump_data_sources_dumps_with_password():
  57. database = {'name': 'foo', 'username': 'root', 'password': 'trustsome1'}
  58. process = flexmock()
  59. flexmock(module).should_receive('make_dump_path').and_return('')
  60. flexmock(module).should_receive('database_names_to_dump').and_return(('foo',)).and_return(
  61. ('bar',)
  62. )
  63. flexmock(module).should_receive('execute_dump_command').with_args(
  64. database=database,
  65. dump_path=object,
  66. database_names=('foo',),
  67. extra_environment={'MYSQL_PWD': 'trustsome1'},
  68. dry_run=object,
  69. dry_run_label=object,
  70. ).and_return(process).once()
  71. assert module.dump_data_sources(
  72. [database],
  73. {},
  74. config_paths=('test.yaml',),
  75. borgmatic_runtime_directory='/run/borgmatic',
  76. patterns=[],
  77. dry_run=False,
  78. ) == [process]
  79. def test_dump_data_sources_dumps_all_databases_at_once():
  80. databases = [{'name': 'all'}]
  81. process = flexmock()
  82. flexmock(module).should_receive('make_dump_path').and_return('')
  83. flexmock(module).should_receive('database_names_to_dump').and_return(('foo', 'bar'))
  84. flexmock(module).should_receive('execute_dump_command').with_args(
  85. database={'name': 'all'},
  86. dump_path=object,
  87. database_names=('foo', 'bar'),
  88. extra_environment=object,
  89. dry_run=object,
  90. dry_run_label=object,
  91. ).and_return(process).once()
  92. assert module.dump_data_sources(
  93. databases,
  94. {},
  95. config_paths=('test.yaml',),
  96. borgmatic_runtime_directory='/run/borgmatic',
  97. patterns=[],
  98. dry_run=False,
  99. ) == [process]
  100. def test_dump_data_sources_dumps_all_databases_separately_when_format_configured():
  101. databases = [{'name': 'all', 'format': 'sql'}]
  102. processes = [flexmock(), flexmock()]
  103. flexmock(module).should_receive('make_dump_path').and_return('')
  104. flexmock(module).should_receive('database_names_to_dump').and_return(('foo', 'bar'))
  105. for name, process in zip(('foo', 'bar'), processes):
  106. flexmock(module).should_receive('execute_dump_command').with_args(
  107. database={'name': name, 'format': 'sql'},
  108. dump_path=object,
  109. database_names=(name,),
  110. extra_environment=object,
  111. dry_run=object,
  112. dry_run_label=object,
  113. ).and_return(process).once()
  114. assert (
  115. module.dump_data_sources(
  116. databases,
  117. {},
  118. config_paths=('test.yaml',),
  119. borgmatic_runtime_directory='/run/borgmatic',
  120. patterns=[],
  121. dry_run=False,
  122. )
  123. == processes
  124. )
  125. def test_database_names_to_dump_runs_mariadb_with_list_options():
  126. database = {'name': 'all', 'list_options': '--defaults-extra-file=mariadb.cnf'}
  127. flexmock(module).should_receive('execute_command_and_capture_output').with_args(
  128. (
  129. 'mariadb',
  130. '--defaults-extra-file=mariadb.cnf',
  131. '--skip-column-names',
  132. '--batch',
  133. '--execute',
  134. 'show schemas',
  135. ),
  136. extra_environment=None,
  137. ).and_return(('foo\nbar')).once()
  138. assert module.database_names_to_dump(database, None, '') == ('foo', 'bar')
  139. def test_database_names_to_dump_runs_non_default_mariadb_with_list_options():
  140. database = {
  141. 'name': 'all',
  142. 'list_options': '--defaults-extra-file=mariadb.cnf',
  143. 'mariadb_command': 'custom_mariadb',
  144. }
  145. flexmock(module).should_receive('execute_command_and_capture_output').with_args(
  146. extra_environment=None,
  147. full_command=(
  148. 'custom_mariadb', # Custom MariaDB command
  149. '--defaults-extra-file=mariadb.cnf',
  150. '--skip-column-names',
  151. '--batch',
  152. '--execute',
  153. 'show schemas',
  154. ),
  155. ).and_return(('foo\nbar')).once()
  156. assert module.database_names_to_dump(database, None, '') == ('foo', 'bar')
  157. def test_execute_dump_command_runs_mariadb_dump():
  158. process = flexmock()
  159. flexmock(module.dump).should_receive('make_data_source_dump_filename').and_return('dump')
  160. flexmock(module.os.path).should_receive('exists').and_return(False)
  161. flexmock(module.dump).should_receive('create_named_pipe_for_dump')
  162. flexmock(module).should_receive('execute_command').with_args(
  163. (
  164. 'mariadb-dump',
  165. '--add-drop-database',
  166. '--databases',
  167. 'foo',
  168. '--result-file',
  169. 'dump',
  170. ),
  171. extra_environment=None,
  172. run_to_completion=False,
  173. ).and_return(process).once()
  174. assert (
  175. module.execute_dump_command(
  176. database={'name': 'foo'},
  177. dump_path=flexmock(),
  178. database_names=('foo',),
  179. extra_environment=None,
  180. dry_run=False,
  181. dry_run_label='',
  182. )
  183. == process
  184. )
  185. def test_execute_dump_command_runs_mariadb_dump_without_add_drop_database():
  186. process = flexmock()
  187. flexmock(module.dump).should_receive('make_data_source_dump_filename').and_return('dump')
  188. flexmock(module.os.path).should_receive('exists').and_return(False)
  189. flexmock(module.dump).should_receive('create_named_pipe_for_dump')
  190. flexmock(module).should_receive('execute_command').with_args(
  191. (
  192. 'mariadb-dump',
  193. '--databases',
  194. 'foo',
  195. '--result-file',
  196. 'dump',
  197. ),
  198. extra_environment=None,
  199. run_to_completion=False,
  200. ).and_return(process).once()
  201. assert (
  202. module.execute_dump_command(
  203. database={'name': 'foo', 'add_drop_database': False},
  204. dump_path=flexmock(),
  205. database_names=('foo',),
  206. extra_environment=None,
  207. dry_run=False,
  208. dry_run_label='',
  209. )
  210. == process
  211. )
  212. def test_execute_dump_command_runs_mariadb_dump_with_hostname_and_port():
  213. process = flexmock()
  214. flexmock(module.dump).should_receive('make_data_source_dump_filename').and_return('dump')
  215. flexmock(module.os.path).should_receive('exists').and_return(False)
  216. flexmock(module.dump).should_receive('create_named_pipe_for_dump')
  217. flexmock(module).should_receive('execute_command').with_args(
  218. (
  219. 'mariadb-dump',
  220. '--add-drop-database',
  221. '--host',
  222. 'database.example.org',
  223. '--port',
  224. '5433',
  225. '--protocol',
  226. 'tcp',
  227. '--databases',
  228. 'foo',
  229. '--result-file',
  230. 'dump',
  231. ),
  232. extra_environment=None,
  233. run_to_completion=False,
  234. ).and_return(process).once()
  235. assert (
  236. module.execute_dump_command(
  237. database={'name': 'foo', 'hostname': 'database.example.org', 'port': 5433},
  238. dump_path=flexmock(),
  239. database_names=('foo',),
  240. extra_environment=None,
  241. dry_run=False,
  242. dry_run_label='',
  243. )
  244. == process
  245. )
  246. def test_execute_dump_command_runs_mariadb_dump_with_username_and_password():
  247. process = flexmock()
  248. flexmock(module.dump).should_receive('make_data_source_dump_filename').and_return('dump')
  249. flexmock(module.os.path).should_receive('exists').and_return(False)
  250. flexmock(module.dump).should_receive('create_named_pipe_for_dump')
  251. flexmock(module).should_receive('execute_command').with_args(
  252. (
  253. 'mariadb-dump',
  254. '--add-drop-database',
  255. '--user',
  256. 'root',
  257. '--databases',
  258. 'foo',
  259. '--result-file',
  260. 'dump',
  261. ),
  262. extra_environment={'MYSQL_PWD': 'trustsome1'},
  263. run_to_completion=False,
  264. ).and_return(process).once()
  265. assert (
  266. module.execute_dump_command(
  267. database={'name': 'foo', 'username': 'root', 'password': 'trustsome1'},
  268. dump_path=flexmock(),
  269. database_names=('foo',),
  270. extra_environment={'MYSQL_PWD': 'trustsome1'},
  271. dry_run=False,
  272. dry_run_label='',
  273. )
  274. == process
  275. )
  276. def test_execute_dump_command_runs_mariadb_dump_with_options():
  277. process = flexmock()
  278. flexmock(module.dump).should_receive('make_data_source_dump_filename').and_return('dump')
  279. flexmock(module.os.path).should_receive('exists').and_return(False)
  280. flexmock(module.dump).should_receive('create_named_pipe_for_dump')
  281. flexmock(module).should_receive('execute_command').with_args(
  282. (
  283. 'mariadb-dump',
  284. '--stuff=such',
  285. '--add-drop-database',
  286. '--databases',
  287. 'foo',
  288. '--result-file',
  289. 'dump',
  290. ),
  291. extra_environment=None,
  292. run_to_completion=False,
  293. ).and_return(process).once()
  294. assert (
  295. module.execute_dump_command(
  296. database={'name': 'foo', 'options': '--stuff=such'},
  297. dump_path=flexmock(),
  298. database_names=('foo',),
  299. extra_environment=None,
  300. dry_run=False,
  301. dry_run_label='',
  302. )
  303. == process
  304. )
  305. def test_execute_dump_command_runs_non_default_mariadb_dump_with_options():
  306. process = flexmock()
  307. flexmock(module.dump).should_receive('make_data_source_dump_filename').and_return('dump')
  308. flexmock(module.os.path).should_receive('exists').and_return(False)
  309. flexmock(module.dump).should_receive('create_named_pipe_for_dump')
  310. flexmock(module).should_receive('execute_command').with_args(
  311. (
  312. 'custom_mariadb_dump', # Custom MariaDB dump command
  313. '--stuff=such',
  314. '--add-drop-database',
  315. '--databases',
  316. 'foo',
  317. '--result-file',
  318. 'dump',
  319. ),
  320. extra_environment=None,
  321. run_to_completion=False,
  322. ).and_return(process).once()
  323. assert (
  324. module.execute_dump_command(
  325. database={
  326. 'name': 'foo',
  327. 'mariadb_dump_command': 'custom_mariadb_dump',
  328. 'options': '--stuff=such',
  329. }, # Custom MariaDB dump command specified
  330. dump_path=flexmock(),
  331. database_names=('foo',),
  332. extra_environment=None,
  333. dry_run=False,
  334. dry_run_label='',
  335. )
  336. == process
  337. )
  338. def test_execute_dump_command_with_duplicate_dump_skips_mariadb_dump():
  339. flexmock(module.dump).should_receive('make_data_source_dump_filename').and_return('dump')
  340. flexmock(module.os.path).should_receive('exists').and_return(True)
  341. flexmock(module.dump).should_receive('create_named_pipe_for_dump').never()
  342. flexmock(module).should_receive('execute_command').never()
  343. assert (
  344. module.execute_dump_command(
  345. database={'name': 'foo'},
  346. dump_path=flexmock(),
  347. database_names=('foo',),
  348. extra_environment=None,
  349. dry_run=True,
  350. dry_run_label='SO DRY',
  351. )
  352. is None
  353. )
  354. def test_execute_dump_command_with_dry_run_skips_mariadb_dump():
  355. flexmock(module.dump).should_receive('make_data_source_dump_filename').and_return('dump')
  356. flexmock(module.os.path).should_receive('exists').and_return(False)
  357. flexmock(module.dump).should_receive('create_named_pipe_for_dump')
  358. flexmock(module).should_receive('execute_command').never()
  359. assert (
  360. module.execute_dump_command(
  361. database={'name': 'foo'},
  362. dump_path=flexmock(),
  363. database_names=('foo',),
  364. extra_environment=None,
  365. dry_run=True,
  366. dry_run_label='SO DRY',
  367. )
  368. is None
  369. )
  370. def test_dump_data_sources_errors_for_missing_all_databases():
  371. databases = [{'name': 'all'}]
  372. flexmock(module).should_receive('make_dump_path').and_return('')
  373. flexmock(module.dump).should_receive('make_data_source_dump_filename').and_return(
  374. 'databases/localhost/all'
  375. )
  376. flexmock(module).should_receive('database_names_to_dump').and_return(())
  377. with pytest.raises(ValueError):
  378. assert module.dump_data_sources(
  379. databases,
  380. {},
  381. config_paths=('test.yaml',),
  382. borgmatic_runtime_directory='/run/borgmatic',
  383. patterns=[],
  384. dry_run=False,
  385. )
  386. def test_dump_data_sources_does_not_error_for_missing_all_databases_with_dry_run():
  387. databases = [{'name': 'all'}]
  388. flexmock(module).should_receive('make_dump_path').and_return('')
  389. flexmock(module.dump).should_receive('make_data_source_dump_filename').and_return(
  390. 'databases/localhost/all'
  391. )
  392. flexmock(module).should_receive('database_names_to_dump').and_return(())
  393. assert (
  394. module.dump_data_sources(
  395. databases,
  396. {},
  397. config_paths=('test.yaml',),
  398. borgmatic_runtime_directory='/run/borgmatic',
  399. patterns=[],
  400. dry_run=True,
  401. )
  402. == []
  403. )
  404. def test_restore_data_source_dump_runs_mariadb_to_restore():
  405. hook_config = [{'name': 'foo'}, {'name': 'bar'}]
  406. extract_process = flexmock(stdout=flexmock())
  407. flexmock(module).should_receive('execute_command_with_processes').with_args(
  408. ('mariadb', '--batch'),
  409. processes=[extract_process],
  410. output_log_level=logging.DEBUG,
  411. input_file=extract_process.stdout,
  412. extra_environment=None,
  413. ).once()
  414. module.restore_data_source_dump(
  415. hook_config,
  416. {},
  417. data_source={'name': 'foo'},
  418. dry_run=False,
  419. extract_process=extract_process,
  420. connection_params={
  421. 'hostname': None,
  422. 'port': None,
  423. 'username': None,
  424. 'password': None,
  425. },
  426. borgmatic_runtime_directory='/run/borgmatic',
  427. )
  428. def test_restore_data_source_dump_runs_mariadb_with_options():
  429. hook_config = [{'name': 'foo', 'restore_options': '--harder'}]
  430. extract_process = flexmock(stdout=flexmock())
  431. flexmock(module).should_receive('execute_command_with_processes').with_args(
  432. ('mariadb', '--batch', '--harder'),
  433. processes=[extract_process],
  434. output_log_level=logging.DEBUG,
  435. input_file=extract_process.stdout,
  436. extra_environment=None,
  437. ).once()
  438. module.restore_data_source_dump(
  439. hook_config,
  440. {},
  441. data_source=hook_config[0],
  442. dry_run=False,
  443. extract_process=extract_process,
  444. connection_params={
  445. 'hostname': None,
  446. 'port': None,
  447. 'username': None,
  448. 'password': None,
  449. },
  450. borgmatic_runtime_directory='/run/borgmatic',
  451. )
  452. def test_restore_data_source_dump_runs_non_default_mariadb_with_options():
  453. hook_config = [
  454. {'name': 'foo', 'restore_options': '--harder', 'mariadb_command': 'custom_mariadb'}
  455. ]
  456. extract_process = flexmock(stdout=flexmock())
  457. flexmock(module).should_receive('execute_command_with_processes').with_args(
  458. ('custom_mariadb', '--batch', '--harder'),
  459. processes=[extract_process],
  460. output_log_level=logging.DEBUG,
  461. input_file=extract_process.stdout,
  462. extra_environment=None,
  463. ).once()
  464. module.restore_data_source_dump(
  465. hook_config,
  466. {},
  467. data_source=hook_config[0],
  468. dry_run=False,
  469. extract_process=extract_process,
  470. connection_params={
  471. 'hostname': None,
  472. 'port': None,
  473. 'username': None,
  474. 'password': None,
  475. },
  476. borgmatic_runtime_directory='/run/borgmatic',
  477. )
  478. def test_restore_data_source_dump_runs_mariadb_with_hostname_and_port():
  479. hook_config = [{'name': 'foo', 'hostname': 'database.example.org', 'port': 5433}]
  480. extract_process = flexmock(stdout=flexmock())
  481. flexmock(module).should_receive('execute_command_with_processes').with_args(
  482. (
  483. 'mariadb',
  484. '--batch',
  485. '--host',
  486. 'database.example.org',
  487. '--port',
  488. '5433',
  489. '--protocol',
  490. 'tcp',
  491. ),
  492. processes=[extract_process],
  493. output_log_level=logging.DEBUG,
  494. input_file=extract_process.stdout,
  495. extra_environment=None,
  496. ).once()
  497. module.restore_data_source_dump(
  498. hook_config,
  499. {},
  500. data_source=hook_config[0],
  501. dry_run=False,
  502. extract_process=extract_process,
  503. connection_params={
  504. 'hostname': None,
  505. 'port': None,
  506. 'username': None,
  507. 'password': None,
  508. },
  509. borgmatic_runtime_directory='/run/borgmatic',
  510. )
  511. def test_restore_data_source_dump_runs_mariadb_with_username_and_password():
  512. hook_config = [{'name': 'foo', 'username': 'root', 'password': 'trustsome1'}]
  513. extract_process = flexmock(stdout=flexmock())
  514. flexmock(module).should_receive('execute_command_with_processes').with_args(
  515. ('mariadb', '--batch', '--user', 'root'),
  516. processes=[extract_process],
  517. output_log_level=logging.DEBUG,
  518. input_file=extract_process.stdout,
  519. extra_environment={'MYSQL_PWD': 'trustsome1'},
  520. ).once()
  521. module.restore_data_source_dump(
  522. hook_config,
  523. {},
  524. data_source=hook_config[0],
  525. dry_run=False,
  526. extract_process=extract_process,
  527. connection_params={
  528. 'hostname': None,
  529. 'port': None,
  530. 'username': None,
  531. 'password': None,
  532. },
  533. borgmatic_runtime_directory='/run/borgmatic',
  534. )
  535. def test_restore_data_source_dump_with_connection_params_uses_connection_params_for_restore():
  536. hook_config = [
  537. {
  538. 'name': 'foo',
  539. 'username': 'root',
  540. 'password': 'trustsome1',
  541. 'restore_hostname': 'restorehost',
  542. 'restore_port': 'restoreport',
  543. 'restore_username': 'restoreusername',
  544. 'restore_password': 'restorepassword',
  545. }
  546. ]
  547. extract_process = flexmock(stdout=flexmock())
  548. flexmock(module).should_receive('execute_command_with_processes').with_args(
  549. (
  550. 'mariadb',
  551. '--batch',
  552. '--host',
  553. 'clihost',
  554. '--port',
  555. 'cliport',
  556. '--protocol',
  557. 'tcp',
  558. '--user',
  559. 'cliusername',
  560. ),
  561. processes=[extract_process],
  562. output_log_level=logging.DEBUG,
  563. input_file=extract_process.stdout,
  564. extra_environment={'MYSQL_PWD': 'clipassword'},
  565. ).once()
  566. module.restore_data_source_dump(
  567. hook_config,
  568. {},
  569. data_source=hook_config[0],
  570. dry_run=False,
  571. extract_process=extract_process,
  572. connection_params={
  573. 'hostname': 'clihost',
  574. 'port': 'cliport',
  575. 'username': 'cliusername',
  576. 'password': 'clipassword',
  577. },
  578. borgmatic_runtime_directory='/run/borgmatic',
  579. )
  580. def test_restore_data_source_dump_without_connection_params_uses_restore_params_in_config_for_restore():
  581. hook_config = [
  582. {
  583. 'name': 'foo',
  584. 'username': 'root',
  585. 'password': 'trustsome1',
  586. 'hostname': 'dbhost',
  587. 'port': 'dbport',
  588. 'restore_username': 'restoreuser',
  589. 'restore_password': 'restorepass',
  590. 'restore_hostname': 'restorehost',
  591. 'restore_port': 'restoreport',
  592. }
  593. ]
  594. extract_process = flexmock(stdout=flexmock())
  595. flexmock(module).should_receive('execute_command_with_processes').with_args(
  596. (
  597. 'mariadb',
  598. '--batch',
  599. '--host',
  600. 'restorehost',
  601. '--port',
  602. 'restoreport',
  603. '--protocol',
  604. 'tcp',
  605. '--user',
  606. 'restoreuser',
  607. ),
  608. processes=[extract_process],
  609. output_log_level=logging.DEBUG,
  610. input_file=extract_process.stdout,
  611. extra_environment={'MYSQL_PWD': 'restorepass'},
  612. ).once()
  613. module.restore_data_source_dump(
  614. hook_config,
  615. {},
  616. data_source=hook_config[0],
  617. dry_run=False,
  618. extract_process=extract_process,
  619. connection_params={
  620. 'hostname': None,
  621. 'port': None,
  622. 'username': None,
  623. 'password': None,
  624. },
  625. borgmatic_runtime_directory='/run/borgmatic',
  626. )
  627. def test_restore_data_source_dump_with_dry_run_skips_restore():
  628. hook_config = [{'name': 'foo'}]
  629. flexmock(module).should_receive('execute_command_with_processes').never()
  630. module.restore_data_source_dump(
  631. hook_config,
  632. {},
  633. data_source={'name': 'foo'},
  634. dry_run=True,
  635. extract_process=flexmock(),
  636. connection_params={
  637. 'hostname': None,
  638. 'port': None,
  639. 'username': None,
  640. 'password': None,
  641. },
  642. borgmatic_runtime_directory='/run/borgmatic',
  643. )