Blame SOURCES/0019-Issue-4504-Fix-pytest-test_dsconf_replication_monito.patch

27c138
From 1fef5649ce05a17a741789cafb65269c099b396b Mon Sep 17 00:00:00 2001
27c138
From: progier389 <72748589+progier389@users.noreply.github.com>
27c138
Date: Wed, 16 Dec 2020 16:21:35 +0100
27c138
Subject: [PATCH 2/3] Issue #4504 - Fix pytest test_dsconf_replication_monitor
27c138
 (#4505)
27c138
27c138
(cherry picked from commit 0b08e6f35b000d1383580be59f902ac813e940f2)
27c138
---
27c138
 .../tests/suites/clu/repl_monitor_test.py     | 50 +++++++++++++------
27c138
 1 file changed, 36 insertions(+), 14 deletions(-)
27c138
27c138
diff --git a/dirsrvtests/tests/suites/clu/repl_monitor_test.py b/dirsrvtests/tests/suites/clu/repl_monitor_test.py
27c138
index b03d170c8..eb18d2da2 100644
27c138
--- a/dirsrvtests/tests/suites/clu/repl_monitor_test.py
27c138
+++ b/dirsrvtests/tests/suites/clu/repl_monitor_test.py
27c138
@@ -9,6 +9,7 @@
27c138
 import time
27c138
 import subprocess
27c138
 import pytest
27c138
+import re
27c138
 
27c138
 from lib389.cli_conf.replication import get_repl_monitor_info
27c138
 from lib389.tasks import *
27c138
@@ -67,6 +68,25 @@ def check_value_in_log_and_reset(content_list, second_list=None, single_value=No
27c138
         log.info('Reset log file')
27c138
         f.truncate(0)
27c138
 
27c138
+def get_hostnames_from_log(port1, port2):
27c138
+    # Get the supplier host names as displayed in replication monitor output
27c138
+    with open(LOG_FILE, 'r') as logfile:
27c138
+        logtext = logfile.read()
27c138
+    # search for Supplier :hostname:port 
27c138
+    # and use \D to insure there is no more number is after
27c138
+    # the matched port (i.e that 10 is not matching 101)
27c138
+    regexp = '(Supplier: )([^:]*)(:' + str(port1) + '\D)'
27c138
+    match=re.search(regexp, logtext)
27c138
+    host_m1 = 'localhost.localdomain'
27c138
+    if (match is not None):
27c138
+        host_m1 = match.group(2)
27c138
+    # Same for master 2 
27c138
+    regexp = '(Supplier: )([^:]*)(:' + str(port2) + '\D)'
27c138
+    match=re.search(regexp, logtext)
27c138
+    host_m2 = 'localhost.localdomain'
27c138
+    if (match is not None):
27c138
+        host_m2 = match.group(2)
27c138
+    return (host_m1, host_m2)
27c138
 
27c138
 @pytest.mark.ds50545
27c138
 @pytest.mark.bz1739718
27c138
@@ -95,9 +115,6 @@ def test_dsconf_replication_monitor(topology_m2, set_log_file):
27c138
     m1 = topology_m2.ms["master1"]
27c138
     m2 = topology_m2.ms["master2"]
27c138
 
27c138
-    alias_content = ['Supplier: M1 (' + m1.host + ':' + str(m1.port) + ')',
27c138
-                     'Supplier: M2 (' + m2.host + ':' + str(m2.port) + ')']
27c138
-
27c138
     connection_content = 'Supplier: '+ m1.host + ':' + str(m1.port)
27c138
     content_list = ['Replica Root: dc=example,dc=com',
27c138
                     'Replica ID: 1',
27c138
@@ -160,20 +177,9 @@ def test_dsconf_replication_monitor(topology_m2, set_log_file):
27c138
                  '001',
27c138
                  m1.host + ':' + str(m1.port)]
27c138
 
27c138
-    dsrc_content = '[repl-monitor-connections]\n' \
27c138
-                   'connection1 = ' + m1.host + ':' + str(m1.port) + ':' + DN_DM + ':' + PW_DM + '\n' \
27c138
-                   'connection2 = ' + m2.host + ':' + str(m2.port) + ':' + DN_DM + ':' + PW_DM + '\n' \
27c138
-                   '\n' \
27c138
-                   '[repl-monitor-aliases]\n' \
27c138
-                   'M1 = ' + m1.host + ':' + str(m1.port) + '\n' \
27c138
-                   'M2 = ' + m2.host + ':' + str(m2.port)
27c138
-
27c138
     connections = [m1.host + ':' + str(m1.port) + ':' + DN_DM + ':' + PW_DM,
27c138
                    m2.host + ':' + str(m2.port) + ':' + DN_DM + ':' + PW_DM]
27c138
 
27c138
-    aliases = ['M1=' + m1.host + ':' + str(m1.port),
27c138
-               'M2=' + m2.host + ':' + str(m2.port)]
27c138
-
27c138
     args = FakeArgs()
27c138
     args.connections = connections
27c138
     args.aliases = None
27c138
@@ -181,8 +187,24 @@ def test_dsconf_replication_monitor(topology_m2, set_log_file):
27c138
 
27c138
     log.info('Run replication monitor with connections option')
27c138
     get_repl_monitor_info(m1, DEFAULT_SUFFIX, log, args)
27c138
+    (host_m1, host_m2) = get_hostnames_from_log(m1.port, m2.port)
27c138
     check_value_in_log_and_reset(content_list, connection_content, error_list=error_list)
27c138
 
27c138
+    # Prepare the data for next tests
27c138
+    aliases = ['M1=' + host_m1 + ':' + str(m1.port),
27c138
+               'M2=' + host_m2 + ':' + str(m2.port)]
27c138
+
27c138
+    alias_content = ['Supplier: M1 (' + host_m1 + ':' + str(m1.port) + ')',
27c138
+                     'Supplier: M2 (' + host_m2 + ':' + str(m2.port) + ')']
27c138
+
27c138
+    dsrc_content = '[repl-monitor-connections]\n' \
27c138
+                   'connection1 = ' + m1.host + ':' + str(m1.port) + ':' + DN_DM + ':' + PW_DM + '\n' \
27c138
+                   'connection2 = ' + m2.host + ':' + str(m2.port) + ':' + DN_DM + ':' + PW_DM + '\n' \
27c138
+                   '\n' \
27c138
+                   '[repl-monitor-aliases]\n' \
27c138
+                   'M1 = ' + host_m1 + ':' + str(m1.port) + '\n' \
27c138
+                   'M2 = ' + host_m2 + ':' + str(m2.port)
27c138
+
27c138
     log.info('Run replication monitor with aliases option')
27c138
     args.aliases = aliases
27c138
     get_repl_monitor_info(m1, DEFAULT_SUFFIX, log, args)
27c138
-- 
27c138
2.26.2
27c138