On Mon, Sep 19, 2016 at 10:41:13AM +0200, Lukas Slebodnik wrote:
> On (19/09/16 10:06), Lukas Slebodnik wrote:
> >On (12/09/16 00:25), Jakub Hrozek wrote:
> >>From fd71b7ed7c588cc22402573b9877020234949e22 Mon Sep 17 00:00:00 2001
> >>From: Jakub Hrozek <jhro...@redhat.com>
> >>Date: Fri, 9 Sep 2016 12:23:04 +0200
> >>Subject: [PATCH 3/3] TESTS: Test offline netgroups resolution
> >>
> >>---
> >> src/tests/intg/test_netgroup.py | 35 +++++++++++++++++++++++++++++------
> >> 1 file changed, 29 insertions(+), 6 deletions(-)
> >>
> >>diff --git a/src/tests/intg/test_netgroup.py 
> >>b/src/tests/intg/test_netgroup.py
> >>index 
> >>b99476126844e35d5dbc1793077720b4020c2fb7..1d00f0ecdc912dc7ecc23a818a79828d2b2727e6
> >> 100644
> >>--- a/src/tests/intg/test_netgroup.py
> >>+++ b/src/tests/intg/test_netgroup.py
> >>@@ -104,6 +104,7 @@ def format_basic_conf(ldap_conn, schema):
> >>         [sssd]
> >>         domains             = LDAP
> >>         services            = nss
> >>+        disable_netlink     = true
> >> 
> >>         [domain/LDAP]
> >>         {schema_conf}
> >>@@ -148,11 +149,16 @@ def create_sssd_process():
> >>         raise Exception("sssd start failed")
> >> 
> >> 
> >>+def get_sssd_pid():
> >>+    pid_file = open(config.PIDFILE_PATH, "r")
> >>+    pid = int(pid_file.read())
> >>+    return pid
> >>+
> >>+
> >> def cleanup_sssd_process():
> >>     """Stop the SSSD process and remove its state"""
> >>     try:
> >>-        pid_file = open(config.PIDFILE_PATH, "r")
> >>-        pid = int(pid_file.read())
> >>+        pid = get_sssd_pid()
> >>         os.kill(pid, signal.SIGTERM)
> >>         while True:
> >>             try:
> >>@@ -172,6 +178,9 @@ def create_sssd_cleanup(request):
> >>     """Add teardown for stopping SSSD and removing its state"""
> >>     request.addfinalizer(cleanup_sssd_process)
> >> 
> >>+def simulate_offline():
> >>+    pid = get_sssd_pid()
> >>+    os.kill(pid, signal.SIGUSR1)
> >> 
> >> def create_sssd_fixture(request):
> >>     """Start SSSD and add teardown for stopping it and removing its 
> >> state"""
> >>@@ -351,7 +360,7 @@ def test_remove_step_by_step(remove_step_by_step, 
> >>ldap_conn):
> >>     ent_list.remove(ent_list[0])
> >> 
> >>     if subprocess.call(["sss_cache", "-N"]) != 0:
> >>-        raise Exception("sssd_cache failed")
> >>+        raise Exception("sss_cache failed")
> >> 
> >>     res, _, netgroups = 
> >> sssd_netgroup.get_sssd_netgroups("rm_empty_netgroup1")
> >>     assert res == sssd_netgroup.NssReturnCode.NOTFOUND
> >>@@ -366,7 +375,7 @@ def test_remove_step_by_step(remove_step_by_step, 
> >>ldap_conn):
> >>     ent_list.remove(ent_list[0])
> >> 
> >>     if subprocess.call(["sss_cache", "-N"]) != 0:
> >>-        raise Exception("sssd_cache failed")
> >>+        raise Exception("sss_cache failed")
> >> 
> >>     res, _, netgroups = 
> >> sssd_netgroup.get_sssd_netgroups("rm_empty_netgroup1")
> >>     assert res == sssd_netgroup.NssReturnCode.NOTFOUND
> >>@@ -422,7 +431,7 @@ def 
> >>test_removing_nested_netgroups(removing_nested_netgroups, ldap_conn):
> >>     ldap_conn.modify_s(netgrp_dn, ldif)
> >> 
> >>     if subprocess.call(["sss_cache", "-N"]) != 0:
> >>-        raise Exception("sssd_cache failed")
> >>+        raise Exception("sss_cache failed")
> >> 
> >>     res, _, netgroups = sssd_netgroup.get_sssd_netgroups("t2841_netgroup1")
> >>     assert res == sssd_netgroup.NssReturnCode.SUCCESS
> >>@@ -444,7 +453,7 @@ def 
> >>test_removing_nested_netgroups(removing_nested_netgroups, ldap_conn):
> >>     ldap_conn.modify_s(netgrp_dn, ldif)
> >> 
> >>     if subprocess.call(["sss_cache", "-N"]) != 0:
> >>-        raise Exception("sssd_cache failed")
> >>+        raise Exception("sss_cache failed")
> >Above changes are unrelated to the test.
> >If you decide to touch the code then it would be better
> >to use subprocess.check_call
> >
> >
> >> 
> >>     res, _, netgroups = sssd_netgroup.get_sssd_netgroups("t2841_netgroup1")
> >>     assert res == sssd_netgroup.NssReturnCode.SUCCESS
> >>@@ -457,3 +466,17 @@ def 
> >>test_removing_nested_netgroups(removing_nested_netgroups, ldap_conn):
> >>     res, _, netgroups = sssd_netgroup.get_sssd_netgroups("t2841_netgroup3")
> >>     assert res == sssd_netgroup.NssReturnCode.SUCCESS
> >>     assert netgroups == []
> >>+
> >>+def test_offline_netgroups(add_tripled_netgroup):
> >>+    res, _, netgrps = sssd_netgroup.get_sssd_netgroups("tripled_netgroup")
> >>+    assert res == sssd_netgroup.NssReturnCode.SUCCESS
> >>+    assert netgrps == [("host", "user", "domain")]
> >>+
> >>+    if subprocess.call(["sss_cache", "-N"]) != 0:
> >>+        raise Exception("sss_cache failed")
> >>+
> >>+    simulate_offline()
> >>+
> >>+    res, _, netgrps = sssd_netgroup.get_sssd_netgroups("tripled_netgroup")
> >>+    assert res == sssd_netgroup.NssReturnCode.SUCCESS
> >>+    assert netgrps == [("host", "user", "domain")]
> >
> >otherwise LGTM
> >
> Actually, there are trivial pep8 errors
> src/tests/intg/test_netgroup.py:181:1: E302 expected 2 blank lines, found 1
> src/tests/intg/test_netgroup.py:185:1: E302 expected 2 blank lines, found 1
> src/tests/intg/test_netgroup.py:470:1: E302 expected 2 blank lines, found 1

OK, see the new patches.
>From f52a0399dab5b9e82939e3af14d128be8e7b59f7 Mon Sep 17 00:00:00 2001
From: Jakub Hrozek <jhro...@redhat.com>
Date: Thu, 4 Aug 2016 17:58:32 +0200
Subject: [PATCH 1/3] AUTOFS: Fix offline resolution of autofs maps

https://fedorahosted.org/sssd/ticket/3080

If talking to the Data Provider failed, we never re-tried looking into
the cache. We should consult the cache on DP failures and return cached
results, if possible.
---
 src/responder/autofs/autofssrv_cmd.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/src/responder/autofs/autofssrv_cmd.c 
b/src/responder/autofs/autofssrv_cmd.c
index 
9666ab2d195a581f18eaa7ff9bbc4c8167a71b15..f5aa25a483c3b3352f40e8cc66dfd3a24a60af0d
 100644
--- a/src/responder/autofs/autofssrv_cmd.c
+++ b/src/responder/autofs/autofssrv_cmd.c
@@ -871,17 +871,25 @@ static void lookup_automntmap_cache_updated(uint16_t 
err_maj, uint32_t err_min,
     if (err_maj) {
         DEBUG(SSSDBG_CRIT_FAILURE,
               "Unable to get information from Data Provider\n"
-               "Error: %u, %u, %s\n"
-               "Will try to return what we have in cache\n",
+              "Error: %u, %u, %s\n"
+              "Will try to return what we have in cache\n",
                (unsigned int)err_maj, (unsigned int)err_min, err_msg);
-        /* Loop to the next domain if possible */
+
+        /* Try to fall back to cache */
+        ret = lookup_automntmap_step(lookup_ctx);
+        if (ret == EOK) {
+            /* We have cached results to return */
+            autofs_setent_notify(lookup_ctx->map, ret);
+            return;
+        }
+
+        /* Otherwise try the next domain */
         if (dctx->cmd_ctx->check_next
                 && (dctx->domain = get_next_domain(dctx->domain, 0))) {
             dctx->check_provider = NEED_CHECK_PROVIDER(dctx->domain->provider);
         }
     }
 
-    /* ok the backend returned, search to see if we have updated results */
     ret = lookup_automntmap_step(lookup_ctx);
     if (ret != EOK) {
         if (ret == EAGAIN) {
-- 
2.7.4

>From d96180a8b1353e611ea562cc4d4715d14c97c980 Mon Sep 17 00:00:00 2001
From: Jakub Hrozek <jhro...@redhat.com>
Date: Thu, 4 Aug 2016 17:58:47 +0200
Subject: [PATCH 2/3] NSS: Fix offline resolution of netgroups

https://fedorahosted.org/sssd/ticket/3123

If talking to the Data Provider failed, we never re-tried looking into
the cache. We should consult the cache on DP failures and return cached
results, if possible.
---
 src/responder/nss/nsssrv_netgroup.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/src/responder/nss/nsssrv_netgroup.c 
b/src/responder/nss/nsssrv_netgroup.c
index 
e42976b245952291cd1eb36480138514e3d4ec09..49ef0f5c9b264a6252880a2944e8a1bd38ae0527
 100644
--- a/src/responder/nss/nsssrv_netgroup.c
+++ b/src/responder/nss/nsssrv_netgroup.c
@@ -674,6 +674,15 @@ static void lookup_netgr_dp_callback(uint16_t err_maj, 
uint32_t err_min,
                   "Error: %u, %u, %s\n"
                   "Will try to return what we have in cache\n",
                   (unsigned int)err_maj, (unsigned int)err_min, err_msg);
+
+        /* Try to fall back to cache */
+        ret = lookup_netgr_step(step_ctx);
+        if (ret == EOK) {
+            /* We have cached results to return */
+            nss_setent_notify_done(dctx->netgr);
+            return;
+        }
+
         /* Loop to the next domain if possible */
         if (cmdctx->check_next
                 && (dctx->domain = get_next_domain(dctx->domain, 0))) {
-- 
2.7.4

>From 6cfda25bee80d3ac14e7e9b0a12febd6948adbd3 Mon Sep 17 00:00:00 2001
From: Jakub Hrozek <jhro...@redhat.com>
Date: Fri, 9 Sep 2016 12:23:04 +0200
Subject: [PATCH 3/3] TESTS: Test offline netgroups resolution

---
 src/tests/intg/test_netgroup.py | 30 ++++++++++++++++++++++++++++--
 1 file changed, 28 insertions(+), 2 deletions(-)

diff --git a/src/tests/intg/test_netgroup.py b/src/tests/intg/test_netgroup.py
index 
b99476126844e35d5dbc1793077720b4020c2fb7..46ac42c0587a58e624904ac8bf80a723ff52b814
 100644
--- a/src/tests/intg/test_netgroup.py
+++ b/src/tests/intg/test_netgroup.py
@@ -104,6 +104,7 @@ def format_basic_conf(ldap_conn, schema):
         [sssd]
         domains             = LDAP
         services            = nss
+        disable_netlink     = true
 
         [domain/LDAP]
         {schema_conf}
@@ -148,11 +149,16 @@ def create_sssd_process():
         raise Exception("sssd start failed")
 
 
+def get_sssd_pid():
+    pid_file = open(config.PIDFILE_PATH, "r")
+    pid = int(pid_file.read())
+    return pid
+
+
 def cleanup_sssd_process():
     """Stop the SSSD process and remove its state"""
     try:
-        pid_file = open(config.PIDFILE_PATH, "r")
-        pid = int(pid_file.read())
+        pid = get_sssd_pid()
         os.kill(pid, signal.SIGTERM)
         while True:
             try:
@@ -173,6 +179,11 @@ def create_sssd_cleanup(request):
     request.addfinalizer(cleanup_sssd_process)
 
 
+def simulate_offline():
+    pid = get_sssd_pid()
+    os.kill(pid, signal.SIGUSR1)
+
+
 def create_sssd_fixture(request):
     """Start SSSD and add teardown for stopping it and removing its state"""
     create_sssd_process()
@@ -457,3 +468,18 @@ def 
test_removing_nested_netgroups(removing_nested_netgroups, ldap_conn):
     res, _, netgroups = sssd_netgroup.get_sssd_netgroups("t2841_netgroup3")
     assert res == sssd_netgroup.NssReturnCode.SUCCESS
     assert netgroups == []
+
+
+def test_offline_netgroups(add_tripled_netgroup):
+    res, _, netgrps = sssd_netgroup.get_sssd_netgroups("tripled_netgroup")
+    assert res == sssd_netgroup.NssReturnCode.SUCCESS
+    assert netgrps == [("host", "user", "domain")]
+
+    if subprocess.call(["sss_cache", "-N"]) != 0:
+        raise Exception("sss_cache failed")
+
+    simulate_offline()
+
+    res, _, netgrps = sssd_netgroup.get_sssd_netgroups("tripled_netgroup")
+    assert res == sssd_netgroup.NssReturnCode.SUCCESS
+    assert netgrps == [("host", "user", "domain")]
-- 
2.7.4

_______________________________________________
sssd-devel mailing list -- sssd-devel@lists.fedorahosted.org
To unsubscribe send an email to sssd-devel-le...@lists.fedorahosted.org

Reply via email to