2022-07-07 03:20:51 +02:00
|
|
|
import os
|
|
|
|
import shutil
|
|
|
|
import subprocess
|
|
|
|
import tempfile
|
|
|
|
|
|
|
|
|
|
|
|
def generate_configuration(config_path, repository_path):
|
|
|
|
'''
|
|
|
|
Generate borgmatic configuration into a file at the config path, and update the defaults so as
|
|
|
|
to work for testing (including injecting the given repository path and tacking on an encryption
|
|
|
|
passphrase).
|
|
|
|
'''
|
2023-06-25 00:35:10 +02:00
|
|
|
subprocess.check_call(f'borgmatic config generate --destination {config_path}'.split(' '))
|
2022-07-07 03:20:51 +02:00
|
|
|
config = (
|
|
|
|
open(config_path)
|
|
|
|
.read()
|
2022-08-22 08:29:13 +02:00
|
|
|
.replace('ssh://user@backupserver/./sourcehostname.borg', repository_path)
|
2023-03-24 07:11:14 +01:00
|
|
|
.replace('- ssh://user@backupserver/./{fqdn}', '') # noqa: FS003
|
2022-08-22 08:29:13 +02:00
|
|
|
.replace('- /var/local/backups/local.borg', '')
|
2022-07-07 03:20:51 +02:00
|
|
|
.replace('- /home/user/path with spaces', '')
|
2023-03-24 07:11:14 +01:00
|
|
|
.replace('- /home', f'- {config_path}')
|
2022-07-07 03:20:51 +02:00
|
|
|
.replace('- /etc', '')
|
|
|
|
.replace('- /var/log/syslog*', '')
|
|
|
|
+ 'storage:\n encryption_passphrase: "test"'
|
|
|
|
)
|
|
|
|
config_file = open(config_path, 'w')
|
|
|
|
config_file.write(config)
|
|
|
|
config_file.close()
|
|
|
|
|
|
|
|
|
|
|
|
def test_override_get_normalized():
|
|
|
|
temporary_directory = tempfile.mkdtemp()
|
|
|
|
repository_path = os.path.join(temporary_directory, 'test.borg')
|
|
|
|
|
|
|
|
original_working_directory = os.getcwd()
|
|
|
|
|
|
|
|
try:
|
|
|
|
config_path = os.path.join(temporary_directory, 'test.yaml')
|
|
|
|
generate_configuration(config_path, repository_path)
|
|
|
|
|
|
|
|
subprocess.check_call(
|
2023-06-25 00:52:20 +02:00
|
|
|
f'borgmatic -v 2 --config {config_path} rcreate --encryption repokey'.split(' ')
|
2022-07-07 03:20:51 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
# Run borgmatic with an override structured for an outdated config file format. If
|
|
|
|
# normalization is working, it should get normalized and shouldn't error.
|
|
|
|
subprocess.check_call(
|
|
|
|
f'borgmatic create --config {config_path} --override hooks.healthchecks=http://localhost:8888/someuuid'.split(
|
|
|
|
' '
|
|
|
|
)
|
|
|
|
)
|
|
|
|
finally:
|
|
|
|
os.chdir(original_working_directory)
|
|
|
|
shutil.rmtree(temporary_directory)
|