test_mysql.py 23 KB

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