diff options
| author | Colin Wilk <colin@wilk.cx> | 2026-06-28 22:47:11 +0200 |
|---|---|---|
| committer | Colin Wilk <colin@wilk.cx> | 2026-06-28 23:18:35 +0200 |
| commit | 7d96c1a11fc442b4efddf9ce5250cf0a9dfaf02e (patch) | |
| tree | 5561dbeee61aaab05e21f3bc2895ff703a2ce137 /molecule/default/tests/test_manual_backup.py | |
| parent | 785e6c88e4c0a3ccc44fd357b4f693c5aadd432c (diff) | |
| download | ansible-role-borgbackup-7d96c1a11fc442b4efddf9ce5250cf0a9dfaf02e.tar.gz ansible-role-borgbackup-7d96c1a11fc442b4efddf9ce5250cf0a9dfaf02e.zip | |
Parametrize server-side borg user
Adds option to choose a non-default borg backup user on the server.
Diffstat (limited to 'molecule/default/tests/test_manual_backup.py')
| -rw-r--r-- | molecule/default/tests/test_manual_backup.py | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/molecule/default/tests/test_manual_backup.py b/molecule/default/tests/test_manual_backup.py index 31a8693..b4068bc 100644 --- a/molecule/default/tests/test_manual_backup.py +++ b/molecule/default/tests/test_manual_backup.py @@ -1,7 +1,13 @@ import pytest from datetime import datetime -testinfra_hosts = ['borg-client'] +testinfra_hosts = ['borg-client', 'borg-client-2'] + + +def get_server_info(hostname): + if hostname == 'borg-client-2': + return ('backupserver', 'borg-server-2', '/var/backups') + return ('borg', 'borg-server', '/opt/borg') compression_types = [ @@ -20,8 +26,11 @@ host""" @pytest.mark.parametrize('compression', compression_types) def test_backup_push(host, compression): + hostname = host.backend.get_hostname() + server_user, server_host, server_path = get_server_info(hostname) + c = host.run( - f'borg create -C "{compression}" borg@borg-server:/opt/borg/borg-client::testinfra-{{now:%S.%f}} /etc' + f'borg create -C "{compression}" {server_user}@{server_host}:{server_path}/{hostname}::testinfra-{{now:%S.%f}} /etc' ) assert c.rc == 0 assert c.stdout == '' @@ -30,12 +39,14 @@ def test_backup_push(host, compression): @pytest.mark.parametrize('compression', compression_types) def test_backup_restore(host, compression): + hostname = host.backend.get_hostname() + server_user, server_host, server_path = get_server_info(hostname) timestamp = datetime.now().strftime('%Y%m%d-%H%M%S-%f') archive_name = f"testinfra-backup-restore-{compression}-{timestamp}" # Create backup c = host.run( - f'borg create -C "{compression}" borg@borg-server:/opt/borg/borg-client::{archive_name} /etc' + f'borg create -C "{compression}" {server_user}@{server_host}:{server_path}/{hostname}::{archive_name} /etc' ) assert c.rc == 0 assert c.stdout == '' @@ -43,7 +54,7 @@ def test_backup_restore(host, compression): # Restore Backup c = host.run( - f"cd /mnt && borg extract borg@borg-server:/opt/borg/borg-client::{archive_name}" + f"cd /mnt && borg extract {server_user}@{server_host}:{server_path}/{hostname}::{archive_name}" ) assert c.rc == 0 assert c.stdout == '' @@ -67,7 +78,7 @@ def test_backup_restore(host, compression): assert c.stderr == '' # Delete backup - c = host.run(f"borg delete borg@borg-server:/opt/borg/borg-client::{archive_name}") + c = host.run(f"borg delete {server_user}@{server_host}:{server_path}/{hostname}::{archive_name}") assert c.rc == 0 assert c.stdout == '' assert c.stderr == '' |