|
|
6cf099 |
From 6c1e606c3e9da9910554e48a6409a9b3001deedb Mon Sep 17 00:00:00 2001
|
|
|
6cf099 |
From: Jakub Hrozek <jhrozek@redhat.com>
|
|
|
6cf099 |
Date: Fri, 4 Sep 2015 09:27:17 +0200
|
|
|
6cf099 |
Subject: [PATCH 75/87] DP: Provide a way to mark subdomain as disabled and
|
|
|
6cf099 |
auto-enable it later with offline_timeout
|
|
|
6cf099 |
MIME-Version: 1.0
|
|
|
6cf099 |
Content-Type: text/plain; charset=UTF-8
|
|
|
6cf099 |
Content-Transfer-Encoding: 8bit
|
|
|
6cf099 |
|
|
|
6cf099 |
https://fedorahosted.org/sssd/ticket/2637
|
|
|
6cf099 |
|
|
|
6cf099 |
Adds a new Data Provider function be_mark_dom_offline() that is a
|
|
|
6cf099 |
replacement for be_mark_offline(). When called, the function would
|
|
|
6cf099 |
either set the whole back end offline, just like be_mark_offline or just
|
|
|
6cf099 |
set the subdomain status to inactive.
|
|
|
6cf099 |
|
|
|
6cf099 |
When a subdomain is inactive, there is a singleton timed task that would
|
|
|
6cf099 |
re-set the subdomin after offline_timeout seconds.
|
|
|
6cf099 |
|
|
|
6cf099 |
Reviewed-by: Pavel Březina <pbrezina@redhat.com>
|
|
|
6cf099 |
---
|
|
|
6cf099 |
Makefile.am | 26 +++
|
|
|
6cf099 |
src/providers/data_provider_be.c | 102 +++++++++++-
|
|
|
6cf099 |
src/providers/dp_backend.h | 1 +
|
|
|
6cf099 |
src/tests/cmocka/test_data_provider_be.c | 275 +++++++++++++++++++++++++++++++
|
|
|
6cf099 |
4 files changed, 395 insertions(+), 9 deletions(-)
|
|
|
6cf099 |
create mode 100644 src/tests/cmocka/test_data_provider_be.c
|
|
|
6cf099 |
|
|
|
6cf099 |
diff --git a/Makefile.am b/Makefile.am
|
|
|
6cf099 |
index e1102333b019e32c516c59c5fa969c970b688737..4e80701872c0e4e1391f0c6de8a2f68e719f8236 100644
|
|
|
6cf099 |
--- a/Makefile.am
|
|
|
6cf099 |
+++ b/Makefile.am
|
|
|
6cf099 |
@@ -236,6 +236,7 @@ if HAVE_CMOCKA
|
|
|
6cf099 |
test_ipa_subdom_server \
|
|
|
6cf099 |
test_krb5_wait_queue \
|
|
|
6cf099 |
test_cert_utils \
|
|
|
6cf099 |
+ test_data_provider_be \
|
|
|
6cf099 |
$(NULL)
|
|
|
6cf099 |
|
|
|
6cf099 |
if HAVE_LIBRESOLV
|
|
|
6cf099 |
@@ -2603,6 +2604,31 @@ test_cert_utils_LDADD = \
|
|
|
6cf099 |
libsss_cert.la \
|
|
|
6cf099 |
libsss_crypt.la \
|
|
|
6cf099 |
$(NULL)
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+test_data_provider_be_SOURCES = \
|
|
|
6cf099 |
+ $(sssd_be_SOURCES) \
|
|
|
6cf099 |
+ src/tests/cmocka/test_data_provider_be.c \
|
|
|
6cf099 |
+ src/tests/cmocka/common_mock_be.c \
|
|
|
6cf099 |
+ $(NULL)
|
|
|
6cf099 |
+test_data_provider_be_CFLAGS = \
|
|
|
6cf099 |
+ $(AM_CFLAGS) \
|
|
|
6cf099 |
+ -DUNIT_TESTING \
|
|
|
6cf099 |
+ $(CRYPTO_CFLAGS) \
|
|
|
6cf099 |
+ $(NULL)
|
|
|
6cf099 |
+test_data_provider_be_LDFLAGS = \
|
|
|
6cf099 |
+ -Wl,-wrap,_tevent_add_timer \
|
|
|
6cf099 |
+ $(NULL)
|
|
|
6cf099 |
+test_data_provider_be_LDADD = \
|
|
|
6cf099 |
+ $(CMOCKA_LIBS) \
|
|
|
6cf099 |
+ $(CARES_LIBS) \
|
|
|
6cf099 |
+ $(POPT_LIBS) \
|
|
|
6cf099 |
+ $(PAM_LIBS) \
|
|
|
6cf099 |
+ $(TALLOC_LIBS) \
|
|
|
6cf099 |
+ $(SSSD_INTERNAL_LTLIBS) \
|
|
|
6cf099 |
+ libsss_debug.la \
|
|
|
6cf099 |
+ libsss_test_common.la \
|
|
|
6cf099 |
+ $(NULL)
|
|
|
6cf099 |
+
|
|
|
6cf099 |
endif # HAVE_CMOCKA
|
|
|
6cf099 |
|
|
|
6cf099 |
noinst_PROGRAMS = pam_test_client
|
|
|
6cf099 |
diff --git a/src/providers/data_provider_be.c b/src/providers/data_provider_be.c
|
|
|
6cf099 |
index d147630248f0a24f5a632760b55b9284a6928e40..f477ac8bde2b1e3eea862e8e8f503566282ea8f3 100644
|
|
|
6cf099 |
--- a/src/providers/data_provider_be.c
|
|
|
6cf099 |
+++ b/src/providers/data_provider_be.c
|
|
|
6cf099 |
@@ -478,6 +478,24 @@ try_to_go_online(TALLOC_CTX *mem_ctx,
|
|
|
6cf099 |
return EOK;
|
|
|
6cf099 |
}
|
|
|
6cf099 |
|
|
|
6cf099 |
+static int get_offline_timeout(struct be_ctx *ctx)
|
|
|
6cf099 |
+{
|
|
|
6cf099 |
+ errno_t ret;
|
|
|
6cf099 |
+ int offline_timeout;
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ ret = confdb_get_int(ctx->cdb, ctx->conf_path,
|
|
|
6cf099 |
+ CONFDB_DOMAIN_OFFLINE_TIMEOUT, 60,
|
|
|
6cf099 |
+ &offline_timeout);
|
|
|
6cf099 |
+ if (ret != EOK) {
|
|
|
6cf099 |
+ DEBUG(SSSDBG_CRIT_FAILURE,
|
|
|
6cf099 |
+ "Failed to get offline_timeout from confdb. "
|
|
|
6cf099 |
+ "Will use 60 seconds.\n");
|
|
|
6cf099 |
+ offline_timeout = 60;
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ return offline_timeout;
|
|
|
6cf099 |
+}
|
|
|
6cf099 |
+
|
|
|
6cf099 |
void be_mark_offline(struct be_ctx *ctx)
|
|
|
6cf099 |
{
|
|
|
6cf099 |
int offline_timeout;
|
|
|
6cf099 |
@@ -493,15 +511,9 @@ void be_mark_offline(struct be_ctx *ctx)
|
|
|
6cf099 |
/* This is the first time we go offline - create a periodic task
|
|
|
6cf099 |
* to check if we can switch to online. */
|
|
|
6cf099 |
DEBUG(SSSDBG_TRACE_INTERNAL, "Initialize check_if_online_ptask.\n");
|
|
|
6cf099 |
- ret = confdb_get_int(ctx->cdb, ctx->conf_path,
|
|
|
6cf099 |
- CONFDB_DOMAIN_OFFLINE_TIMEOUT, 60,
|
|
|
6cf099 |
- &offline_timeout);
|
|
|
6cf099 |
- if (ret != EOK) {
|
|
|
6cf099 |
- DEBUG(SSSDBG_CRIT_FAILURE,
|
|
|
6cf099 |
- "Failed to get offline_timeout from confdb. "
|
|
|
6cf099 |
- "Will use 60 seconds.\n");
|
|
|
6cf099 |
- offline_timeout = 60;
|
|
|
6cf099 |
- }
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ offline_timeout = get_offline_timeout(ctx);
|
|
|
6cf099 |
+
|
|
|
6cf099 |
ret = be_ptask_create_sync(ctx, ctx,
|
|
|
6cf099 |
offline_timeout, offline_timeout,
|
|
|
6cf099 |
offline_timeout, 30, offline_timeout,
|
|
|
6cf099 |
@@ -524,10 +536,82 @@ void be_mark_offline(struct be_ctx *ctx)
|
|
|
6cf099 |
be_run_offline_cb(ctx);
|
|
|
6cf099 |
}
|
|
|
6cf099 |
|
|
|
6cf099 |
+static void be_subdom_reset_status(struct tevent_context *ev,
|
|
|
6cf099 |
+ struct tevent_timer *te,
|
|
|
6cf099 |
+ struct timeval current_time,
|
|
|
6cf099 |
+ void *pvt)
|
|
|
6cf099 |
+{
|
|
|
6cf099 |
+ struct sss_domain_info *subdom = talloc_get_type(pvt,
|
|
|
6cf099 |
+ struct sss_domain_info);
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ DEBUG(SSSDBG_TRACE_LIBS, "Resetting subdomain %s\n", subdom->name);
|
|
|
6cf099 |
+ subdom->state = DOM_ACTIVE;
|
|
|
6cf099 |
+}
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+static void be_mark_subdom_offline(struct sss_domain_info *subdom,
|
|
|
6cf099 |
+ struct be_ctx *be_ctx)
|
|
|
6cf099 |
+{
|
|
|
6cf099 |
+ struct timeval tv;
|
|
|
6cf099 |
+ struct tevent_timer *timeout = NULL;
|
|
|
6cf099 |
+ int reset_status_timeout;
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ reset_status_timeout = get_offline_timeout(be_ctx);
|
|
|
6cf099 |
+ tv = tevent_timeval_current_ofs(reset_status_timeout, 0);
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ switch (subdom->state) {
|
|
|
6cf099 |
+ case DOM_DISABLED:
|
|
|
6cf099 |
+ DEBUG(SSSDBG_MINOR_FAILURE, "Won't touch disabled subdomain\n");
|
|
|
6cf099 |
+ return;
|
|
|
6cf099 |
+ case DOM_INACTIVE:
|
|
|
6cf099 |
+ DEBUG(SSSDBG_TRACE_ALL, "Subdomain already inactive\n");
|
|
|
6cf099 |
+ return;
|
|
|
6cf099 |
+ case DOM_ACTIVE:
|
|
|
6cf099 |
+ DEBUG(SSSDBG_TRACE_LIBS,
|
|
|
6cf099 |
+ "Marking subdomain %s as inactive\n", subdom->name);
|
|
|
6cf099 |
+ break;
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ timeout = tevent_add_timer(be_ctx->ev, be_ctx, tv,
|
|
|
6cf099 |
+ be_subdom_reset_status, subdom);
|
|
|
6cf099 |
+ if (timeout == NULL) {
|
|
|
6cf099 |
+ DEBUG(SSSDBG_OP_FAILURE, "Cannot create timer\n");
|
|
|
6cf099 |
+ return;
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ subdom->state = DOM_INACTIVE;
|
|
|
6cf099 |
+}
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+void be_mark_dom_offline(struct sss_domain_info *dom, struct be_ctx *ctx)
|
|
|
6cf099 |
+{
|
|
|
6cf099 |
+ if (IS_SUBDOMAIN(dom) == false) {
|
|
|
6cf099 |
+ DEBUG(SSSDBG_TRACE_LIBS, "Marking back end offline\n");
|
|
|
6cf099 |
+ be_mark_offline(ctx);
|
|
|
6cf099 |
+ } else {
|
|
|
6cf099 |
+ DEBUG(SSSDBG_TRACE_LIBS, "Marking subdomain %s offline\n", dom->name);
|
|
|
6cf099 |
+ be_mark_subdom_offline(dom, ctx);
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+}
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+static void reactivate_subdoms(struct sss_domain_info *head)
|
|
|
6cf099 |
+{
|
|
|
6cf099 |
+ struct sss_domain_info *dom;
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ DEBUG(SSSDBG_TRACE_LIBS, "Resetting all subdomains");
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ for (dom = head; dom; dom = get_next_domain(dom, true)) {
|
|
|
6cf099 |
+ if (sss_domain_get_state(dom) == DOM_INACTIVE) {
|
|
|
6cf099 |
+ sss_domain_set_state(dom, DOM_ACTIVE);
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+}
|
|
|
6cf099 |
+
|
|
|
6cf099 |
static void be_reset_offline(struct be_ctx *ctx)
|
|
|
6cf099 |
{
|
|
|
6cf099 |
ctx->offstat.went_offline = 0;
|
|
|
6cf099 |
ctx->offstat.offline = false;
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ reactivate_subdoms(ctx->domain);
|
|
|
6cf099 |
+
|
|
|
6cf099 |
be_ptask_disable(ctx->check_if_online_ptask);
|
|
|
6cf099 |
be_run_online_cb(ctx);
|
|
|
6cf099 |
}
|
|
|
6cf099 |
diff --git a/src/providers/dp_backend.h b/src/providers/dp_backend.h
|
|
|
6cf099 |
index e4e22ea343a5cbf4c75f176c3002dc579c2893fe..4d54bf547682379bcb8cf855b8fae39214495728 100644
|
|
|
6cf099 |
--- a/src/providers/dp_backend.h
|
|
|
6cf099 |
+++ b/src/providers/dp_backend.h
|
|
|
6cf099 |
@@ -189,6 +189,7 @@ struct be_host_req {
|
|
|
6cf099 |
|
|
|
6cf099 |
bool be_is_offline(struct be_ctx *ctx);
|
|
|
6cf099 |
void be_mark_offline(struct be_ctx *ctx);
|
|
|
6cf099 |
+void be_mark_dom_offline(struct sss_domain_info *dom, struct be_ctx *ctx);
|
|
|
6cf099 |
|
|
|
6cf099 |
int be_add_reconnect_cb(TALLOC_CTX *mem_ctx,
|
|
|
6cf099 |
struct be_ctx *ctx,
|
|
|
6cf099 |
diff --git a/src/tests/cmocka/test_data_provider_be.c b/src/tests/cmocka/test_data_provider_be.c
|
|
|
6cf099 |
new file mode 100644
|
|
|
6cf099 |
index 0000000000000000000000000000000000000000..68eb5841bee568bef64cb62461403036b1320bec
|
|
|
6cf099 |
--- /dev/null
|
|
|
6cf099 |
+++ b/src/tests/cmocka/test_data_provider_be.c
|
|
|
6cf099 |
@@ -0,0 +1,275 @@
|
|
|
6cf099 |
+/*
|
|
|
6cf099 |
+ Copyright (C) 2015 Red Hat
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ This program is free software; you can redistribute it and/or modify
|
|
|
6cf099 |
+ it under the terms of the GNU General Public License as published by
|
|
|
6cf099 |
+ the Free Software Foundation; either version 3 of the License, or
|
|
|
6cf099 |
+ (at your option) any later version.
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ This program is distributed in the hope that it will be useful,
|
|
|
6cf099 |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
6cf099 |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
6cf099 |
+ GNU General Public License for more details.
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ You should have received a copy of the GNU General Public License
|
|
|
6cf099 |
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
6cf099 |
+*/
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+#include <talloc.h>
|
|
|
6cf099 |
+#include <tevent.h>
|
|
|
6cf099 |
+#include <errno.h>
|
|
|
6cf099 |
+#include <popt.h>
|
|
|
6cf099 |
+#include <time.h>
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+#include "providers/dp_backend.h"
|
|
|
6cf099 |
+#include "tests/cmocka/common_mock.h"
|
|
|
6cf099 |
+#include "tests/cmocka/common_mock_be.h"
|
|
|
6cf099 |
+#include "tests/common.h"
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+#define TESTS_PATH "tests_dp_be"
|
|
|
6cf099 |
+#define TEST_CONF_DB "test_dp_be_conf.ldb"
|
|
|
6cf099 |
+#define TEST_DOM_NAME "dp_be_test"
|
|
|
6cf099 |
+#define TEST_ID_PROVIDER "ldap"
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+#define OFFLINE_TIMEOUT 2
|
|
|
6cf099 |
+#define AS_STR(param) (#param)
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+static TALLOC_CTX *global_mock_context = NULL;
|
|
|
6cf099 |
+static bool global_timer_added;
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+struct tevent_timer *__real__tevent_add_timer(struct tevent_context *ev,
|
|
|
6cf099 |
+ TALLOC_CTX *mem_ctx,
|
|
|
6cf099 |
+ struct timeval next_event,
|
|
|
6cf099 |
+ tevent_timer_handler_t handler,
|
|
|
6cf099 |
+ void *private_data,
|
|
|
6cf099 |
+ const char *handler_name,
|
|
|
6cf099 |
+ const char *location);
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+struct tevent_timer *__wrap__tevent_add_timer(struct tevent_context *ev,
|
|
|
6cf099 |
+ TALLOC_CTX *mem_ctx,
|
|
|
6cf099 |
+ struct timeval next_event,
|
|
|
6cf099 |
+ tevent_timer_handler_t handler,
|
|
|
6cf099 |
+ void *private_data,
|
|
|
6cf099 |
+ const char *handler_name,
|
|
|
6cf099 |
+ const char *location)
|
|
|
6cf099 |
+{
|
|
|
6cf099 |
+ global_timer_added = true;
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ return __real__tevent_add_timer(ev, mem_ctx, next_event,
|
|
|
6cf099 |
+ handler, private_data, handler_name,
|
|
|
6cf099 |
+ location);
|
|
|
6cf099 |
+}
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+struct test_ctx {
|
|
|
6cf099 |
+ struct sss_test_ctx *tctx;
|
|
|
6cf099 |
+ struct be_ctx *be_ctx;
|
|
|
6cf099 |
+};
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+static struct sss_domain_info *named_domain(TALLOC_CTX *mem_ctx,
|
|
|
6cf099 |
+ const char *name,
|
|
|
6cf099 |
+ struct sss_domain_info *parent)
|
|
|
6cf099 |
+{
|
|
|
6cf099 |
+ struct sss_domain_info *dom = NULL;
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ dom = talloc_zero(mem_ctx, struct sss_domain_info);
|
|
|
6cf099 |
+ assert_non_null(dom);
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ dom->name = talloc_strdup(dom, name);
|
|
|
6cf099 |
+ assert_non_null(dom->name);
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ dom->parent = parent;
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ return dom;
|
|
|
6cf099 |
+}
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+static int test_setup(void **state)
|
|
|
6cf099 |
+{
|
|
|
6cf099 |
+ struct test_ctx *test_ctx = NULL;
|
|
|
6cf099 |
+ struct sss_test_conf_param params[] = {
|
|
|
6cf099 |
+ { "offline_timeout", AS_STR(OFFLINE_TIMEOUT) },
|
|
|
6cf099 |
+ { NULL, NULL }, /* Sentinel */
|
|
|
6cf099 |
+ };
|
|
|
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_talloc_context, struct test_ctx);
|
|
|
6cf099 |
+ assert_non_null(test_ctx);
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ test_ctx->tctx = create_dom_test_ctx(test_ctx, TESTS_PATH,
|
|
|
6cf099 |
+ TEST_CONF_DB, TEST_DOM_NAME,
|
|
|
6cf099 |
+ TEST_ID_PROVIDER, params);
|
|
|
6cf099 |
+ assert_non_null(test_ctx->tctx);
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ test_ctx->be_ctx = mock_be_ctx(test_ctx, test_ctx->tctx);
|
|
|
6cf099 |
+ assert_non_null(test_ctx->be_ctx);
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ test_ctx->be_ctx->domain->subdomains = named_domain(test_ctx,
|
|
|
6cf099 |
+ "subdomains",
|
|
|
6cf099 |
+ test_ctx->be_ctx->domain);
|
|
|
6cf099 |
+ assert_non_null(test_ctx->be_ctx->domain->subdomains);
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ *state = test_ctx;
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ return 0;
|
|
|
6cf099 |
+}
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+static int test_teardown(void **state)
|
|
|
6cf099 |
+{
|
|
|
6cf099 |
+ talloc_zfree(*state);
|
|
|
6cf099 |
+ assert_true(leak_check_teardown());
|
|
|
6cf099 |
+ return 0;
|
|
|
6cf099 |
+}
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+static void assert_domain_state(struct sss_domain_info *dom,
|
|
|
6cf099 |
+ enum sss_domain_state expected_state)
|
|
|
6cf099 |
+{
|
|
|
6cf099 |
+ enum sss_domain_state dom_state;
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ dom_state = sss_domain_get_state(dom);
|
|
|
6cf099 |
+ assert_int_equal(dom_state, expected_state);
|
|
|
6cf099 |
+}
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+static void test_mark_subdom_offline_check(struct tevent_context *ev,
|
|
|
6cf099 |
+ struct tevent_timer *te,
|
|
|
6cf099 |
+ struct timeval current_time,
|
|
|
6cf099 |
+ void *pvt)
|
|
|
6cf099 |
+{
|
|
|
6cf099 |
+ struct test_ctx *test_ctx = talloc_get_type(pvt, struct test_ctx);
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ assert_domain_state(test_ctx->be_ctx->domain->subdomains,
|
|
|
6cf099 |
+ DOM_ACTIVE);
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ test_ctx->tctx->done = true;
|
|
|
6cf099 |
+ test_ctx->tctx->error = EOK;
|
|
|
6cf099 |
+}
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+static void test_mark_dom_offline(void **state)
|
|
|
6cf099 |
+{
|
|
|
6cf099 |
+ struct test_ctx *test_ctx = talloc_get_type(*state, struct test_ctx);
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ assert_domain_state(test_ctx->be_ctx->domain, DOM_ACTIVE);
|
|
|
6cf099 |
+ assert_false(be_is_offline(test_ctx->be_ctx));
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ be_mark_dom_offline(test_ctx->be_ctx->domain, test_ctx->be_ctx);
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ assert_true(be_is_offline(test_ctx->be_ctx));
|
|
|
6cf099 |
+ assert_domain_state(test_ctx->be_ctx->domain, DOM_ACTIVE);
|
|
|
6cf099 |
+}
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+static void test_mark_subdom_offline(void **state)
|
|
|
6cf099 |
+{
|
|
|
6cf099 |
+ struct timeval tv;
|
|
|
6cf099 |
+ struct tevent_timer *check_ev = NULL;
|
|
|
6cf099 |
+ struct test_ctx *test_ctx = talloc_get_type(*state, struct test_ctx);
|
|
|
6cf099 |
+ errno_t ret;
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ assert_domain_state(test_ctx->be_ctx->domain->subdomains,
|
|
|
6cf099 |
+ DOM_ACTIVE);
|
|
|
6cf099 |
+ assert_false(be_is_offline(test_ctx->be_ctx));
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ global_timer_added = false;
|
|
|
6cf099 |
+ be_mark_dom_offline(test_ctx->be_ctx->domain->subdomains, test_ctx->be_ctx);
|
|
|
6cf099 |
+ assert_domain_state(test_ctx->be_ctx->domain->subdomains,
|
|
|
6cf099 |
+ DOM_INACTIVE);
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ /* A timer must be added that resets the state back */
|
|
|
6cf099 |
+ assert_true(global_timer_added);
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ /* Global offline state must not change */
|
|
|
6cf099 |
+ assert_false(be_is_offline(test_ctx->be_ctx));
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ /* Make sure we don't add a second timer */
|
|
|
6cf099 |
+ global_timer_added = false;
|
|
|
6cf099 |
+ be_mark_dom_offline(test_ctx->be_ctx->domain->subdomains, test_ctx->be_ctx);
|
|
|
6cf099 |
+ assert_domain_state(test_ctx->be_ctx->domain->subdomains,
|
|
|
6cf099 |
+ DOM_INACTIVE);
|
|
|
6cf099 |
+ assert_false(global_timer_added);
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ /* Wait for the internal timer to reset our subdomain back */
|
|
|
6cf099 |
+ tv = tevent_timeval_current_ofs(OFFLINE_TIMEOUT + 1, 0);
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ check_ev = tevent_add_timer(test_ctx->tctx->ev, test_ctx, tv,
|
|
|
6cf099 |
+ test_mark_subdom_offline_check,
|
|
|
6cf099 |
+ test_ctx);
|
|
|
6cf099 |
+ if (check_ev == NULL) {
|
|
|
6cf099 |
+ DEBUG(SSSDBG_OP_FAILURE, "Cannot create timer\n");
|
|
|
6cf099 |
+ return;
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ ret = test_ev_loop(test_ctx->tctx);
|
|
|
6cf099 |
+ assert_int_equal(ret, EOK);
|
|
|
6cf099 |
+}
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+static void test_mark_subdom_offline_disabled(void **state)
|
|
|
6cf099 |
+{
|
|
|
6cf099 |
+ struct test_ctx *test_ctx = talloc_get_type(*state, struct test_ctx);
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ sss_domain_set_state(test_ctx->be_ctx->domain->subdomains, DOM_DISABLED);
|
|
|
6cf099 |
+ assert_domain_state(test_ctx->be_ctx->domain->subdomains,
|
|
|
6cf099 |
+ DOM_DISABLED);
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ be_mark_dom_offline(test_ctx->be_ctx->domain->subdomains, test_ctx->be_ctx);
|
|
|
6cf099 |
+ assert_domain_state(test_ctx->be_ctx->domain->subdomains,
|
|
|
6cf099 |
+ DOM_DISABLED);
|
|
|
6cf099 |
+}
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+int main(int argc, const char *argv[])
|
|
|
6cf099 |
+{
|
|
|
6cf099 |
+ poptContext pc;
|
|
|
6cf099 |
+ int opt;
|
|
|
6cf099 |
+ int rv;
|
|
|
6cf099 |
+ int no_cleanup = 0;
|
|
|
6cf099 |
+ struct poptOption long_options[] = {
|
|
|
6cf099 |
+ POPT_AUTOHELP
|
|
|
6cf099 |
+ SSSD_DEBUG_OPTS
|
|
|
6cf099 |
+ {"no-cleanup", 'n', POPT_ARG_NONE, &no_cleanup, 0,
|
|
|
6cf099 |
+ _("Do not delete the test database after a test run"), NULL },
|
|
|
6cf099 |
+ POPT_TABLEEND
|
|
|
6cf099 |
+ };
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ const struct CMUnitTest tests[] = {
|
|
|
6cf099 |
+ cmocka_unit_test_setup_teardown(test_mark_dom_offline,
|
|
|
6cf099 |
+ test_setup,
|
|
|
6cf099 |
+ test_teardown),
|
|
|
6cf099 |
+ cmocka_unit_test_setup_teardown(test_mark_subdom_offline,
|
|
|
6cf099 |
+ test_setup,
|
|
|
6cf099 |
+ test_teardown),
|
|
|
6cf099 |
+ cmocka_unit_test_setup_teardown(test_mark_subdom_offline_disabled,
|
|
|
6cf099 |
+ test_setup,
|
|
|
6cf099 |
+ test_teardown),
|
|
|
6cf099 |
+ };
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ /* Set debug level to invalid value so we can deside if -d 0 was used. */
|
|
|
6cf099 |
+ debug_level = SSSDBG_INVALID;
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ pc = poptGetContext(argv[0], argc, argv, long_options, 0);
|
|
|
6cf099 |
+ while((opt = poptGetNextOpt(pc)) != -1) {
|
|
|
6cf099 |
+ switch(opt) {
|
|
|
6cf099 |
+ default:
|
|
|
6cf099 |
+ fprintf(stderr, "\nInvalid option %s: %s\n\n",
|
|
|
6cf099 |
+ poptBadOption(pc, 0), poptStrerror(opt));
|
|
|
6cf099 |
+ poptPrintUsage(pc, stderr, 0);
|
|
|
6cf099 |
+ return 1;
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+ poptFreeContext(pc);
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ DEBUG_CLI_INIT(debug_level);
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ /* Even though normally the tests should clean up after themselves
|
|
|
6cf099 |
+ * they might not after a failed run. Remove the old db to be sure */
|
|
|
6cf099 |
+ tests_set_cwd();
|
|
|
6cf099 |
+ test_dom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, TEST_DOM_NAME);
|
|
|
6cf099 |
+ test_dom_suite_setup(TESTS_PATH);
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ rv = cmocka_run_group_tests(tests, NULL, NULL);
|
|
|
6cf099 |
+ if (rv == 0 && !no_cleanup) {
|
|
|
6cf099 |
+ test_dom_suite_cleanup(TESTS_PATH, TEST_CONF_DB, TEST_DOM_NAME);
|
|
|
6cf099 |
+ }
|
|
|
6cf099 |
+ return rv;
|
|
|
6cf099 |
+
|
|
|
6cf099 |
+ return cmocka_run_group_tests(tests, NULL, NULL);
|
|
|
6cf099 |
+}
|
|
|
6cf099 |
--
|
|
|
6cf099 |
2.4.3
|
|
|
6cf099 |
|