aboutsummaryrefslogtreecommitdiffstats
path: root/molecule/default/tests/test_client_setup.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_client_setup.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_client_setup.py')
-rw-r--r--molecule/default/tests/test_client_setup.py192
1 files changed, 192 insertions, 0 deletions
diff --git a/molecule/default/tests/test_client_setup.py b/molecule/default/tests/test_client_setup.py
new file mode 100644
index 0000000..25bf8e2
--- /dev/null
+++ b/molecule/default/tests/test_client_setup.py
@@ -0,0 +1,192 @@
+"""Tests for client setup configuration"""
+import pytest
+
+testinfra_hosts = ['borg-client', 'borg-client-2', 'borg-client-multi']
+
+
+class TestSSHSetup:
+ def test_ssh_directory_exists(self, host):
+ ssh_dir = host.file('/root/.ssh')
+ assert ssh_dir.exists
+ assert ssh_dir.is_directory
+ assert ssh_dir.user == 'root'
+ assert ssh_dir.group == 'root'
+ assert ssh_dir.mode == 0o640
+
+ def test_ssh_private_key_exists(self, host):
+ key = host.file('/root/.ssh/id_rsa')
+ assert key.exists
+ assert key.user == 'root'
+ assert key.group == 'root'
+ assert key.mode == 0o600
+
+ def test_ssh_public_key_exists(self, host):
+ key = host.file('/root/.ssh/id_rsa.pub')
+ assert key.exists
+ assert key.user == 'root'
+ assert key.group == 'root'
+
+ def test_known_hosts_contains_borg_server(self, host):
+ known_hosts = host.file('/root/.ssh/known_hosts')
+ assert known_hosts.exists
+ assert known_hosts.contains('borg-server')
+
+
+class TestBackupScript:
+ def test_backup_script_exists(self, host):
+ hostname = host.backend.get_hostname()
+
+ if hostname == 'borg-client-multi':
+ script1 = host.file('/usr/local/bin/run_borg_backup@configs')
+ script2 = host.file('/usr/local/bin/run_borg_backup@home-data')
+ assert script1.exists
+ assert script1.user == 'root'
+ assert script1.group == 'root'
+ assert script1.mode == 0o711
+ assert script2.exists
+ assert script2.user == 'root'
+ assert script2.group == 'root'
+ assert script2.mode == 0o711
+ elif hostname in ('borg-client', 'borg-client-2'):
+ script = host.file('/usr/local/bin/run_borg_backup')
+ assert script.exists
+ assert script.user == 'root'
+ assert script.group == 'root'
+ assert script.mode == 0o711
+ else:
+ pytest.fail(f"Unexpected hostname: {hostname}")
+
+ def test_backup_script_contains_borg_command(self, host):
+ hostname = host.backend.get_hostname()
+
+ if hostname == 'borg-client-multi':
+ script1 = host.file('/usr/local/bin/run_borg_backup@configs')
+ script2 = host.file('/usr/local/bin/run_borg_backup@home-data')
+ assert script1.contains('borg create')
+ assert script2.contains('borg create')
+ elif hostname in ('borg-client', 'borg-client-2'):
+ script = host.file('/usr/local/bin/run_borg_backup')
+ assert script.contains('borg create')
+ else:
+ pytest.fail(f"Unexpected hostname: {hostname}")
+
+ def test_backup_script_contains_compression(self, host):
+ hostname = host.backend.get_hostname()
+
+ if hostname == 'borg-client-multi':
+ script1 = host.file('/usr/local/bin/run_borg_backup@configs')
+ script2 = host.file('/usr/local/bin/run_borg_backup@home-data')
+ assert script1.contains('-C zstd')
+ assert script2.contains('-C lz4')
+ elif hostname == 'borg-client-2':
+ script = host.file('/usr/local/bin/run_borg_backup')
+ assert script.contains('-C')
+ assert script.contains('lz4')
+ elif hostname == 'borg-client':
+ script = host.file('/usr/local/bin/run_borg_backup')
+ assert script.contains('-C')
+ assert script.contains('zstd')
+ else:
+ pytest.fail(f"Unexpected hostname: {hostname}")
+
+ def test_backup_script_contains_repo_path(self, host):
+ hostname = host.backend.get_hostname()
+
+ if hostname == 'borg-client-multi':
+ script1 = host.file('/usr/local/bin/run_borg_backup@configs')
+ script2 = host.file('/usr/local/bin/run_borg_backup@home-data')
+ assert script1.contains('borg@borg-server')
+ assert script1.contains('/opt/borg/configs')
+ assert script2.contains('borg@borg-server')
+ assert script2.contains('/opt/borg/home-data')
+ elif hostname in ('borg-client', 'borg-client-2'):
+ script = host.file('/usr/local/bin/run_borg_backup')
+ assert script.contains('borg@borg-server')
+ assert script.contains('/opt/borg')
+ else:
+ pytest.fail(f"Unexpected hostname: {hostname}")
+
+ def test_backup_script_contains_backup_paths(self, host):
+ hostname = host.backend.get_hostname()
+
+ if hostname == 'borg-client-multi':
+ script1 = host.file('/usr/local/bin/run_borg_backup@configs')
+ script2 = host.file('/usr/local/bin/run_borg_backup@home-data')
+ assert '/etc' in script1.content_string
+ assert '/home' in script2.content_string
+ assert '--exclude' in script2.content_string
+ elif hostname in ('borg-client', 'borg-client-2'):
+ script = host.file('/usr/local/bin/run_borg_backup')
+ content = script.content_string
+ assert '/etc' in content or '/home' in content
+ else:
+ pytest.fail(f"Unexpected hostname: {hostname}")
+
+ def test_backup_script_is_executable(self, host):
+ hostname = host.backend.get_hostname()
+
+ if hostname == 'borg-client-multi':
+ script1 = host.file('/usr/local/bin/run_borg_backup@configs')
+ script2 = host.file('/usr/local/bin/run_borg_backup@home-data')
+ assert script1.mode == 0o711
+ assert script2.mode == 0o711
+ elif hostname in ('borg-client', 'borg-client-2'):
+ script = host.file('/usr/local/bin/run_borg_backup')
+ assert script.mode == 0o711
+ else:
+ pytest.fail(f"Unexpected hostname: {hostname}")
+
+
+class TestMultiInstanceBaseScript:
+ def test_base_script_exists(self, host):
+ hostname = host.backend.get_hostname()
+ if hostname != 'borg-client-multi':
+ return
+
+ base_script = host.file('/usr/local/bin/run_borg_backup')
+ assert base_script.exists
+ assert base_script.user == 'root'
+ assert base_script.mode == 0o711
+
+ def test_base_script_contains_both_blocks(self, host):
+ hostname = host.backend.get_hostname()
+ if hostname != 'borg-client-multi':
+ return
+
+ base_script = host.file('/usr/local/bin/run_borg_backup')
+ content = base_script.content_string
+
+ assert 'borg-server/configs' in content
+ assert 'borg-server/home-data' in content
+
+ def test_base_script_contains_both_repos(self, host):
+ hostname = host.backend.get_hostname()
+ if hostname != 'borg-client-multi':
+ return
+
+ base_script = host.file('/usr/local/bin/run_borg_backup')
+ content = base_script.content_string
+
+ assert '/opt/borg/configs' in content
+ assert '/opt/borg/home-data' in content
+
+ def test_base_script_contains_both_compressions(self, host):
+ hostname = host.backend.get_hostname()
+ if hostname != 'borg-client-multi':
+ return
+
+ base_script = host.file('/usr/local/bin/run_borg_backup')
+ content = base_script.content_string
+
+ assert '-C zstd' in content
+ assert '-C lz4' in content
+
+ def test_base_script_two_borg_create_commands(self, host):
+ hostname = host.backend.get_hostname()
+ if hostname != 'borg-client-multi':
+ return
+
+ base_script = host.file('/usr/local/bin/run_borg_backup')
+ content = base_script.content_string
+
+ assert content.count('borg create') == 2