Skip to content

Commit

Permalink
Fixing testcases
Browse files Browse the repository at this point in the history
  • Loading branch information
tbordaz committed Sep 18, 2024
1 parent 1de4904 commit 760cb30
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 115 deletions.
24 changes: 16 additions & 8 deletions dirsrvtests/tests/suites/automember_plugin/automember_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,9 @@ def test_delete_default_group(automember_fixture, topo):
from lib389.plugins import MemberOfPlugin
memberof = MemberOfPlugin(topo.standalone)
if (memberof.get_memberofdeferredupdate() and memberof.get_memberofdeferredupdate().lower() == "on"):
delay = 10 # to avoid any risk of transient failure
tries = 10 # to avoid any risk of transient failure
else:
delay = 0
tries = 1
memberof.enable()
topo.standalone.restart()
topo.standalone.setLogLevel(65536)
Expand All @@ -187,12 +187,20 @@ def test_delete_default_group(automember_fixture, topo):
try:
assert group.is_member(user_1.dn)
group.delete()
time.sleep(delay)
error_lines = topo.standalone.ds_error_log.match('.*auto-membership-plugin - automember_update_member_value - group .default or target. does not exist .%s.$' % group.dn)
log.info("len(error_lines)=%d" % len(error_lines))
for i in error_lines:
log.info(" - %s" % i)
assert (len(error_lines) == 1)
# Check there is the expected message
while tries > 0:
error_lines = topo.standalone.ds_error_log.match('.*auto-membership-plugin - automember_update_member_value - group .default or target. does not exist .%s.$' % group.dn)
nb_match = len(error_lines)
log.info("len(error_lines)=%d" % nb_match)
for i in error_lines:
log.info(" - %s" % i)
assert nb_match <= 1
if (nb_match == 1):
# we are done the test is successful
break
time.sleep(1)
tries -= 1
assert tries > 0
finally:
user_1.delete()
topo.standalone.setLogLevel(0)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# --- BEGIN COPYRIGHT BLOCK ---
# Copyright (C) 2023 Red Hat, Inc.
# Copyright (C) 2024 Red Hat, Inc.
# All rights reserved.
#
# License: GPL (version 3 or any later version).
Expand Down
37 changes: 12 additions & 25 deletions dirsrvtests/tests/suites/memberof_plugin/regression_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -688,12 +688,9 @@ def test_entrycache_on_modrdn_failure(topology_st):
topology_st.standalone.restart(timeout=10)

if (memberof.get_memberofdeferredupdate() and memberof.get_memberofdeferredupdate().lower() == "on"):
# move group2 into the scope and check it fails
try:
topology_st.standalone.rename_s(group2_dn, 'cn=group_in2', newsuperior=peoplebase, delold=0)
topology_st.standalone.log.info("This is expected, modrdn does not fail only updates of members will fail")
except ldap.OBJECT_CLASS_VIOLATION:
pass
# move group2 into the scope and check it succeeds
topology_st.standalone.rename_s(group2_dn, 'cn=group_in2', newsuperior=peoplebase, delold=0)
topology_st.standalone.log.info("This is expected, modrdn does not fail only updates of members will fail")
else:
# move group2 into the scope and check it fails
try:
Expand Down Expand Up @@ -878,12 +875,9 @@ def test_silent_memberof_failure(topology_st, request):
topology_st.standalone.restart(timeout=10)

if (memberof.get_memberofdeferredupdate() and memberof.get_memberofdeferredupdate().lower() == "on"):
# move group2 into the scope and check it fails
try:
topology_st.standalone.rename_s(group2_dn, 'cn=group_in2', newsuperior=peoplebase, delold=0)
topology_st.standalone.log.info("This is expected, modrdn does not fail only updates of members will fail")
except ldap.OBJECT_CLASS_VIOLATION:
pass
# move group2 into the scope and check it succeeds
topology_st.standalone.rename_s(group2_dn, 'cn=group_in2', newsuperior=peoplebase, delold=0)
topology_st.standalone.log.info("This is expected, modrdn does not fail only updates of members will fail")
else:
# move group2 into the scope and check it fails
try:
Expand All @@ -904,18 +898,11 @@ def test_silent_memberof_failure(topology_st, request):
if (memberof.get_memberofdeferredupdate() and memberof.get_memberofdeferredupdate().lower() == "on"):
# Create a group3 in the scope
group3_dn = 'cn=group3_in,%s' % peoplebase
try:
topology_st.standalone.add_s(Entry((group3_dn, {'objectclass': ['top', 'groupofnames'],
'member': [
'cn=user4,%s' % peoplebase,
'cn=user5,%s' % peoplebase,
],
'description': 'mygroup'})))
topology_st.standalone.log.info("This is expected, add does not fail only updates of members will fail")
except ldap.OBJECT_CLASS_VIOLATION:
pass
except ldap.OPERATIONS_ERROR:
pass
topology_st.standalone.add_s(Entry((group3_dn, {'objectclass': ['top', 'groupofnames'],
'member': ['cn=user4,%s' % peoplebase,
'cn=user5,%s' % peoplebase,],
'description': 'mygroup'})))
topology_st.standalone.log.info("This is expected, add does not fail only updates of members will fail")
else:
# Create a group3 in the scope
group3_dn = 'cn=group3_in,%s' % peoplebase
Expand Down Expand Up @@ -987,7 +974,7 @@ def check_memberof_consistency(inst, group):
- entries having 'memberOf' attribute
- members in the group
"""
suffix = Domain (inst, SUFFIX)
suffix = Domain(inst, SUFFIX)
group_members = len(group.get_attr_vals('member'))
users_memberof = len(suffix.search(filter='(memberof=*)'))
assert group_members == users_memberof
Expand Down
107 changes: 26 additions & 81 deletions dirsrvtests/tests/suites/plugins/memberof_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@
GROUP_RDN = "group"
GROUPS_CONTAINER = "ou=groups,%s" % SUFFIX

def _memberof_checking_delay(inst):
memberof = MemberOfPlugin(inst)
if (memberof.get_memberofdeferredupdate() and memberof.get_memberofdeferredupdate().lower() == "on"):
# In case of deferred update then a safe delay
# to let the deferred thread processing is 3 sec
delay = 3
else:
# Else it is the same TXN, no reason to wait
delay = 0
return delay

def _set_memberofgroupattr_add(topology_st, values):
topology_st.standalone.modify_s(MEMBEROF_PLUGIN_DN,
Expand Down Expand Up @@ -201,12 +211,7 @@ def test_member_add(topology_st):
2. Success
3. Success
"""
memberof = MemberOfPlugin(topology_st.standalone)
if (memberof.get_memberofdeferredupdate() and memberof.get_memberofdeferredupdate().lower() == "on"):
delay = 3
else:
delay = 0

delay = _memberof_checking_delay(topology_st.standalone)

topology_st.standalone.plugins.enable(name=PLUGIN_MEMBER_OF)
topology_st.standalone.restart()
Expand Down Expand Up @@ -249,11 +254,7 @@ def test_member_delete_gr1(topology_st):
2. Success
"""

memberof = MemberOfPlugin(topology_st.standalone)
if (memberof.get_memberofdeferredupdate() and memberof.get_memberofdeferredupdate().lower() == "on"):
delay = 3
else:
delay = 0
delay = _memberof_checking_delay(topology_st.standalone)

memofenh1 = _get_user_dn('memofenh1')
memofenh2 = _get_user_dn('memofenh2')
Expand Down Expand Up @@ -286,11 +287,7 @@ def test_member_delete_gr2(topology_st):
1. Success
2. Success
"""
memberof = MemberOfPlugin(topology_st.standalone)
if (memberof.get_memberofdeferredupdate() and memberof.get_memberofdeferredupdate().lower() == "on"):
delay = 3
else:
delay = 0
delay = _memberof_checking_delay(topology_st.standalone)

memofenh1 = _get_user_dn('memofenh1')
memofenh2 = _get_user_dn('memofenh2')
Expand Down Expand Up @@ -324,11 +321,7 @@ def test_member_delete_all(topology_st):
1. Success
2. Success
"""
memberof = MemberOfPlugin(topology_st.standalone)
if (memberof.get_memberofdeferredupdate() and memberof.get_memberofdeferredupdate().lower() == "on"):
delay = 3
else:
delay = 0
delay = _memberof_checking_delay(topology_st.standalone)

memofenh1 = _get_user_dn('memofenh1')
memofenh2 = _get_user_dn('memofenh2')
Expand Down Expand Up @@ -368,11 +361,7 @@ def test_member_after_restart(topology_st):
2. Success
3. Success
"""
memberof = MemberOfPlugin(topology_st.standalone)
if (memberof.get_memberofdeferredupdate() and memberof.get_memberofdeferredupdate().lower() == "on"):
delay = 3
else:
delay = 0
delay = _memberof_checking_delay(topology_st.standalone)

memofenh1 = _get_user_dn('memofenh1')
memofenh2 = _get_user_dn('memofenh2')
Expand Down Expand Up @@ -584,11 +573,7 @@ def test_member_uniquemember_same_user(topology_st):
6. Success
"""

memberof = MemberOfPlugin(topology_st.standalone)
if (memberof.get_memberofdeferredupdate() and memberof.get_memberofdeferredupdate().lower() == "on"):
delay = 3
else:
delay = 0
delay = _memberof_checking_delay(topology_st.standalone)

memofenh1 = _get_user_dn('memofenh1')
memofenh2 = _get_user_dn('memofenh2')
Expand Down Expand Up @@ -702,11 +687,7 @@ def test_member_not_exists(topology_st):
2. Success
3. Success
"""
memberof = MemberOfPlugin(topology_st.standalone)
if (memberof.get_memberofdeferredupdate() and memberof.get_memberofdeferredupdate().lower() == "on"):
delay = 3
else:
delay = 0
delay = _memberof_checking_delay(topology_st.standalone)

memofenh1 = _get_user_dn('memofenh1')
memofenh2 = _get_user_dn('memofenh2')
Expand Down Expand Up @@ -820,11 +801,7 @@ def test_member_not_exists_complex(topology_st):
5. Success
6. Success
"""
memberof = MemberOfPlugin(topology_st.standalone)
if (memberof.get_memberofdeferredupdate() and memberof.get_memberofdeferredupdate().lower() == "on"):
delay = 3
else:
delay = 0
delay = _memberof_checking_delay(topology_st.standalone)

memofenh1 = _get_user_dn('memofenh1')
memofenh2 = _get_user_dn('memofenh2')
Expand Down Expand Up @@ -1001,11 +978,7 @@ def test_complex_group_scenario_1(topology_st):
8. Success
"""

memberof = MemberOfPlugin(topology_st.standalone)
if (memberof.get_memberofdeferredupdate() and memberof.get_memberofdeferredupdate().lower() == "on"):
delay = 3
else:
delay = 0
delay = _memberof_checking_delay(topology_st.standalone)

memofenh1 = _get_user_dn('memofenh1')
memofenh2 = _get_user_dn('memofenh2')
Expand Down Expand Up @@ -1232,11 +1205,7 @@ def test_complex_group_scenario_2(topology_st):
6. Success
7. Success
"""
memberof = MemberOfPlugin(topology_st.standalone)
if (memberof.get_memberofdeferredupdate() and memberof.get_memberofdeferredupdate().lower() == "on"):
delay = 3
else:
delay = 0
delay = _memberof_checking_delay(topology_st.standalone)

memofenh1 = _get_user_dn('memofenh1')
memofenh2 = _get_user_dn('memofenh2')
Expand Down Expand Up @@ -1513,11 +1482,7 @@ def test_complex_group_scenario_3(topology_st):
11. Success
12. Success
"""
memberof = MemberOfPlugin(topology_st.standalone)
if (memberof.get_memberofdeferredupdate() and memberof.get_memberofdeferredupdate().lower() == "on"):
delay = 3
else:
delay = 0
delay = _memberof_checking_delay(topology_st.standalone)

memofenh1 = _get_user_dn('memofenh1')
memofenh2 = _get_user_dn('memofenh2')
Expand Down Expand Up @@ -1755,11 +1720,7 @@ def test_complex_group_scenario_4(topology_st):
5. Success
6. Success
"""
memberof = MemberOfPlugin(topology_st.standalone)
if (memberof.get_memberofdeferredupdate() and memberof.get_memberofdeferredupdate().lower() == "on"):
delay = 3
else:
delay = 0
delay = _memberof_checking_delay(topology_st.standalone)

memofenh1 = _get_user_dn('memofenh1')
memofenh2 = _get_user_dn('memofenh2')
Expand Down Expand Up @@ -1901,11 +1862,7 @@ def test_complex_group_scenario_5(topology_st):
10. Success
11. Success
"""
memberof = MemberOfPlugin(topology_st.standalone)
if (memberof.get_memberofdeferredupdate() and memberof.get_memberofdeferredupdate().lower() == "on"):
delay = 3
else:
delay = 0
delay = _memberof_checking_delay(topology_st.standalone)

memofenh1 = _get_user_dn('memofenh1')
memofenh2 = _get_user_dn('memofenh2')
Expand Down Expand Up @@ -2101,11 +2058,7 @@ def test_complex_group_scenario_6(topology_st):
7. Success
8. Success
"""
memberof = MemberOfPlugin(topology_st.standalone)
if (memberof.get_memberofdeferredupdate() and memberof.get_memberofdeferredupdate().lower() == "on"):
delay = 3
else:
delay = 0
delay = _memberof_checking_delay(topology_st.standalone)

memofenh1 = _get_user_dn('memofenh1')
memofenh2 = _get_user_dn('memofenh2')
Expand Down Expand Up @@ -2387,11 +2340,7 @@ def test_complex_group_scenario_7(topology_st):
|<--uniquemember-/
"""
memberof = MemberOfPlugin(topology_st.standalone)
if (memberof.get_memberofdeferredupdate() and memberof.get_memberofdeferredupdate().lower() == "on"):
delay = 3
else:
delay = 0
delay = _memberof_checking_delay(topology_st.standalone)

memofenh1 = _get_user_dn('memofenh1')
memofenh2 = _get_user_dn('memofenh2')
Expand Down Expand Up @@ -2610,11 +2559,7 @@ def test_complex_group_scenario_8(topology_st):
|<--uniquemember-/
"""
memberof = MemberOfPlugin(topology_st.standalone)
if (memberof.get_memberofdeferredupdate() and memberof.get_memberofdeferredupdate().lower() == "on"):
delay = 3
else:
delay = 0
delay = _memberof_checking_delay(topology_st.standalone)

memofuser1 = _get_user_dn('memofuser1')
memofuser2 = _get_user_dn('memofuser2')
Expand Down

0 comments on commit 760cb30

Please sign in to comment.