Pārlūkot izejas kodu

Ticket 48832 - Fix timing and localhost issues

Description: Add smart time.sleep() before a checking of access log.
Replace 'localhost' with DirSrvTools.getLocalhost() function for
rootdn-allow-host and rootdn-deny-host attrs.

https://fedorahosted.org/389/ticket/48832

Reviewed by: mreynolds (Thanks!)
Simon Pichugin 9 gadi atpakaļ
vecāks
revīzija
6d472e4818

+ 4 - 2
dirsrvtests/tests/suites/rootdn_plugin/rootdn_plugin_test.py

@@ -377,13 +377,14 @@ def test_rootdn_access_denied_host(topology):
 
     log.info('Running test_rootdn_access_denied_host...')
     hostname = socket.gethostname()
+    localhost = DirSrvTools.getLocalhost()
     try:
         topology.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_ADD,
                                                   'rootdn-deny-host',
                                                   hostname)])
         topology.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_ADD,
                                                   'rootdn-deny-host',
-                                                  'localhost')])
+                                                  localhost)])
     except ldap.LDAPError as e:
         log.fatal('test_rootdn_access_denied_host: Failed to set deny host: error ' +
                   e.message['desc'])
@@ -559,10 +560,11 @@ def test_rootdn_access_allowed_host(topology):
         assert False
 
     hostname = socket.gethostname()
+    localhost = DirSrvTools.getLocalhost()
     try:
         topology.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_ADD,
                                                   'rootdn-allow-host',
-                                                  'localhost')])
+                                                  localhost)])
         topology.standalone.modify_s(PLUGIN_DN, [(ldap.MOD_ADD,
                                                   'rootdn-allow-host',
                                                   hostname)])

+ 23 - 21
dirsrvtests/tests/tickets/ticket1347760_test.py

@@ -85,27 +85,29 @@ def topology(request):
 
 
 def pattern_accesslog(file, log_pattern):
-    try:
-        pattern_accesslog.last_pos += 1
-    except AttributeError:
-        pattern_accesslog.last_pos = 0
-
-    found = None
-    file.seek(pattern_accesslog.last_pos)
-
-    # Use a while true iteration because 'for line in file: hit a
-    # python bug that break file.tell()
-    while True:
-        line = file.readline()
-        found = log_pattern.search(line)
-        if ((line == '') or (found)):
-            break
-
-    pattern_accesslog.last_pos = file.tell()
-    if found:
-        return line
-    else:
-        return None
+    for i in range(5):
+        try:
+            pattern_accesslog.last_pos += 1
+        except AttributeError:
+            pattern_accesslog.last_pos = 0
+
+        found = None
+        file.seek(pattern_accesslog.last_pos)
+
+        # Use a while true iteration because 'for line in file: hit a
+        # python bug that break file.tell()
+        while True:
+            line = file.readline()
+            found = log_pattern.search(line)
+            if ((line == '') or (found)):
+                break
+
+        pattern_accesslog.last_pos = file.tell()
+        if found:
+            return line
+        else:
+            time.sleep(1)
+    return None
 
 
 def check_op_result(server, op, dn, superior, exists, rc):

+ 11 - 14
dirsrvtests/tests/tickets/ticket47838_test.py

@@ -373,7 +373,7 @@ def test_47838_run_4(topology):
     global plus_all_ecount
     global plus_all_dcount
     if nss_version >= NSS323:
-        assert ecount == 23
+        assert ecount == 29
     else:
         assert ecount == 20
     assert dcount == (plus_all_ecount + plus_all_dcount - ecount)
@@ -411,10 +411,10 @@ def test_47838_run_5(topology):
     log.info("Disabled ciphers: %d" % dcount)
     global plus_all_ecount
     global plus_all_dcount
-    if nss_version >= NSS320:
-        assert ecount == 23
+    if nss_version >= NSS323:
+        assert ecount == 29
     else:
-        assert ecount == 12
+        assert ecount == 23
     assert dcount == (plus_all_ecount + plus_all_dcount - ecount)
     weak = os.popen('egrep "SSL alert:" %s | egrep \": enabled\" | egrep "WEAK CIPHER" | wc -l' % topology.standalone.errlog)
     wcount = int(weak.readline().rstrip())
@@ -516,10 +516,10 @@ def test_47838_run_8(topology):
     log.info("Disabled ciphers: %d" % dcount)
     global plus_all_ecount
     global plus_all_dcount
-    if nss_version >= NSS320:
-       assert ecount == 23
+    if nss_version >= NSS323:
+       assert ecount == 29
     else:
-       assert ecount == 12
+       assert ecount == 23
     assert dcount == (plus_all_ecount + plus_all_dcount - ecount)
     weak = os.popen('egrep "SSL alert:" %s | egrep \": enabled\" | egrep "WEAK CIPHER" | wc -l' % topology.standalone.errlog)
     wcount = int(weak.readline().rstrip())
@@ -556,10 +556,10 @@ def test_47838_run_9(topology):
 
     log.info("Enabled ciphers: %d" % ecount)
     log.info("Disabled ciphers: %d" % dcount)
-    if nss_version >= NSS320:
-        assert ecount == 30
+    if nss_version >= NSS323:
+        assert ecount == 36
     else:
-        assert ecount == 23
+        assert ecount == 30
     assert dcount == 0
     weak = os.popen('egrep "SSL alert:" %s | egrep \": enabled\" | egrep "WEAK CIPHER" | wc -l' % topology.standalone.errlog)
     wcount = int(weak.readline().rstrip())
@@ -606,10 +606,7 @@ def test_47838_run_10(topology):
     log.info("Disabled ciphers: %d" % dcount)
     global plus_all_ecount
     global plus_all_dcount
-    if nss_version >= NSS320:
-        assert ecount == 5
-    else:
-        assert ecount == 9
+    assert ecount == 9
     assert dcount == 0
     weak = os.popen('egrep "SSL alert:" %s | egrep \": enabled\" | egrep "WEAK CIPHER" | wc -l' % topology.standalone.errlog)
     wcount = int(weak.readline().rstrip())