aboutsummaryrefslogtreecommitdiffstats
path: root/molecule/default/tests/test_systemd_success_exit_status.py
blob: 61c20c4f30b0ef43e7fd3126ceca495ffa12ece6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
"""Tests for systemd success exit status functionality"""
import pytest

testinfra_hosts = ['borg-client', 'borg-client-success-exit-status']


def test_systemd_service_has_correct_success_exit_status(host):
    service = host.file('/etc/systemd/system/borg_backup@borg-server.service')
    assert service.exists

    if host.backend.get_hostname() == 'borg-client-success-exit-status':
        assert service.contains('SuccessExitStatus=1 TEMPFAIL')
    else:
        assert not service.contains('SuccessExitStatus=')


def test_systemd_timer_is_enabled(host):
    timer_name = 'borg_backup@borg-server.timer'
    c = host.run(f"systemctl is-enabled {timer_name}")
    assert c.rc == 0


def test_systemd_timer_is_active(host):
    timer_name = 'borg_backup@borg-server.timer'
    c = host.run(f"systemctl is-active {timer_name}")
    assert c.rc == 0


@pytest.mark.parametrize('exit_status', [1, 'TEMPFAIL'])
def test_success_exit_status_values(host, exit_status):
    if host.backend.get_hostname() == 'borg-client-success-exit-status':
        service = host.file('/etc/systemd/system/borg_backup@borg-server.service')
        assert service.contains(str(exit_status))