diff options
| author | Colin Wilk <colin@wilk.cx> | 2026-06-27 21:25:37 +0200 |
|---|---|---|
| committer | Colin Wilk <colin@wilk.cx> | 2026-06-27 21:25:37 +0200 |
| commit | cce7d2d258292c283d64ce8da14a6d1e366b564d (patch) | |
| tree | fe9de437636098066c6bf160d5787b6b35659835 /molecule/default/tests/test_systemd.py | |
| parent | a22ff185f9836023817f9d4f8df3157b948f8cf2 (diff) | |
| download | ansible-role-borgbackup-cce7d2d258292c283d64ce8da14a6d1e366b564d.tar.gz ansible-role-borgbackup-cce7d2d258292c283d64ce8da14a6d1e366b564d.zip | |
Add support for non-root backup clients
Diffstat (limited to 'molecule/default/tests/test_systemd.py')
| -rw-r--r-- | molecule/default/tests/test_systemd.py | 57 |
1 files changed, 50 insertions, 7 deletions
diff --git a/molecule/default/tests/test_systemd.py b/molecule/default/tests/test_systemd.py index 9421959..7b7b2ab 100644 --- a/molecule/default/tests/test_systemd.py +++ b/molecule/default/tests/test_systemd.py @@ -2,7 +2,20 @@ import pytest -testinfra_hosts = ['borg-client', 'borg-client-2', 'borg-client-multi'] +testinfra_hosts = ['borg-client', 'borg-client-2', 'borg-client-multi', 'borg-client-nonroot'] + + +CLIENT_USER_MAP = { + 'borg-client': 'root', + 'borg-client-2': 'root', + 'borg-client-multi': 'root', + 'borg-client-nonroot': 'backupuser', +} + + +def get_client_user(host): + hostname = host.backend.get_hostname() + return CLIENT_USER_MAP.get(hostname, 'root') class TestSystemdServiceFile: @@ -18,6 +31,12 @@ class TestSystemdServiceFile: assert service2.exists assert service2.user == 'root' assert service2.group == 'root' + elif hostname == 'borg-client-nonroot': + service = host.file('/etc/systemd/system/borg_backup@borg-server.service') + assert service.exists + assert service.user == 'root' + assert service.group == 'root' + assert service.mode == 0o644 elif hostname in ('borg-client', 'borg-client-2'): service = host.file('/etc/systemd/system/borg_backup@borg-server.service') assert service.exists @@ -38,6 +57,13 @@ class TestSystemdServiceFile: assert service.contains('[Service]') assert service.contains('[Install]') assert service.contains('Type=oneshot') + elif hostname == 'borg-client-nonroot': + service = host.file('/etc/systemd/system/borg_backup@borg-server.service') + assert service.contains('[Unit]') + assert service.contains('[Service]') + assert service.contains('[Install]') + assert service.contains('Type=oneshot') + assert service.contains('ExecStart=/usr/local/bin/run_borg_backup') elif hostname in ('borg-client', 'borg-client-2'): service = host.file('/etc/systemd/system/borg_backup@borg-server.service') assert service.contains('[Unit]') @@ -48,9 +74,26 @@ class TestSystemdServiceFile: else: pytest.fail(f"Unexpected hostname: {hostname}") - def test_success_exit_status(self, host): + def test_service_user(self, host): hostname = host.backend.get_hostname() + client_user = get_client_user(host) + if hostname == 'borg-client-multi': + service1 = host.file('/etc/systemd/system/borg_backup@configs.service') + service2 = host.file('/etc/systemd/system/borg_backup@home-data.service') + for service in [service1, service2]: + assert service.contains(f'User={client_user}') + assert service.contains(f'Group={client_user}') + elif hostname in ('borg-client', 'borg-client-2', 'borg-client-nonroot'): + service = host.file('/etc/systemd/system/borg_backup@borg-server.service') + assert service.contains(f'User={client_user}') + assert service.contains(f'Group={client_user}') + else: + pytest.fail(f"Unexpected hostname: {hostname}") + + def test_success_exit_status(self, host): + hostname = host.backend.get_hostname() + if hostname in ('borg-client-multi', 'borg-client-nonroot'): return service = host.file('/etc/systemd/system/borg_backup@borg-server.service') @@ -80,7 +123,7 @@ class TestSystemdTimerFile: timer2 = host.file('/etc/systemd/system/borg_backup@home-data.timer') assert timer1.exists assert timer2.exists - elif hostname in ('borg-client', 'borg-client-2'): + elif hostname in ('borg-client', 'borg-client-2', 'borg-client-nonroot'): timer = host.file('/etc/systemd/system/borg_backup@borg-server.timer') assert timer.exists assert timer.user == 'root' @@ -101,7 +144,7 @@ class TestSystemdTimerFile: assert timer.contains('[Install]') assert timer.contains('OnCalendar=') assert timer.contains('AccuracySec=') - elif hostname in ('borg-client', 'borg-client-2'): + elif hostname in ('borg-client', 'borg-client-2', 'borg-client-nonroot'): timer = host.file('/etc/systemd/system/borg_backup@borg-server.timer') assert timer.contains('[Unit]') assert timer.contains('[Timer]') @@ -122,7 +165,7 @@ class TestSystemdTimerFile: elif hostname == 'borg-client-2': timer = host.file('/etc/systemd/system/borg_backup@borg-server.timer') assert 'OnCalendar=*-*-* 03:00:00' in timer.content_string - elif hostname == 'borg-client': + elif hostname in ('borg-client', 'borg-client-nonroot'): timer = host.file('/etc/systemd/system/borg_backup@borg-server.timer') assert 'OnCalendar=*-*-* 02:00:00' in timer.content_string else: @@ -140,7 +183,7 @@ class TestSystemdState: assert c1.stdout.strip() == 'enabled' assert c2.rc == 0 assert c2.stdout.strip() == 'enabled' - elif hostname in ('borg-client', 'borg-client-2'): + elif hostname in ('borg-client', 'borg-client-2', 'borg-client-nonroot'): timer_name = 'borg_backup@borg-server.timer' c = host.run(f"systemctl is-enabled {timer_name}") assert c.rc == 0 @@ -156,7 +199,7 @@ class TestSystemdState: c2 = host.run('systemctl is-active borg_backup@home-data.timer') assert c1.rc == 0 assert c2.rc == 0 - elif hostname in ('borg-client', 'borg-client-2'): + elif hostname in ('borg-client', 'borg-client-2', 'borg-client-nonroot'): timer_name = 'borg_backup@borg-server.timer' c = host.run(f"systemctl is-active {timer_name}") assert c.rc == 0 |