Files
@ 0004ec73b902
Branch filter:
Location: majic-ansible-roles/roles/backup_client/tests/test_default.py - annotation
0004ec73b902
5.7 KiB
text/x-python
MAR-28: Implemented scaffolding for testing the mail_server role:
- Added Molecule configuration.
- Added test playbook.
- Restart Postfix for truststore changes.
- Added test data (private keys and certificates).
- Fixed small documentation inaccuracy.
- Added Molecule configuration.
- Added test playbook.
- Restart Postfix for truststore changes.
- Added test data (private keys and certificates).
- Fixed small documentation inaccuracy.
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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 | 19020779a000 19020779a000 0b4f215b3b4e 19020779a000 19020779a000 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 19020779a000 0b4f215b3b4e 0b4f215b3b4e 19020779a000 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e 19020779a000 0b4f215b3b4e 0b4f215b3b4e 0b4f215b3b4e | import testinfra.utils.ansible_runner
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
'.molecule/ansible_inventory').get_hosts('all')
testinfra_hosts.remove('backup-server')
def test_installed_packages(Package):
"""
Tests if the necessary packages are installed.
"""
assert Package('python-pexpect').is_installed
assert Package('duply').is_installed
assert Package('duplicity').is_installed
def test_duply_directories(File, Sudo):
"""
Tests if Duply directories have been set-up correctly.
"""
with Sudo():
for directory_path in ["/etc/duply",
"/etc/duply/main",
"/etc/duply/main/patterns",
"/etc/duply/main/gnupg",
"/etc/duply/main/ssh",
"/var/cache/duply",
"/var/cache/duply/main"]:
directory = File(directory_path)
assert directory.is_directory
assert directory.user == 'root'
assert directory.group == 'root'
assert directory.mode == 0o700
def test_gnupg_private_keys_file(File, Sudo):
"""
Tests if file containing GnuPG private keys has been created and has correct
permissions.
"""
with Sudo():
gnupg_private_keys = File('/etc/duply/main/private_keys.asc')
assert gnupg_private_keys.is_file
assert gnupg_private_keys.user == 'root'
assert gnupg_private_keys.group == 'root'
assert gnupg_private_keys.mode == 0o600
def test_gnupg_public_keys_file(File, Sudo):
"""
Tests if file containing additional GnuPG public keys used for encryption
has been created and has correct permissions.
"""
with Sudo():
gnupg_public_keys = File('/etc/duply/main/public_keys.asc')
assert gnupg_public_keys.is_file
assert gnupg_public_keys.user == 'root'
assert gnupg_public_keys.group == 'root'
assert gnupg_public_keys.mode == 0o600
def test_private_ssh_key_file(File, Sudo):
"""
Tests if the file containing client SSH key used for logging-in into the
backup server has been deployed and has correct permissions.
"""
with Sudo():
ssh_key = File('/etc/duply/main/ssh/identity')
assert ssh_key.is_file
assert ssh_key.user == 'root'
assert ssh_key.group == 'root'
assert ssh_key.mode == 0o600
def test_known_hosts(File, Sudo):
"""
Tests if the Duply known_hosts file has been deployed and has correct
permissions.
"""
with Sudo():
known_hosts = File('/etc/duply/main/ssh/known_hosts')
assert known_hosts.is_file
assert known_hosts.user == 'root'
assert known_hosts.group == 'root'
assert known_hosts.mode == 0o600
def test_duply_configuration(File, Sudo):
"""
Tests if Duply configuraiton file has been deployed and has correct file
permissions.
"""
with Sudo():
duply_configuration = File('/etc/duply/main/conf')
assert duply_configuration.is_file
assert duply_configuration.user == 'root'
assert duply_configuration.group == 'root'
assert duply_configuration.mode == 0o600
def test_exclude_file(File, Sudo):
with Sudo():
exclude = File('/etc/duply/main/exclude')
assert exclude.is_file
assert exclude.user == 'root'
assert exclude.group == 'root'
assert exclude.mode == 0o600
assert exclude.content == "- **"
def test_pre_backup_script_directory(File, Sudo):
with Sudo():
pre_backup_dir = File('/etc/duply/main/pre.d')
assert pre_backup_dir.is_directory
assert pre_backup_dir.user == 'root'
assert pre_backup_dir.group == 'root'
assert pre_backup_dir.mode == 0o700
def test_pre_backup_script(File, Sudo):
"""
Tests if the script used for running pre-backup handles has been deployed
and has correct permissions.x
"""
with Sudo():
pre_backup_script = File('/etc/duply/main/pre')
assert pre_backup_script.is_file
assert pre_backup_script.user == 'root'
assert pre_backup_script.group == 'root'
assert pre_backup_script.mode == 0o700
def test_cron_entry(File):
"""
Tests if cron job has been correctly set-up for running backups.
"""
cron = File('/etc/cron.d/backup')
assert cron.is_file
assert cron.user == 'root'
assert cron.group == 'root'
assert cron.mode == 0o644
assert cron.content == "#Ansible: backup\n0 2 * * * root /usr/bin/duply main backup"
def test_duply_include_file(File, Sudo):
"""
Tests include file existence and permissions.
"""
with Sudo():
include = File('/etc/duply/main/include')
assert include.is_file
assert include.user == 'root'
assert include.group == 'root'
assert include.mode == 0o600
def test_backup_and_restore(Ansible, Command, File, Sudo):
"""
Tests a simple backup and restore to a directory. Includes tests for
checking if the pre-backup handles are run correctly.
"""
with Sudo():
# Remove this file so we can be sure the pre-backup script has been run.
Ansible("file", "path=/var/lib/pre-backup-test state=absent")
backup_run = Command('duply main backup')
assert backup_run.rc == 0
assert File('/var/lib/pre-backup-test').is_file
# Remove restore directory in order to make sure restore has worked
# correctly.
Ansible("file", "path=/root/restore state=absent")
restore_run = Command('duply main restore /root/restore')
assert restore_run.rc == 0
assert File('/root/restore').is_directory
|