[SSSD] [PATCH] test_memory_cache: Wait short time after cache invalidation

Lukas Slebodnik lslebodn at redhat.com
Thu Aug 6 10:58:22 UTC 2015


On (06/08/15 12:57), Lukas Slebodnik wrote:
>ehlo,
>
>As you can see in ticket #2748, there are some failures in test_memory_cache.
>I was not bale to reproduce on my local machine and I didn't saw it before
>because of other broken tests responder_cache_req-tests, pam-srv-tests.
>
>I'm waiting from results from CI whether it will fail enev with attached patch.
>
and now with attached patches.

LS
-------------- next part --------------
>From 771d83bd36a06aa6f270ef8188d3ba85fdd68b15 Mon Sep 17 00:00:00 2001
From: Lukas Slebodnik <lslebodn at redhat.com>
Date: Thu, 6 Aug 2015 11:09:38 +0200
Subject: [PATCH 1/3] test_memory_cache: Wait short time after cache
 invalidation

The sss_cache cannot invlaidate memory cache directly
because the nss responder owns file locks to memory caches.
Therefore sss_cache just "tell" nss responder to invalidate
memory cache.

However there might be short interval between calling
the utility sss_cache and stopping sssd. So nss responder
needn't be so fast and therefore memory cache neend't be invalidated

Resolves:
https://fedorahosted.org/sssd/ticket/2748
---
 src/tests/intg/test_memory_cache.py | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/src/tests/intg/test_memory_cache.py b/src/tests/intg/test_memory_cache.py
index 1fd577e652d278c35211b55c871797a3dee98b13..4f61efd47afed69367460c25f7a592114416f6f3 100644
--- a/src/tests/intg/test_memory_cache.py
+++ b/src/tests/intg/test_memory_cache.py
@@ -618,6 +618,17 @@ def assert_missing_mc_records_for_user1():
         "User %s, errno:%d" % (user, err)
 
 
+def wait_till_nss_responder_invalidate_cache():
+    # 1 second (200 * 0.005) should be enough time for nss responder
+    for _ in range(1, 200):
+        if os.path.isfile(config.MCACHE_PATH + "/clear_mc_flag"):
+            time.sleep(.005)
+        else:
+            return
+
+    assert False, "nss responder didn't invalidate memory cache within second"
+
+
 def test_invalidate_user_before_stop(ldap_conn, sanity_rfc2307):
     # initialize cache with full ID
     (res, errno, _) = sssd_id.get_user_groups("user1")
@@ -626,6 +637,7 @@ def test_invalidate_user_before_stop(ldap_conn, sanity_rfc2307):
     assert_mc_records_for_user1()
 
     subprocess.call(["sss_cache", "-u", "user1"])
+    wait_till_nss_responder_invalidate_cache()
     stop_sssd()
 
     assert_missing_mc_records_for_user1()
@@ -652,6 +664,7 @@ def test_invalidate_users_before_stop(ldap_conn, sanity_rfc2307):
     assert_mc_records_for_user1()
 
     subprocess.call(["sss_cache", "-U"])
+    wait_till_nss_responder_invalidate_cache()
     stop_sssd()
 
     assert_missing_mc_records_for_user1()
@@ -678,6 +691,7 @@ def test_invalidate_group_before_stop(ldap_conn, sanity_rfc2307):
     assert_mc_records_for_user1()
 
     subprocess.call(["sss_cache", "-g", "group1"])
+    wait_till_nss_responder_invalidate_cache()
     stop_sssd()
 
     assert_missing_mc_records_for_user1()
@@ -704,6 +718,7 @@ def test_invalidate_groups_before_stop(ldap_conn, sanity_rfc2307):
     assert_mc_records_for_user1()
 
     subprocess.call(["sss_cache", "-G"])
+    wait_till_nss_responder_invalidate_cache()
     stop_sssd()
 
     assert_missing_mc_records_for_user1()
@@ -730,6 +745,7 @@ def test_invalidate_everything_before_stop(ldap_conn, sanity_rfc2307):
     assert_mc_records_for_user1()
 
     subprocess.call(["sss_cache", "-E"])
+    wait_till_nss_responder_invalidate_cache()
     stop_sssd()
 
     assert_missing_mc_records_for_user1()
-- 
2.5.0

-------------- next part --------------
>From 0ad054215dd8fb687e48a800115ab91bb63b0a17 Mon Sep 17 00:00:00 2001
From: Lukas Slebodnik <lslebodn at redhat.com>
Date: Thu, 6 Aug 2015 12:28:16 +0200
Subject: [PATCH 2/3] test_memory_cache: Fix few python issues

W:438,17: Unused variable 'gids' (unused-variable)
W:438,10: Unused variable 'errno' (unused-variable)
E:618,31: Undefined variable 'user' (undefined-variable)
W:443,17: Unused variable 'gids' (unused-variable)
W:443,10: Unused variable 'errno' (unused-variable)
---
 src/tests/intg/test_memory_cache.py | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/tests/intg/test_memory_cache.py b/src/tests/intg/test_memory_cache.py
index 4f61efd47afed69367460c25f7a592114416f6f3..16da67e8ae1d0456232298e418a0b31b80802f34 100644
--- a/src/tests/intg/test_memory_cache.py
+++ b/src/tests/intg/test_memory_cache.py
@@ -435,14 +435,14 @@ def assert_stored_last_initgroups(user1_case1, user1_case2, user1_case_last,
     stop_sssd()
 
     user = user1_case1
-    (res, errno, gids) = sssd_id.call_sssd_initgroups(user, primary_gid)
+    (res, errno, _) = sssd_id.call_sssd_initgroups(user, primary_gid)
     assert res == sssd_id.NssReturnCode.UNAVAIL, \
-        "Initgroups for user shoudl fail user %s, %d" % (user, res)
+        "Initgroups for user shoudl fail user %s, %d, %d" % (user, res, errno)
 
     user = user1_case2
-    (res, errno, gids) = sssd_id.call_sssd_initgroups(user, primary_gid)
+    (res, errno, _) = sssd_id.call_sssd_initgroups(user, primary_gid)
     assert res == sssd_id.NssReturnCode.UNAVAIL, \
-        "Initgroups for user shoudl fail user %s, %d" % (user, res)
+        "Initgroups for user shoudl fail user %s, %d, %d" % (user, res, errno)
 
     # Just last invocation of initgroups shoudl PASS
     # Otherwise, we would not be able to invalidate it
@@ -615,7 +615,7 @@ def assert_missing_mc_records_for_user1():
     (res, err, _) = sssd_id.call_sssd_initgroups("user1", 2001)
     assert res == sssd_id.NssReturnCode.UNAVAIL, \
         "Initgroups should not find anything after invalidation of mc.\n" \
-        "User %s, errno:%d" % (user, err)
+        "User user1, errno:%d" % err
 
 
 def wait_till_nss_responder_invalidate_cache():
-- 
2.5.0



More information about the sssd-devel mailing list