-- 
Oleg Fayans
Quality Engineer
FreeIPA team
RedHat.
From f1821a41498f7829df4d1bdffd338cb70b413667 Mon Sep 17 00:00:00 2001
From: Oleg Fayans <ofay...@redhat.com>
Date: Thu, 31 Mar 2016 11:58:26 +0200
Subject: [PATCH] Added assertion error messages in topology tests

Added a global sleep interval used to wait for replication
https://fedorahosted.org/freeipa/ticket/5772
---
 ipatests/test_integration/test_topology.py | 113 +++++++++++++++++------------
 1 file changed, 67 insertions(+), 46 deletions(-)

diff --git a/ipatests/test_integration/test_topology.py b/ipatests/test_integration/test_topology.py
index 8119aa9d7c9a57e68a89ef1d8086920286e64316..ea03fb6eac7db9e4acc0f8ffcfa38e0fba92d761 100644
--- a/ipatests/test_integration/test_topology.py
+++ b/ipatests/test_integration/test_topology.py
@@ -14,6 +14,8 @@ from ipalib.constants import DOMAIN_SUFFIX_NAME
 
 config = get_global_config()
 reasoning = "Topology plugin disabled due to domain level 0"
+REPLICATION_SLEEP_TIME = 10
+
 
 @pytest.mark.skipif(config.domain_level == 0, reason=reasoning)
 class TestTopologyOptions(IntegrationTest):
@@ -59,38 +61,49 @@ class TestTopologyOptions(IntegrationTest):
         Test_plan#Test_case:
         _Replication_topology_should_be_saved_in_the_LDAP_tree
         """
-        tasks.kinit_admin(self.master)
-        result1 = self.master.run_command(['ipa', 'topologysegment-find',
-                                           DOMAIN_SUFFIX_NAME])
-        first_segment_name = "%s-to-%s" % (self.master.hostname,
-                                           self.replicas[0].hostname)
+        master = self.master
+        replica1 = self.replicas[0]
+        replica2 = self.replicas[1]
+        tasks.kinit_admin(master)
+        result1 = master.run_command(['ipa', 'topologysegment-find',
+                                      DOMAIN_SUFFIX_NAME])
+        first_segment_name = "%s-to-%s" % (master.hostname,
+                                           replica1.hostname)
         output1 = result1.stdout_text
         firstsegment = self.tokenize_topologies(output1)[0]
-        assert(firstsegment['name'] == first_segment_name)
-        assert(self.noentries_re.search(output1).group(1) == "1")
-        assert(firstsegment['leftnode'] == self.master.hostname)
-        assert(firstsegment['rightnode'] == self.replicas[0].hostname)
-        tasks.install_replica(self.master, self.replicas[1], setup_ca=False,
+        num_of_entries = self.noentries_re.search(output1).group(1)
+        assert(firstsegment['name'] == first_segment_name,
+               "A segment with non-standard name was created: %s" %
+               firstsegment['name'])
+        assert(num_of_entries == "1",
+               "Unexpected number of segments found: %s" % num_of_entries)
+        assert(firstsegment['leftnode'] == master.hostname,
+               "Incorrect leftnode: %s" % firstsegment['leftnode'])
+        assert(firstsegment['rightnode'] == replica1.hostname,
+               "Incorrect rightnode: %s" % firstsegment['rightnode'])
+        tasks.install_replica(master, replica2, setup_ca=False,
                               setup_dns=False)
         # We need to make sure topology information is consistent across all
         # replicas
-        result2 = self.master.run_command(['ipa', 'topologysegment-find',
-                                           DOMAIN_SUFFIX_NAME])
-        result3 = self.replicas[0].run_command(['ipa', 'topologysegment-find',
-                                                DOMAIN_SUFFIX_NAME])
-        result4 = self.replicas[1].run_command(['ipa', 'topologysegment-find',
-                                                DOMAIN_SUFFIX_NAME])
+        result2 = master.run_command(['ipa', 'topologysegment-find',
+                                      DOMAIN_SUFFIX_NAME])
+        result3 = replica1.run_command(['ipa', 'topologysegment-find',
+                                        DOMAIN_SUFFIX_NAME])
+        result4 = replica2.run_command(['ipa', 'topologysegment-find',
+                                        DOMAIN_SUFFIX_NAME])
         segments = self.tokenize_topologies(result2.stdout_text)
-        assert(len(segments) == 2)
-        assert(result2.stdout_text == result3.stdout_text)
-        assert(result3.stdout_text == result4.stdout_text)
+        assert(len(segments) == 2,
+               "Unexpected number of segments found: %i" % len(segments))
+        assert(result2.stdout_text == result3.stdout_text,
+               "Failed replication between %s and %s" % (master.hostname,
+                                                         replica1.hostname))
+        assert(result3.stdout_text == result4.stdout_text,
+               "Failed replication between %s and %s" % (replica1.hostname,
+                                                         replica2.hostname))
         # Now let's check that uninstalling the replica will update the topology
         # info on the rest of replicas.
-        tasks.uninstall_master(self.replicas[1])
-        tasks.clean_replication_agreement(self.master, self.replicas[1])
-        result5 = self.master.run_command(['ipa', 'topologysegment-find',
-                                           DOMAIN_SUFFIX_NAME])
-        assert(self.noentries_re.search(result5.stdout_text).group(1) == "1")
+        tasks.uninstall_master(replica2)
+        tasks.clean_replication_agreement(master, replica2)
 
     def test_add_remove_segment(self):
         """
@@ -99,38 +112,46 @@ class TestTopologyOptions(IntegrationTest):
         Testcase http://www.freeipa.org/page/V4/Manage_replication_topology/
         Test_plan#Test_case:_Basic_CRUD_test
         """
-        tasks.kinit_admin(self.master)
+
+        master = self.master
+        replica1 = self.replicas[0]
+        replica2 = self.replicas[1]
+        tasks.kinit_admin(master)
         # Install the second replica
-        tasks.install_replica(self.master, self.replicas[1], setup_ca=False,
+        tasks.install_replica(master, replica2, setup_ca=False,
                               setup_dns=False)
         # turn a star into a ring
-        segment, err = tasks.create_segment(self.master,
-                                            self.replicas[0],
-                                            self.replicas[1])
+        segment, err = tasks.create_segment(master, replica1, replica2)
         assert err == "", err
         # Make sure the new segment is shown by `ipa topologysegment-find`
-        result1 = self.master.run_command(['ipa', 'topologysegment-find',
-                                           DOMAIN_SUFFIX_NAME])
-        assert(result1.stdout_text.find(segment['name']) > 0)
+        result1 = master.run_command(['ipa', 'topologysegment-find',
+                                      DOMAIN_SUFFIX_NAME])
+        assert(result1.stdout_text.find(segment['name']) > 0,
+               "The segment %s was not found on master" % segment['name'])
         # Remove master <-> replica2 segment and make sure that the changes get
         # there through replica1
-        deleteme = "%s-to-%s" % (self.master.hostname,
-                                 self.replicas[1].hostname)
-        returncode, error = tasks.destroy_segment(self.master, deleteme)
+        deleteme = "%s-to-%s" % (master.hostname,
+                                 replica2.hostname)
+        returncode, error = tasks.destroy_segment(master, deleteme)
         assert returncode == 0, error
-        # make sure replica1 does not have segment that was deleted on master
-        result3 = self.replicas[0].run_command(['ipa', 'topologysegment-find',
-                                               DOMAIN_SUFFIX_NAME])
-        assert(result3.stdout_text.find(deleteme) < 0)
+        # wait till the changes get replicated and make sure replica1 does not
+        # have segment that was deleted on master
+        time.sleep(REPLICATION_SLEEP_TIME)
+        result3 = replica1.run_command(['ipa', 'topologysegment-find',
+                                        DOMAIN_SUFFIX_NAME])
+        assert(result3.stdout_text.find(deleteme) < 0,
+               "The segment %s deleted on master is still shown on replica" % deleteme)
         # Create test data on master and make sure it gets all the way down to
         # replica2 through replica1
-        self.master.run_command(['ipa', 'user-add', 'someuser',
-                                 '--first', 'test',
-                                 '--last', 'user'])
-        time.sleep(60)  # replication requires some time
-        users_on_replica2 = self.replicas[1].run_command(['ipa',
-                                                         'user-find'])
-        assert(users_on_replica2.find('someuser') > 0)
+        master.run_command(['ipa', 'user-add', 'someuser',
+                            '--first', 'test',
+                            '--last', 'user'])
+        time.sleep(REPLICATION_SLEEP_TIME)  # replication requires some time
+        users_on_replica2 = replica2.run_command(['ipa',
+                                                  'user-find']).stdout_text
+        assert(users_on_replica2.find('someuser') > 0,
+               "Replication was not completed within %s seconds" %
+               REPLICATION_SLEEP_TIME)
         # We end up having a line topology: master <-> replica1 <-> replica2
 
     def test_remove_the_only_connection(self):
-- 
1.8.3.1

-- 
Manage your subscription for the Freeipa-devel mailing list:
https://www.redhat.com/mailman/listinfo/freeipa-devel
Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code

Reply via email to