>From 63de05590cd0a9c1319880f44c6c1557e272d249 Mon Sep 17 00:00:00 2001 From: Jakub Hrozek Date: Mon, 21 Sep 2015 12:31:38 +0200 Subject: [PATCH 3/6] FO: Also reset the server common data in addition to SRV In a server that is expanded from a SRV query was reset, only it's 'meta-server' status was set to neutral, but the server->common structure still retained its not_working status. This patch also resets the status of the common structure so that both the SRV query and resolving the server are retried next time. --- src/providers/fail_over.c | 4 +++- src/tests/cmocka/test_fo_srv.c | 44 +++++++++++++++++++++++++++++++++++++----- 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/src/providers/fail_over.c b/src/providers/fail_over.c index 562f0b3fd7870387a80c889b245cda0d39dea509..b076687ac6e571f7e27402fd11ac60183ea46951 100644 --- a/src/providers/fail_over.c +++ b/src/providers/fail_over.c @@ -1554,7 +1554,9 @@ void fo_reset_servers(struct fo_service *service) DLIST_FOR_EACH(server, service->server_list) { if (server->srv_data != NULL) { set_srv_data_status(server->srv_data, SRV_NEUTRAL); - } else { + } + + if (server->common) { fo_set_server_status(server, SERVER_NAME_NOT_RESOLVED); } diff --git a/src/tests/cmocka/test_fo_srv.c b/src/tests/cmocka/test_fo_srv.c index e5c5e4fe3b818ca2df0ab7bcd1a83719fefba191..953f8b48b951e241b43d0236ff5971cf0e0703d8 100644 --- a/src/tests/cmocka/test_fo_srv.c +++ b/src/tests/cmocka/test_fo_srv.c @@ -292,13 +292,10 @@ static void test_fo_srv_done1(struct tevent_req *req); static void test_fo_srv_done2(struct tevent_req *req); static void test_fo_srv_done3(struct tevent_req *req); static void test_fo_srv_done4(struct tevent_req *req); +static void test_fo_srv_done5(struct tevent_req *req); -void test_fo_srv(void **state) +static void test_fo_srv_mock_dns(struct test_fo_srv_ctx *test_ctx) { - errno_t ret; - struct tevent_req *req; - struct test_fo_srv_ctx *test_ctx = - talloc_get_type(*state, struct test_fo_srv_ctx); struct ares_srv_reply *s1; struct ares_srv_reply *s2; char *dns_domain; @@ -325,6 +322,16 @@ void test_fo_srv(void **state) assert_non_null(dns_domain); mock_srv_results(s1, TEST_SRV_TTL, dns_domain); +} + +static void test_fo_srv(void **state) +{ + errno_t ret; + struct tevent_req *req; + struct test_fo_srv_ctx *test_ctx = + talloc_get_type(*state, struct test_fo_srv_ctx); + + test_fo_srv_mock_dns(test_ctx); ret = fo_add_srv_server(test_ctx->fo_svc, "_ldap", "sssd.com", "sssd.local", "tcp", test_ctx); @@ -425,6 +432,33 @@ static void test_fo_srv_done4(struct tevent_req *req) /* No servers are left..*/ assert_int_equal(ret, ENOENT); + /* reset the server status and try again.. */ + fo_reset_servers(test_ctx->fo_svc); + test_fo_srv_mock_dns(test_ctx); + + req = fo_resolve_service_send(test_ctx, test_ctx->ctx->ev, + test_ctx->resolv, test_ctx->fo_ctx, + test_ctx->fo_svc); + assert_non_null(req); + tevent_req_set_callback(req, test_fo_srv_done5, test_ctx); +} + +static void test_fo_srv_done5(struct tevent_req *req) +{ + struct test_fo_srv_ctx *test_ctx = \ + tevent_req_callback_data(req, struct test_fo_srv_ctx); + struct fo_server *srv; + errno_t ret; + + ret = fo_resolve_service_recv(req, &srv); + talloc_zfree(req); + + assert_int_equal(ret, ERR_OK); + + /* ldap1.sssd.com has lower priority, it must always be first */ + check_server(srv, 389, "ldap1.sssd.com"); + + /* OK, we made a full circle with the test, done */ test_ctx->ctx->error = ERR_OK; test_ctx->ctx->done = true; } -- 2.4.3