From b733e54e14622a58e4a53f8ce7038c617af2281b Mon Sep 17 00:00:00 2001 From: William Brown Date: Wed, 8 Nov 2017 13:23:59 +1000 Subject: [PATCH] Ticket 3 lib389 - python 3 support ds_logs tests Bug Description: Support python 3 for the ds logs tests Fix Description: Fix the logs test to use DSLdapObjects correctly. Change the doc string on DSLdapObjects.get to reflect it's use with "*", as well as correct how it searches attrs. https://pagure.io/lib389/issue/3 Author: wibrown Review by: ??? --- dirsrvtests/tests/suites/ds_logs/ds_logs_test.py | 58 +++++++++--------------- src/lib389/lib389/_mapped_object.py | 4 +- 2 files changed, 24 insertions(+), 38 deletions(-) diff --git a/dirsrvtests/tests/suites/ds_logs/ds_logs_test.py b/dirsrvtests/tests/suites/ds_logs/ds_logs_test.py index fb73a22..cfea0d2 100644 --- a/dirsrvtests/tests/suites/ds_logs/ds_logs_test.py +++ b/dirsrvtests/tests/suites/ds_logs/ds_logs_test.py @@ -13,6 +13,8 @@ from lib389.tasks import * from lib389.utils import * from lib389.topologies import topology_st +from lib389.idm.user import UserAccounts + logging.getLogger(__name__).setLevel(logging.DEBUG) log = logging.getLogger(__name__) @@ -21,42 +23,24 @@ USER1_DN = 'uid=user1,' + DEFAULT_SUFFIX def add_users(topology_st, users_num): - """Add users to the default suffix""" - - users_list = [] + users = UserAccounts(topology_st, DEFAULT_SUFFIX) log.info('Adding %d users' % users_num) - for num in sample(range(1000), users_num): - num_ran = int(round(num)) - USER_NAME = 'test%05d' % num_ran - USER_DN = 'uid=%s,%s' % (USER_NAME, DEFAULT_SUFFIX) - users_list.append(USER_DN) - try: - topology_st.standalone.add_s(Entry((USER_DN, { - 'objectclass': 'top person'.split(), - 'objectclass': 'organizationalPerson', - 'objectclass': 'inetorgperson', - 'cn': USER_NAME, - 'sn': USER_NAME, - 'userpassword': 'pass%s' % num_ran, - 'mail': '%s@redhat.com' % USER_NAME, - 'uid': USER_NAME - }))) - except ldap.LDAPError as e: - log.error('Failed to add user (%s): error (%s)' % (USER_DN, - e.message['desc'])) - raise e - + for i in range(0, users_num): + uid = 1000 + i + users.create(properties={ + 'uid': 'testuser%d' % uid, + 'cn' : 'testuser%d' % uid, + 'sn' : 'user', + 'uidNumber' : '%d' % uid, + 'gidNumber' : '%d' % uid, + 'homeDirectory' : '/home/testuser%d' % uid + }) def search_users(topology_st): - try: - entries = topology_st.standalone.search_s(DEFAULT_SUFFIX, ldap.SCOPE_SUBTREE, '(cn=*)', ['cn']) - for entry in entries: - if 'user1' in entry.data['cn']: - log.info('Search found "user1"') - - except ldap.LDAPError as e: - log.fatal('Search failed, error: ' + e.message['desc']) - raise e + users = UserAccounts(topology_st, DEFAULT_SUFFIX) + entries = users.list() + # We just assert we got some data ... + assert len(entries) > 0 @pytest.mark.bz1273549 def test_check_default(topology_st): @@ -77,7 +61,7 @@ def test_check_default(topology_st): """ # Get the default value of nsslapd-logging-hr-timestamps-enabled attribute - default = topology_st.standalone.config.get_attr_val(PLUGIN_TIMESTAMP) + default = topology_st.standalone.config.get_attr_val_utf8(PLUGIN_TIMESTAMP) # Now check it should be ON by default assert (default == "on") @@ -127,8 +111,8 @@ def test_log_plugin_on(topology_st): log.info('Bug 1273549 - Check access logs for millisecond, when attribute is ON') log.info('perform any ldap operation, which will trigger the logs') - add_users(topology_st, 100) - search_users(topology_st) + add_users(topology_st.standalone, 10) + search_users(topology_st.standalone) log.info('Restart the server to flush the logs') topology_st.standalone.restart(timeout=10) @@ -176,7 +160,7 @@ def test_log_plugin_off(topology_st): topology_st.standalone.deleteAccessLogs() # Now generate some fresh logs - search_users(topology_st) + search_users(topology_st.standalone) log.info('Restart the server to flush the logs') topology_st.standalone.restart(timeout=10) diff --git a/src/lib389/lib389/_mapped_object.py b/src/lib389/lib389/_mapped_object.py index ae0cbe0..c898648 100644 --- a/src/lib389/lib389/_mapped_object.py +++ b/src/lib389/lib389/_mapped_object.py @@ -776,9 +776,11 @@ class DSLdapObjects(DSLogging): """Get a child entry (DSLdapObject, Replica, etc.) with dn or selector using a base DN and objectClasses of our object (DSLdapObjects, Replicas, etc.) + Note that * is not a valid selector, you should use "list()" instead. + :param dn: DN of wanted entry :type dn: str - :param selector: An additional filter to objectClasses, i.e. 'backend_name' + :param selector: An additional filter to search for, i.e. 'backend_name'. The attributes selected are based on object type, ie user will search for uid and cn. :type dn: str :returns: A child entry -- 1.8.3.1