system-config/testinfra/test_backups.py
Ian Wienand 814e4be128 Ansible roles for backup
This introduces two new roles for managing the backup-server and hosts
that we wish to back up.

Firstly the "backup" role runs on hosts we wish to backup.  This
generates and configures a separate ssh key for running bup and
installs the appropriate cron job to run the backup daily.

The "backup-server" job runs on the backup server (or, indeed
servers).  It creates users for each backup host, accepts the remote
keys mentioned above and initalises bup.  It is then ready to receive
backups from the remote hosts.

This eliminates a fairly long-standing requirement for manual setup of
the backup server users and keys; this section is removed from the
documentation.

testinfra coverage is added.

Change-Id: I9bf74df351e056791ed817180436617048224d2c
2019-08-05 16:59:57 +10:00

62 lines
1.9 KiB
Python

# Copyright 2019 Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import os.path
import pytest
testinfra_hosts = ['backup01.region.provider.opendev.org',
'backup-test01.opendev.org',
'backup-test02.opendev.org']
def test_bup_installed(host):
package = host.package("bup")
assert package.is_installed
def test_server_users(host):
hostname = host.backend.get_hostname()
if hostname.startswith('backup-test'):
pytest.skip()
for username in 'bup-backup01', 'bup-backup-test02':
homedir = os.path.join('/opt/backups/', username)
bup_config = os.path.join(homedir, '.bup', 'config')
authorized_keys = os.path.join(homedir, '.ssh', 'authorized_keys')
user = host.user(username)
assert user.exists
assert user.home == homedir
f = host.file(authorized_keys)
assert f.exists
assert f.contains("ssh-ed25519")
f = host.file(bup_config)
assert f.exists
def test_backup_host_config(host):
hostname = host.backend.get_hostname()
if hostname == 'backup01.region.provider.opendev.org':
pytest.skip()
f = host.file('/root/.ssh/id_backup_ed25519')
assert f.exists
f = host.file('/root/.ssh/ssh_config')
assert f.exists
assert f.contains('Host backup01.region.provider.opendev.org')
f = host.file('/root/.bup/config')
assert f.exists