From 05e8f4c7ca636c629f0919356573c4681f8273c6 Mon Sep 17 00:00:00 2001
From: Mark Reynolds <mreynolds@redhat.com>
Date: Fri, 19 Aug 2016 11:21:24 -0400
Subject: [PATCH] Ticket 48832 - Fix more CI test failures

Description:  More timing issues needed to be addressed by adding sleeps
              to certain tests.

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

Reviewed by: ?
---
 .../tests/suites/replication/cleanallruv_test.py   |  4 +++
 dirsrvtests/tests/tickets/ticket47536_test.py      |  1 +
 dirsrvtests/tests/tickets/ticket47819_test.py      |  8 +++--
 dirsrvtests/tests/tickets/ticket47838_test.py      |  8 +++--
 dirsrvtests/tests/tickets/ticket48194_test.py      | 38 ++++++++++++++++------
 dirsrvtests/tests/tickets/ticket48784_test.py      |  4 ++-
 6 files changed, 47 insertions(+), 16 deletions(-)

diff --git a/dirsrvtests/tests/suites/replication/cleanallruv_test.py b/dirsrvtests/tests/suites/replication/cleanallruv_test.py
index e1518bd..afed323 100644
--- a/dirsrvtests/tests/suites/replication/cleanallruv_test.py
+++ b/dirsrvtests/tests/suites/replication/cleanallruv_test.py
@@ -584,6 +584,7 @@ def restore_master4(topology):
     topology.master4.start(timeout=30)
     topology.master1.agreement.init(SUFFIX, HOST_MASTER_4, PORT_MASTER_4)
     topology.master1.waitForReplInit(topology.m1_m4_agmt)
+    time.sleep(5)
 
     #
     # Test Replication is working
@@ -594,6 +595,7 @@ def restore_master4(topology):
     else:
         log.fatal('restore_master4: Replication is not working from m1 -> m2.')
         assert False
+    time.sleep(1)
 
     # Check replication is working from master 1 to  master 4...
     if topology.master1.testReplication(DEFAULT_SUFFIX, topology.master4):
@@ -601,6 +603,7 @@ def restore_master4(topology):
     else:
         log.fatal('restore_master4: Replication is not working from m1 -> m4.')
         assert False
+    time.sleep(1)
 
     # Check replication is working from master 4 to master1...
     if topology.master4.testReplication(DEFAULT_SUFFIX, topology.master1):
@@ -608,6 +611,7 @@ def restore_master4(topology):
     else:
         log.fatal('restore_master4: Replication is not working from m4 -> 1.')
         assert False
+    time.sleep(5)
 
     log.info('Master 4 has been successfully restored.')
 
diff --git a/dirsrvtests/tests/tickets/ticket47536_test.py b/dirsrvtests/tests/tickets/ticket47536_test.py
index fe47ab7..cf20746 100644
--- a/dirsrvtests/tests/tickets/ticket47536_test.py
+++ b/dirsrvtests/tests/tickets/ticket47536_test.py
@@ -269,6 +269,7 @@ def create_keys_certs(topology):
     noisewdfd = open(noisefile, "w")
     noisewdfd.write(noise.readline())
     noisewdfd.close()
+    time.sleep(1)
 
     cmdline = ['certutil', '-N', '-d', m1confdir, '-f', pwdfile]
     log.info("##### Create key3.db and cert8.db database (master1): %s" % cmdline)
diff --git a/dirsrvtests/tests/tickets/ticket47819_test.py b/dirsrvtests/tests/tickets/ticket47819_test.py
index d127fc0..2168fe5 100644
--- a/dirsrvtests/tests/tickets/ticket47819_test.py
+++ b/dirsrvtests/tests/tickets/ticket47819_test.py
@@ -139,17 +139,20 @@ def test_ticket47819(topology):
         exportTask.exportLDIF(DEFAULT_SUFFIX, None, ldif_file, args)
     except ValueError:
         assert False
+    time.sleep(1)
 
     # open the ldif file, get the lines, then rewrite the file
     ldif = open(ldif_file, "r")
     lines = ldif.readlines()
     ldif.close()
+    time.sleep(1)
 
     ldif = open(ldif_file, "w")
     for line in lines:
         if not line.lower().startswith('nstombstonecsn'):
             ldif.write(line)
     ldif.close()
+    time.sleep(1)
 
     # import the new ldif file
     log.info('Import replication LDIF file...')
@@ -161,6 +164,7 @@ def test_ticket47819(topology):
     except ValueError:
         os.remove(ldif_file)
         assert False
+    time.sleep(1)
 
     # Search for the tombstone again
     log.info('Search for tombstone entries...')
@@ -190,6 +194,7 @@ def test_ticket47819(topology):
         fixupTombTask.fixupTombstones(DEFAULT_BENAME, args)
     except:
         assert False
+    time.sleep(1)
 
     # Search for tombstones with nsTombstoneCSN - better not find any
     log.info('Search for tombstone entries...')
@@ -211,7 +216,6 @@ def test_ticket47819(topology):
         fixupTombTask.fixupTombstones(DEFAULT_BENAME, args)
     except:
         assert False
-
     time.sleep(1)
 
     # Search for tombstones with nsTombstoneCSN - better find some
@@ -244,7 +248,7 @@ def test_ticket47819(topology):
 
     # Wait for the interval to pass
     log.info('Wait for tombstone purge interval to pass...')
-    time.sleep(6)
+    time.sleep(10)
 
     # Add an entry to trigger replication
     log.info('Perform an update to help trigger tombstone purging...')
diff --git a/dirsrvtests/tests/tickets/ticket47838_test.py b/dirsrvtests/tests/tickets/ticket47838_test.py
index 475bec4..a9d4307 100644
--- a/dirsrvtests/tests/tickets/ticket47838_test.py
+++ b/dirsrvtests/tests/tickets/ticket47838_test.py
@@ -127,6 +127,7 @@ def test_47838_init(topology):
     noisewdfd = open(noisefile, "w")
     noisewdfd.write(noise.readline())
     noisewdfd.close()
+    time.sleep(1)
 
     log.info("\n######################### Create key3.db and cert8.db database ######################\n")
     os.system("ls %s" % pwdfile)
@@ -137,7 +138,8 @@ def test_47838_init(topology):
     os.system('certutil -G -d %s -z %s -f %s' % (conf_dir, noisefile, pwdfile))
 
     log.info("\n######################### Creating self-signed CA certificate ######################\n")
-    os.system('( echo y ; echo ; echo y ) | certutil -S -n "CA certificate" -s "cn=CAcert" -x -t "CT,," -m 1000 -v 120 -d %s -z %s -f %s -2' % (conf_dir, noisefile, pwdfile))
+    os.system('( echo y ; echo ; echo y ) | certutil -S -n "CA certificate" -s "cn=CAcert" -x -t "CT,," -m 1000 -v 120 -d %s -z %s -f %s -2' %
+              (conf_dir, noisefile, pwdfile))
 
     log.info("\n######################### Exporting the CA certificate to cacert.asc ######################\n")
     cafile = '%s/cacert.asc' % conf_dir
@@ -161,6 +163,7 @@ def test_47838_init(topology):
     pinfd = open(pinfile, "w")
     pinfd.write(pintxt)
     pinfd.close()
+    time.sleep(1)
 
     log.info("\n######################### enable SSL in the directory server with all ciphers ######################\n")
     topology.standalone.simple_bind_s(DN_DM, PASSWORD)
@@ -213,7 +216,6 @@ def test_47838_run_0(topology):
     time.sleep(5)
     log.info("\n######################### Restarting the server ######################\n")
     topology.standalone.restart(timeout=120)
-
     enabled = os.popen('egrep "SSL alert:" %s | egrep \": enabled\" | wc -l' % topology.standalone.errlog)
     disabled = os.popen('egrep "SSL alert:" %s | egrep \": disabled\" | wc -l' % topology.standalone.errlog)
     ecount = int(enabled.readline().rstrip())
@@ -250,7 +252,7 @@ def test_47838_run_1(topology):
 
     topology.standalone.simple_bind_s(DN_DM, PASSWORD)
     topology.standalone.modify_s(CONFIG_DN, [(ldap.MOD_REPLACE, 'nsslapd-errorlog-level', '64')])
-    time.sleep(5)
+    time.sleep(1)
     # Make sure allowWeakCipher is not set.
     topology.standalone.modify_s(ENCRYPTION_DN, [(ldap.MOD_DELETE, 'allowWeakCipher', None)])
 
diff --git a/dirsrvtests/tests/tickets/ticket48194_test.py b/dirsrvtests/tests/tickets/ticket48194_test.py
index 8e04d8b..92f4371 100644
--- a/dirsrvtests/tests/tickets/ticket48194_test.py
+++ b/dirsrvtests/tests/tickets/ticket48194_test.py
@@ -33,6 +33,7 @@ plus_all_dcount = 0
 plus_all_ecount_noweak = 0
 plus_all_dcount_noweak = 0
 
+
 class TopologyStandalone(object):
     def __init__(self, standalone):
         standalone.open()
@@ -109,6 +110,7 @@ def test_init(topology):
     noisewdfd = open(noisefile, "w")
     noisewdfd.write(noise.readline())
     noisewdfd.close()
+    time.sleep(1)
 
     log.info("\n######################### Create key3.db and cert8.db database ######################\n")
     os.system("ls %s" % pwdfile)
@@ -119,7 +121,8 @@ def test_init(topology):
     os.system('certutil -G -d %s -z %s -f %s' % (conf_dir, noisefile, pwdfile))
 
     log.info("\n######################### Creating self-signed CA certificate ######################\n")
-    os.system('( echo y ; echo ; echo y ) | certutil -S -n "CA certificate" -s "cn=CAcert" -x -t "CT,," -m 1000 -v 120 -d %s -z %s -f %s -2' % (conf_dir, noisefile, pwdfile))
+    os.system('( echo y ; echo ; echo y ) | certutil -S -n "CA certificate" -s "cn=CAcert" -x -t "CT,," -m 1000 -v 120 -d %s -z %s -f %s -2' %
+              (conf_dir, noisefile, pwdfile))
 
     log.info("\n######################### Exporting the CA certificate to cacert.asc ######################\n")
     cafile = '%s/cacert.asc' % conf_dir
@@ -135,7 +138,8 @@ def test_init(topology):
     log.info("\n######################### Generate the server certificate ######################\n")
     ohostname = os.popen('hostname --fqdn', "r")
     myhostname = ohostname.readline()
-    os.system('certutil -S -n "%s" -s "cn=%s,ou=389 Directory Server" -c "CA certificate" -t "u,u,u" -m 1001 -v 120 -d %s -z %s -f %s' % (SERVERCERT, myhostname.rstrip(), conf_dir, noisefile, pwdfile))
+    os.system('certutil -S -n "%s" -s "cn=%s,ou=389 Directory Server" -c "CA certificate" -t "u,u,u" -m 1001 -v 120 -d %s -z %s -f %s' %
+              (SERVERCERT, myhostname.rstrip(), conf_dir, noisefile, pwdfile))
 
     log.info("\n######################### create the pin file ######################\n")
     pinfile = '%s/pin.txt' % (conf_dir)
@@ -143,6 +147,7 @@ def test_init(topology):
     pinfd = open(pinfile, "w")
     pinfd.write(pintxt)
     pinfd.close()
+    time.sleep(1)
 
     log.info("\n######################### enable SSL in the directory server with all ciphers ######################\n")
     topology.standalone.simple_bind_s(DN_DM, PASSWORD)
@@ -162,6 +167,7 @@ def test_init(topology):
                                               'nsSSLToken': 'internal (software)',
                                               'nsSSLActivation': 'on'})))
 
+
 def connectWithOpenssl(topology, cipher, expect):
     """
     Connect with the given cipher
@@ -204,6 +210,7 @@ def connectWithOpenssl(topology, cipher, expect):
                     proc.stdin.close()
                     assert False
 
+
 def test_run_0(topology):
     """
     Check nsSSL3Ciphers: +all
@@ -221,6 +228,7 @@ def test_run_0(topology):
     connectWithOpenssl(topology, 'RC4-SHA', True)
     connectWithOpenssl(topology, 'AES256-SHA256', True)
 
+
 def test_run_1(topology):
     """
     Check nsSSL3Ciphers: +all
@@ -238,12 +246,13 @@ def test_run_1(topology):
     topology.standalone.stop(timeout=10)
     os.system('mv %s %s.48194_0' % (topology.standalone.errlog, topology.standalone.errlog))
     os.system('touch %s' % (topology.standalone.errlog))
-    time.sleep(1)
+    time.sleep(2)
     topology.standalone.start(timeout=120)
 
     connectWithOpenssl(topology, 'RC4-SHA', False)
     connectWithOpenssl(topology, 'AES256-SHA256', True)
 
+
 def test_run_2(topology):
     """
     Check nsSSL3Ciphers: +rsa_aes_128_sha,+rsa_aes_256_sha
@@ -259,7 +268,7 @@ def test_run_2(topology):
     topology.standalone.stop(timeout=10)
     os.system('mv %s %s.48194_1' % (topology.standalone.errlog, topology.standalone.errlog))
     os.system('touch %s' % (topology.standalone.errlog))
-    time.sleep(1)
+    time.sleep(2)
     topology.standalone.start(timeout=120)
 
     connectWithOpenssl(topology, 'RC4-SHA', False)
@@ -267,6 +276,7 @@ def test_run_2(topology):
     connectWithOpenssl(topology, 'AES128-SHA', True)
     connectWithOpenssl(topology, 'AES256-SHA', True)
 
+
 def test_run_3(topology):
     """
     Check nsSSL3Ciphers: -all
@@ -288,6 +298,7 @@ def test_run_3(topology):
     connectWithOpenssl(topology, 'RC4-SHA', False)
     connectWithOpenssl(topology, 'AES256-SHA256', False)
 
+
 def test_run_4(topology):
     """
     Check no nsSSL3Ciphers
@@ -303,12 +314,13 @@ def test_run_4(topology):
     topology.standalone.stop(timeout=10)
     os.system('mv %s %s.48194_3' % (topology.standalone.errlog, topology.standalone.errlog))
     os.system('touch %s' % (topology.standalone.errlog))
-    time.sleep(1)
+    time.sleep(2)
     topology.standalone.start(timeout=120)
 
     connectWithOpenssl(topology, 'RC4-SHA', False)
     connectWithOpenssl(topology, 'AES256-SHA256', True)
 
+
 def test_run_5(topology):
     """
     Check nsSSL3Ciphers: default
@@ -324,12 +336,13 @@ def test_run_5(topology):
     topology.standalone.stop(timeout=10)
     os.system('mv %s %s.48194_4' % (topology.standalone.errlog, topology.standalone.errlog))
     os.system('touch %s' % (topology.standalone.errlog))
-    time.sleep(1)
+    time.sleep(2)
     topology.standalone.start(timeout=120)
 
     connectWithOpenssl(topology, 'RC4-SHA', False)
     connectWithOpenssl(topology, 'AES256-SHA256', True)
 
+
 def test_run_6(topology):
     """
     Check nsSSL3Ciphers: +all,-TLS_RSA_WITH_AES_256_CBC_SHA256
@@ -345,13 +358,14 @@ def test_run_6(topology):
     topology.standalone.stop(timeout=10)
     os.system('mv %s %s.48194_5' % (topology.standalone.errlog, topology.standalone.errlog))
     os.system('touch %s' % (topology.standalone.errlog))
-    time.sleep(1)
+    time.sleep(2)
     topology.standalone.start(timeout=120)
 
     connectWithOpenssl(topology, 'RC4-SHA', False)
     connectWithOpenssl(topology, 'AES256-SHA256', False)
     connectWithOpenssl(topology, 'AES128-SHA', True)
 
+
 def test_run_7(topology):
     """
     Check nsSSL3Ciphers: -all,+rsa_rc4_128_md5
@@ -367,13 +381,14 @@ def test_run_7(topology):
     topology.standalone.stop(timeout=10)
     os.system('mv %s %s.48194_6' % (topology.standalone.errlog, topology.standalone.errlog))
     os.system('touch %s' % (topology.standalone.errlog))
-    time.sleep(1)
+    time.sleep(2)
     topology.standalone.start(timeout=120)
 
     connectWithOpenssl(topology, 'RC4-SHA', False)
     connectWithOpenssl(topology, 'AES256-SHA256', False)
     connectWithOpenssl(topology, 'RC4-MD5', True)
 
+
 def test_run_8(topology):
     """
     Check nsSSL3Ciphers: default + allowWeakCipher: off
@@ -389,12 +404,13 @@ def test_run_8(topology):
     topology.standalone.stop(timeout=10)
     os.system('mv %s %s.48194_7' % (topology.standalone.errlog, topology.standalone.errlog))
     os.system('touch %s' % (topology.standalone.errlog))
-    time.sleep(1)
+    time.sleep(2)
     topology.standalone.start(timeout=120)
 
     connectWithOpenssl(topology, 'RC4-SHA', False)
     connectWithOpenssl(topology, 'AES256-SHA256', True)
 
+
 def test_run_9(topology):
     """
     Check no nsSSL3Ciphers
@@ -413,12 +429,13 @@ def test_run_9(topology):
     topology.standalone.stop(timeout=10)
     os.system('mv %s %s.48194_8' % (topology.standalone.errlog, topology.standalone.errlog))
     os.system('touch %s' % (topology.standalone.errlog))
-    time.sleep(1)
+    time.sleep(2)
     topology.standalone.start(timeout=120)
 
     connectWithOpenssl(topology, 'RC4-SHA', True)
     connectWithOpenssl(topology, 'AES256-SHA256', True)
 
+
 def test_run_10(topology):
     """
     Check nsSSL3Ciphers: -TLS_RSA_WITH_NULL_MD5,+TLS_RSA_WITH_RC4_128_MD5,
@@ -449,6 +466,7 @@ def test_run_10(topology):
     connectWithOpenssl(topology, 'RC4-MD5', True)
     connectWithOpenssl(topology, 'AES256-SHA256', False)
 
+
 def test_run_11(topology):
     """
     Check nsSSL3Ciphers: +fortezza
diff --git a/dirsrvtests/tests/tickets/ticket48784_test.py b/dirsrvtests/tests/tickets/ticket48784_test.py
index a94415a..2898807 100644
--- a/dirsrvtests/tests/tickets/ticket48784_test.py
+++ b/dirsrvtests/tests/tickets/ticket48784_test.py
@@ -181,6 +181,7 @@ def enable_ssl(server, ldapsport, mycert):
                                  'nsSSLToken': 'internal (software)',
                                  'nsSSLActivation': 'on'})))
 
+
 def doAndPrintIt(cmdline, filename):
     proc = subprocess.Popen(cmdline, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
     if filename is None:
@@ -206,6 +207,7 @@ def doAndPrintIt(cmdline, filename):
 
     if filename is not None:
         fd.close()
+    time.sleep(1)
 
 
 def create_keys_certs(topology):
@@ -245,6 +247,7 @@ def create_keys_certs(topology):
     noisewdfd = open(noisefile, "w")
     noisewdfd.write(noise.readline())
     noisewdfd.close()
+    time.sleep(1)
 
     cmdline = ['certutil', '-N', '-d', m1confdir, '-f', pwdfile]
     log.info("##### Create key3.db and cert8.db database (master1): %s" % cmdline)
@@ -333,7 +336,6 @@ def create_keys_certs(topology):
     log.info("##### restart master1")
     topology.master1.restart(timeout=10)
 
-
     log.info("\n######################### Creating SSL Keys and Certs Done ######################\n")
 
 
-- 
2.7.4

