URL: https://github.com/freeipa/freeipa/pull/1515
Author: mrizwan93
 Title: #1515: Test to check second replica installation after master restore
Action: opened

PR body:
"""
When master is restored from backup and replica1 is re-initialize,
second replica installation was failing. The issue was with ipa-backup
tool which was not backing up the /etc/ipa/custodia/custodia.conf and
/etc/ipa/custodia/server.keys.

related ticket: https://pagure.io/freeipa/issue/7247

Signed-off-by: Mohammad Rizwan Yusuf <myu...@redhat.com>
"""

To pull the PR as Git branch:
git remote add ghfreeipa https://github.com/freeipa/freeipa
git fetch ghfreeipa pull/1515/head:pr1515
git checkout pr1515
From 183986dfc7cbb90ab6e4ee942f4cf7d8d7bb0e69 Mon Sep 17 00:00:00 2001
From: Mohammad Rizwan Yusuf <myu...@redhat.com>
Date: Fri, 2 Feb 2018 16:32:15 +0530
Subject: [PATCH] Test to check second replica installation after master
 restore

When master is restored from backup and replica1 is re-initialize,
second replica installation was failing. The issue was with ipa-backup
tool which was not backing up the /etc/ipa/custodia/custodia.conf and
/etc/ipa/custodia/server.keys.

    related ticket: https://pagure.io/freeipa/issue/7247

Signed-off-by: Mohammad Rizwan Yusuf <myu...@redhat.com>
---
 .../test_integration/test_backup_and_restore.py    | 115 +++++++++++++++++++++
 1 file changed, 115 insertions(+)

diff --git a/ipatests/test_integration/test_backup_and_restore.py b/ipatests/test_integration/test_backup_and_restore.py
index 13118fd773..7e5bc3dbf4 100644
--- a/ipatests/test_integration/test_backup_and_restore.py
+++ b/ipatests/test_integration/test_backup_and_restore.py
@@ -23,6 +23,9 @@
 import os
 import re
 import contextlib
+import textwrap
+import time
+from tempfile import NamedTemporaryFile
 
 from ipaplatform.paths import paths
 from ipapython.dn import DN
@@ -153,6 +156,18 @@ def backup(host):
         raise AssertionError('Backup directory not found in output')
 
 
+def user_add(host, username):
+    arg = ['ipa', 'user-add', '--first', 'None', '--last', 'None', username]
+    cmd = host.run_command(arg)
+    return cmd
+
+
+def user_show(host, username):
+    arg = ['ipa', 'user-show', username]
+    cmd = host.run_command(arg)
+    return cmd
+
+
 class TestBackupAndRestore(IntegrationTest):
     topology = 'star'
 
@@ -434,3 +449,103 @@ class TestBackupReinstallRestoreWithKRA(BaseBackupAndRestoreWithKRA):
     def test_full_backup_reinstall_restore_with_vault(self):
         """backup, uninstall, reinstall, restore"""
         self._full_backup_restore_with_vault(reinstall=True)
+
+
+class TestReplicaInstallAfterRestore(IntegrationTest):
+    """Test to check second replica installation after master restore
+
+    When master is restored from backup and replica1 is re-initialize,
+    second replica installation was failing. The issue was with ipa-backup
+    tool which was not backing up the /etc/ipa/custodia/custodia.conf and
+    /etc/ipa/custodia/server.keys.
+
+    related ticket: https://pagure.io/freeipa/issue/7247
+    """
+
+    num_replicas = 2
+
+    def test_replica_install_after_restore(self):
+        master = self.master
+        replica1 = self.replicas[0]
+        replica2 = self.replicas[1]
+        test1 = "test1"
+        test2 = "test2"
+
+        tasks.install_master(master)
+        tasks.install_replica(master, replica1)
+
+        result = user_add(master, test1)
+        assert result.returncode == 0
+
+        result = user_add(replica1, test2)
+        assert result.returncode == 0
+
+        time.sleep(100)
+        result = user_show(replica1, test1)
+        assert result.returncode == 0
+
+        result = user_show(master, test2)
+        assert result.returncode == 0
+
+        # backup master
+        backup_path = backup(master)
+
+        tf = NamedTemporaryFile()
+        ldif_file = tf.name
+        entry_ldif = textwrap.dedent(
+            "dn: cn=meTo{hostname},cn=replica,"
+            "cn=dc\\3Dtestrelm\\2Cdc\\3Dtest,cn=mapping tree,cn=config\n"
+            "changetype: modify\n"
+            "replace: nsds5ReplicaEnabled\n"
+            "nsds5ReplicaEnabled: off\n\n"
+
+            "dn: cn=caTo{hostname},cn=replica,"
+            "cn=o\\3Dipaca,cn=mapping tree,cn=config\n"
+            "changetype: modify\n"
+            "replace: nsds5ReplicaEnabled\n"
+            "nsds5ReplicaEnabled: off").format(
+            hostname=replica1.hostname)
+        master.put_file_contents(ldif_file, entry_ldif)
+
+        # disable replication agreement
+        arg = ['ldapmodify',
+               '-h', master.hostname,
+               '-p', '389', '-D',
+               str(master.config.dirman_dn),  # pylint: disable=no-member
+               '-w', master.config.dirman_password,
+               '-f', ldif_file]
+        master.run_command(arg)
+
+        # uninstall master
+        tasks.uninstall_master(master)
+
+        # master restore
+        dirman_password = master.config.dirman_password
+        master.run_command(['ipa-restore', backup_path],
+                           stdin_text=dirman_password + '\nyes')
+
+        # re-initialize topology after restore
+        topo_name = "%s-to-%s" % (master.hostname, replica1.hostname)
+        arg = ['ipa',
+               'topologysegment-reinitialize',
+               'domain',
+               topo_name,
+               '--left']
+        replica1.run_command(arg)
+
+        arg = ['ipa',
+               'topologysegment-reinitialize',
+               'ca',
+               topo_name,
+               '--left']
+        replica1.run_command(arg)
+
+        # wait sometime for re-initialization
+        time.sleep(100)
+
+        # install second replica after restore
+        tasks.install_replica(master, replica2)
+
+        # check for user added at master on replica2
+        result = user_show(replica2, 'test1')
+        assert result.returncode == 0
_______________________________________________
FreeIPA-devel mailing list -- freeipa-devel@lists.fedorahosted.org
To unsubscribe send an email to freeipa-devel-le...@lists.fedorahosted.org

Reply via email to