From 15789e895c4b976774dc3cb3ba5e64f23bcd8c3b Mon Sep 17 00:00:00 2001 From: Viktor Ashirov Date: Nov 12 2019 10:11:27 +0000 Subject: Issue 49761 - Fix CI test suite issues Description: Fix various test issues on RHEL7 and RHEL8: * systemd on RHEL7 doesn't have --value option. Drop --value option and parse the output manually. * Use newer BDB config only on 1.4.2+. * Skip tests/suites/password/pbkdf2_upgrade_plugin_test.py on <1.4.1. * Unhashed passwords are not logged by default only on 1.4.1.6+. * String literal comparison doesn't work with double digits, i.e. '1.3.10.1' > '1.3.2.1' returns False. Use packaging.version to compare versions. * Don't use nsAccount objectClass on versions <=1.4.x. * Update skipif/xfail version to match downstream versions too. Relates: https://pagure.io/389-ds-base/issue/49761 Reviewed by: firstyear (Thanks!) --- diff --git a/dirsrvtests/tests/suites/automember_plugin/basic_test.py b/dirsrvtests/tests/suites/automember_plugin/basic_test.py index 1fd34f5..d9bfe7c 100644 --- a/dirsrvtests/tests/suites/automember_plugin/basic_test.py +++ b/dirsrvtests/tests/suites/automember_plugin/basic_test.py @@ -11,6 +11,8 @@ Will test AutoMememer Plugin with AotoMember Task and Retro Changelog """ import os +import ldap +import pytest from lib389.topologies import topology_m1 as topo from lib389.idm.organizationalunit import OrganizationalUnits from lib389.idm.domain import Domain @@ -20,9 +22,8 @@ from lib389.plugins import AutoMembershipPlugin, AutoMembershipDefinitions, \ from lib389.backend import Backends from lib389.config import Config from lib389._constants import DEFAULT_SUFFIX -import ldap -import pytest from lib389.idm.group import Groups, Group, UniqueGroup, nsAdminGroups, nsAdminGroup +from lib389.utils import ds_is_older pytestmark = pytest.mark.tier1 @@ -72,6 +73,11 @@ def add_user(topo, user_id, suffix, uid_no, gid_no, role_usr): """ Will create entries with nsAdminGroup objectclass """ + objectclasses = ['top', 'person', 'posixaccount', 'inetuser', + 'nsMemberOf', 'nsAccount', 'nsAdminGroup'] + if ds_is_older('1.4.0'): + objectclasses.remove('nsAccount') + user = nsAdminGroups(topo.ms["master1"], suffix, rdn=None).create(properties={ 'cn': user_id, 'sn': user_id, @@ -80,8 +86,7 @@ def add_user(topo, user_id, suffix, uid_no, gid_no, role_usr): 'loginShell': '/bin/bash', 'uidNumber': uid_no, 'gidNumber': gid_no, - 'objectclass': ['top', 'person', 'posixaccount', 'inetuser', - 'nsMemberOf', 'nsAccount', 'nsAdminGroup'], + 'objectclass': objectclasses, 'nsAdminGroupName': role_usr, 'seeAlso': 'uid={},{}'.format(user_id, suffix), 'entrydn': 'uid={},{}'.format(user_id, suffix) diff --git a/dirsrvtests/tests/suites/basic/basic_test.py b/dirsrvtests/tests/suites/basic/basic_test.py index b1edfd2..156e205 100644 --- a/dirsrvtests/tests/suites/basic/basic_test.py +++ b/dirsrvtests/tests/suites/basic/basic_test.py @@ -624,7 +624,7 @@ search_params = [(['1.1'], 'cn', False), (['+'], 'nsUniqueId', True), (['*'], 'cn', True), (['cn'], 'cn', True)] -@pytest.mark.skipif(ds_is_older("1.4.1.6"), reason="Not implemented") +@pytest.mark.skipif(ds_is_older("1.4.2.0"), reason="Not implemented") @pytest.mark.parametrize("attrs, attr, present", search_params) def test_search_req_attrs(topology_st, add_test_entry, attrs, attr, present): """Test requested attributes in search operations. @@ -1355,7 +1355,7 @@ sample_entries = yes return inst -@pytest.mark.skipif(not get_user_is_root() or not default_paths.perl_enabled or ds_is_older('1.4.0.0'), +@pytest.mark.skipif(not get_user_is_root() or not default_paths.perl_enabled or ds_is_older('1.4.2.0'), reason="This test is only required with new admin cli, and requires root.") @pytest.mark.bz1748016 @pytest.mark.ds50581 diff --git a/dirsrvtests/tests/suites/config/autotuning_test.py b/dirsrvtests/tests/suites/config/autotuning_test.py index f27d0ea..f40046e 100644 --- a/dirsrvtests/tests/suites/config/autotuning_test.py +++ b/dirsrvtests/tests/suites/config/autotuning_test.py @@ -124,11 +124,17 @@ def test_cache_autosize_non_zero(topo, autosize, autosize_split): cachesize = '33333333' - dbcachesize_val = bdb_config_ldbm.get_attr_val('nsslapd-dbcachesize') + if ds_is_older('1.4.2'): + dbcachesize_val = config_ldbm.get_attr_val('nsslapd-dbcachesize') + autosize_val = config_ldbm.get_attr_val('nsslapd-cache-autosize') + autosize_split_val = config_ldbm.get_attr_val('nsslapd-cache-autosize-split') + else: + dbcachesize_val = bdb_config_ldbm.get_attr_val('nsslapd-dbcachesize') + autosize_val = bdb_config_ldbm.get_attr_val('nsslapd-cache-autosize') + autosize_split_val = bdb_config_ldbm.get_attr_val('nsslapd-cache-autosize-split') + cachenensize_val = userroot_ldbm.get_attr_val('nsslapd-cachememsize') dncachenensize_val = userroot_ldbm.get_attr_val('nsslapd-dncachememsize') - autosize_val = bdb_config_ldbm.get_attr_val('nsslapd-cache-autosize') - autosize_split_val = bdb_config_ldbm.get_attr_val('nsslapd-cache-autosize-split') log.info("Check nsslapd-dbcachesize and nsslapd-cachememsize before the test") log.info("nsslapd-dbcachesize == {}".format(dbcachesize_val)) @@ -165,11 +171,17 @@ def test_cache_autosize_non_zero(topo, autosize, autosize_split): config_ldbm.set('nsslapd-dbcachesize ', cachesize) topo.standalone.restart() - dbcachesize_val = bdb_config_ldbm.get_attr_val('nsslapd-dbcachesize') + if ds_is_older('1.4.2'): + dbcachesize_val = config_ldbm.get_attr_val('nsslapd-dbcachesize') + autosize_val = config_ldbm.get_attr_val('nsslapd-cache-autosize') + autosize_split_val = config_ldbm.get_attr_val('nsslapd-cache-autosize-split') + else: + dbcachesize_val = bdb_config_ldbm.get_attr_val('nsslapd-dbcachesize') + autosize_val = bdb_config_ldbm.get_attr_val('nsslapd-cache-autosize') + autosize_split_val = bdb_config_ldbm.get_attr_val('nsslapd-cache-autosize-split') + cachenensize_val = userroot_ldbm.get_attr_val('nsslapd-cachememsize') dncachenensize_val = userroot_ldbm.get_attr_val('nsslapd-dncachememsize') - autosize_val = bdb_config_ldbm.get_attr_val('nsslapd-cache-autosize') - autosize_split_val = bdb_config_ldbm.get_attr_val('nsslapd-cache-autosize-split') log.info("Check nsslapd-dbcachesize and nsslapd-cachememsize in the appropriate range.") log.info("nsslapd-dbcachesize == {}".format(dbcachesize_val)) @@ -215,11 +227,17 @@ def test_cache_autosize_basic_sane(topo, autosize_split): # Test with caches with both real values and 0 for cachesize in ('0', '33333333'): - dbcachesize_val = bdb_config_ldbm.get_attr_val('nsslapd-dbcachesize') + if ds_is_older('1.4.2'): + dbcachesize_val = config_ldbm.get_attr_val('nsslapd-dbcachesize') + autosize_val = config_ldbm.get_attr_val('nsslapd-cache-autosize') + autosize_split_val = config_ldbm.get_attr_val('nsslapd-cache-autosize-split') + else: + dbcachesize_val = bdb_config_ldbm.get_attr_val('nsslapd-dbcachesize') + autosize_val = bdb_config_ldbm.get_attr_val('nsslapd-cache-autosize') + autosize_split_val = bdb_config_ldbm.get_attr_val('nsslapd-cache-autosize-split') + cachenensize_val = userroot_ldbm.get_attr_val('nsslapd-cachememsize') dncachenensize_val = userroot_ldbm.get_attr_val('nsslapd-dncachememsize') - autosize_val = bdb_config_ldbm.get_attr_val('nsslapd-cache-autosize') - autosize_split_val = bdb_config_ldbm.get_attr_val('nsslapd-cache-autosize-split') log.info("Check nsslapd-dbcachesize and nsslapd-cachememsize before the test") log.info("nsslapd-dbcachesize == {}".format(dbcachesize_val)) @@ -243,11 +261,17 @@ def test_cache_autosize_basic_sane(topo, autosize_split): userroot_ldbm.set('nsslapd-cachememsize', cachesize) topo.standalone.restart() - dbcachesize_val = bdb_config_ldbm.get_attr_val('nsslapd-dbcachesize') + if ds_is_older('1.4.2'): + dbcachesize_val = config_ldbm.get_attr_val('nsslapd-dbcachesize') + autosize_val = config_ldbm.get_attr_val('nsslapd-cache-autosize') + autosize_split_val = config_ldbm.get_attr_val('nsslapd-cache-autosize-split') + else: + dbcachesize_val = bdb_config_ldbm.get_attr_val('nsslapd-dbcachesize') + autosize_val = bdb_config_ldbm.get_attr_val('nsslapd-cache-autosize') + autosize_split_val = bdb_config_ldbm.get_attr_val('nsslapd-cache-autosize-split') + cachenensize_val = userroot_ldbm.get_attr_val('nsslapd-cachememsize') dncachenensize_val = userroot_ldbm.get_attr_val('nsslapd-dncachememsize') - autosize_val = bdb_config_ldbm.get_attr_val('nsslapd-cache-autosize') - autosize_split_val = bdb_config_ldbm.get_attr_val('nsslapd-cache-autosize-split') log.info("Check nsslapd-dbcachesize and nsslapd-cachememsize in the appropriate range.") log.info("nsslapd-dbcachesize == {}".format(dbcachesize_val)) @@ -280,8 +304,12 @@ def test_cache_autosize_invalid_values(topo, invalid_value): config_ldbm = DSLdapObject(topo.standalone, DN_CONFIG_LDBM) bdb_config_ldbm = DSLdapObject(topo.standalone, DN_CONFIG_LDBM_BDB) - autosize_val = bdb_config_ldbm.get_attr_val('nsslapd-cache-autosize') - autosize_split_val = bdb_config_ldbm.get_attr_val('nsslapd-cache-autosize-split') + if ds_is_older('1.4.2'): + autosize_val = config_ldbm.get_attr_val('nsslapd-cache-autosize') + autosize_split_val = config_ldbm.get_attr_val('nsslapd-cache-autosize-split') + else: + autosize_val = bdb_config_ldbm.get_attr_val('nsslapd-cache-autosize') + autosize_split_val = bdb_config_ldbm.get_attr_val('nsslapd-cache-autosize-split') log.info("Set nsslapd-cache-autosize-split to {}".format(invalid_value)) with pytest.raises(ldap.UNWILLING_TO_PERFORM): diff --git a/dirsrvtests/tests/suites/config/config_test.py b/dirsrvtests/tests/suites/config/config_test.py index e9e5bf3..02c767b 100644 --- a/dirsrvtests/tests/suites/config/config_test.py +++ b/dirsrvtests/tests/suites/config/config_test.py @@ -146,13 +146,21 @@ def test_config_deadlock_policy(topology_m2): ldbmconfig = LDBMConfig(topology_m2.ms["master1"]) bdbconfig = BDB_LDBMConfig(topology_m2.ms["master1"]) - deadlock_policy = bdbconfig.get_attr_val_bytes('nsslapd-db-deadlock-policy') + if ds_is_older('1.4.2'): + deadlock_policy = ldbmconfig.get_attr_val_bytes('nsslapd-db-deadlock-policy') + else: + deadlock_policy = bdbconfig.get_attr_val_bytes('nsslapd-db-deadlock-policy') + assert deadlock_policy == default_val # Try a range of valid values for val in (b'0', b'5', b'9'): ldbmconfig.replace('nsslapd-db-deadlock-policy', val) - deadlock_policy = bdbconfig.get_attr_val_bytes('nsslapd-db-deadlock-policy') + if ds_is_older('1.4.2'): + deadlock_policy = ldbmconfig.get_attr_val_bytes('nsslapd-db-deadlock-policy') + else: + deadlock_policy = bdbconfig.get_attr_val_bytes('nsslapd-db-deadlock-policy') + assert deadlock_policy == val # Try a range of invalid values diff --git a/dirsrvtests/tests/suites/ds_logs/ds_logs_test.py b/dirsrvtests/tests/suites/ds_logs/ds_logs_test.py index c8f7ef0..31e984a 100644 --- a/dirsrvtests/tests/suites/ds_logs/ds_logs_test.py +++ b/dirsrvtests/tests/suites/ds_logs/ds_logs_test.py @@ -641,7 +641,7 @@ def test_internal_log_level_516(topology_st, add_user_log_level_516): assert topo.ds_access_log.match(r'.*conn=Internal\([0-9]+\) op=[0-9]+\([0-9]+\)\([0-9]+\).*') -@pytest.mark.skipif(ds_is_older('1.4.1.4'), reason="Not implemented") +@pytest.mark.skipif(ds_is_older('1.4.2.0'), reason="Not implemented") @pytest.mark.bz1358706 @pytest.mark.ds49232 def test_access_log_truncated_search_message(topology_st, clean_access_logs): @@ -678,7 +678,7 @@ def test_access_log_truncated_search_message(topology_st, clean_access_logs): -@pytest.mark.xfail(ds_is_older('1.4.1.6'), reason="May fail because of bug 1732053") +@pytest.mark.xfail(ds_is_older('1.4.2.0'), reason="May fail because of bug 1732053") @pytest.mark.bz1732053 @pytest.mark.ds50510 def test_etime_at_border_of_second(topology_st, clean_access_logs): 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 a29b33f..24a0855 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 @@ -18,6 +18,7 @@ from lib389.dbgen import dbgen pytestmark = pytest.mark.tier1 +@pytest.mark.skipif(ds_is_older("1.4.0.0"), reason="Not implemented") def test_referral_during_tot(topology_m2): master1 = topology_m2.ms["master1"] diff --git a/dirsrvtests/tests/suites/password/pbkdf2_upgrade_plugin_test.py b/dirsrvtests/tests/suites/password/pbkdf2_upgrade_plugin_test.py index ca69fb4..90dae36 100644 --- a/dirsrvtests/tests/suites/password/pbkdf2_upgrade_plugin_test.py +++ b/dirsrvtests/tests/suites/password/pbkdf2_upgrade_plugin_test.py @@ -9,9 +9,11 @@ import pytest from lib389.topologies import topology_st from lib389.password_plugins import PBKDF2Plugin +from lib389.utils import ds_is_older pytestmark = pytest.mark.tier1 +@pytest.mark.skipif(ds_is_older('1.4.1'), reason="Not implemented") def test_pbkdf2_upgrade(topology_st): """On upgrade pbkdf2 doesn't ship. We need to be able to provide this on upgrade to make sure default hashes work. diff --git a/dirsrvtests/tests/suites/password/regression_test.py b/dirsrvtests/tests/suites/password/regression_test.py index c239799..93570f9 100644 --- a/dirsrvtests/tests/suites/password/regression_test.py +++ b/dirsrvtests/tests/suites/password/regression_test.py @@ -12,7 +12,7 @@ from lib389._constants import SUFFIX, PASSWORD, DN_DM, DN_CONFIG, PLUGIN_RETRO_C from lib389 import Entry from lib389.topologies import topology_m1 as topo_master from lib389.idm.user import UserAccounts -from lib389.utils import ldap, os, logging, ensure_bytes +from lib389.utils import ldap, os, logging, ensure_bytes, ds_is_newer from lib389.topologies import topology_st as topo from lib389.idm.organizationalunit import OrganizationalUnits @@ -40,7 +40,7 @@ TEST_PASSWORDS2 = ( 'CN12pwtest31', 'SN3pwtest231', 'UID1pwtest123', 'MAIL2pwtest12@redhat.com', '2GN1pwtest123', 'People123') def _check_unhashed_userpw(inst, user_dn, is_present=False): - """Check if unhashed#user#password attribute is present of not in the changelog""" + """Check if unhashed#user#password attribute is present or not in the changelog""" unhashed_pwd_attribute = 'unhashed#user#password' changelog_dbdir = os.path.join(os.path.dirname(inst.dbdir), DEFAULT_CHANGELOG_DB) @@ -274,13 +274,16 @@ def test_unhashed_pw_switch(topo_master): log.fatal('Failed to add user (%s): error %s' % (USER_DN, e.message['desc'])) assert False - # Check default is that unhashed#user#password is not logged + # Check default is that unhashed#user#password is not logged on 1.4.1.6+ user = "uid=member1,%s" % (PEOPLE_DN) inst.modify_s(user, [(ldap.MOD_REPLACE, 'userpassword', PASSWORD.encode())]) inst.stop() - _check_unhashed_userpw(inst, user, is_present=False) + if ds_is_newer('1.4.1.6'): + _check_unhashed_userpw(inst, user, is_present=False) + else: + _check_unhashed_userpw(inst, user, is_present=True) # Check with nolog that unhashed#user#password is not logged inst.modify_s(DN_CONFIG, diff --git a/dirsrvtests/tests/suites/resource_limits/fdlimits_test.py b/dirsrvtests/tests/suites/resource_limits/fdlimits_test.py index bd2b1e7..1a2f547 100644 --- a/dirsrvtests/tests/suites/resource_limits/fdlimits_test.py +++ b/dirsrvtests/tests/suites/resource_limits/fdlimits_test.py @@ -15,7 +15,7 @@ log = logging.getLogger(__name__) FD_ATTR = "nsslapd-maxdescriptors" GLOBAL_LIMIT = resource.getrlimit(resource.RLIMIT_NOFILE)[1] -SYSTEMD_LIMIT = ensure_str(check_output("systemctl show --value -p LimitNOFILE dirsrv@standalone1".split(" ")).strip()) +SYSTEMD_LIMIT = ensure_str(check_output("systemctl show -p LimitNOFILE dirsrv@standalone1".split(" ")).strip()).split('=')[1] CUSTOM_VAL = str(int(SYSTEMD_LIMIT) - 10) TOO_HIGH_VAL = str(GLOBAL_LIMIT * 2) TOO_HIGH_VAL2 = str(int(SYSTEMD_LIMIT) * 2) diff --git a/src/lib389/lib389/utils.py b/src/lib389/lib389/utils.py index c271d86..e817468 100644 --- a/src/lib389/lib389/utils.py +++ b/src/lib389/lib389/utils.py @@ -39,6 +39,7 @@ import six import shlex import operator import subprocess +from packaging import version from socket import getfqdn from ldapurl import LDAPUrl from contextlib import closing @@ -1075,9 +1076,9 @@ def ds_is_related(relation, *ver): if len(ver) > 1: for cmp_ver in ver: if cmp_ver.startswith(ds_ver[:3]): - return ops[relation](ds_ver,cmp_ver) + return ops[relation](version.parse(ds_ver),version.parse(cmp_ver)) else: - return ops[relation](ds_ver, ver[0]) + return ops[relation](version.parse(ds_ver), version.parse(ver[0])) def ds_is_older(*ver):