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

Lukas Slebodnik lslebodn at redhat.com
Mon Aug 10 10:26:03 UTC 2015


On (10/08/15 10:41), Lukas Slebodnik wrote:
>On (07/08/15 21:19), Michal Židek wrote:
>>On 08/07/2015 06:16 AM, Lukas Slebodnik wrote:
>>>
>>>+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"
>>
>>Grammar nazi nitpick :) : Missing "a" -> within a second
>>But the nitpick is not relevant due to the following:
>>
>>I would give it at least 5 seconds for 2 reasons:
>>a) if it ends sooner nothing happens, everything is fine
>>b) if it ends later (CI machine under heavy load
>>   makes even this possible) it breaks the test.
>>
>I realized it might be better to implement it directly in the utility
>sss_cache. I didn't increased time to 5 seconds because
>It would be a long time for users
>and they might to decide to cancel it (ctrl-c).
>
and now with patches

LS
-------------- next part --------------
>From 89c88cff939193abdad2b3af940a23e70938e2fc Mon Sep 17 00:00:00 2001
From: Lukas Slebodnik <lslebodn at redhat.com>
Date: Mon, 10 Aug 2015 10:16:58 +0200
Subject: [PATCH 1/3] sss_cache: Wait a while for invalidation of mc by nss
 responder

The sss_cache cannot invalidate 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 needn't be invalidated.

Resolves:
https://fedorahosted.org/sssd/ticket/2748
---
 src/tools/tools_mc_util.c | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/src/tools/tools_mc_util.c b/src/tools/tools_mc_util.c
index c1b5c616d0e6d50147ecd81308aaa1e69304af92..65c461093e859d4da73761782a3a694bf5bda8fb 100644
--- a/src/tools/tools_mc_util.c
+++ b/src/tools/tools_mc_util.c
@@ -21,6 +21,7 @@
 
 #include <talloc.h>
 #include <fcntl.h>
+#include <sys/stat.h>
 
 #include "db/sysdb.h"
 #include "util/util.h"
@@ -161,6 +162,33 @@ static int clear_fastcache(bool *sssd_nss_is_off)
     return EOK;
 }
 
+static errno_t wait_till_nss_responder_invalidate_cache(void)
+{
+    struct stat stat_buf = { 0 };
+    const time_t max_wait = 1000000; /* 1 second */
+    const time_t step_time = 5000; /* 5 miliseconds */
+    const size_t steps_count = max_wait / step_time;
+    int ret;
+
+    for (size_t i = 0; i < steps_count; ++i) {
+        ret = stat(SSS_NSS_MCACHE_DIR "/" CLEAR_MC_FLAG, &stat_buf);
+        if (ret == -1) {
+            ret = errno;
+            if (ret == ENOENT) {
+                /* nss responder has already invalidated memory caches */
+                return EOK;
+            }
+
+            DEBUG(SSSDBG_CRIT_FAILURE,
+                  "stat failed: %s (%d)\n", sss_strerror(ret), ret);
+        }
+
+        usleep(step_time);
+    }
+
+    return EAGAIN;
+}
+
 errno_t sss_memcache_clear_all(void)
 {
     errno_t ret;
@@ -196,6 +224,12 @@ errno_t sss_memcache_clear_all(void)
                   "Failed to send SIGHUP to monitor.\n");
             return EIO;
         }
+
+        ret = wait_till_nss_responder_invalidate_cache();
+        if (ret != EOK) {
+            ERROR("The fast memory caches was not invalidated by NSS "
+                  "responder.\n");
+        }
     }
 
     return EOK;
-- 
2.5.0

-------------- next part --------------
>From 15d6f3ea961d828c69dc726ac09c0f697ac048ee 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 1fd577e652d278c35211b55c871797a3dee98b13..a33314771f3b744be03dd46a0fd1f59a8c8c37e7 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 test_invalidate_user_before_stop(ldap_conn, sanity_rfc2307):
-- 
2.5.0



More information about the sssd-devel mailing list