From a81d8854331153519d77d4c96cb02500f5e52773 Mon Sep 17 00:00:00 2001 From: Sankar Ramalingam Date: Mon, 21 Aug 2017 12:56:38 +0530 Subject: [PATCH] Ticket #48067 - Add bugzilla tests for ds_logs Description: Adding regression tests for error log level. Also changing the import calls to import only required variables and functions. Add user function is also changed to use UserAccounts. https://pagure.io/389-ds-base/issue/48067 Reviewed by: ? --- dirsrvtests/tests/suites/ds_logs/ds_logs_test.py | 146 +++++++++++++++-------- 1 file changed, 97 insertions(+), 49 deletions(-) diff --git a/dirsrvtests/tests/suites/ds_logs/ds_logs_test.py b/dirsrvtests/tests/suites/ds_logs/ds_logs_test.py index e052112..086fc26 100644 --- a/dirsrvtests/tests/suites/ds_logs/ds_logs_test.py +++ b/dirsrvtests/tests/suites/ds_logs/ds_logs_test.py @@ -9,47 +9,50 @@ from random import sample import pytest -from lib389.tasks import * -from lib389.utils import * -from lib389.topologies import topology_st - -logging.getLogger(__name__).setLevel(logging.DEBUG) +from lib389.dseldif import DSEldif +from lib389.idm.user import UserAccounts +from lib389._constants import SUFFIX, DN_CONFIG +from lib389.utils import ldap, os, logging, time +from lib389.topologies import topology_st as topo + +DEBUGGING = os.getenv("DEBUGGING", default=False) +if DEBUGGING: + logging.getLogger(__name__).setLevel(logging.DEBUG) +else: + logging.getLogger(__name__).setLevel(logging.INFO) log = logging.getLogger(__name__) PLUGIN_TIMESTAMP = 'nsslapd-logging-hr-timestamps-enabled' -USER1_DN = 'uid=user1,' + DEFAULT_SUFFIX +USER1_DN = 'uid=user1,' + SUFFIX +DEFAULT_LEVEL = "16384" +COMB_LEVEL = "73864" # 65536+8192+128+8 = 73864 +COMB_DEFAULT_LEVEL = "90248" # 65536+8192+128+8+16384 = 90248 -def add_users(topology_st, users_num): +def add_users(topo, users_num): """Add users to the default suffix""" - users_list = [] - log.info('Adding %d users' % users_num) + log.info('Adding {} users'.format(users_num)) + users = UserAccounts(topo.standalone, SUFFIX) 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 - - -def search_users(topology_st): + USER_NAME = 'test{:0>5}'.format(num_ran) + USER_DN = 'uid={},{}'.format(USER_NAME, SUFFIX) + user_properties = { + 'uid': USER_NAME, + 'cn': USER_NAME, + 'sn': USER_NAME, + 'uidNumber': '1001', + 'gidNumber': '2001', + 'userpassword': 'pass{}'.format(num_ran), + 'mail': '{}@redhat.com'.format(USER_NAME), + 'homeDirectory': '/home/{}'.format(USER_NAME, )} + users.create(properties=user_properties) + + +def search_users(topo): try: - entries = topology_st.standalone.search_s(DEFAULT_SUFFIX, ldap.SCOPE_SUBTREE, '(cn=*)', ['cn']) + entries = topo.standalone.search_s(SUFFIX, ldap.SCOPE_SUBTREE, '(cn=*)', ['cn']) for entry in entries: if 'user1' in entry.data['cn']: log.info('Search found "user1"') @@ -59,7 +62,7 @@ def search_users(topology_st): raise e -def test_check_default(topology_st): +def test_check_default(topo): """Bug 1273549 - Check the default value of nsslapd-logging-hr-timestamps-enabled, it should be ON """ @@ -67,62 +70,107 @@ def test_check_default(topology_st): log.info('Check the default value of nsslapd-logging-hr-timestamps-enabled, it should be ON') # Get the default value of nsslapd-logging-hr-timestamps-enabled attribute - default = topology_st.standalone.config.get_attr_val(PLUGIN_TIMESTAMP) + default = topo.standalone.config.get_attr_val(PLUGIN_TIMESTAMP) # Now check it should be ON by default assert (default == "on") log.debug(default) -def test_plugin_set_invalid(topology_st): +def test_plugin_set_invalid(topo): """Bug 1273549 - Try to set some invalid values for the newly added attribute""" log.info('test_plugin_set_invalid - Expect to fail with junk value') with pytest.raises(ldap.OPERATIONS_ERROR): - result = topology_st.standalone.config.set(PLUGIN_TIMESTAMP, 'JUNK') + result = topo.standalone.config.set(PLUGIN_TIMESTAMP, 'JUNK') -def test_log_plugin_on(topology_st): +def test_log_plugin_on(topo): """Bug 1273549 - Check access logs for milisecond, when attribute is ON""" log.info('Bug 1273549 - Check access logs for milisecond, 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(topo, 100) + search_users(topo) log.info('Restart the server to flush the logs') - topology_st.standalone.restart(timeout=10) + topo.standalone.restart(timeout=10) log.info('parse the access logs') - access_log_lines = topology_st.standalone.ds_access_log.readlines() + access_log_lines = topo.standalone.ds_access_log.readlines() assert len(access_log_lines) > 0 - assert topology_st.standalone.ds_access_log.match('^\[.+\d{9}.+\].+') + assert topo.standalone.ds_access_log.match('^\[.+\d{9}.+\].+') -def test_log_plugin_off(topology_st): +def test_log_plugin_off(topo): """Bug 1273549 - Check access logs for missing milisecond, when attribute is OFF""" log.info('Bug 1273549 - Check access logs for missing milisecond, when attribute is OFF') log.info('test_log_plugin_off - set the configuraton attribute to OFF') - topology_st.standalone.config.set(PLUGIN_TIMESTAMP, 'OFF') + topo.standalone.config.set(PLUGIN_TIMESTAMP, 'OFF') log.info('Restart the server to flush the logs') - topology_st.standalone.restart(timeout=10) + topo.standalone.restart(timeout=10) log.info('test_log_plugin_off - delete the privious access logs') - topology_st.standalone.deleteAccessLogs() + topo.standalone.deleteAccessLogs() # Now generate some fresh logs - search_users(topology_st) + search_users(topo) log.info('Restart the server to flush the logs') - topology_st.standalone.restart(timeout=10) + topo.standalone.restart(timeout=10) log.info('check access log that microseconds are not present') - access_log_lines = topology_st.standalone.ds_access_log.readlines() + access_log_lines = topo.standalone.ds_access_log.readlines() assert len(access_log_lines) > 0 - assert not topology_st.standalone.ds_access_log.match('^\[.+\d{9}.+\].+') + assert not topo.standalone.ds_access_log.match('^\[.+\d{9}.+\].+') + + +@pytest.mark.bz1460718 +@pytest.mark.parametrize("log_level", [DEFAULT_LEVEL, COMB_LEVEL, COMB_DEFAULT_LEVEL]) +def test_error_log_reset(topo, log_level): + """ The default log level 16384 is stripped from the log level returned to a client + + :id: c300f8f1-aa11-4621-b124-e2be51930a6b + :feature: Logging + :setup: Standalone instance + :steps: 1. Change the error log level to the default and custom value. + 2. Check if the server returns the new value. + :expectedresults: + 1. Changing the error log level should be successful. + 2. Server should return the new log level. + """ + + assert topo.standalone.config.set('nsslapd-errorlog-level', str(log_level)) + assert topo.standalone.config.get_attr_val('nsslapd-errorlog-level') == log_level + + +@pytest.mark.bz1460718 +def test_dse_error_log(topo): + """ Manually setting nsslapd-errorlog-level in dse.ldif throws error + + :id: 0eeefa17-ec1c-4208-8e7b-44d8fbc38f10 + :feature: Logging + :setup: Standalone instance + :steps: 1. Stop the server, edit dse.ldif file and change nsslapd-errorlog-level value to 64 + 2. Start the server and observe the error logs. + :expectedresults: + 1. Server should be successfully stopped and nsslapd-errorlog-level value should be changed. + 2. Server should be successfully started without any errors being reported in the logs. + """ + + topo.standalone.stop(timeout=10) + dse_ldif = DSEldif(topo.standalone) + try: + dse_ldif.replace(DN_CONFIG, 'nsslapd-errorlog-level', 64) + except: + log.error('Failed to replace cn=config values of nsslapd-errorlog-level') + raise + topo.standalone.start(timeout=10) + assert not topo.standalone.ds_error_log.match( + '.*nsslapd-errorlog-level: ignoring 64 \\(since -d 266354688 was given on the command line\\).*') if __name__ == '__main__': -- 2.7.4