2018-09-30 08:15:18 +02:00
|
|
|
import logging
|
2017-08-06 01:21:39 +02:00
|
|
|
|
|
|
|
from flexmock import flexmock
|
|
|
|
|
|
|
|
from borgmatic.borg import extract as module
|
2019-05-13 23:39:10 +02:00
|
|
|
|
2018-09-30 22:57:20 +02:00
|
|
|
from ..test_verbosity import insert_logging_mock
|
2017-08-06 01:21:39 +02:00
|
|
|
|
|
|
|
|
2019-06-13 05:56:20 +02:00
|
|
|
def insert_execute_command_mock(command):
|
|
|
|
flexmock(module).should_receive('execute_command').with_args(command).once()
|
2017-08-06 01:21:39 +02:00
|
|
|
|
|
|
|
|
2019-06-13 05:56:20 +02:00
|
|
|
def insert_execute_command_output_mock(command, result):
|
|
|
|
flexmock(module).should_receive('execute_command').with_args(
|
|
|
|
command, output_log_level=None
|
|
|
|
).and_return(result).once()
|
2017-08-06 01:21:39 +02:00
|
|
|
|
|
|
|
|
2019-02-18 19:31:52 +01:00
|
|
|
def test_extract_last_archive_dry_run_calls_borg_with_last_archive():
|
2019-06-13 05:56:20 +02:00
|
|
|
insert_execute_command_output_mock(
|
|
|
|
('borg', 'list', '--short', 'repo'), result='archive1\narchive2\n'
|
2017-08-06 01:21:39 +02:00
|
|
|
)
|
2019-06-13 05:56:20 +02:00
|
|
|
insert_execute_command_mock(('borg', 'extract', '--dry-run', 'repo::archive2'))
|
2017-08-06 01:21:39 +02:00
|
|
|
|
2018-09-30 07:45:00 +02:00
|
|
|
module.extract_last_archive_dry_run(repository='repo', lock_wait=None)
|
2017-08-06 01:21:39 +02:00
|
|
|
|
|
|
|
|
2019-06-13 05:56:20 +02:00
|
|
|
def test_extract_last_archive_dry_run_without_any_archives_should_not_raise():
|
|
|
|
insert_execute_command_output_mock(('borg', 'list', '--short', 'repo'), result='\n')
|
2017-08-06 01:21:39 +02:00
|
|
|
|
2018-09-30 07:45:00 +02:00
|
|
|
module.extract_last_archive_dry_run(repository='repo', lock_wait=None)
|
2017-08-06 01:21:39 +02:00
|
|
|
|
|
|
|
|
2019-02-18 19:31:52 +01:00
|
|
|
def test_extract_last_archive_dry_run_with_log_info_calls_borg_with_info_parameter():
|
2019-06-13 05:56:20 +02:00
|
|
|
insert_execute_command_output_mock(
|
|
|
|
('borg', 'list', '--short', 'repo', '--info'), result='archive1\narchive2\n'
|
2017-08-06 01:21:39 +02:00
|
|
|
)
|
2019-06-13 05:56:20 +02:00
|
|
|
insert_execute_command_mock(('borg', 'extract', '--dry-run', 'repo::archive2', '--info'))
|
2018-09-08 22:53:37 +02:00
|
|
|
insert_logging_mock(logging.INFO)
|
2017-08-06 01:21:39 +02:00
|
|
|
|
2018-09-30 07:45:00 +02:00
|
|
|
module.extract_last_archive_dry_run(repository='repo', lock_wait=None)
|
2017-08-06 01:21:39 +02:00
|
|
|
|
|
|
|
|
2019-02-18 19:31:52 +01:00
|
|
|
def test_extract_last_archive_dry_run_with_log_debug_calls_borg_with_debug_parameter():
|
2019-06-13 05:56:20 +02:00
|
|
|
insert_execute_command_output_mock(
|
|
|
|
('borg', 'list', '--short', 'repo', '--debug', '--show-rc'), result='archive1\narchive2\n'
|
2017-08-06 01:21:39 +02:00
|
|
|
)
|
2019-06-13 05:56:20 +02:00
|
|
|
insert_execute_command_mock(
|
2018-09-30 07:45:00 +02:00
|
|
|
('borg', 'extract', '--dry-run', 'repo::archive2', '--debug', '--show-rc', '--list')
|
2017-08-06 01:21:39 +02:00
|
|
|
)
|
2018-09-08 22:53:37 +02:00
|
|
|
insert_logging_mock(logging.DEBUG)
|
2017-08-06 01:21:39 +02:00
|
|
|
|
2018-09-30 07:45:00 +02:00
|
|
|
module.extract_last_archive_dry_run(repository='repo', lock_wait=None)
|
2017-08-06 01:21:39 +02:00
|
|
|
|
|
|
|
|
2019-02-18 19:31:52 +01:00
|
|
|
def test_extract_last_archive_dry_run_calls_borg_via_local_path():
|
2019-06-13 05:56:20 +02:00
|
|
|
insert_execute_command_output_mock(
|
|
|
|
('borg1', 'list', '--short', 'repo'), result='archive1\narchive2\n'
|
2018-01-15 01:35:24 +01:00
|
|
|
)
|
2019-06-13 05:56:20 +02:00
|
|
|
insert_execute_command_mock(('borg1', 'extract', '--dry-run', 'repo::archive2'))
|
2018-01-15 01:35:24 +01:00
|
|
|
|
2018-09-30 07:45:00 +02:00
|
|
|
module.extract_last_archive_dry_run(repository='repo', lock_wait=None, local_path='borg1')
|
2018-01-15 01:35:24 +01:00
|
|
|
|
|
|
|
|
2019-02-18 19:31:52 +01:00
|
|
|
def test_extract_last_archive_dry_run_calls_borg_with_remote_path_parameters():
|
2019-06-13 05:56:20 +02:00
|
|
|
insert_execute_command_output_mock(
|
|
|
|
('borg', 'list', '--short', 'repo', '--remote-path', 'borg1'), result='archive1\narchive2\n'
|
2017-08-06 01:21:39 +02:00
|
|
|
)
|
2019-06-13 05:56:20 +02:00
|
|
|
insert_execute_command_mock(
|
2018-09-30 07:45:00 +02:00
|
|
|
('borg', 'extract', '--dry-run', 'repo::archive2', '--remote-path', 'borg1')
|
2017-08-06 01:21:39 +02:00
|
|
|
)
|
|
|
|
|
2018-09-30 07:45:00 +02:00
|
|
|
module.extract_last_archive_dry_run(repository='repo', lock_wait=None, remote_path='borg1')
|
2018-02-20 00:51:04 +01:00
|
|
|
|
|
|
|
|
2019-02-18 19:31:52 +01:00
|
|
|
def test_extract_last_archive_dry_run_calls_borg_with_lock_wait_parameters():
|
2019-06-13 05:56:20 +02:00
|
|
|
insert_execute_command_output_mock(
|
|
|
|
('borg', 'list', '--short', 'repo', '--lock-wait', '5'), result='archive1\narchive2\n'
|
|
|
|
)
|
|
|
|
insert_execute_command_mock(
|
|
|
|
('borg', 'extract', '--dry-run', 'repo::archive2', '--lock-wait', '5')
|
2018-02-20 00:51:04 +01:00
|
|
|
)
|
|
|
|
|
2018-09-30 07:45:00 +02:00
|
|
|
module.extract_last_archive_dry_run(repository='repo', lock_wait=5)
|
2019-02-18 19:31:52 +01:00
|
|
|
|
|
|
|
|
2019-02-19 06:59:09 +01:00
|
|
|
def test_extract_archive_calls_borg_with_restore_path_parameters():
|
2019-06-13 05:56:20 +02:00
|
|
|
insert_execute_command_mock(('borg', 'extract', 'repo::archive', 'path1', 'path2'))
|
2019-02-19 06:59:09 +01:00
|
|
|
|
|
|
|
module.extract_archive(
|
|
|
|
dry_run=False,
|
|
|
|
repository='repo',
|
|
|
|
archive='archive',
|
|
|
|
restore_paths=['path1', 'path2'],
|
2019-03-05 18:11:35 +01:00
|
|
|
location_config={},
|
2019-02-19 06:59:09 +01:00
|
|
|
storage_config={},
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2019-02-18 19:31:52 +01:00
|
|
|
def test_extract_archive_calls_borg_with_remote_path_parameters():
|
2019-06-13 05:56:20 +02:00
|
|
|
insert_execute_command_mock(('borg', 'extract', 'repo::archive', '--remote-path', 'borg1'))
|
2019-02-18 19:31:52 +01:00
|
|
|
|
|
|
|
module.extract_archive(
|
|
|
|
dry_run=False,
|
|
|
|
repository='repo',
|
|
|
|
archive='archive',
|
|
|
|
restore_paths=None,
|
2019-03-05 18:11:35 +01:00
|
|
|
location_config={},
|
2019-02-18 19:31:52 +01:00
|
|
|
storage_config={},
|
|
|
|
remote_path='borg1',
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2019-03-05 18:11:35 +01:00
|
|
|
def test_extract_archive_calls_borg_with_numeric_owner_parameter():
|
2019-06-13 05:56:20 +02:00
|
|
|
insert_execute_command_mock(('borg', 'extract', 'repo::archive', '--numeric-owner'))
|
2019-03-05 18:11:35 +01:00
|
|
|
|
|
|
|
module.extract_archive(
|
|
|
|
dry_run=False,
|
|
|
|
repository='repo',
|
|
|
|
archive='archive',
|
|
|
|
restore_paths=None,
|
|
|
|
location_config={'numeric_owner': True},
|
|
|
|
storage_config={},
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2019-02-18 19:31:52 +01:00
|
|
|
def test_extract_archive_calls_borg_with_umask_parameters():
|
2019-06-13 05:56:20 +02:00
|
|
|
insert_execute_command_mock(('borg', 'extract', 'repo::archive', '--umask', '0770'))
|
2019-02-18 19:31:52 +01:00
|
|
|
|
|
|
|
module.extract_archive(
|
|
|
|
dry_run=False,
|
|
|
|
repository='repo',
|
|
|
|
archive='archive',
|
|
|
|
restore_paths=None,
|
2019-03-05 18:11:35 +01:00
|
|
|
location_config={},
|
2019-02-18 19:31:52 +01:00
|
|
|
storage_config={'umask': '0770'},
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def test_extract_archive_calls_borg_with_lock_wait_parameters():
|
2019-06-13 05:56:20 +02:00
|
|
|
insert_execute_command_mock(('borg', 'extract', 'repo::archive', '--lock-wait', '5'))
|
2019-02-18 19:31:52 +01:00
|
|
|
|
|
|
|
module.extract_archive(
|
|
|
|
dry_run=False,
|
|
|
|
repository='repo',
|
|
|
|
archive='archive',
|
|
|
|
restore_paths=None,
|
2019-03-05 18:11:35 +01:00
|
|
|
location_config={},
|
2019-02-18 19:31:52 +01:00
|
|
|
storage_config={'lock_wait': '5'},
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def test_extract_archive_with_log_info_calls_borg_with_info_parameter():
|
2019-06-13 05:56:20 +02:00
|
|
|
insert_execute_command_mock(('borg', 'extract', 'repo::archive', '--info'))
|
2019-02-18 19:31:52 +01:00
|
|
|
insert_logging_mock(logging.INFO)
|
|
|
|
|
|
|
|
module.extract_archive(
|
2019-03-05 18:11:35 +01:00
|
|
|
dry_run=False,
|
|
|
|
repository='repo',
|
|
|
|
archive='archive',
|
|
|
|
restore_paths=None,
|
|
|
|
location_config={},
|
|
|
|
storage_config={},
|
2019-02-18 19:31:52 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def test_extract_archive_with_log_debug_calls_borg_with_debug_parameters():
|
2019-06-13 05:56:20 +02:00
|
|
|
insert_execute_command_mock(
|
|
|
|
('borg', 'extract', 'repo::archive', '--debug', '--list', '--show-rc')
|
|
|
|
)
|
2019-02-18 19:31:52 +01:00
|
|
|
insert_logging_mock(logging.DEBUG)
|
|
|
|
|
|
|
|
module.extract_archive(
|
2019-03-05 18:11:35 +01:00
|
|
|
dry_run=False,
|
|
|
|
repository='repo',
|
|
|
|
archive='archive',
|
|
|
|
restore_paths=None,
|
|
|
|
location_config={},
|
|
|
|
storage_config={},
|
2019-02-18 19:31:52 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def test_extract_archive_calls_borg_with_dry_run_parameter():
|
2019-06-13 05:56:20 +02:00
|
|
|
insert_execute_command_mock(('borg', 'extract', 'repo::archive', '--dry-run'))
|
2019-02-18 19:31:52 +01:00
|
|
|
|
|
|
|
module.extract_archive(
|
2019-03-05 18:11:35 +01:00
|
|
|
dry_run=True,
|
|
|
|
repository='repo',
|
|
|
|
archive='archive',
|
|
|
|
restore_paths=None,
|
|
|
|
location_config={},
|
|
|
|
storage_config={},
|
2019-02-18 19:31:52 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def test_extract_archive_calls_borg_with_progress_parameter():
|
2019-06-13 05:56:20 +02:00
|
|
|
insert_execute_command_mock(('borg', 'extract', 'repo::archive', '--progress'))
|
2019-02-18 19:31:52 +01:00
|
|
|
|
|
|
|
module.extract_archive(
|
|
|
|
dry_run=False,
|
|
|
|
repository='repo',
|
|
|
|
archive='archive',
|
|
|
|
restore_paths=None,
|
2019-03-05 18:11:35 +01:00
|
|
|
location_config={},
|
2019-02-18 19:31:52 +01:00
|
|
|
storage_config={},
|
|
|
|
progress=True,
|
|
|
|
)
|