test_mariadb.py 23 KB

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