|
|
@@ -65,6 +65,7 @@ def test_database_names_to_dump_queries_mysql_for_database_names():
|
|
|
flexmock(module.borgmatic.hooks.data_source.mariadb).should_receive(
|
|
|
'parse_extra_options',
|
|
|
).and_return((), None)
|
|
|
+ flexmock(module.database_config).should_receive('resolve_database_option').and_return(None)
|
|
|
flexmock(module.borgmatic.hooks.data_source.mariadb).should_receive(
|
|
|
'make_defaults_file_options',
|
|
|
).with_args('root', 'trustsome1', None).and_return(('--defaults-extra-file=/dev/fd/99',))
|
|
|
@@ -102,6 +103,7 @@ def test_database_names_to_dump_with_database_name_all_and_skip_names_filters_ou
|
|
|
flexmock(module.borgmatic.hooks.data_source.mariadb).should_receive(
|
|
|
'parse_extra_options'
|
|
|
).and_return((), None)
|
|
|
+ flexmock(module.database_config).should_receive('resolve_database_option').and_return(None)
|
|
|
flexmock(module.borgmatic.hooks.data_source.mariadb).should_receive(
|
|
|
'make_defaults_file_options'
|
|
|
).with_args(
|
|
|
@@ -135,6 +137,46 @@ def test_database_names_to_dump_with_database_name_all_and_skip_names_filters_ou
|
|
|
assert names == ('baz',)
|
|
|
|
|
|
|
|
|
+def test_database_names_to_dump_runs_mysql_with_socket_path():
|
|
|
+ environment = flexmock()
|
|
|
+ flexmock(module.borgmatic.hooks.credential.parse).should_receive(
|
|
|
+ 'resolve_credential',
|
|
|
+ ).replace_with(lambda value, config: value)
|
|
|
+ flexmock(module.borgmatic.hooks.data_source.mariadb).should_receive(
|
|
|
+ 'parse_extra_options',
|
|
|
+ ).and_return((), None)
|
|
|
+ flexmock(module.database_config).should_receive('resolve_database_option').and_return(None)
|
|
|
+ flexmock(module.borgmatic.hooks.data_source.mariadb).should_receive(
|
|
|
+ 'make_defaults_file_options',
|
|
|
+ ).with_args('root', 'trustsome1', None).and_return(('--defaults-extra-file=/dev/fd/99',))
|
|
|
+ flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
|
|
|
+ flexmock(module).should_receive('execute_command_and_capture_output').with_args(
|
|
|
+ (
|
|
|
+ 'mysql',
|
|
|
+ '--defaults-extra-file=/dev/fd/99',
|
|
|
+ '--socket',
|
|
|
+ '/socket',
|
|
|
+ '--skip-column-names',
|
|
|
+ '--batch',
|
|
|
+ '--execute',
|
|
|
+ 'show schemas',
|
|
|
+ ),
|
|
|
+ environment=environment,
|
|
|
+ working_directory=None,
|
|
|
+ ).and_return('foo\nbar\nmysql\n').once()
|
|
|
+
|
|
|
+ names = module.database_names_to_dump(
|
|
|
+ {'name': 'all', 'socket_path': '/socket'},
|
|
|
+ {},
|
|
|
+ 'root',
|
|
|
+ 'trustsome1',
|
|
|
+ environment,
|
|
|
+ dry_run=False,
|
|
|
+ )
|
|
|
+
|
|
|
+ assert names == ('foo', 'bar')
|
|
|
+
|
|
|
+
|
|
|
def test_database_names_to_dump_with_environment_password_transport_skips_defaults_file_and_passes_user_flag():
|
|
|
environment = flexmock()
|
|
|
flexmock(module.borgmatic.hooks.credential.parse).should_receive(
|
|
|
@@ -143,6 +185,7 @@ def test_database_names_to_dump_with_environment_password_transport_skips_defaul
|
|
|
flexmock(module.borgmatic.hooks.data_source.mariadb).should_receive(
|
|
|
'parse_extra_options',
|
|
|
).and_return((), None)
|
|
|
+ flexmock(module.database_config).should_receive('resolve_database_option').and_return(None)
|
|
|
flexmock(module.borgmatic.hooks.data_source.mariadb).should_receive(
|
|
|
'make_defaults_file_options',
|
|
|
).never()
|
|
|
@@ -181,6 +224,7 @@ def test_database_names_to_dump_runs_mysql_with_tls():
|
|
|
flexmock(module.borgmatic.hooks.data_source.mariadb).should_receive(
|
|
|
'parse_extra_options',
|
|
|
).and_return((), None)
|
|
|
+ flexmock(module.database_config).should_receive('resolve_database_option').and_return(None)
|
|
|
flexmock(module.borgmatic.hooks.data_source.mariadb).should_receive(
|
|
|
'make_defaults_file_options',
|
|
|
).with_args('root', 'trustsome1', None).and_return(('--defaults-extra-file=/dev/fd/99',))
|
|
|
@@ -219,6 +263,7 @@ def test_database_names_to_dump_runs_mysql_without_tls():
|
|
|
flexmock(module.borgmatic.hooks.data_source.mariadb).should_receive(
|
|
|
'parse_extra_options',
|
|
|
).and_return((), None)
|
|
|
+ flexmock(module.database_config).should_receive('resolve_database_option').and_return(None)
|
|
|
flexmock(module.borgmatic.hooks.data_source.mariadb).should_receive(
|
|
|
'make_defaults_file_options',
|
|
|
).with_args('root', 'trustsome1', None).and_return(('--defaults-extra-file=/dev/fd/99',))
|
|
|
@@ -591,6 +636,7 @@ def test_database_names_to_dump_runs_mysql_with_list_options():
|
|
|
flexmock(module.borgmatic.hooks.data_source.mariadb).should_receive(
|
|
|
'parse_extra_options',
|
|
|
).and_return(('--skip-ssl',), 'my.cnf')
|
|
|
+ flexmock(module.database_config).should_receive('resolve_database_option').and_return(None)
|
|
|
flexmock(module.borgmatic.hooks.data_source.mariadb).should_receive(
|
|
|
'make_defaults_file_options',
|
|
|
).with_args('root', 'trustsome1', 'my.cnf').and_return(('--defaults-extra-file=/dev/fd/99',))
|
|
|
@@ -624,6 +670,7 @@ def test_database_names_to_dump_runs_non_default_mysql_with_list_options():
|
|
|
flexmock(module.borgmatic.hooks.data_source.mariadb).should_receive(
|
|
|
'parse_extra_options',
|
|
|
).and_return(('--skip-ssl',), 'my.cnf')
|
|
|
+ flexmock(module.database_config).should_receive('resolve_database_option').and_return(None)
|
|
|
flexmock(module.borgmatic.hooks.data_source.mariadb).should_receive(
|
|
|
'make_defaults_file_options',
|
|
|
).with_args('root', 'trustsome1', 'my.cnf').and_return(('--defaults-extra-file=/dev/fd/99',))
|
|
|
@@ -658,6 +705,7 @@ def test_execute_dump_command_runs_mysqldump():
|
|
|
flexmock(module.borgmatic.hooks.data_source.mariadb).should_receive(
|
|
|
'parse_extra_options',
|
|
|
).and_return((), None)
|
|
|
+ flexmock(module.database_config).should_receive('resolve_database_option').and_return(None)
|
|
|
flexmock(module.borgmatic.hooks.data_source.mariadb).should_receive(
|
|
|
'make_defaults_file_options',
|
|
|
).with_args('root', 'trustsome1', None).and_return(('--defaults-extra-file=/dev/fd/99',))
|
|
|
@@ -705,6 +753,7 @@ def test_execute_dump_command_with_environment_password_transport_skips_defaults
|
|
|
flexmock(module.borgmatic.hooks.data_source.mariadb).should_receive(
|
|
|
'parse_extra_options',
|
|
|
).and_return((), None)
|
|
|
+ flexmock(module.database_config).should_receive('resolve_database_option').and_return(None)
|
|
|
flexmock(module.borgmatic.hooks.data_source.mariadb).should_receive(
|
|
|
'make_defaults_file_options',
|
|
|
).never()
|
|
|
@@ -753,6 +802,7 @@ def test_execute_dump_command_runs_mysqldump_without_add_drop_database():
|
|
|
flexmock(module.borgmatic.hooks.data_source.mariadb).should_receive(
|
|
|
'parse_extra_options',
|
|
|
).and_return((), None)
|
|
|
+ flexmock(module.database_config).should_receive('resolve_database_option').and_return(None)
|
|
|
flexmock(module.borgmatic.hooks.data_source.mariadb).should_receive(
|
|
|
'make_defaults_file_options',
|
|
|
).with_args('root', 'trustsome1', None).and_return(('--defaults-extra-file=/dev/fd/99',))
|
|
|
@@ -799,6 +849,9 @@ def test_execute_dump_command_runs_mysqldump_with_hostname_and_port():
|
|
|
flexmock(module.borgmatic.hooks.data_source.mariadb).should_receive(
|
|
|
'parse_extra_options',
|
|
|
).and_return((), None)
|
|
|
+ flexmock(module.database_config).should_receive('resolve_database_option').and_return(
|
|
|
+ 'database.example.org'
|
|
|
+ )
|
|
|
flexmock(module.borgmatic.hooks.data_source.mariadb).should_receive(
|
|
|
'make_defaults_file_options',
|
|
|
).with_args('root', 'trustsome1', None).and_return(('--defaults-extra-file=/dev/fd/99',))
|
|
|
@@ -852,6 +905,7 @@ def test_execute_dump_command_runs_mysqldump_with_tls():
|
|
|
flexmock(module.borgmatic.hooks.data_source.mariadb).should_receive(
|
|
|
'parse_extra_options',
|
|
|
).and_return((), None)
|
|
|
+ flexmock(module.database_config).should_receive('resolve_database_option').and_return(None)
|
|
|
flexmock(module.borgmatic.hooks.data_source.mariadb).should_receive(
|
|
|
'make_defaults_file_options',
|
|
|
).with_args('root', 'trustsome1', None).and_return(('--defaults-extra-file=/dev/fd/99',))
|
|
|
@@ -900,6 +954,7 @@ def test_execute_dump_command_runs_mysqldump_without_tls():
|
|
|
flexmock(module.borgmatic.hooks.data_source.mariadb).should_receive(
|
|
|
'parse_extra_options',
|
|
|
).and_return((), None)
|
|
|
+ flexmock(module.database_config).should_receive('resolve_database_option').and_return(None)
|
|
|
flexmock(module.borgmatic.hooks.data_source.mariadb).should_receive(
|
|
|
'make_defaults_file_options',
|
|
|
).with_args('root', 'trustsome1', None).and_return(('--defaults-extra-file=/dev/fd/99',))
|
|
|
@@ -948,6 +1003,7 @@ def test_execute_dump_command_runs_mysqldump_with_username_and_password():
|
|
|
flexmock(module.borgmatic.hooks.data_source.mariadb).should_receive(
|
|
|
'parse_extra_options',
|
|
|
).and_return((), None)
|
|
|
+ flexmock(module.database_config).should_receive('resolve_database_option').and_return(None)
|
|
|
flexmock(module.borgmatic.hooks.data_source.mariadb).should_receive(
|
|
|
'make_defaults_file_options',
|
|
|
).with_args('root', 'trustsome1', None).and_return(('--defaults-extra-file=/dev/fd/99',))
|
|
|
@@ -995,6 +1051,7 @@ def test_execute_dump_command_runs_mysqldump_with_options():
|
|
|
flexmock(module.borgmatic.hooks.data_source.mariadb).should_receive(
|
|
|
'parse_extra_options',
|
|
|
).and_return(('--stuff=such',), None)
|
|
|
+ flexmock(module.database_config).should_receive('resolve_database_option').and_return(None)
|
|
|
flexmock(module.borgmatic.hooks.data_source.mariadb).should_receive(
|
|
|
'make_defaults_file_options',
|
|
|
).with_args('root', 'trustsome1', None).and_return(('--defaults-extra-file=/dev/fd/99',))
|
|
|
@@ -1043,6 +1100,7 @@ def test_execute_dump_command_runs_non_default_mysqldump():
|
|
|
flexmock(module.borgmatic.hooks.data_source.mariadb).should_receive(
|
|
|
'parse_extra_options',
|
|
|
).and_return((), None)
|
|
|
+ flexmock(module.database_config).should_receive('resolve_database_option').and_return(None)
|
|
|
flexmock(module.borgmatic.hooks.data_source.mariadb).should_receive(
|
|
|
'make_defaults_file_options',
|
|
|
).with_args('root', 'trustsome1', None).and_return(('--defaults-extra-file=/dev/fd/99',))
|
|
|
@@ -1089,6 +1147,7 @@ def test_execute_dump_command_with_duplicate_dump_skips_mysqldump():
|
|
|
flexmock(module.borgmatic.hooks.data_source.mariadb).should_receive(
|
|
|
'parse_extra_options',
|
|
|
).and_return((), None)
|
|
|
+ flexmock(module.database_config).should_receive('resolve_database_option').and_return(None)
|
|
|
flexmock(module.borgmatic.hooks.data_source.mariadb).should_receive(
|
|
|
'make_defaults_file_options',
|
|
|
).with_args('root', 'trustsome1', None).and_return(('--defaults-extra-file=/dev/fd/99',))
|
|
|
@@ -1120,6 +1179,7 @@ def test_execute_dump_command_with_dry_run_skips_mysqldump():
|
|
|
flexmock(module.borgmatic.hooks.data_source.mariadb).should_receive(
|
|
|
'parse_extra_options',
|
|
|
).and_return((), None)
|
|
|
+ flexmock(module.database_config).should_receive('resolve_database_option').and_return(None)
|
|
|
flexmock(module.borgmatic.hooks.data_source.mariadb).should_receive(
|
|
|
'make_defaults_file_options',
|
|
|
).with_args('root', 'trustsome1', None).and_return(('--defaults-extra-file=/dev/fd/99',))
|
|
|
@@ -1153,6 +1213,7 @@ def test_restore_data_source_dump_runs_mysql_to_restore():
|
|
|
flexmock(module.borgmatic.hooks.data_source.mariadb).should_receive(
|
|
|
'parse_extra_options',
|
|
|
).and_return((), None)
|
|
|
+ flexmock(module.database_config).should_receive('resolve_database_option').and_return(None)
|
|
|
flexmock(module.borgmatic.hooks.data_source.mariadb).should_receive(
|
|
|
'make_defaults_file_options',
|
|
|
).with_args(None, None, None).and_return(())
|
|
|
@@ -1193,6 +1254,7 @@ def test_restore_data_source_dump_runs_mysql_with_options():
|
|
|
flexmock(module.borgmatic.hooks.data_source.mariadb).should_receive(
|
|
|
'parse_extra_options',
|
|
|
).and_return(('--harder',), None)
|
|
|
+ flexmock(module.database_config).should_receive('resolve_database_option').and_return(None)
|
|
|
flexmock(module.borgmatic.hooks.data_source.mariadb).should_receive(
|
|
|
'make_defaults_file_options',
|
|
|
).with_args(None, None, None).and_return(())
|
|
|
@@ -1233,6 +1295,7 @@ def test_restore_data_source_dump_runs_non_default_mysql_with_options():
|
|
|
flexmock(module.borgmatic.hooks.data_source.mariadb).should_receive(
|
|
|
'parse_extra_options',
|
|
|
).and_return(('--harder',), None)
|
|
|
+ flexmock(module.database_config).should_receive('resolve_database_option').and_return(None)
|
|
|
flexmock(module.borgmatic.hooks.data_source.mariadb).should_receive(
|
|
|
'make_defaults_file_options',
|
|
|
).with_args(None, None, None).and_return(())
|
|
|
@@ -1273,6 +1336,9 @@ def test_restore_data_source_dump_runs_mysql_with_hostname_and_port():
|
|
|
flexmock(module.borgmatic.hooks.data_source.mariadb).should_receive(
|
|
|
'parse_extra_options',
|
|
|
).and_return((), None)
|
|
|
+ flexmock(module.database_config).should_receive('resolve_database_option').replace_with(
|
|
|
+ lambda option, data_source, connection_params=None, restore=False: data_source.get(option)
|
|
|
+ )
|
|
|
flexmock(module.borgmatic.hooks.data_source.mariadb).should_receive(
|
|
|
'make_defaults_file_options',
|
|
|
).with_args(None, None, None).and_return(())
|
|
|
@@ -1312,6 +1378,58 @@ def test_restore_data_source_dump_runs_mysql_with_hostname_and_port():
|
|
|
)
|
|
|
|
|
|
|
|
|
+def test_restore_data_source_dump_runs_mysql_with_socket_path():
|
|
|
+ hook_config = [{'name': 'foo', 'socket_path': '/socket'}]
|
|
|
+ extract_process = flexmock(stdout=flexmock())
|
|
|
+
|
|
|
+ flexmock(module.borgmatic.hooks.credential.parse).should_receive(
|
|
|
+ 'resolve_credential',
|
|
|
+ ).replace_with(lambda value, config: value)
|
|
|
+ flexmock(module.borgmatic.hooks.data_source.mariadb).should_receive(
|
|
|
+ 'parse_extra_options',
|
|
|
+ ).and_return((), None)
|
|
|
+ flexmock(module.database_config).should_receive('resolve_database_option').replace_with(
|
|
|
+ lambda option, data_source, connection_params=None, restore=False: data_source.get(option)
|
|
|
+ )
|
|
|
+ flexmock(module.borgmatic.hooks.data_source.mariadb).should_receive(
|
|
|
+ 'make_defaults_file_options'
|
|
|
+ ).with_args(
|
|
|
+ None,
|
|
|
+ None,
|
|
|
+ None,
|
|
|
+ ).and_return(())
|
|
|
+ flexmock(module.os).should_receive('environ').and_return({'USER': 'root'})
|
|
|
+ flexmock(module.borgmatic.config.paths).should_receive('get_working_directory').and_return(None)
|
|
|
+ flexmock(module).should_receive('execute_command_with_processes').with_args(
|
|
|
+ (
|
|
|
+ 'mysql',
|
|
|
+ '--batch',
|
|
|
+ '--socket',
|
|
|
+ '/socket',
|
|
|
+ ),
|
|
|
+ processes=[extract_process],
|
|
|
+ output_log_level=logging.DEBUG,
|
|
|
+ input_file=extract_process.stdout,
|
|
|
+ environment={'USER': 'root'},
|
|
|
+ working_directory=None,
|
|
|
+ ).once()
|
|
|
+
|
|
|
+ module.restore_data_source_dump(
|
|
|
+ hook_config,
|
|
|
+ {},
|
|
|
+ data_source=hook_config[0],
|
|
|
+ dry_run=False,
|
|
|
+ extract_process=extract_process,
|
|
|
+ connection_params={
|
|
|
+ 'hostname': None,
|
|
|
+ 'port': None,
|
|
|
+ 'username': None,
|
|
|
+ 'password': None,
|
|
|
+ },
|
|
|
+ borgmatic_runtime_directory='/run/borgmatic',
|
|
|
+ )
|
|
|
+
|
|
|
+
|
|
|
def test_restore_data_source_dump_runs_mysql_with_tls():
|
|
|
hook_config = [{'name': 'foo', 'tls': True}]
|
|
|
extract_process = flexmock(stdout=flexmock())
|
|
|
@@ -1322,6 +1440,9 @@ def test_restore_data_source_dump_runs_mysql_with_tls():
|
|
|
flexmock(module.borgmatic.hooks.data_source.mariadb).should_receive(
|
|
|
'parse_extra_options',
|
|
|
).and_return((), None)
|
|
|
+ flexmock(module.database_config).should_receive('resolve_database_option').replace_with(
|
|
|
+ lambda option, data_source, connection_params=None, restore=False: data_source.get(option)
|
|
|
+ )
|
|
|
flexmock(module.borgmatic.hooks.data_source.mariadb).should_receive(
|
|
|
'make_defaults_file_options',
|
|
|
).with_args(None, None, None).and_return(())
|
|
|
@@ -1363,6 +1484,9 @@ def test_restore_data_source_dump_runs_mysql_without_tls():
|
|
|
flexmock(module.borgmatic.hooks.credential.parse).should_receive(
|
|
|
'resolve_credential',
|
|
|
).replace_with(lambda value, config: value)
|
|
|
+ flexmock(module.database_config).should_receive('resolve_database_option').replace_with(
|
|
|
+ lambda option, data_source, connection_params=None, restore=False: data_source.get(option)
|
|
|
+ )
|
|
|
flexmock(module.borgmatic.hooks.data_source.mariadb).should_receive(
|
|
|
'parse_extra_options',
|
|
|
).and_return((), None)
|
|
|
@@ -1410,6 +1534,9 @@ def test_restore_data_source_dump_runs_mysql_with_username_and_password():
|
|
|
flexmock(module.borgmatic.hooks.data_source.mariadb).should_receive(
|
|
|
'parse_extra_options',
|
|
|
).and_return((), None)
|
|
|
+ flexmock(module.database_config).should_receive('resolve_database_option').replace_with(
|
|
|
+ lambda option, data_source, connection_params=None, restore=False: data_source.get(option)
|
|
|
+ )
|
|
|
flexmock(module.borgmatic.hooks.data_source.mariadb).should_receive(
|
|
|
'make_defaults_file_options',
|
|
|
).with_args('root', 'trustsome1', None).and_return(('--defaults-extra-file=/dev/fd/99',))
|
|
|
@@ -1457,6 +1584,9 @@ def test_restore_data_source_with_environment_password_transport_skips_defaults_
|
|
|
flexmock(module.borgmatic.hooks.data_source.mariadb).should_receive(
|
|
|
'parse_extra_options',
|
|
|
).and_return((), None)
|
|
|
+ flexmock(module.database_config).should_receive('resolve_database_option').replace_with(
|
|
|
+ lambda option, data_source, connection_params=None, restore=False: data_source.get(option)
|
|
|
+ )
|
|
|
flexmock(module.borgmatic.hooks.data_source.mariadb).should_receive(
|
|
|
'make_defaults_file_options',
|
|
|
).never()
|
|
|
@@ -1509,6 +1639,11 @@ def test_restore_data_source_dump_with_connection_params_uses_connection_params_
|
|
|
flexmock(module.borgmatic.hooks.data_source.mariadb).should_receive(
|
|
|
'parse_extra_options',
|
|
|
).and_return((), None)
|
|
|
+ flexmock(module.database_config).should_receive('resolve_database_option').replace_with(
|
|
|
+ lambda option, data_source, connection_params=None, restore=False: (
|
|
|
+ connection_params or {}
|
|
|
+ ).get(option)
|
|
|
+ )
|
|
|
flexmock(module.borgmatic.hooks.data_source.mariadb).should_receive(
|
|
|
'make_defaults_file_options',
|
|
|
).with_args('cliusername', 'clipassword', None).and_return(
|
|
|
@@ -1575,6 +1710,11 @@ def test_restore_data_source_dump_without_connection_params_uses_restore_params_
|
|
|
flexmock(module.borgmatic.hooks.data_source.mariadb).should_receive(
|
|
|
'parse_extra_options',
|
|
|
).and_return((), None)
|
|
|
+ flexmock(module.database_config).should_receive('resolve_database_option').replace_with(
|
|
|
+ lambda option, data_source, connection_params=None, restore=False: data_source.get(
|
|
|
+ f'restore_{option}'
|
|
|
+ )
|
|
|
+ )
|
|
|
flexmock(module.borgmatic.hooks.data_source.mariadb).should_receive(
|
|
|
'make_defaults_file_options',
|
|
|
).with_args('restoreuser', 'restorepass', None).and_return(
|
|
|
@@ -1627,6 +1767,7 @@ def test_restore_data_source_dump_with_dry_run_skips_restore():
|
|
|
flexmock(module.borgmatic.hooks.data_source.mariadb).should_receive(
|
|
|
'parse_extra_options',
|
|
|
).and_return((), None)
|
|
|
+ flexmock(module.database_config).should_receive('resolve_database_option').and_return(None)
|
|
|
flexmock(module.borgmatic.hooks.data_source.mariadb).should_receive(
|
|
|
'make_defaults_file_options',
|
|
|
).with_args(None, None, None).and_return(())
|