From a1d2050ef6f50a18f2054d3f930ed84b8c9b6c78 Mon Sep 17 00:00:00 2001
From: Simon Pichugin <spichugi@redhat.com>
Date: Fri, 17 Feb 2017 15:26:08 +0100
Subject: [PATCH] Issue 49147 - Fix tests compatibility with older versions

Bug description: A lot of tests are failing on older versions. We need
to fix them or add "skipif" mark if required.

Fix description: Fix logging regex in 47431, 47823.
Chanfe 'rc' class to 'rc.__name__' str, so it won't fail.
In 48226, put valgrind_disable function to a finally block.
Add "skipif" mark to 48896, 49008, 49020, 49073, 49104, 49121.

https://pagure.io/389-ds-base/issue/49147

Reviewed by: ?
---
 .../suites/paged_results/paged_results_test.py     |   3 -
 dirsrvtests/tests/tickets/ticket47431_test.py      |   3 +-
 dirsrvtests/tests/tickets/ticket47823_test.py      |   8 +-
 dirsrvtests/tests/tickets/ticket48226_test.py      | 114 ++++++++++-----------
 dirsrvtests/tests/tickets/ticket48896_test.py      |   5 +-
 dirsrvtests/tests/tickets/ticket49008_test.py      |   3 +
 dirsrvtests/tests/tickets/ticket49020_test.py      |   6 +-
 dirsrvtests/tests/tickets/ticket49073_test.py      |   3 +
 dirsrvtests/tests/tickets/ticket49104_test.py      |   3 +
 dirsrvtests/tests/tickets/ticket49121_test.py      |   3 +
 10 files changed, 78 insertions(+), 73 deletions(-)

diff --git a/dirsrvtests/tests/suites/paged_results/paged_results_test.py b/dirsrvtests/tests/suites/paged_results/paged_results_test.py
index f01bbc8..149a2ea 100644
--- a/dirsrvtests/tests/suites/paged_results/paged_results_test.py
+++ b/dirsrvtests/tests/suites/paged_results/paged_results_test.py
@@ -370,9 +370,6 @@ def test_search_limits_fail(topology_st, test_user, page_size, users_num,
             else:
                 break
     finally:
-        if expected_err == ldap.UNAVAILABLE_CRITICAL_EXTENSION:
-            topology_st.standalone.open()
-
         log.info('Set Directory Manager bind back (test_search_limits_fail)')
         topology_st.standalone.simple_bind_s(DN_DM, PASSWORD)
         del_users(topology_st, users_list)
diff --git a/dirsrvtests/tests/tickets/ticket47431_test.py b/dirsrvtests/tests/tickets/ticket47431_test.py
index 7c726ac..3953937 100644
--- a/dirsrvtests/tests/tickets/ticket47431_test.py
+++ b/dirsrvtests/tests/tickets/ticket47431_test.py
@@ -28,7 +28,6 @@ def test_ticket47431_0(topology_st):
     log.info("Ticket 47431 - 0: Enable 7bit plugin...")
     topology_st.standalone.plugins.enable(name=PLUGIN_7_BIT_CHECK)
 
-
 def test_ticket47431_1(topology_st):
     '''
     nsslapd-pluginarg0: uid
@@ -43,7 +42,7 @@ def test_ticket47431_1(topology_st):
     '''
 
     log.info("Ticket 47431 - 1: Check 26 duplicate values are treated as one...")
-    expected = "str2entry_dupcheck - .* duplicate values for attribute type nsslapd-pluginarg2 detected in entry cn=7-bit check,cn=plugins,cn=config."
+    expected = "str2entry_dupcheck.* duplicate values for attribute type nsslapd-pluginarg2 detected in entry cn=7-bit check,cn=plugins,cn=config."
 
     log.debug('modify_s %s' % DN_7BITPLUGIN)
     try:
diff --git a/dirsrvtests/tests/tickets/ticket47823_test.py b/dirsrvtests/tests/tickets/ticket47823_test.py
index 2beeb25..f5d4e53 100644
--- a/dirsrvtests/tests/tickets/ticket47823_test.py
+++ b/dirsrvtests/tests/tickets/ticket47823_test.py
@@ -620,7 +620,7 @@ def test_ticket47823_invalid_config_1(topology_st):
         pass
 
     # Check the expected error message
-    regex = re.compile("Unable to parse old style")
+    regex = re.compile("[U|u]nable to parse old style")
     res = _pattern_errorlog(topology_st.standalone.errorlog_file, regex)
     if not res:
         # be sure to restore a valid config before assert
@@ -728,7 +728,7 @@ def test_ticket47823_invalid_config_3(topology_st):
         pass
 
     # Check the expected error message
-    regex = re.compile("Unable to parse old style")
+    regex = re.compile("[U|u]nable to parse old style")
     res = _pattern_errorlog(topology_st.standalone.errorlog_file, regex)
     if not res:
         # be sure to restore a valid config before assert
@@ -835,7 +835,7 @@ def test_ticket47823_invalid_config_5(topology_st):
         pass
 
     # Check the expected error message
-    regex = re.compile("Attribute name not defined")
+    regex = re.compile("[A|a]ttribute name not defined")
     res = _pattern_errorlog(topology_st.standalone.errorlog_file, regex)
     if not res:
         # be sure to restore a valid config before assert
@@ -888,7 +888,7 @@ def test_ticket47823_invalid_config_6(topology_st):
         pass
 
     # Check the expected error message
-    regex = re.compile("Objectclass for subtree entries is not defined")
+    regex = re.compile("[O|o]bjectclass for subtree entries is not defined")
     res = _pattern_errorlog(topology_st.standalone.errorlog_file, regex)
     if not res:
         # be sure to restore a valid config before assert
diff --git a/dirsrvtests/tests/tickets/ticket48226_test.py b/dirsrvtests/tests/tickets/ticket48226_test.py
index 3ed58d2..95afd3e 100644
--- a/dirsrvtests/tests/tickets/ticket48226_test.py
+++ b/dirsrvtests/tests/tickets/ticket48226_test.py
@@ -71,68 +71,62 @@ def test_ticket48226_1(topology_m2):
     # Get the sbin directory so we know where to replace 'ns-slapd'
     sbin_dir = topology_m2.ms["master2"].get_sbin_dir()
 
-    # Enable valgrind
-    if not topology_m2.ms["master2"].has_asan():
-        valgrind_enable(sbin_dir)
-
-    # start M2 to do the next updates
-    topology_m2.ms["master2"].start()
-
-    # ADD 'description' by '5'
-    mods = [(ldap.MOD_DELETE, 'description', '5')]
-    topology_m2.ms["master2"].modify_s(dn, mods)
-
-    # DEL 'description' by '5'
-    mods = [(ldap.MOD_ADD, 'description', '5')]
-    topology_m2.ms["master2"].modify_s(dn, mods)
-
-    # sleep of purge delay so that the next update will purge the CSN_7
-    time.sleep(6)
-
-    # ADD 'description' by '6' that purge the state info
-    mods = [(ldap.MOD_ADD, 'description', '6')]
-    topology_m2.ms["master2"].modify_s(dn, mods)
-
-    # Restart master1
-    # topology_m2.ms["master1"].start(30)
-
-    if not topology_m2.ms["master2"].has_asan():
-        results_file = valgrind_get_results_file(topology_m2.ms["master2"])
-
-    # Stop master2
-    topology_m2.ms["master2"].stop(30)
-
-    # Check for leak
-    if not topology_m2.ms["master2"].has_asan():
-        if valgrind_check_file(results_file, VALGRIND_LEAK_STR, 'csnset_dup'):
-            log.info('Valgrind reported leak in csnset_dup!')
-            valgrind_disable(sbin_dir)
-            assert False
-        else:
-            log.info('Valgrind is happy!')
-
-        # Check for invalid read/write
-        if valgrind_check_file(results_file, VALGRIND_INVALID_STR, 'csnset_dup'):
-            log.info('Valgrind reported invalid!')
-            valgrind_disable(sbin_dir)
-            assert False
-        else:
-            log.info('Valgrind is happy!')
-
-        # Check for invalid read/write
-        if valgrind_check_file(results_file, VALGRIND_INVALID_STR, 'csnset_free'):
-            log.info('Valgrind reported invalid!')
-            valgrind_disable(sbin_dir)
-            assert False
-        else:
-            log.info('Valgrind is happy!')
-
-    # Disable valgrind
-    if not topology_m2.ms["master2"].has_asan():
+    # Wrap valgrind in the try-finally block to make sure it is teared down
+    try:
+        if not topology_m2.ms["master2"].has_asan():
+            valgrind_enable(sbin_dir)
+
+        # start M2 to do the next updates
+        topology_m2.ms["master2"].start()
+
+        # ADD 'description' by '5'
+        mods = [(ldap.MOD_DELETE, 'description', '5')]
+        topology_m2.ms["master2"].modify_s(dn, mods)
+
+        # DEL 'description' by '5'
+        mods = [(ldap.MOD_ADD, 'description', '5')]
+        topology_m2.ms["master2"].modify_s(dn, mods)
+
+        # sleep of purge delay so that the next update will purge the CSN_7
+        time.sleep(6)
+
+        # ADD 'description' by '6' that purge the state info
+        mods = [(ldap.MOD_ADD, 'description', '6')]
+        topology_m2.ms["master2"].modify_s(dn, mods)
+
+        # Restart master1
+        # topology_m2.ms["master1"].start(30)
+
+        if not topology_m2.ms["master2"].has_asan():
+            results_file = valgrind_get_results_file(topology_m2.ms["master2"])
+
+        # Stop master2
+        topology_m2.ms["master2"].stop(30)
+
+        # Check for leak
+        if not topology_m2.ms["master2"].has_asan():
+            if valgrind_check_file(results_file, VALGRIND_LEAK_STR, 'csnset_dup'):
+                log.info('Valgrind reported leak in csnset_dup!')
+                assert False
+            else:
+                log.info('Valgrind is happy!')
+
+            # Check for invalid read/write
+            if valgrind_check_file(results_file, VALGRIND_INVALID_STR, 'csnset_dup'):
+                log.info('Valgrind reported invalid!')
+                assert False
+            else:
+                log.info('Valgrind is happy!')
+
+            # Check for invalid read/write
+            if valgrind_check_file(results_file, VALGRIND_INVALID_STR, 'csnset_free'):
+                log.info('Valgrind reported invalid!')
+                assert False
+            else:
+                log.info('Valgrind is happy!')
+    finally:
         valgrind_disable(sbin_dir)
 
-    log.info('Testcase PASSED')
-
 
 if __name__ == '__main__':
     # Run isolated
diff --git a/dirsrvtests/tests/tickets/ticket48896_test.py b/dirsrvtests/tests/tickets/ticket48896_test.py
index a170e1c..8c5314b 100644
--- a/dirsrvtests/tests/tickets/ticket48896_test.py
+++ b/dirsrvtests/tests/tickets/ticket48896_test.py
@@ -11,6 +11,9 @@ from lib389.tasks import *
 from lib389.utils import *
 from lib389.topologies import topology_st
 
+# Skip on older versions
+pytestmark = pytest.mark.skipif(ds_is_older('1.3.6'), reason="Not implemented")
+
 logging.getLogger(__name__).setLevel(logging.DEBUG)
 log = logging.getLogger(__name__)
 
@@ -51,7 +54,7 @@ def replace_pw(server, curpw, newpw, expstr, rc):
         assert isinstance(e, rc)
 
     if (0 != rc) and (0 == hit):
-        log.info('Expected to fail with %d, but passed' % rc)
+        log.info('Expected to fail with %s, but passed' % rc.__name__)
         assert False
 
     log.info('PASSED')
diff --git a/dirsrvtests/tests/tickets/ticket49008_test.py b/dirsrvtests/tests/tickets/ticket49008_test.py
index 67ee7c7..0944eee 100644
--- a/dirsrvtests/tests/tickets/ticket49008_test.py
+++ b/dirsrvtests/tests/tickets/ticket49008_test.py
@@ -3,6 +3,9 @@ from lib389.tasks import *
 from lib389.utils import *
 from lib389.topologies import topology_m3 as T
 
+# Skip on older versions
+pytestmark = pytest.mark.skipif(ds_is_older('1.3.6'), reason="Not implemented")
+
 DEBUGGING = os.getenv("DEBUGGING", default=False)
 if DEBUGGING:
     logging.getLogger(__name__).setLevel(logging.DEBUG)
diff --git a/dirsrvtests/tests/tickets/ticket49020_test.py b/dirsrvtests/tests/tickets/ticket49020_test.py
index c5bf6c6..f4fc8df 100644
--- a/dirsrvtests/tests/tickets/ticket49020_test.py
+++ b/dirsrvtests/tests/tickets/ticket49020_test.py
@@ -10,6 +10,9 @@ from lib389.tasks import *
 from lib389.utils import *
 from lib389.topologies import topology_m3 as T
 
+# Skip on older versions
+pytestmark = pytest.mark.skipif(ds_is_older('1.3.6'), reason="Not implemented")
+
 DEBUGGING = os.getenv("DEBUGGING", default=False)
 if DEBUGGING:
     logging.getLogger(__name__).setLevel(logging.DEBUG)
@@ -60,9 +63,6 @@ def test_ticket49020(T):
 
     assert len(A_entries) == len(C_entries)
     assert len(B_entries) == len(A_entries) - 11
-    if DEBUGGING:
-        # Add debugging steps(if any)...
-        pass
 
 
 if __name__ == '__main__':
diff --git a/dirsrvtests/tests/tickets/ticket49073_test.py b/dirsrvtests/tests/tickets/ticket49073_test.py
index 79e98e0..d8ba082 100644
--- a/dirsrvtests/tests/tickets/ticket49073_test.py
+++ b/dirsrvtests/tests/tickets/ticket49073_test.py
@@ -3,6 +3,9 @@ from lib389.tasks import *
 from lib389.utils import *
 from lib389.topologies import topology_m2
 
+# Skip on older versions
+pytestmark = pytest.mark.skipif(ds_is_older('1.3.6'), reason="Not implemented")
+
 DEBUGGING = os.getenv('DEBUGGING', False)
 GROUP_DN = ("cn=group," + DEFAULT_SUFFIX)
 
diff --git a/dirsrvtests/tests/tickets/ticket49104_test.py b/dirsrvtests/tests/tickets/ticket49104_test.py
index 9840b1d..f215a6e 100644
--- a/dirsrvtests/tests/tickets/ticket49104_test.py
+++ b/dirsrvtests/tests/tickets/ticket49104_test.py
@@ -11,8 +11,11 @@ import subprocess
 
 import pytest
 from lib389.tasks import *
+from lib389.utils import *
 from lib389.topologies import topology_st
 
+# Skip on older versions
+pytestmark = pytest.mark.skipif(ds_is_older('1.3.6'), reason="Not implemented")
 log = logging.getLogger(__name__)
 
 def test_ticket49104_setup(topology_st):
diff --git a/dirsrvtests/tests/tickets/ticket49121_test.py b/dirsrvtests/tests/tickets/ticket49121_test.py
index 6450297..e754caa 100644
--- a/dirsrvtests/tests/tickets/ticket49121_test.py
+++ b/dirsrvtests/tests/tickets/ticket49121_test.py
@@ -13,6 +13,9 @@ from lib389.tasks import *
 from lib389.utils import *
 from lib389.topologies import topology_m2
 
+# Skip on older versions
+pytestmark = pytest.mark.skipif(ds_is_older('1.3.6'), reason="Not implemented")
+
 DEBUGGING = os.getenv('DEBUGGING', False)
 
 if DEBUGGING:
-- 
2.9.3

