[SSSD] [PATCH] Do not attempt to resolve localhost during tests

Jakub Hrozek jhrozek at redhat.com
Thu May 2 14:46:32 UTC 2013


Hi,

Timo Aaltonen discovered that one of our fail over unit tests require
the "localhost" host name to be resolvable, while there is no guarantee
that a buildsystem that runs the build can resolve "localhost".

Attached are three very small patches:

[PATCH 1/3] tests: Do not attempt to resolve localhost unless -n is
selected
This patch disables the test that was relying on "localhost".

[PATCH 2/3] tests: enable network tests based on environment variable
Currently the tests that require a network connection can be enabled by
selecting the -n command line parameter for the test. But in some cases,
like the buildsystems, it might be better to actually enable network
tests globally for all tests.

[PATCH 3/3] RPM: run network tests by default
Enables the unit tests that require a network connectin before calling
"make check".
I tried building a SRPM with these changes in Koji and the build
succeeded:
http://koji.fedoraproject.org/koji/taskinfo?taskID=5325056
-------------- next part --------------
>From cdf0cff27ec7dfb45478a2dc666497747b762aa9 Mon Sep 17 00:00:00 2001
From: Jakub Hrozek <jhrozek at redhat.com>
Date: Thu, 2 May 2013 16:23:54 +0200
Subject: [PATCH 1/3] tests: Do not attempt to resolve localhost unless -n is
 selected

Some build environments cannot resolve even "localhost". Disable the
failover test that resolves "localhost" unless network-facing tests are
enabled.
---
 src/tests/fail_over-tests.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/tests/fail_over-tests.c b/src/tests/fail_over-tests.c
index c00025960f9ee593eb7f33a1bb13df056a702816..ea5eb8b0b7db46be74f46ab70e32e9539484d0c6 100644
--- a/src/tests/fail_over-tests.c
+++ b/src/tests/fail_over-tests.c
@@ -267,8 +267,8 @@ create_suite(void)
     tcase_add_checked_fixture(tc, ck_leak_check_setup, ck_leak_check_teardown);
     /* Do some testing */
     tcase_add_test(tc, test_fo_new_service);
-    tcase_add_test(tc, test_fo_resolve_service);
     if (use_net_test) {
+        tcase_add_test(tc, test_fo_resolve_service);
     }
     /* Add all test cases to the test suite */
     suite_add_tcase(s, tc);
-- 
1.8.2.1

-------------- next part --------------
>From d37171c459734b0430fe4b55eb39b2606aba45f0 Mon Sep 17 00:00:00 2001
From: Jakub Hrozek <jhrozek at redhat.com>
Date: Thu, 2 May 2013 16:19:22 +0200
Subject: [PATCH 2/3] tests: enable network tests based on environment variable

Currently the tests that require a network connection can be enabled by
selecting the -n command line parameter for the test. But in some cases,
like the buildsystems, it might be better to actually enable network
tests globally for all tests.

This patch enables the network tests if the environment variable
SSS_TESTS_USE_NETWORK is set.
---
 src/tests/fail_over-tests.c | 17 ++++++++++++++++-
 src/tests/resolv-tests.c    | 12 +++++++++++-
 2 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/src/tests/fail_over-tests.c b/src/tests/fail_over-tests.c
index ea5eb8b0b7db46be74f46ab70e32e9539484d0c6..9e5523c835055b21d4a0512e3f7664db73c3ed4d 100644
--- a/src/tests/fail_over-tests.c
+++ b/src/tests/fail_over-tests.c
@@ -288,7 +288,11 @@ main(int argc, const char *argv[])
     struct poptOption long_options[] = {
         POPT_AUTOHELP
         { "debug-level", 'd', POPT_ARG_INT, &debug_level, 0, "Set debug level", NULL },
-        { "use-net-test", 'n', POPT_ARG_NONE, 0, 'n', "Run tests that need an active internet connection", NULL },
+        { "use-net-test", 'n', POPT_ARG_NONE, 0, 'n',
+                    "Run tests that need an active internet connection. " \
+                    "These tests can also be enabled by setting the " \
+                    "environment variable SSS_TESTS_USE_NETWORK",
+                    NULL },
         POPT_TABLEEND
     };
 
@@ -315,6 +319,17 @@ main(int argc, const char *argv[])
 
     tests_set_cwd();
 
+    if (getenv("SSS_TESTS_USE_NETWORK") != NULL) {
+        DEBUG(SSSDBG_CONF_SETTINGS,
+              ("Enabling unit tests that require network access\n"));
+        use_net_test = 1;
+    }
+
+    if (!use_net_test) {
+        printf("Network tests disabled. Rerun with the \"-n\" "
+               "option to run the full suite of tests\n");
+    }
+
     suite = create_suite();
     sr = srunner_create(suite);
     /* If CK_VERBOSITY is set, use that, otherwise it defaults to CK_NORMAL */
diff --git a/src/tests/resolv-tests.c b/src/tests/resolv-tests.c
index dd212c055f6c25c9add3c49a701df19c2e802faf..99d8e3ad5073b212712aeac3539c69014652a323 100644
--- a/src/tests/resolv-tests.c
+++ b/src/tests/resolv-tests.c
@@ -826,7 +826,11 @@ int main(int argc, const char *argv[])
     struct poptOption long_options[] = {
         POPT_AUTOHELP
         { "debug-level", 'd', POPT_ARG_INT, &debug, 0, "Set debug level", NULL },
-        { "use-net-test", 'n', POPT_ARG_NONE, 0, 'n', "Run tests that need an active internet connection", NULL },
+        { "use-net-test", 'n', POPT_ARG_NONE, 0, 'n',
+                    "Run tests that need an active internet connection. " \
+                    "These tests can also be enabled by setting the " \
+                    "environment variable SSS_TESTS_USE_NETWORK",
+                    NULL },
         { "txt-host", 't', POPT_ARG_STRING, 0, 't', "Specify the host used for TXT record testing", NULL },
         { "srv-host", 's', POPT_ARG_STRING, 0, 's', "Specify the host used for SRV record testing", NULL },
         POPT_TABLEEND
@@ -858,6 +862,12 @@ int main(int argc, const char *argv[])
 
     DEBUG_INIT(debug);
 
+    if (getenv("SSS_TESTS_USE_NETWORK") != NULL) {
+        DEBUG(SSSDBG_CONF_SETTINGS,
+              ("Enabling unit tests that require network access\n"));
+        use_net_test = 1;
+    }
+
     if (!use_net_test) {
         printf("Network tests disabled. Rerun with the \"-n\" "
                "option to run the full suite of tests\n");
-- 
1.8.2.1

-------------- next part --------------
>From cb676c6d55acbfa71dd5c5a97a646be9b3ba596f Mon Sep 17 00:00:00 2001
From: Jakub Hrozek <jhrozek at redhat.com>
Date: Thu, 2 May 2013 16:22:56 +0200
Subject: [PATCH 3/3] RPM: run network tests by default

Enables the unit tests that require a network connectin before calling
"make check".
---
 contrib/sssd.spec.in | 1 +
 1 file changed, 1 insertion(+)

diff --git a/contrib/sssd.spec.in b/contrib/sssd.spec.in
index eb21831fb8d4ebe221af2ab791e5858f87668760..8beeeb6f7d8be27f3e6520af7d6df4d9332e3a0b 100644
--- a/contrib/sssd.spec.in
+++ b/contrib/sssd.spec.in
@@ -299,6 +299,7 @@ make %{?_smp_mflags} docs
 
 %check
 export CK_TIMEOUT_MULTIPLIER=10
+export SSS_TESTS_USE_NETWORK=1
 make %{?_smp_mflags} check
 unset CK_TIMEOUT_MULTIPLIER
 
-- 
1.8.2.1



More information about the sssd-devel mailing list