Hello, These patches add integration tests for backup & restore.
I'm also attaching a patch for the job definitions at https://github.com/encukou/freeipa-ci
-- PetrĀ³
From 33249c830eeaaf813b7ebae7c5b52b5954bf3c0e Mon Sep 17 00:00:00 2001 From: Petr Viktorin <pvikt...@redhat.com> Date: Wed, 6 Aug 2014 16:34:16 +0200 Subject: [PATCH] Add job for the backup & restore integration test --- jenkins-job-builder/freeipa-jobs.yaml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/jenkins-job-builder/freeipa-jobs.yaml b/jenkins-job-builder/freeipa-jobs.yaml index 710187f..dc957ea 100644 --- a/jenkins-job-builder/freeipa-jobs.yaml +++ b/jenkins-job-builder/freeipa-jobs.yaml @@ -512,6 +512,16 @@ role: ad_subdomain name: ad.test type: AD + - '{prefix}-integration-{os}-{pretty_name}': + pretty_name: backup_and_restore + suite: test_integration/test_backup_and_restore.py + config_template: | + domains: + - hosts: + - name: master.ipa.test + role: master + name: ipa.test + type: IPA - job-template: name: '{prefix}-stats-{os}' -- 1.9.3
From 8e7b24420b664ec924357109fea5e01536819972 Mon Sep 17 00:00:00 2001 From: Petr Viktorin <pvikt...@redhat.com> Date: Tue, 5 Aug 2014 17:10:57 +0200 Subject: [PATCH] Add basic test for backup & restore https://fedorahosted.org/freeipa/ticket/3893 --- .../test_integration/test_backup_and_restore.py | 110 +++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 ipatests/test_integration/test_backup_and_restore.py diff --git a/ipatests/test_integration/test_backup_and_restore.py b/ipatests/test_integration/test_backup_and_restore.py new file mode 100644 index 0000000000000000000000000000000000000000..b7cf55b7e5c3124db4b3281e6f9fce7e723514a3 --- /dev/null +++ b/ipatests/test_integration/test_backup_and_restore.py @@ -0,0 +1,110 @@ +# Authors: +# Petr Viktorin <pvikt...@redhat.com> +# +# Copyright (C) 2014 Red Hat +# see file 'COPYING' for use and warranty information +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +import re +import contextlib + +from ipapython.dn import DN +from ipatests.test_integration.base import IntegrationTest +from ipatests.test_integration import tasks +from ipatests.util import assert_deepequal + + +def assert_entries_equal(a, b): + assert_deepequal(a.dn, b.dn) + assert_deepequal(dict(a), dict(b)) + + +def assert_results_equal(a, b): + def to_dict(r): + return { + 'stdout': r.stdout_text, + 'stderr': r.stderr_text, + 'returncode': r.returncode, + } + assert_deepequal(to_dict(a), to_dict(b)) + + +def check_admin_in_ldap(host): + ldap = host.ldap_connect() + basedn = host.domain.basedn + user_dn = DN(('uid', 'admin'), ('cn', 'users'), ('cn', 'accounts'), basedn) + entry = ldap.get_entry(user_dn) + print entry + assert entry.dn == user_dn + assert entry['uid'] == ['admin'] + + del entry['krbLastSuccessfulAuth'] + + return entry + + +def check_admin_in_cli(host): + result = host.run_command(['ipa', 'user-show', 'admin']) + assert 'User login: admin' in result.stdout_text, result.stdout_text + return result + + +def check_certs(host): + result = host.run_command(['ipa', 'cert-find']) + assert re.search('^Number of entries returned [1-9]\d*$', + result.stdout_text, re.MULTILINE), result.stdout_text + return result + + +@contextlib.contextmanager +def restore_checker(host): + """Check that the IPA at host works the same at context enter and exit""" + tasks.kinit_admin(host) + + admin_entry = check_admin_in_ldap(host) + admin_cli_result = check_admin_in_cli(host) + certs_output = check_certs(host) + + yield + + assert_entries_equal(admin_entry, check_admin_in_ldap(host)) + assert_results_equal(admin_cli_result, check_admin_in_cli(host)) + assert_results_equal(certs_output, check_certs(host)) + + +class TestBackupAndRestore(IntegrationTest): + topology = 'star' + + def test_full_backup_and_restore(self): + """backup, uninstall, restore""" + with restore_checker(self.master): + result = self.master.run_command(['ipa-backup', '-v']) + + # Get the backup location from the command's output + for line in result.stderr_text.splitlines(): + prefix = ('ipa.ipaserver.install.ipa_backup.Backup: ' + 'INFO: Backed up to ') + if line.startswith(prefix): + backup_path = line[len(prefix):].strip() + + self.log.info('Backup path for %s is %s', self.master, backup_path) + + self.master.run_command(['ipa-server-install', + '--uninstall', + '-U']) + + dirman_password = self.master.config.dirman_password + self.master.run_command(['ipa-restore', backup_path], + stdin_text=dirman_password + '\nyes') -- 1.9.3
From f54d8d9bd0f9eac667723fdf8df00ba37e9f2fae Mon Sep 17 00:00:00 2001 From: Petr Viktorin <pvikt...@redhat.com> Date: Wed, 6 Aug 2014 15:30:58 +0200 Subject: [PATCH] Add test for backup/delete system users/restore Regression test for: https://fedorahosted.org/freeipa/ticket/3866 --- .../test_integration/test_backup_and_restore.py | 58 ++++++++++++++++++---- 1 file changed, 48 insertions(+), 10 deletions(-) diff --git a/ipatests/test_integration/test_backup_and_restore.py b/ipatests/test_integration/test_backup_and_restore.py index b7cf55b7e5c3124db4b3281e6f9fce7e723514a3..4b52002056f7fcdc2ce62d04bfa155a5fa25af30 100644 --- a/ipatests/test_integration/test_backup_and_restore.py +++ b/ipatests/test_integration/test_backup_and_restore.py @@ -17,14 +17,18 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. +import os import re import contextlib +from ipapython.ipa_log_manager import log_mgr from ipapython.dn import DN from ipatests.test_integration.base import IntegrationTest from ipatests.test_integration import tasks from ipatests.util import assert_deepequal +log = log_mgr.get_logger(__name__) + def assert_entries_equal(a, b): assert_deepequal(a.dn, b.dn) @@ -84,22 +88,30 @@ def restore_checker(host): assert_results_equal(certs_output, check_certs(host)) +def backup(host): + """Run backup on host, return the path to the backup directory""" + result = host.run_command(['ipa-backup', '-v']) + + # Get the backup location from the command's output + for line in result.stderr_text.splitlines(): + prefix = ('ipa.ipaserver.install.ipa_backup.Backup: ' + 'INFO: Backed up to ') + if line.startswith(prefix): + backup_path = line[len(prefix):].strip() + log.info('Backup path for %s is %s', host, backup_path) + return backup_path + else: + raise AssertionError('Backup directory not found in output') + + + class TestBackupAndRestore(IntegrationTest): topology = 'star' def test_full_backup_and_restore(self): """backup, uninstall, restore""" with restore_checker(self.master): - result = self.master.run_command(['ipa-backup', '-v']) - - # Get the backup location from the command's output - for line in result.stderr_text.splitlines(): - prefix = ('ipa.ipaserver.install.ipa_backup.Backup: ' - 'INFO: Backed up to ') - if line.startswith(prefix): - backup_path = line[len(prefix):].strip() - - self.log.info('Backup path for %s is %s', self.master, backup_path) + backup_path = backup(self.master) self.master.run_command(['ipa-server-install', '--uninstall', @@ -108,3 +120,29 @@ def test_full_backup_and_restore(self): dirman_password = self.master.config.dirman_password self.master.run_command(['ipa-restore', backup_path], stdin_text=dirman_password + '\nyes') + + def test_full_backup_and_restore_with_removed_users(self): + """regression test for https://fedorahosted.org/freeipa/ticket/3866""" + with restore_checker(self.master): + backup_path = backup(self.master) + + self.log.info('Backup path for %s is %s', self.master, backup_path) + + self.master.run_command(['ipa-server-install', + '--uninstall', + '-U']) + + self.master.run_command(['userdel', 'dirsrv']) + self.master.run_command(['userdel', 'pkiuser']) + + homedir = os.path.join(self.master.config.test_dir, + 'testuser_homedir') + self.master.run_command(['useradd', 'ipatest_user1', + '--system', + '-d', homedir]) + try: + dirman_password = self.master.config.dirman_password + self.master.run_command(['ipa-restore', backup_path], + stdin_text=dirman_password + '\nyes') + finally: + self.master.run_command(['userdel', 'ipatest_user1']) -- 1.9.3
_______________________________________________ Freeipa-devel mailing list Freeipa-devel@redhat.com https://www.redhat.com/mailman/listinfo/freeipa-devel