aboutsummaryrefslogtreecommitdiffstats
path: root/molecule/default/tests/test_manual_backup.py
diff options
context:
space:
mode:
authorColin Wilk <colin@wilk.cx>2026-06-26 22:35:40 +0000
committerColin Wilk <colin@wilk.cx>2026-06-27 15:43:21 +0200
commite15d494e96e9f9e6cdf21676ce3644c7894b3b53 (patch)
tree51266a035df33c1ff9204299fdd0b89bd8adca4a /molecule/default/tests/test_manual_backup.py
parentb8d11180605fbf193e76fba04bb63b5ea4908dcf (diff)
downloadansible-role-borgbackup-e15d494e96e9f9e6cdf21676ce3644c7894b3b53.tar.gz
ansible-role-borgbackup-e15d494e96e9f9e6cdf21676ce3644c7894b3b53.zip
test: add larger test suite for role
- Add test systems for client/server setup - Add tests for systemd service and timer files - Add tests for SSH connectivity - Add tests for security configurations - Add tests for multi-instance backup scenarios
Diffstat (limited to 'molecule/default/tests/test_manual_backup.py')
-rw-r--r--molecule/default/tests/test_manual_backup.py30
1 files changed, 23 insertions, 7 deletions
diff --git a/molecule/default/tests/test_manual_backup.py b/molecule/default/tests/test_manual_backup.py
index 4aa9f27..31a8693 100644
--- a/molecule/default/tests/test_manual_backup.py
+++ b/molecule/default/tests/test_manual_backup.py
@@ -1,4 +1,5 @@
import pytest
+from datetime import datetime
testinfra_hosts = ['borg-client']
@@ -15,9 +16,13 @@ compression_types = [
"""Creates backups with all possible combinations of compression to the backup
host"""
+
+
@pytest.mark.parametrize('compression', compression_types)
def test_backup_push(host, compression):
- c = host.run(f'borg create -C "{compression}" borg@borg-server:/opt/borg/borg-client::testinfra-{{now:%S.%f}} /etc')
+ c = host.run(
+ f'borg create -C "{compression}" borg@borg-server:/opt/borg/borg-client::testinfra-{{now:%S.%f}} /etc'
+ )
assert c.rc == 0
assert c.stdout == ''
assert c.stderr == ''
@@ -25,33 +30,44 @@ def test_backup_push(host, compression):
@pytest.mark.parametrize('compression', compression_types)
def test_backup_restore(host, compression):
+ 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::testinfra-backup-restore-{compression} /var')
+ c = host.run(
+ f'borg create -C "{compression}" borg@borg-server:/opt/borg/borg-client::{archive_name} /etc'
+ )
assert c.rc == 0
assert c.stdout == ''
assert c.stderr == ''
# Restore Backup
- c = host.run(f'cd /mnt && borg extract borg@borg-server:/opt/borg/borg-client::testinfra-backup-restore-{compression}')
+ c = host.run(
+ f"cd /mnt && borg extract borg@borg-server:/opt/borg/borg-client::{archive_name}"
+ )
assert c.rc == 0
assert c.stdout == ''
assert c.stderr == ''
# Check if every file exists, content has, and permissions / metadata
- c1 = host.run('cd /var && find /var -type f -printf "%P\n" | sort | xargs -i sh -c "echo {}; sha512sum {} | cut -d \' \' -f 1; ls -l {}; echo"')
- c2 = host.run('cd /mnt/var && find /var -type f -printf "%P\n" | sort | xargs -i sh -c "echo {}; sha512sum {} | cut -d \' \' -f 1; ls -l {}; echo"')
+ c1 = host.run(
+ 'cd /etc && find /etc -type f -printf "%P\\n" | sort | xargs -i sh -c "echo {}; sha512sum {} | cut -d \' \' -f 1; ls -l {}; echo"'
+ )
+ c2 = host.run(
+ 'cd /mnt/etc && find /etc -type f -printf "%P\\n" | sort | xargs -i sh -c "echo {}; sha512sum {} | cut -d \' \' -f 1; ls -l {}; echo"'
+ )
assert c1.rc == 0 and c2.rc == 0
assert c1.stderr == '' and c2.stderr == ''
assert c1.stdout == c2.stdout
# Delete directory extract directory again for future tests
- c = host.run('rm -rf /mnt/var')
+ c = host.run('rm -rf /mnt/etc')
assert c.rc == 0
assert c.stdout == ''
assert c.stderr == ''
# Delete backup
- c = host.run(f'borg delete borg@borg-server:/opt/borg/borg-client::testinfra-backup-restore-{compression}')
+ c = host.run(f"borg delete borg@borg-server:/opt/borg/borg-client::{archive_name}")
assert c.rc == 0
assert c.stdout == ''
assert c.stderr == ''