From 2c7ae98f31a07f3b6bd8c2c083ffc7c935270771 Mon Sep 17 00:00:00 2001
From: William Brown <firstyear@redhat.com>
Date: Thu, 12 Jan 2017 08:20:40 +1000
Subject: [PATCH] Ticket 49087 - ds resolve jenkins issues.

Bug Description:  Our jenkins tests were failing, resolve it!

Fix Description:  This fixes the use of the paths module in many cases, and
fixes the debugging in addn tests.

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

Author: wibrown

Review by: ???
---
 dirsrvtests/tests/suites/basic/basic_test.py       |  3 +++
 .../tests/suites/dynamic-plugins/plugin_tests.py   |  2 ++
 dirsrvtests/tests/tickets/ticket1347760_test.py    |  4 ++--
 dirsrvtests/tests/tickets/ticket48272_test.py      |  4 ++++
 dirsrvtests/tests/tickets/ticket48383_test.py      |  8 +++----
 dirsrvtests/tests/tickets/ticket48956_test.py      | 27 ++++++++++------------
 6 files changed, 27 insertions(+), 21 deletions(-)

diff --git a/dirsrvtests/tests/suites/basic/basic_test.py b/dirsrvtests/tests/suites/basic/basic_test.py
index 21db6c5..c7b9566 100644
--- a/dirsrvtests/tests/suites/basic/basic_test.py
+++ b/dirsrvtests/tests/suites/basic/basic_test.py
@@ -8,6 +8,7 @@
 #
 from subprocess import check_output
 
+import time
 import ldap.sasl
 import pytest
 from lib389.tasks import *
@@ -659,6 +660,8 @@ def test_basic_dse(topology_st, import_example_ldif):
     log.info('dse.ldif was not corrupted, and the server was restarted')
 
     log.info('test_basic_dse: PASSED')
+    # Give the server time to startup, in some conditions this can be racey without systemd notification. Only affects this one test though...
+    time.sleep(10)
 
 
 @pytest.mark.parametrize("rootdse_attr_name", ROOTDSE_DEF_ATTR_LIST)
diff --git a/dirsrvtests/tests/suites/dynamic-plugins/plugin_tests.py b/dirsrvtests/tests/suites/dynamic-plugins/plugin_tests.py
index c32f3e5..1ae1034 100644
--- a/dirsrvtests/tests/suites/dynamic-plugins/plugin_tests.py
+++ b/dirsrvtests/tests/suites/dynamic-plugins/plugin_tests.py
@@ -1783,6 +1783,8 @@ def test_passthru(inst, args=None):
     args_instance[SER_CREATION_SUFFIX] = PASS_SUFFIX1
     args_passthru_inst = args_instance.copy()
     passthru_inst.allocate(args_passthru_inst)
+    if passthru_inst.exists():
+        passthru_inst.delete()
     passthru_inst.create()
     passthru_inst.open()
 
diff --git a/dirsrvtests/tests/tickets/ticket1347760_test.py b/dirsrvtests/tests/tickets/ticket1347760_test.py
index e7fb07f..9019764 100644
--- a/dirsrvtests/tests/tickets/ticket1347760_test.py
+++ b/dirsrvtests/tests/tickets/ticket1347760_test.py
@@ -420,8 +420,8 @@ def test_ticket1347760(topology_st):
     check_op_result(topology_st.standalone, 'delete', BOGUSDN, None, exists, rc)
 
     log.info('Inactivate %s' % BINDDN)
-    nsinactivate = '%s/sbin/ns-inactivate.pl' % topology_st.standalone.prefix
-    p = Popen([nsinactivate, '-Z', 'standalone', '-D', DN_DM, '-w', PASSWORD, '-I', BINDDN])
+    nsinactivate = os.path.join(topology_st.standalone.get_sbin_dir(), 'ns-inactivate.pl')
+    p = Popen([nsinactivate, '-Z', topology_st.standalone.serverid, '-D', DN_DM, '-w', PASSWORD, '-I', BINDDN])
     assert (p.wait() == 0)
 
     log.info('Bind as {%s,%s} which should fail with %s.' % (BINDDN, BUID, ldap.UNWILLING_TO_PERFORM.__name__))
diff --git a/dirsrvtests/tests/tickets/ticket48272_test.py b/dirsrvtests/tests/tickets/ticket48272_test.py
index 2b71609..8f3af70 100644
--- a/dirsrvtests/tests/tickets/ticket48272_test.py
+++ b/dirsrvtests/tests/tickets/ticket48272_test.py
@@ -79,6 +79,10 @@ def test_ticket48272(topology_st):
     # Add a user
     _create_user(topology_st.standalone, USER1, USER1_DN)
 
+    if DEBUGGING is not False:
+        print("Attach now")
+        time.sleep(20)
+
     # Make sure our binds still work.
     assert (_bind(USER1_DN, PW))
     # Test an anonymous bind
diff --git a/dirsrvtests/tests/tickets/ticket48383_test.py b/dirsrvtests/tests/tickets/ticket48383_test.py
index 50f17f0..b1fa93d 100644
--- a/dirsrvtests/tests/tickets/ticket48383_test.py
+++ b/dirsrvtests/tests/tickets/ticket48383_test.py
@@ -66,15 +66,15 @@ def test_ticket48383(topology_st):
     # Given the formula, by default, this means DS will make the buffsize 400k
     # So an object with a 1MB attribute should break indexing
 
+    ldifpath = os.path.join(topology_st.standalone.get_ldif_dir(), "%s.ldif" % SERVERID_STANDALONE)
+
     # stop the server
     topology_st.standalone.stop(timeout=30)
     # Now export and import the DB. It's easier than db2index ...
     topology_st.standalone.db2ldif(bename=DEFAULT_BENAME, suffixes=[DEFAULT_SUFFIX], excludeSuffixes=[],
-                                   encrypt=False, repl_data=True,
-                                   outputfile='{}/{}.ldif'.format(topology_st.standalone.ldifdir, SERVERID_STANDALONE))
+                                   encrypt=False, repl_data=True, outputfile=ldifpath)
 
-    result = topology_st.standalone.ldif2db(DEFAULT_BENAME, None, None, False,
-                                            '{}/{}.ldif'.format(topology_st.standalone.ldifdir, SERVERID_STANDALONE))
+    result = topology_st.standalone.ldif2db(DEFAULT_BENAME, None, None, False, ldifpath)
 
     assert (result)
 
diff --git a/dirsrvtests/tests/tickets/ticket48956_test.py b/dirsrvtests/tests/tickets/ticket48956_test.py
index b1200be..8715d9e 100644
--- a/dirsrvtests/tests/tickets/ticket48956_test.py
+++ b/dirsrvtests/tests/tickets/ticket48956_test.py
@@ -27,21 +27,18 @@ log = logging.getLogger(__name__)
 
 
 def _check_status(topology_st, user, expected):
-    nsaccountstatus = '%s/sbin/ns-accountstatus.pl' % topology_st.standalone.prefix
-    proc = subprocess.Popen(
-        [nsaccountstatus, '-Z', 'standalone', '-D', DN_DM, '-w', PASSWORD, '-p', str(topology_st.standalone.port), '-I',
-         user], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
-
-    found = False
-    while True:
-        l = proc.stdout.readline()
-        log.info("output: %s" % l)
-        if l == "":
-            break
-        if expected in l:
-            found = True
-            break
-    return found
+    nsaccountstatus = os.path.join(topology_st.standalone.ds_paths.sbin_dir, "ns-accountstatus.pl")
+
+    try:
+        output = subprocess.check_output( [nsaccountstatus, '-Z', topology_st.standalone.serverid, '-D', DN_DM, '-w', PASSWORD, '-p', str(topology_st.standalone.port), '-I', user])
+    except subprocess.CalledProcessError as err:
+        output = err.output
+
+    log.info("output: %s" % output)
+
+    if expected in output:
+        return True
+    return False
 
 
 def _check_inactivity(topology_st, mysuffix):
-- 
1.8.3.1

