Replace goss tests with testinfra
This commit is contained in:
parent
b4695d7403
commit
97faa7429c
65 changed files with 163 additions and 1281 deletions
2
molecule/generic_files/tests/.flake8
Normal file
2
molecule/generic_files/tests/.flake8
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
[flake8]
|
||||
ignore = E501
|
||||
6
molecule/generic_files/tests/test_all.py
Normal file
6
molecule/generic_files/tests/test_all.py
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
def test_borg_binary(host):
|
||||
borg = host.file("/usr/local/bin/borg")
|
||||
assert borg.exists
|
||||
assert borg.user == "root"
|
||||
assert borg.group == "root"
|
||||
assert borg.mode == 0o755
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
# Molecule managed
|
||||
|
||||
---
|
||||
file:
|
||||
/usr/local/bin/borg:
|
||||
exists: true
|
||||
owner: root
|
||||
group: root
|
||||
mode: "0755"
|
||||
45
molecule/generic_files/tests/test_client.py
Normal file
45
molecule/generic_files/tests/test_client.py
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
import os
|
||||
import pytest
|
||||
import re
|
||||
from testinfra.utils.ansible_runner import AnsibleRunner
|
||||
|
||||
testinfra_hosts = ["ansible://all:!borgbackup_servers"]
|
||||
|
||||
|
||||
def test_log(host):
|
||||
logfile = host.file("/var/log/borg-backup.log")
|
||||
assert logfile.contains("Backup succeeded")
|
||||
assert logfile.user == "root"
|
||||
assert logfile.group == "root"
|
||||
|
||||
|
||||
# to do read inventory variable : export BORG_PASSPHRASE="{{ borgbackup_passphrase }}"
|
||||
def test_passphrase(host):
|
||||
pfile = host.file("/root/.borg.passphrase")
|
||||
assert pfile.contains("BORG_PASSPHRASE=")
|
||||
assert pfile.user == "root"
|
||||
assert pfile.group == "root"
|
||||
|
||||
|
||||
@pytest.mark.parametrize('server', AnsibleRunner(os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('borgbackup_servers'))
|
||||
def test_sshconfig(host, server):
|
||||
sshconf = host.file("/root/.ssh/config")
|
||||
assert sshconf.contains(" ANSIBLE MANAGED BLOCK %s " % server)
|
||||
assert sshconf.contains("Host %s" % server)
|
||||
assert sshconf.user == "root"
|
||||
assert sshconf.group == "root"
|
||||
|
||||
|
||||
def test_scriptfile(host):
|
||||
script = host.file("/usr/local/bin/borg-backup")
|
||||
assert script.user == "root"
|
||||
assert script.group == "root"
|
||||
assert script.mode == 0o744
|
||||
|
||||
|
||||
@pytest.mark.parametrize('server', AnsibleRunner(os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('borgbackup_servers'))
|
||||
def test_list_backups(host, server):
|
||||
command = host.run("bash /usr/local/bin/borg-backup list")
|
||||
assert command.rc == 0
|
||||
assert command.stderr == ''
|
||||
assert re.match("Archives on %s :\n[0-9]{8}-[0-9]{4}.*" % server, command.stdout) is not None
|
||||
|
|
@ -1,38 +0,0 @@
|
|||
# Molecule managed
|
||||
|
||||
---
|
||||
file:
|
||||
/var/log/borg-backup.log:
|
||||
exists: true
|
||||
owner: root
|
||||
group: root
|
||||
contains:
|
||||
- "Backup succeeded"
|
||||
/root/.borg.passphrase:
|
||||
exists: true
|
||||
owner: root
|
||||
group: root
|
||||
contains:
|
||||
- 'export BORG_PASSPHRASE="{{ borgbackup_passphrase }}"'
|
||||
/root/.ssh/config:
|
||||
exists: true
|
||||
owner: root
|
||||
group: root
|
||||
contains:
|
||||
{% for item in borgbackup_servers %}
|
||||
- 'ANSIBLE MANAGED BLOCK {{ item.fqdn }}'
|
||||
{% endfor %}
|
||||
/usr/local/bin/borg-backup:
|
||||
exists: true
|
||||
owner: root
|
||||
group: root
|
||||
mode: "0744"
|
||||
|
||||
command:
|
||||
bash /usr/local/bin/borg-backup list:
|
||||
exit-status: 0
|
||||
stdout:
|
||||
{% for item in borgbackup_servers %}
|
||||
- "Archives on {{ item.fqdn }}"
|
||||
{% endfor %}
|
||||
- "/[[:digit:]]{8}-[[:digit:]]{4}.*/"
|
||||
9
molecule/generic_files/tests/test_client_folders.py
Normal file
9
molecule/generic_files/tests/test_client_folders.py
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
testinfra_hosts = ["ansible://folders"]
|
||||
|
||||
|
||||
def test_include_exclude(host):
|
||||
script = host.file("/usr/local/bin/borg-backup")
|
||||
assert script.contains("/var/cache")
|
||||
assert script.contains("--exclude '/var/cache/apt'")
|
||||
assert script.user == "root"
|
||||
assert script.group == "root"
|
||||
24
molecule/generic_files/tests/test_client_restore.py
Normal file
24
molecule/generic_files/tests/test_client_restore.py
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
import os
|
||||
import pytest
|
||||
from testinfra.utils.ansible_runner import AnsibleRunner
|
||||
|
||||
testinfra_hosts = ["ansible://all:!borgbackup_servers"]
|
||||
|
||||
|
||||
def test_client_sample_file(host):
|
||||
sample = host.file("/root/sample.txt")
|
||||
assert sample.is_file
|
||||
|
||||
|
||||
@pytest.mark.parametrize('server', AnsibleRunner(os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('borgbackup_servers'))
|
||||
def test_client_dir(host, server):
|
||||
command = host.run("diff -s /root/sample.txt /root/restore/%s/root/sample.txt" % server)
|
||||
assert command.rc == 0
|
||||
assert "Files /root/sample.txt and /root/restore/%s/root/sample.txt are identical" % server in command.stdout
|
||||
|
||||
|
||||
@pytest.mark.parametrize('server', AnsibleRunner(os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('borgbackup_servers'))
|
||||
def test_client_verify(host, server):
|
||||
vcommand = host.run("/root/restore.sh verify")
|
||||
assert vcommand.rc == 0
|
||||
assert vcommand.stdout.rstrip("verifying on %s" % server)
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
---
|
||||
file:
|
||||
/root/sample.txt:
|
||||
exists: true
|
||||
|
||||
command:
|
||||
{% for item in borgbackup_servers %}
|
||||
diff -s /root/sample.txt /root/restore/{{ item.fqdn }}/root/sample.txt:
|
||||
exit-status: 0
|
||||
stdout:
|
||||
- "Files /root/sample.txt and /root/restore/{{ item.fqdn }}/root/sample.txt are identical"
|
||||
{% endfor %}
|
||||
/root/restore.sh verify:
|
||||
exit-status: 0
|
||||
stdout:
|
||||
{% for item in borgbackup_servers %}
|
||||
- "verifying on {{ item.fqdn }}"
|
||||
{% endfor %}
|
||||
16
molecule/generic_files/tests/test_lamp.py
Normal file
16
molecule/generic_files/tests/test_lamp.py
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
testinfra_hosts = ["ansible://lamp"]
|
||||
|
||||
|
||||
def test_lamp_default(host):
|
||||
script = host.file("/usr/local/bin/borg-backup")
|
||||
assert script.contains("/usr/sbin/automysqlbackup")
|
||||
assert script.contains("/var/lib/automysqlbackup")
|
||||
assert script.contains("/var/www")
|
||||
assert script.user == "root"
|
||||
assert script.group == "root"
|
||||
|
||||
|
||||
def test_lamp_automysqlbackup(host):
|
||||
backup_dir = host.file("/var/lib/automysqlbackup/daily")
|
||||
assert backup_dir.exists
|
||||
assert backup_dir.is_directory
|
||||
18
molecule/generic_files/tests/test_mgt.py
Normal file
18
molecule/generic_files/tests/test_mgt.py
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
import os
|
||||
import pytest
|
||||
from testinfra.utils.ansible_runner import AnsibleRunner
|
||||
|
||||
testinfra_hosts = ["ansible://borgbackup_management"]
|
||||
|
||||
|
||||
# to do read inventory variable : export BORG_PASSPHRASE="{{ borgbackup_passphrase }}"
|
||||
@pytest.mark.parametrize('client', AnsibleRunner(os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all:!borgbackup_management:!borgbackup_servers'))
|
||||
def test_prune_script(host, client):
|
||||
prune = host.file("/root/prune.sh")
|
||||
assert prune.user == "root"
|
||||
assert prune.group == "root"
|
||||
assert prune.mode == 0o700
|
||||
assert prune.contains("/usr/local/bin/borg prune")
|
||||
assert prune.contains("export BORG_PASSPHRASE=")
|
||||
assert prune.contains("Host: %s" % client)
|
||||
assert prune.contains(":/var/backup/repos/%s" % client)
|
||||
23
molecule/generic_files/tests/test_server.py
Normal file
23
molecule/generic_files/tests/test_server.py
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
import os
|
||||
import pytest
|
||||
from testinfra.utils.ansible_runner import AnsibleRunner
|
||||
|
||||
testinfra_hosts = ["ansible://borgbackup_servers"]
|
||||
|
||||
|
||||
def test_client_parent_dir(host):
|
||||
parentdir = host.file("/var/backup/repos")
|
||||
assert parentdir.is_directory
|
||||
|
||||
|
||||
@pytest.mark.parametrize('client', AnsibleRunner(os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all:!borgbackup_servers'))
|
||||
def test_client_dir(host, client):
|
||||
clientdir = host.file("/var/backup/repos/%s" % client)
|
||||
assert clientdir.is_directory
|
||||
|
||||
|
||||
@pytest.mark.parametrize('client', AnsibleRunner(os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all:!borgbackup_servers'))
|
||||
def test_ssh_client_conf(host, client):
|
||||
sshconf = host.file("/var/backup/.ssh/authorized_keys")
|
||||
assert sshconf.is_file
|
||||
assert sshconf.contains("%s;borg serve" % client)
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
# Molecule managed
|
||||
|
||||
---
|
||||
file:
|
||||
{% for item in borgbackup_servers %}
|
||||
{% if item.fqdn == inventory_hostname %}
|
||||
{{ item.home }}:
|
||||
exists: true
|
||||
owner: "{{ item.user }}"
|
||||
group: "{{ item.user }}"
|
||||
{% for host in groups.all|difference(groups.borgbackup_servers) %}
|
||||
{{ item.home }}/repos/{{ host }}:
|
||||
exists: true
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% for item in borgbackup_servers %}
|
||||
{% if item.fqdn == inventory_hostname %}
|
||||
{{ item.home }}/.ssh/authorized_keys:
|
||||
exists: true
|
||||
owner: "{{ item.user }}"
|
||||
group: "{{ item.user }}"
|
||||
contains:
|
||||
{% for host in groups.all|difference(groups.borgbackup_servers) %}
|
||||
- "{{ host }};borg serve"
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
Loading…
Add table
Add a link
Reference in a new issue