test_mariadb.py 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770
  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(
  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_mariadb_for_database_names():
  19. extra_environment = flexmock()
  20. flexmock(module).should_receive('execute_command_and_capture_output').with_args(
  21. ('mariadb', '--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_mariadb_with_list_options():
  135. database = {'name': 'all', 'list_options': '--defaults-extra-file=mariadb.cnf'}
  136. flexmock(module).should_receive('execute_command_and_capture_output').with_args(
  137. (
  138. 'mariadb',
  139. '--defaults-extra-file=mariadb.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_mariadb_with_list_options():
  149. database = {
  150. 'name': 'all',
  151. 'list_options': '--defaults-extra-file=mariadb.cnf',
  152. 'mariadb_command': 'custom_mariadb',
  153. }
  154. flexmock(module).should_receive('execute_command_and_capture_output').with_args(
  155. extra_environment=None,
  156. full_command=(
  157. 'custom_mariadb', # Custom MariaDB command
  158. '--defaults-extra-file=mariadb.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_mariadb_dump():
  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. 'mariadb-dump',
  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_mariadb_dump_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. 'mariadb-dump',
  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_mariadb_dump_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. 'mariadb-dump',
  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_mariadb_dump_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. 'mariadb-dump',
  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_mariadb_dump_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. 'mariadb-dump',
  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_mariadb_dump_with_options():
  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_mariadb_dump', # Custom MariaDB dump command
  322. '--stuff=such',
  323. '--add-drop-database',
  324. '--databases',
  325. 'foo',
  326. '--result-file',
  327. 'dump',
  328. ),
  329. extra_environment=None,
  330. run_to_completion=False,
  331. ).and_return(process).once()
  332. assert (
  333. module.execute_dump_command(
  334. database={
  335. 'name': 'foo',
  336. 'mariadb_dump_command': 'custom_mariadb_dump',
  337. 'options': '--stuff=such',
  338. }, # Custom MariaDB dump command specified
  339. dump_path=flexmock(),
  340. database_names=('foo',),
  341. extra_environment=None,
  342. dry_run=False,
  343. dry_run_label='',
  344. )
  345. == process
  346. )
  347. def test_execute_dump_command_with_duplicate_dump_skips_mariadb_dump():
  348. flexmock(module.dump).should_receive('make_data_source_dump_filename').and_return('dump')
  349. flexmock(module.os.path).should_receive('exists').and_return(True)
  350. flexmock(module.dump).should_receive('create_named_pipe_for_dump').never()
  351. flexmock(module).should_receive('execute_command').never()
  352. assert (
  353. module.execute_dump_command(
  354. database={'name': 'foo'},
  355. dump_path=flexmock(),
  356. database_names=('foo',),
  357. extra_environment=None,
  358. dry_run=True,
  359. dry_run_label='SO DRY',
  360. )
  361. is None
  362. )
  363. def test_execute_dump_command_with_dry_run_skips_mariadb_dump():
  364. flexmock(module.dump).should_receive('make_data_source_dump_filename').and_return('dump')
  365. flexmock(module.os.path).should_receive('exists').and_return(False)
  366. flexmock(module.dump).should_receive('create_named_pipe_for_dump')
  367. flexmock(module).should_receive('execute_command').never()
  368. assert (
  369. module.execute_dump_command(
  370. database={'name': 'foo'},
  371. dump_path=flexmock(),
  372. database_names=('foo',),
  373. extra_environment=None,
  374. dry_run=True,
  375. dry_run_label='SO DRY',
  376. )
  377. is None
  378. )
  379. def test_dump_data_sources_errors_for_missing_all_databases():
  380. databases = [{'name': 'all'}]
  381. flexmock(module).should_receive('make_dump_path').and_return('')
  382. flexmock(module.dump).should_receive('make_data_source_dump_filename').and_return(
  383. 'databases/localhost/all'
  384. )
  385. flexmock(module).should_receive('database_names_to_dump').and_return(())
  386. with pytest.raises(ValueError):
  387. assert module.dump_data_sources(
  388. databases,
  389. {},
  390. 'test.yaml',
  391. config_paths=('test.yaml',),
  392. borgmatic_runtime_directory='/run/borgmatic',
  393. patterns=[],
  394. dry_run=False,
  395. )
  396. def test_dump_data_sources_does_not_error_for_missing_all_databases_with_dry_run():
  397. databases = [{'name': 'all'}]
  398. flexmock(module).should_receive('make_dump_path').and_return('')
  399. flexmock(module.dump).should_receive('make_data_source_dump_filename').and_return(
  400. 'databases/localhost/all'
  401. )
  402. flexmock(module).should_receive('database_names_to_dump').and_return(())
  403. assert (
  404. module.dump_data_sources(
  405. databases,
  406. {},
  407. 'test.yaml',
  408. config_paths=('test.yaml',),
  409. borgmatic_runtime_directory='/run/borgmatic',
  410. patterns=[],
  411. dry_run=True,
  412. )
  413. == []
  414. )
  415. def test_restore_data_source_dump_runs_mariadb_to_restore():
  416. hook_config = [{'name': 'foo'}, {'name': 'bar'}]
  417. extract_process = flexmock(stdout=flexmock())
  418. flexmock(module).should_receive('execute_command_with_processes').with_args(
  419. ('mariadb', '--batch'),
  420. processes=[extract_process],
  421. output_log_level=logging.DEBUG,
  422. input_file=extract_process.stdout,
  423. extra_environment=None,
  424. ).once()
  425. module.restore_data_source_dump(
  426. hook_config,
  427. {},
  428. 'test.yaml',
  429. data_source={'name': 'foo'},
  430. dry_run=False,
  431. extract_process=extract_process,
  432. connection_params={
  433. 'hostname': None,
  434. 'port': None,
  435. 'username': None,
  436. 'password': None,
  437. },
  438. borgmatic_runtime_directory='/run/borgmatic',
  439. )
  440. def test_restore_data_source_dump_runs_mariadb_with_options():
  441. hook_config = [{'name': 'foo', 'restore_options': '--harder'}]
  442. extract_process = flexmock(stdout=flexmock())
  443. flexmock(module).should_receive('execute_command_with_processes').with_args(
  444. ('mariadb', '--batch', '--harder'),
  445. processes=[extract_process],
  446. output_log_level=logging.DEBUG,
  447. input_file=extract_process.stdout,
  448. extra_environment=None,
  449. ).once()
  450. module.restore_data_source_dump(
  451. hook_config,
  452. {},
  453. 'test.yaml',
  454. data_source=hook_config[0],
  455. dry_run=False,
  456. extract_process=extract_process,
  457. connection_params={
  458. 'hostname': None,
  459. 'port': None,
  460. 'username': None,
  461. 'password': None,
  462. },
  463. borgmatic_runtime_directory='/run/borgmatic',
  464. )
  465. def test_restore_data_source_dump_runs_non_default_mariadb_with_options():
  466. hook_config = [
  467. {'name': 'foo', 'restore_options': '--harder', 'mariadb_command': 'custom_mariadb'}
  468. ]
  469. extract_process = flexmock(stdout=flexmock())
  470. flexmock(module).should_receive('execute_command_with_processes').with_args(
  471. ('custom_mariadb', '--batch', '--harder'),
  472. processes=[extract_process],
  473. output_log_level=logging.DEBUG,
  474. input_file=extract_process.stdout,
  475. extra_environment=None,
  476. ).once()
  477. module.restore_data_source_dump(
  478. hook_config,
  479. {},
  480. 'test.yaml',
  481. data_source=hook_config[0],
  482. dry_run=False,
  483. extract_process=extract_process,
  484. connection_params={
  485. 'hostname': None,
  486. 'port': None,
  487. 'username': None,
  488. 'password': None,
  489. },
  490. borgmatic_runtime_directory='/run/borgmatic',
  491. )
  492. def test_restore_data_source_dump_runs_mariadb_with_hostname_and_port():
  493. hook_config = [{'name': 'foo', 'hostname': 'database.example.org', 'port': 5433}]
  494. extract_process = flexmock(stdout=flexmock())
  495. flexmock(module).should_receive('execute_command_with_processes').with_args(
  496. (
  497. 'mariadb',
  498. '--batch',
  499. '--host',
  500. 'database.example.org',
  501. '--port',
  502. '5433',
  503. '--protocol',
  504. 'tcp',
  505. ),
  506. processes=[extract_process],
  507. output_log_level=logging.DEBUG,
  508. input_file=extract_process.stdout,
  509. extra_environment=None,
  510. ).once()
  511. module.restore_data_source_dump(
  512. hook_config,
  513. {},
  514. 'test.yaml',
  515. data_source=hook_config[0],
  516. dry_run=False,
  517. extract_process=extract_process,
  518. connection_params={
  519. 'hostname': None,
  520. 'port': None,
  521. 'username': None,
  522. 'password': None,
  523. },
  524. borgmatic_runtime_directory='/run/borgmatic',
  525. )
  526. def test_restore_data_source_dump_runs_mariadb_with_username_and_password():
  527. hook_config = [{'name': 'foo', 'username': 'root', 'password': 'trustsome1'}]
  528. extract_process = flexmock(stdout=flexmock())
  529. flexmock(module).should_receive('execute_command_with_processes').with_args(
  530. ('mariadb', '--batch', '--user', 'root'),
  531. processes=[extract_process],
  532. output_log_level=logging.DEBUG,
  533. input_file=extract_process.stdout,
  534. extra_environment={'MYSQL_PWD': 'trustsome1'},
  535. ).once()
  536. module.restore_data_source_dump(
  537. hook_config,
  538. {},
  539. 'test.yaml',
  540. data_source=hook_config[0],
  541. dry_run=False,
  542. extract_process=extract_process,
  543. connection_params={
  544. 'hostname': None,
  545. 'port': None,
  546. 'username': None,
  547. 'password': None,
  548. },
  549. borgmatic_runtime_directory='/run/borgmatic',
  550. )
  551. def test_restore_data_source_dump_with_connection_params_uses_connection_params_for_restore():
  552. hook_config = [
  553. {
  554. 'name': 'foo',
  555. 'username': 'root',
  556. 'password': 'trustsome1',
  557. 'restore_hostname': 'restorehost',
  558. 'restore_port': 'restoreport',
  559. 'restore_username': 'restoreusername',
  560. 'restore_password': 'restorepassword',
  561. }
  562. ]
  563. extract_process = flexmock(stdout=flexmock())
  564. flexmock(module).should_receive('execute_command_with_processes').with_args(
  565. (
  566. 'mariadb',
  567. '--batch',
  568. '--host',
  569. 'clihost',
  570. '--port',
  571. 'cliport',
  572. '--protocol',
  573. 'tcp',
  574. '--user',
  575. 'cliusername',
  576. ),
  577. processes=[extract_process],
  578. output_log_level=logging.DEBUG,
  579. input_file=extract_process.stdout,
  580. extra_environment={'MYSQL_PWD': 'clipassword'},
  581. ).once()
  582. module.restore_data_source_dump(
  583. hook_config,
  584. {},
  585. 'test.yaml',
  586. data_source=hook_config[0],
  587. dry_run=False,
  588. extract_process=extract_process,
  589. connection_params={
  590. 'hostname': 'clihost',
  591. 'port': 'cliport',
  592. 'username': 'cliusername',
  593. 'password': 'clipassword',
  594. },
  595. borgmatic_runtime_directory='/run/borgmatic',
  596. )
  597. def test_restore_data_source_dump_without_connection_params_uses_restore_params_in_config_for_restore():
  598. hook_config = [
  599. {
  600. 'name': 'foo',
  601. 'username': 'root',
  602. 'password': 'trustsome1',
  603. 'hostname': 'dbhost',
  604. 'port': 'dbport',
  605. 'restore_username': 'restoreuser',
  606. 'restore_password': 'restorepass',
  607. 'restore_hostname': 'restorehost',
  608. 'restore_port': 'restoreport',
  609. }
  610. ]
  611. extract_process = flexmock(stdout=flexmock())
  612. flexmock(module).should_receive('execute_command_with_processes').with_args(
  613. (
  614. 'mariadb',
  615. '--batch',
  616. '--host',
  617. 'restorehost',
  618. '--port',
  619. 'restoreport',
  620. '--protocol',
  621. 'tcp',
  622. '--user',
  623. 'restoreuser',
  624. ),
  625. processes=[extract_process],
  626. output_log_level=logging.DEBUG,
  627. input_file=extract_process.stdout,
  628. extra_environment={'MYSQL_PWD': 'restorepass'},
  629. ).once()
  630. module.restore_data_source_dump(
  631. hook_config,
  632. {},
  633. 'test.yaml',
  634. data_source=hook_config[0],
  635. dry_run=False,
  636. extract_process=extract_process,
  637. connection_params={
  638. 'hostname': None,
  639. 'port': None,
  640. 'username': None,
  641. 'password': None,
  642. },
  643. borgmatic_runtime_directory='/run/borgmatic',
  644. )
  645. def test_restore_data_source_dump_with_dry_run_skips_restore():
  646. hook_config = [{'name': 'foo'}]
  647. flexmock(module).should_receive('execute_command_with_processes').never()
  648. module.restore_data_source_dump(
  649. hook_config,
  650. {},
  651. 'test.yaml',
  652. data_source={'name': 'foo'},
  653. dry_run=True,
  654. extract_process=flexmock(),
  655. connection_params={
  656. 'hostname': None,
  657. 'port': None,
  658. 'username': None,
  659. 'password': None,
  660. },
  661. borgmatic_runtime_directory='/run/borgmatic',
  662. )