]> git.michaelhowe.org Git - packages/o/openafs.git/commitdiff
tests: Improve failure mode for unresolvable hostname
authorMarc Dionne <marc.c.dionne@gmail.com>
Sun, 17 Feb 2013 18:29:38 +0000 (13:29 -0500)
committerDerrick Brashear <shadow@your-file-system.com>
Mon, 18 Feb 2013 04:51:15 +0000 (20:51 -0800)
In the case of a host where gethostbyname is unable to resolve
the hostname, afstest_BuildTestConfig() may return NULL which
can cause several tests to crash.

Add a common function to look out for this condition and use it where
appropriate.  When it occurs, the current module is skipped and
the user gets an error message that indicates the configuration
problem.

Change-Id: I7216876eb2424368f415e5759e2b95009ad055b2
Reviewed-on: http://gerrit.openafs.org/9120
Reviewed-by: Derrick Brashear <shadow@your-file-system.com>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Jeffrey Altman <jaltman@your-file-system.com>
tests/auth/Makefile.in
tests/auth/authcon-t.c
tests/auth/keys-t.c
tests/auth/realms-t.c
tests/auth/superuser-t.c
tests/common/common.h
tests/common/config.c
tests/common/network.c
tests/volser/vos-t.c

index 4cdb639133b6f2a7b0f0cb3a3ee809341b8df92c..ed4ed27ae76e7f980e894ef74e7f453cb69615da 100644 (file)
@@ -15,22 +15,22 @@ MODULE_LIBS =       ../tap/libtap.a \
                $(LIB_rfc3961) $(LIB_roken) \
                $(XLIBS)
 
-authcon-t: authcon-t.o ../common/config.o
-       $(LT_LDRULE_static) authcon-t.o ../common/config.o \
+authcon-t: authcon-t.o ../common/config.o ../common/network.o
+       $(LT_LDRULE_static) authcon-t.o ../common/config.o ../common/network.o \
                $(MODULE_LIBS)
 
 superuser-t: superuser-t.o ../common/config.o ../common/rxkad.o \
-            test.cs.o test.ss.o test.xdr.o
+            test.cs.o test.ss.o test.xdr.o ../common/network.o
        $(LT_LDRULE_static) superuser-t.o ../common/config.o \
                ../common/rxkad.o ../common/servers.o \
-               test.cs.o test.ss.o test.xdr.o \
+               test.cs.o test.ss.o test.xdr.o ../common/network.o \
                $(MODULE_LIBS)
 
-keys-t: keys-t.o ../common/config.o
-       $(LT_LDRULE_static) keys-t.o ../common/config.o $(MODULE_LIBS)
+keys-t: keys-t.o ../common/config.o ../common/network.o
+       $(LT_LDRULE_static) keys-t.o ../common/config.o ../common/network.o $(MODULE_LIBS)
 
-realms-t: realms-t.o ../common/config.o
-       $(LT_LDRULE_static) realms-t.o ../common/config.o $(MODULE_LIBS)
+realms-t: realms-t.o ../common/config.o ../common/network.o
+       $(LT_LDRULE_static) realms-t.o ../common/config.o ../common/network.o $(MODULE_LIBS)
 
 writekeyfile: writekeyfile.o
        $(LT_LDRULE_static) writekeyfile.o $(MODULE_LIBS)
index 46cf3c949c9090b912adbbab002cf64d6b90fde2..e029774f342f6037b7b68f773ac06206b292fded 100644 (file)
@@ -51,6 +51,8 @@ main(int argc, char **argv)
     struct afsconf_typedKey *key;
     int code = 0;
 
+    afstest_SkipTestsIfBadHostname();
+
     plan(9);
     dirname = afstest_BuildTestConfig();
 
index 2f08e08c14d9cdd5d0478c5311caecf5947e8ef6..5c483c5378fa8074b075829b3430f72a70ef3c3c 100644 (file)
@@ -106,6 +106,8 @@ int main(int argc, char **argv)
     int code;
     int i;
 
+    afstest_SkipTestsIfBadHostname();
+
     plan(134);
 
     /* Create a temporary afs configuration directory */
index cdd15da959ebec4f3abb9f5da1ad9bfcd650eb9d..04fac4e2187c13c6f6208cb98f856201bfadc117 100644 (file)
@@ -359,6 +359,8 @@ test_update_config_files(void)
 int
 main(int argc, char **argv)
 {
+    afstest_SkipTestsIfBadHostname();
+
     plan(113);
 
     test_edges();
index 03f67d918a17549497dc560a89e570497560a4a6..bdba611f5097ba8126359bdb9ca63c98ba60470c 100644 (file)
@@ -373,6 +373,8 @@ int main(int argc, char **argv)
     int code;
     int ret = 0;
 
+    afstest_SkipTestsIfBadHostname();
+
     /* Start the client and the server if requested */
 
     if (argc == 3 ) {
index cf196925002b13c928c4fdca06b0ac1658e7b7f1..c9f73497060e763b4c135a8ad3b95e02aeaec793 100644 (file)
@@ -54,3 +54,4 @@ extern int afstest_GetUbikClient(struct afsconf_dir *dir, char *service,
 /* network.c */
 extern int afstest_IsLoopbackNetworkDefault(void);
 extern int afstest_SkipTestsIfLoopbackNetIsDefault(void);
+extern void afstest_SkipTestsIfBadHostname(void);
index 4783753ddf69362d49361a93e5f33e9bf7141fa7..faefc0058e018115814df6c09a0a6d1930361d5b 100644 (file)
@@ -35,6 +35,7 @@
 
 #include <hcrypto/des.h>
 
+#include <tests/tap/basic.h>
 #include "common.h"
 
 static FILE *
index 5611003c8345b80b7c7aa36325b3f4acf8e21a6e..474fc61559b0061592130da6ee5c0cac20385e2f 100644 (file)
@@ -22,6 +22,9 @@ afstest_IsLoopbackNetworkDefault(void)
 
     gethostname(hostname, sizeof(hostname));
     host = gethostbyname(hostname);
+    if (!host) {
+       skip_all("Can't resolve hostname %s\n", hostname);
+    }
     memcpy(&addr, host->h_addr, sizeof(addr));
 
     return(rx_IsLoopbackAddr(ntohl(addr)));
@@ -42,3 +45,19 @@ afstest_SkipTestsIfLoopbackNetIsDefault(void)
     }
     return retval;
 }
+
+/*!
+ * Skips all TAP tests if the current machine's hostname can't be resolved
+ * to any IP address.
+ */
+void
+afstest_SkipTestsIfBadHostname(void)
+{
+    char hostname[MAXHOSTCHARS];
+    struct hostent *host;
+
+    gethostname(hostname, sizeof(hostname));
+    host = gethostbyname(hostname);
+    if (!host)
+       skip_all("Can't resolve hostname %s\n", hostname);
+}
index e3c499cca26efd940fb40021f61665452a1b8df0..3919c0b6926904e06af103da9126c3f15a18610a 100644 (file)
@@ -95,11 +95,13 @@ main(int argc, char **argv)
     struct ubik_client *ubikClient = NULL;
     int ret = 0;
 
-    plan(6);
-
+    /* Skip all tests if the current hostname can't be resolved */
+    afstest_SkipTestsIfBadHostname();
     /* Skip all tests if the current hostname is on the loopback network */
     afstest_SkipTestsIfLoopbackNetIsDefault();
 
+    plan(6);
+
     code = rx_Init(0);
 
     dirname = afstest_BuildTestConfig();