dpward / rpms / sssd

Forked from rpms/sssd 3 years ago
Clone

Blame SOURCES/0095-FO-Also-reset-the-server-common-data-in-addition-to-.patch

6cf099
From 1f861441042380362345d8ce3f9e81151664c6c0 Mon Sep 17 00:00:00 2001
6cf099
From: Jakub Hrozek <jhrozek@redhat.com>
6cf099
Date: Mon, 21 Sep 2015 12:31:38 +0200
6cf099
Subject: [PATCH 95/96] FO: Also reset the server common data in addition to
6cf099
 SRV
6cf099
6cf099
In a server that is expanded from a SRV query was reset, only it's
6cf099
'meta-server' status was set to neutral, but the server->common
6cf099
structure still retained its not_working status.
6cf099
6cf099
This patch also resets the status of the common structure so that both
6cf099
the SRV query and resolving the server are retried next time.
6cf099
6cf099
Reviewed-by: Sumit Bose <sbose@redhat.com>
6cf099
(cherry picked from commit 6ac6e8f83da241458742b7f8a3406ed66bded292)
6cf099
---
6cf099
 src/providers/fail_over.c      |   4 +-
6cf099
 src/tests/cmocka/test_fo_srv.c | 188 ++++++++++++++++++++++++++++++-----------
6cf099
 2 files changed, 142 insertions(+), 50 deletions(-)
6cf099
6cf099
diff --git a/src/providers/fail_over.c b/src/providers/fail_over.c
6cf099
index 562f0b3fd7870387a80c889b245cda0d39dea509..b076687ac6e571f7e27402fd11ac60183ea46951 100644
6cf099
--- a/src/providers/fail_over.c
6cf099
+++ b/src/providers/fail_over.c
6cf099
@@ -1554,7 +1554,9 @@ void fo_reset_servers(struct fo_service *service)
6cf099
     DLIST_FOR_EACH(server, service->server_list) {
6cf099
         if (server->srv_data != NULL) {
6cf099
             set_srv_data_status(server->srv_data, SRV_NEUTRAL);
6cf099
-        } else {
6cf099
+        }
6cf099
+
6cf099
+        if (server->common) {
6cf099
             fo_set_server_status(server, SERVER_NAME_NOT_RESOLVED);
6cf099
         }
6cf099
 
6cf099
diff --git a/src/tests/cmocka/test_fo_srv.c b/src/tests/cmocka/test_fo_srv.c
6cf099
index e5c5e4fe3b818ca2df0ab7bcd1a83719fefba191..e892bab0a261779363ea78a10038b15acefc49b7 100644
6cf099
--- a/src/tests/cmocka/test_fo_srv.c
6cf099
+++ b/src/tests/cmocka/test_fo_srv.c
6cf099
@@ -194,7 +194,7 @@ errno_t resolv_get_domain_recv(TALLOC_CTX *mem_ctx,
6cf099
 }
6cf099
 
6cf099
 /* The unit test */
6cf099
-struct test_fo_srv_ctx {
6cf099
+struct test_fo_ctx {
6cf099
     struct resolv_ctx *resolv;
6cf099
     struct fo_ctx *fo_ctx;
6cf099
     struct fo_resolve_srv_dns_ctx *srv_ctx;
6cf099
@@ -208,19 +208,18 @@ int test_fo_srv_data_cmp(void *ud1, void *ud2)
6cf099
     return strcasecmp((char*) ud1, (char*) ud2);
6cf099
 }
6cf099
 
6cf099
-static int test_fo_srv_setup(void **state)
6cf099
+static int test_fo_setup(void **state)
6cf099
 {
6cf099
-    struct test_fo_srv_ctx *test_ctx;
6cf099
+    struct test_fo_ctx *test_ctx;
6cf099
     errno_t ret;
6cf099
     struct fo_options fopts;
6cf099
-    bool ok;
6cf099
 
6cf099
     assert_true(leak_check_setup());
6cf099
     global_mock_context = talloc_new(global_talloc_context);
6cf099
     assert_non_null(global_mock_context);
6cf099
 
6cf099
     test_ctx = talloc_zero(global_mock_context,
6cf099
-                           struct test_fo_srv_ctx);
6cf099
+                           struct test_fo_ctx);
6cf099
     assert_non_null(test_ctx);
6cf099
 
6cf099
     test_ctx->ctx = create_ev_test_ctx(test_ctx);
6cf099
@@ -237,6 +236,34 @@ static int test_fo_srv_setup(void **state)
6cf099
     test_ctx->fo_ctx = fo_context_init(test_ctx, &fopts);
6cf099
     assert_non_null(test_ctx->fo_ctx);
6cf099
 
6cf099
+    ret = fo_new_service(test_ctx->fo_ctx, "ldap",
6cf099
+                         test_fo_srv_data_cmp,
6cf099
+                         &test_ctx->fo_svc);
6cf099
+    assert_int_equal(ret, ERR_OK);
6cf099
+
6cf099
+    *state = test_ctx;
6cf099
+    return 0;
6cf099
+}
6cf099
+
6cf099
+static int test_fo_teardown(void **state)
6cf099
+{
6cf099
+    struct test_fo_ctx *test_ctx =
6cf099
+        talloc_get_type(*state, struct test_fo_ctx);
6cf099
+
6cf099
+    talloc_free(test_ctx);
6cf099
+    talloc_free(global_mock_context);
6cf099
+    assert_true(leak_check_teardown());
6cf099
+    return 0;
6cf099
+}
6cf099
+
6cf099
+static int test_fo_srv_setup(void **state)
6cf099
+{
6cf099
+    struct test_fo_ctx *test_ctx;
6cf099
+    bool ok;
6cf099
+
6cf099
+    test_fo_setup(state);
6cf099
+    test_ctx = *state;
6cf099
+
6cf099
     test_ctx->srv_ctx = fo_resolve_srv_dns_ctx_init(test_ctx, test_ctx->resolv,
6cf099
                                                     IPV4_FIRST, default_host_dbs,
6cf099
                                                     "client.sssd.com", "sssd.local");
6cf099
@@ -248,23 +275,13 @@ static int test_fo_srv_setup(void **state)
6cf099
                                   test_ctx->srv_ctx);
6cf099
     assert_true(ok);
6cf099
 
6cf099
-    ret = fo_new_service(test_ctx->fo_ctx, "ldap",
6cf099
-                         test_fo_srv_data_cmp,
6cf099
-                         &test_ctx->fo_svc);
6cf099
-    assert_int_equal(ret, ERR_OK);
6cf099
-
6cf099
     *state = test_ctx;
6cf099
     return 0;
6cf099
 }
6cf099
 
6cf099
 static int test_fo_srv_teardown(void **state)
6cf099
 {
6cf099
-    struct test_fo_srv_ctx *test_ctx =
6cf099
-        talloc_get_type(*state, struct test_fo_srv_ctx);
6cf099
-
6cf099
-    talloc_free(test_ctx);
6cf099
-    talloc_free(global_mock_context);
6cf099
-    assert_true(leak_check_teardown());
6cf099
+    test_fo_teardown(state);
6cf099
     return 0;
6cf099
 }
6cf099
 
6cf099
@@ -280,25 +297,30 @@ static void mock_srv_results(struct ares_srv_reply *reply_list,
6cf099
     will_return(resolv_discover_srv_recv, dns_domain);
6cf099
 }
6cf099
 
6cf099
-static void check_server(struct fo_server *srv, int port, const char *name)
6cf099
+static void check_server(struct test_fo_ctx *ctx,
6cf099
+                         struct fo_server *srv,
6cf099
+                         int port,
6cf099
+                         const char *name)
6cf099
 {
6cf099
     assert_non_null(srv);
6cf099
-    assert_true(fo_is_srv_lookup(srv));
6cf099
     assert_int_equal(fo_get_server_port(srv), port);
6cf099
     assert_string_equal(fo_get_server_name(srv), name);
6cf099
+
6cf099
+
6cf099
+    if (ctx->srv_ctx) {
6cf099
+        assert_true(fo_is_srv_lookup(srv));
6cf099
+    }
6cf099
 }
6cf099
 
6cf099
+static void test_fo_srv_step1(struct test_fo_ctx *test_ctx);
6cf099
 static void test_fo_srv_done1(struct tevent_req *req);
6cf099
 static void test_fo_srv_done2(struct tevent_req *req);
6cf099
 static void test_fo_srv_done3(struct tevent_req *req);
6cf099
 static void test_fo_srv_done4(struct tevent_req *req);
6cf099
+static void test_fo_srv_done5(struct tevent_req *req);
6cf099
 
6cf099
-void test_fo_srv(void **state)
6cf099
+static void test_fo_srv_mock_dns(struct test_fo_ctx *test_ctx)
6cf099
 {
6cf099
-    errno_t ret;
6cf099
-    struct tevent_req *req;
6cf099
-    struct test_fo_srv_ctx *test_ctx =
6cf099
-        talloc_get_type(*state, struct test_fo_srv_ctx);
6cf099
     struct ares_srv_reply *s1;
6cf099
     struct ares_srv_reply *s2;
6cf099
     char *dns_domain;
6cf099
@@ -325,25 +347,41 @@ void test_fo_srv(void **state)
6cf099
     assert_non_null(dns_domain);
6cf099
 
6cf099
     mock_srv_results(s1, TEST_SRV_TTL, dns_domain);
6cf099
+}
6cf099
+
6cf099
+static void test_fo_srv(void **state)
6cf099
+{
6cf099
+    errno_t ret;
6cf099
+    struct test_fo_ctx *test_ctx =
6cf099
+        talloc_get_type(*state, struct test_fo_ctx);
6cf099
+
6cf099
+    test_fo_srv_mock_dns(test_ctx);
6cf099
 
6cf099
     ret = fo_add_srv_server(test_ctx->fo_svc, "_ldap", "sssd.com",
6cf099
                             "sssd.local", "tcp", test_ctx);
6cf099
     assert_int_equal(ret, ERR_OK);
6cf099
 
6cf099
+    test_fo_srv_step1(test_ctx);
6cf099
+
6cf099
+    ret = test_ev_loop(test_ctx->ctx);
6cf099
+    assert_int_equal(ret, ERR_OK);
6cf099
+}
6cf099
+
6cf099
+static void test_fo_srv_step1(struct test_fo_ctx *test_ctx)
6cf099
+{
6cf099
+    struct tevent_req *req;
6cf099
+
6cf099
     req = fo_resolve_service_send(test_ctx, test_ctx->ctx->ev,
6cf099
                                   test_ctx->resolv, test_ctx->fo_ctx,
6cf099
                                   test_ctx->fo_svc);
6cf099
     assert_non_null(req);
6cf099
     tevent_req_set_callback(req, test_fo_srv_done1, test_ctx);
6cf099
-
6cf099
-    ret = test_ev_loop(test_ctx->ctx);
6cf099
-    assert_int_equal(ret, ERR_OK);
6cf099
 }
6cf099
 
6cf099
 static void test_fo_srv_done1(struct tevent_req *req)
6cf099
 {
6cf099
-    struct test_fo_srv_ctx *test_ctx = \
6cf099
-        tevent_req_callback_data(req, struct test_fo_srv_ctx);
6cf099
+    struct test_fo_ctx *test_ctx = \
6cf099
+        tevent_req_callback_data(req, struct test_fo_ctx);
6cf099
     struct fo_server *srv;
6cf099
     errno_t ret;
6cf099
 
6cf099
@@ -352,7 +390,7 @@ static void test_fo_srv_done1(struct tevent_req *req)
6cf099
     assert_int_equal(ret, ERR_OK);
6cf099
 
6cf099
     /* ldap1.sssd.com has lower priority, it must always be first */
6cf099
-    check_server(srv, 389, "ldap1.sssd.com");
6cf099
+    check_server(test_ctx, srv, 389, "ldap1.sssd.com");
6cf099
 
6cf099
     /* Mark the server as working and request the service again. The same server
6cf099
      * must be returned */
6cf099
@@ -367,8 +405,8 @@ static void test_fo_srv_done1(struct tevent_req *req)
6cf099
 
6cf099
 static void test_fo_srv_done2(struct tevent_req *req)
6cf099
 {
6cf099
-    struct test_fo_srv_ctx *test_ctx = \
6cf099
-        tevent_req_callback_data(req, struct test_fo_srv_ctx);
6cf099
+    struct test_fo_ctx *test_ctx = \
6cf099
+        tevent_req_callback_data(req, struct test_fo_ctx);
6cf099
     struct fo_server *srv;
6cf099
     errno_t ret;
6cf099
 
6cf099
@@ -377,7 +415,7 @@ static void test_fo_srv_done2(struct tevent_req *req)
6cf099
     assert_int_equal(ret, ERR_OK);
6cf099
 
6cf099
     /* Must be ldap1 again */
6cf099
-    check_server(srv, 389, "ldap1.sssd.com");
6cf099
+    check_server(test_ctx, srv, 389, "ldap1.sssd.com");
6cf099
 
6cf099
     /* Mark it at wrong, next lookup should yield ldap2 */
6cf099
     fo_set_server_status(srv, SERVER_NOT_WORKING);
6cf099
@@ -391,8 +429,8 @@ static void test_fo_srv_done2(struct tevent_req *req)
6cf099
 
6cf099
 static void test_fo_srv_done3(struct tevent_req *req)
6cf099
 {
6cf099
-    struct test_fo_srv_ctx *test_ctx = \
6cf099
-        tevent_req_callback_data(req, struct test_fo_srv_ctx);
6cf099
+    struct test_fo_ctx *test_ctx = \
6cf099
+        tevent_req_callback_data(req, struct test_fo_ctx);
6cf099
     struct fo_server *srv;
6cf099
     errno_t ret;
6cf099
 
6cf099
@@ -401,7 +439,7 @@ static void test_fo_srv_done3(struct tevent_req *req)
6cf099
     assert_int_equal(ret, ERR_OK);
6cf099
 
6cf099
     /* Must be ldap2 now */
6cf099
-    check_server(srv, 389, "ldap2.sssd.com");
6cf099
+    check_server(test_ctx, srv, 389, "ldap2.sssd.com");
6cf099
 
6cf099
     /* Mark is at wrong, next lookup must reach the end of the server list */
6cf099
     fo_set_server_status(srv, SERVER_NOT_WORKING);
6cf099
@@ -415,8 +453,8 @@ static void test_fo_srv_done3(struct tevent_req *req)
6cf099
 
6cf099
 static void test_fo_srv_done4(struct tevent_req *req)
6cf099
 {
6cf099
-    struct test_fo_srv_ctx *test_ctx = \
6cf099
-        tevent_req_callback_data(req, struct test_fo_srv_ctx);
6cf099
+    struct test_fo_ctx *test_ctx = \
6cf099
+        tevent_req_callback_data(req, struct test_fo_ctx);
6cf099
     struct fo_server *srv;
6cf099
     errno_t ret;
6cf099
 
6cf099
@@ -425,6 +463,35 @@ static void test_fo_srv_done4(struct tevent_req *req)
6cf099
     /* No servers are left..*/
6cf099
     assert_int_equal(ret, ENOENT);
6cf099
 
6cf099
+    /* reset the server status and try again.. */
6cf099
+    fo_reset_servers(test_ctx->fo_svc);
6cf099
+    if (test_ctx->srv_ctx) {
6cf099
+        test_fo_srv_mock_dns(test_ctx);
6cf099
+    }
6cf099
+
6cf099
+    req = fo_resolve_service_send(test_ctx, test_ctx->ctx->ev,
6cf099
+                                  test_ctx->resolv, test_ctx->fo_ctx,
6cf099
+                                  test_ctx->fo_svc);
6cf099
+    assert_non_null(req);
6cf099
+    tevent_req_set_callback(req, test_fo_srv_done5, test_ctx);
6cf099
+}
6cf099
+
6cf099
+static void test_fo_srv_done5(struct tevent_req *req)
6cf099
+{
6cf099
+    struct test_fo_ctx *test_ctx = \
6cf099
+        tevent_req_callback_data(req, struct test_fo_ctx);
6cf099
+    struct fo_server *srv;
6cf099
+    errno_t ret;
6cf099
+
6cf099
+    ret = fo_resolve_service_recv(req, &srv;;
6cf099
+    talloc_zfree(req);
6cf099
+
6cf099
+    assert_int_equal(ret, ERR_OK);
6cf099
+
6cf099
+    /* ldap1.sssd.com has lower priority, it must always be first */
6cf099
+    check_server(test_ctx, srv, 389, "ldap1.sssd.com");
6cf099
+
6cf099
+    /* OK, we made a full circle with the test, done */
6cf099
     test_ctx->ctx->error = ERR_OK;
6cf099
     test_ctx->ctx->done = true;
6cf099
 }
6cf099
@@ -432,20 +499,20 @@ static void test_fo_srv_done4(struct tevent_req *req)
6cf099
 /* Make sure that two queries more than TTL seconds apart resolve
6cf099
  * into two different lists
6cf099
  */
6cf099
-static void test_fo_srv_ttl_change_step(struct test_fo_srv_ctx *test_ctx);
6cf099
+static void test_fo_srv_ttl_change_step(struct test_fo_ctx *test_ctx);
6cf099
 static void test_fo_srv_before(struct tevent_req *req);
6cf099
 static void test_fo_srv_after(struct tevent_req *req);
6cf099
 
6cf099
 void test_fo_srv_ttl_change(void **state)
6cf099
 {
6cf099
-    struct test_fo_srv_ctx *test_ctx =
6cf099
-        talloc_get_type(*state, struct test_fo_srv_ctx);
6cf099
+    struct test_fo_ctx *test_ctx =
6cf099
+        talloc_get_type(*state, struct test_fo_ctx);
6cf099
 
6cf099
     test_ctx->ttl = TEST_SRV_SHORT_TTL;
6cf099
     test_fo_srv_ttl_change_step(test_ctx);
6cf099
 }
6cf099
 
6cf099
-static void test_fo_srv_ttl_change_step(struct test_fo_srv_ctx *test_ctx)
6cf099
+static void test_fo_srv_ttl_change_step(struct test_fo_ctx *test_ctx)
6cf099
 {
6cf099
     errno_t ret;
6cf099
     struct tevent_req *req;
6cf099
@@ -497,8 +564,8 @@ static void test_fo_srv_ttl_change_step(struct test_fo_srv_ctx *test_ctx)
6cf099
 
6cf099
 static void test_fo_srv_before(struct tevent_req *req)
6cf099
 {
6cf099
-    struct test_fo_srv_ctx *test_ctx = \
6cf099
-        tevent_req_callback_data(req, struct test_fo_srv_ctx);
6cf099
+    struct test_fo_ctx *test_ctx = \
6cf099
+        tevent_req_callback_data(req, struct test_fo_ctx);
6cf099
     struct fo_server *srv;
6cf099
     struct ares_srv_reply *s1;
6cf099
     struct ares_srv_reply *s2;
6cf099
@@ -511,7 +578,7 @@ static void test_fo_srv_before(struct tevent_req *req)
6cf099
 
6cf099
     DEBUG(SSSDBG_TRACE_FUNC, "Before TTL change\n");
6cf099
 
6cf099
-    check_server(srv, 389, "ldap1.sssd.com");
6cf099
+    check_server(test_ctx, srv, 389, "ldap1.sssd.com");
6cf099
     fo_set_server_status(srv, SERVER_WORKING);
6cf099
 
6cf099
     /* Simulate changing the DNS environment. Change the host names */
6cf099
@@ -548,8 +615,8 @@ static void test_fo_srv_before(struct tevent_req *req)
6cf099
 
6cf099
 static void test_fo_srv_after(struct tevent_req *req)
6cf099
 {
6cf099
-    struct test_fo_srv_ctx *test_ctx = \
6cf099
-        tevent_req_callback_data(req, struct test_fo_srv_ctx);
6cf099
+    struct test_fo_ctx *test_ctx = \
6cf099
+        tevent_req_callback_data(req, struct test_fo_ctx);
6cf099
     struct fo_server *srv;
6cf099
     errno_t ret;
6cf099
 
6cf099
@@ -558,7 +625,7 @@ static void test_fo_srv_after(struct tevent_req *req)
6cf099
     assert_int_equal(ret, ERR_OK);
6cf099
 
6cf099
     /* Must be a different server now */
6cf099
-    check_server(srv, 389, "ldap3.sssd.com");
6cf099
+    check_server(test_ctx, srv, 389, "ldap3.sssd.com");
6cf099
 
6cf099
     test_ctx->ctx->error = ERR_OK;
6cf099
     test_ctx->ctx->done = true;
6cf099
@@ -566,13 +633,33 @@ static void test_fo_srv_after(struct tevent_req *req)
6cf099
 
6cf099
 void test_fo_srv_ttl_zero(void **state)
6cf099
 {
6cf099
-    struct test_fo_srv_ctx *test_ctx =
6cf099
-        talloc_get_type(*state, struct test_fo_srv_ctx);
6cf099
+    struct test_fo_ctx *test_ctx =
6cf099
+        talloc_get_type(*state, struct test_fo_ctx);
6cf099
 
6cf099
     test_ctx->ttl = 0;
6cf099
     test_fo_srv_ttl_change_step(test_ctx);
6cf099
 }
6cf099
 
6cf099
+static void test_fo_hostlist(void **state)
6cf099
+{
6cf099
+    errno_t ret;
6cf099
+    struct test_fo_ctx *test_ctx =
6cf099
+        talloc_get_type(*state, struct test_fo_ctx);
6cf099
+
6cf099
+    ret = fo_add_server(test_ctx->fo_svc,
6cf099
+                        "ldap1.sssd.com", 389, test_ctx, true);
6cf099
+    assert_int_equal(ret, ERR_OK);
6cf099
+
6cf099
+    ret = fo_add_server(test_ctx->fo_svc,
6cf099
+                        "ldap2.sssd.com", 389, test_ctx, true);
6cf099
+    assert_int_equal(ret, ERR_OK);
6cf099
+
6cf099
+    test_fo_srv_step1(test_ctx);
6cf099
+
6cf099
+    ret = test_ev_loop(test_ctx->ctx);
6cf099
+    assert_int_equal(ret, ERR_OK);
6cf099
+}
6cf099
+
6cf099
 int main(int argc, const char *argv[])
6cf099
 {
6cf099
     int rv;
6cf099
@@ -585,6 +672,9 @@ int main(int argc, const char *argv[])
6cf099
     };
6cf099
 
6cf099
     const struct CMUnitTest tests[] = {
6cf099
+        cmocka_unit_test_setup_teardown(test_fo_hostlist,
6cf099
+                                        test_fo_setup,
6cf099
+                                        test_fo_teardown),
6cf099
         cmocka_unit_test_setup_teardown(test_fo_srv,
6cf099
                                         test_fo_srv_setup,
6cf099
                                         test_fo_srv_teardown),
6cf099
-- 
6cf099
2.4.3
6cf099