ansible-role-bareos/molecule/default/tests/test_default.py
2021-09-12 11:55:41 +02:00

152 lines
4.7 KiB
Python

import time
import testinfra.utils.ansible_runner
def test_packages(host):
packages = [
'bareos-bconsole',
'bareos-database-sqlite3',
'bareos-director',
'bareos-filedaemon',
'bareos-storage',
'bareos-webui',
'cron'
]
for package_name in packages:
package = host.package(package_name)
assert package.is_installed
def test_client_config_file(host):
config = host.file('/etc/bareos/bareos-fd.d/director/bareos-dir.conf')
assert config.exists
assert config.is_file
assert config.user == 'root'
assert config.group == 'bareos'
assert config.mode == 0o640
assert config.contains('Name = bareos')
def test_server_catalog_config_file(host):
config = host.file('/etc/bareos/bareos-dir.d/catalog/ansible.conf')
assert config.exists
assert config.is_file
assert config.user == 'root'
assert config.group == 'bareos'
assert config.mode == 0o640
assert config.contains('dbdriver = "sqlite3"')
def test_server_clients_config_file(host):
config = host.file('/etc/bareos/bareos-dir.d/client/ansible.conf')
assert config.exists
assert config.is_file
assert config.user == 'root'
assert config.group == 'bareos'
assert config.mode == 0o640
assert config.contains('Address = "localhost"')
def test_server_fileset_config_file(host):
config = host.file('/etc/bareos/bareos-dir.d/fileset/ansible.conf')
assert config.exists
assert config.is_file
assert config.user == 'root'
assert config.group == 'bareos'
assert config.mode == 0o640
assert config.contains('File = "/etc"')
def test_server_job_config_file(host):
config = host.file('/etc/bareos/bareos-dir.d/job/ansible.conf')
assert config.exists
assert config.is_file
assert config.user == 'root'
assert config.group == 'bareos'
assert config.mode == 0o640
assert config.contains('Name = localhost-full')
assert config.contains('Name = Restore')
assert config.contains('Type = Restore')
assert config.contains('FileSet = config_in_etc')
assert config.contains('Maximum Bandwidth = 5Mb/s')
def test_server_pool_config_file(host):
config = host.file('/etc/bareos/bareos-dir.d/pool/ansible.conf')
assert config.exists
assert config.is_file
assert config.user == 'root'
assert config.group == 'bareos'
assert config.mode == 0o640
assert config.contains('VolumeRetention = 14')
def test_server_schedule_config_file(host):
config = host.file('/etc/bareos/bareos-dir.d/schedule/ansible.conf')
assert config.exists
assert config.is_file
assert config.user == 'root'
assert config.group == 'bareos'
assert config.mode == 0o640
assert config.contains('Run = Level=Full weekly at 0:05')
def test_server_console_config_file(host):
config = host.file('/etc/bareos/bareos-dir.d/console/ansible.conf')
assert config.exists
assert config.is_file
assert config.user == 'root'
assert config.group == 'bareos'
assert config.mode == 0o640
assert config.contains('Profile = "sysadmin"')
def test_server_profile_config_file(host):
config = host.file('/etc/bareos/bareos-dir.d/profile/ansible.conf')
assert config.exists
assert config.is_file
assert config.user == 'root'
assert config.group == 'bareos'
assert config.mode == 0o640
assert config.contains('Command ACL = "all"')
def test_server_clean_old_config_file(host):
files = [
'catalog/MyCatalog.conf',
'client/bareos-fd.conf',
'job/backup-bareos-fd.conf',
'job/BackupCatalog.conf',
'jobdefs/DefaultJob.conf',
'job/RestoreFiles.conf'
]
for file_name in files:
config = host.file('/etc/bareos/bareos-dir.d/%s' % file_name)
assert not config.exists
def test_storage_device_config_file(host):
config = host.file('/etc/bareos/bareos-sd.d/device/ansible.conf')
assert config.exists
assert config.is_file
assert config.user == 'root'
assert config.group == 'bareos'
assert config.mode == 0o640
assert config.contains('ArchiveDevice = /var/lib/bareos/storage')
assert config.contains('AlwaysOpen = yes')
def test_services(host):
for service_name in ['bareos-fd', 'bareos-dir', 'bareos-sd']:
service = host.service(service_name)
assert service.is_running
assert service.is_enabled
def test_sockets(host):
for port in [9101, 9102, 9103]:
socket = host.socket('tcp://0.0.0.0:%s' % port)
assert socket.is_listening
def test_backup(host):
host.run('echo "run job=localhost-full yes" | bconsole')
time.sleep(10)
backup = host.file('/var/lib/bareos/storage/localhost-0001')
assert backup.exists
assert backup.is_file
assert backup.user == 'bareos'
assert backup.group == 'bareos'
assert backup.mode == 0o640
def test_cron(host):
path = host.file('/var/spool/cron/crontabs/root')
assert path.exists
assert path.is_file
assert path.contains('0 9 \\* \\* \\* echo .bvfs_update | bconsole')