From 88950b0d6379e7dc35d721e596a2bd363ebf8d1a Mon Sep 17 00:00:00 2001 From: Simon Pichugin Date: Jun 07 2018 13:37:35 +0000 Subject: Issue 49761 - Fix test suite issues Description: A lot of tests are failing because of the API changes. We need to fix them ASAP. Fix description: Add __init__.py to import and mapping_tree test suite so it will create its own __pycache__. Use the new Agriments object for reinit. Run range_search memory leak test only when ASAN is enabled and remove valgrind support because ASAN is enough. Generate ou=People and ou=Groups in the dbgen.py module, it is required by some tests. In the replica.py module, use existing credentials when we join master to the existing first_master and when we failed to get it from the ReplicationManager. https://pagure.io/389-ds-base/issue/49761 Reviewed by: mreynolds (Thanks!) --- diff --git a/dirsrvtests/tests/suites/import/__init__.py b/dirsrvtests/tests/suites/import/__init__.py new file mode 100644 index 0000000..8d1c8b6 --- /dev/null +++ b/dirsrvtests/tests/suites/import/__init__.py @@ -0,0 +1 @@ + diff --git a/dirsrvtests/tests/suites/mapping_tree/referral_during_tot_init_test.py b/dirsrvtests/tests/suites/mapping_tree/referral_during_tot_init_test.py index 83ad74a..53acfe0 100644 --- a/dirsrvtests/tests/suites/mapping_tree/referral_during_tot_init_test.py +++ b/dirsrvtests/tests/suites/mapping_tree/referral_during_tot_init_test.py @@ -10,6 +10,7 @@ import ldap import pytest from lib389.topologies import topology_m2 from lib389._constants import (DEFAULT_SUFFIX, HOST_MASTER_2, PORT_MASTER_2, TASK_WAIT) +from lib389.agreement import Agreements from lib389.idm.user import (TEST_USER_PROPERTIES, UserAccounts) @@ -41,7 +42,8 @@ def test_referral_during_tot(topology_m2): u = users.create(properties=TEST_USER_PROPERTIES) u.set('userPassword', 'password') # Now export them to master2 - master1.agreement.init(DEFAULT_SUFFIX, HOST_MASTER_2, PORT_MASTER_2) + agmts = Agreements(master1) + agmts.list()[0].begin_reinit() # While that's happening try to bind as a user to master 2 # This should trigger the referral code. diff --git a/dirsrvtests/tests/suites/memberof_plugin/__init__.py b/dirsrvtests/tests/suites/memberof_plugin/__init__.py new file mode 100644 index 0000000..8d1c8b6 --- /dev/null +++ b/dirsrvtests/tests/suites/memberof_plugin/__init__.py @@ -0,0 +1 @@ + diff --git a/dirsrvtests/tests/suites/memory_leaks/range_search_test.py b/dirsrvtests/tests/suites/memory_leaks/range_search_test.py index 93020d3..dc3ac24 100644 --- a/dirsrvtests/tests/suites/memory_leaks/range_search_test.py +++ b/dirsrvtests/tests/suites/memory_leaks/range_search_test.py @@ -9,50 +9,18 @@ import pytest from lib389.tasks import * from lib389.utils import * +from lib389.paths import Paths from lib389.topologies import topology_st - -from lib389._constants import (PLUGIN_RETRO_CHANGELOG, BACKEND_NAME, RETROCL_SUFFIX, - VALGRIND_LEAK_STR) +from lib389._constants import * logging.getLogger(__name__).setLevel(logging.DEBUG) log = logging.getLogger(__name__) +ds_paths = Paths() -@pytest.fixture(scope="module") -def setup(topology_st, request): - """Enable retro cl, and valgrind. Since valgrind tests move the ns-slapd binary - around it's important to always "valgrind_disable" before "assert False"ing, - otherwise we leave the wrong ns-slapd in place if there is a failure - """ - - log.info('Initializing test_range_search...') - - topology_st.standalone.plugins.enable(name=PLUGIN_RETRO_CHANGELOG) - - # First stop the instance - topology_st.standalone.stop(timeout=30) - - # Get the sbin directory so we know where to replace 'ns-slapd' - sbin_dir = get_sbin_dir(prefix=topology_st.standalone.prefix) - - # Enable valgrind - if not topology_st.standalone.has_asan(): - valgrind_enable(sbin_dir) - - def fin(): - if not topology_st.standalone.has_asan(): - topology_st.standalone.stop(timeout=30) - sbin_dir = topology_st.standalone.get_sbin_dir() - valgrind_disable(sbin_dir) - topology_st.standalone.start() - request.addfinalizer(fin) - - # Now start the server with a longer timeout - topology_st.standalone.start() - - -def test_range_search(topology_st, setup): +@pytest.mark.skipif(not ds_paths.asan_enabled, reason="Don't run if ASAN is not enabled") +def test_range_search(topology_st): """Add 100 entries, and run a range search. When we encounter an error we still need to disable valgrind before exiting @@ -62,15 +30,16 @@ def test_range_search(topology_st, setup): :steps: 1. Add 100 test entries 2. Issue a range search with a changenumber filter - 3. If the system doesn't have asan, get the valgrind results file, - stop the server, and check for the leak + 3. There should be no leak :expectedresults: 1. 100 test entries should be added 2. Search should be successful - 3. There should be no leak + 3. Success """ log.info('Running test_range_search...') + topology_st.standalone.plugins.enable(name=PLUGIN_RETRO_CHANGELOG) + topology_st.standalone.restart() success = True @@ -87,21 +56,10 @@ def test_range_search(topology_st, setup): time.sleep(1) # Issue range search - if success: - try: - topology_st.standalone.search_s(RETROCL_SUFFIX, ldap.SCOPE_SUBTREE, - '(&(changenumber>=74)(changenumber<=84))') - except ldap.LDAPError as e: - log.fatal('test_range_search: Failed to search retro changelog(%s), error: %s' % - (RETROCL_SUFFIX, e.message('desc'))) - success = False - if success and not topology_st.standalone.has_asan(): - # Get the results file, stop the server, and check for the leak - results_file = valgrind_get_results_file(topology_st.standalone) - topology_st.standalone.stop(timeout=30) - if valgrind_check_file(results_file, VALGRIND_LEAK_STR, 'range_candidates'): - log.fatal('test_range_search: Memory leak is still present!') - assert False + assert success + entries = topology_st.standalone.search_s(RETROCL_SUFFIX, ldap.SCOPE_SUBTREE, + '(&(changenumber>=74)(changenumber<=84))') + assert entries if __name__ == '__main__': diff --git a/src/lib389/lib389/dbgen.py b/src/lib389/lib389/dbgen.py index e0099a7..3da3e61 100644 --- a/src/lib389/lib389/dbgen.py +++ b/src/lib389/lib389/dbgen.py @@ -71,6 +71,8 @@ DBGEN_OUS = [ "Product Testing", "Human Resources", "Payroll", +"People", +"Groups", ] DBGEN_TEMPLATE = """dn: {DN} diff --git a/src/lib389/lib389/replica.py b/src/lib389/lib389/replica.py index 29a1e2f..5b28b01 100644 --- a/src/lib389/lib389/replica.py +++ b/src/lib389/lib389/replica.py @@ -1661,12 +1661,24 @@ class ReplicationManager(object): """ rdn = '{}:{}'.format(from_instance.host, from_instance.sslport) - creds = self._repl_creds[rdn] + try: + creds = self._repl_creds[rdn] + except KeyError: + # okay, re-use the creds + fr_replicas = Replicas(from_instance) + fr_r = fr_replicas.get(self._suffix) + from_agmts = fr_r.get_agreements() + agmts = from_agmts.list() + + assert len(agmts) > 0, "from_instance agreement is not found and credentials are not present \ + in ReplicationManager. You should call create_first_master first." + agmt = agmts[0] + creds = agmt.get_attr_val_utf8('nsDS5ReplicaCredentials') services = ServiceAccounts(write_instance, self._suffix) sa_dn = services.get(rdn).dn - return (sa_dn, creds) + return sa_dn, creds def ensure_agreement(self, from_instance, to_instance, init=False): """Guarantee that a replication agreement exists 'from_instance' send