2
0

test_mariadb.py 23 KB

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