tests: skip vos tests when a vlserver is already running 21/14021/5
authorMichael Meffie <mmeffie@sinenomine.net>
Fri, 10 Jan 2020 15:54:20 +0000 (10:54 -0500)
committerBenjamin Kaduk <kaduk@mit.edu>
Mon, 20 Jan 2020 20:16:14 +0000 (15:16 -0500)
The vos tests start a temporary vlserver process, which is problematic
when the local system already has an installed vlserver. Attempt to
temporarily bind a socket to the vlserver port, and if unable to bind
with an EADDRINUSE error, assume the vlserver is already running and
skip these tests.

Change-Id: I1dd3bc4c7ebcd2c7bffc8aca422222a50058090e
Reviewed-on: https://gerrit.openafs.org/14021
Reviewed-by: Cheyenne Wills <cwills@sinenomine.net>
Reviewed-by: Andrew Deason <adeason@sinenomine.net>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

tests/common/common.h
tests/common/network.c
tests/volser/vos-t.c

index 003a734..061f707 100644 (file)
@@ -55,6 +55,7 @@ extern int afstest_GetUbikClient(struct afsconf_dir *dir, char *service,
 extern int afstest_IsLoopbackNetworkDefault(void);
 extern int afstest_SkipTestsIfLoopbackNetIsDefault(void);
 extern void afstest_SkipTestsIfBadHostname(void);
+extern void afstest_SkipTestsIfServerRunning(char *name);
 
 /* misc.c */
 extern char *afstest_GetProgname(char **argv);
index 474fc61..c664505 100644 (file)
@@ -61,3 +61,44 @@ afstest_SkipTestsIfBadHostname(void)
     if (!host)
        skip_all("Can't resolve hostname %s\n", hostname);
 }
+
+/*!
+ * Skips all TAP tests if a server is already running on this system.
+ *
+ * \param name[in]  IANA service name, e.g. "afs3-vlserver"
+ */
+void
+afstest_SkipTestsIfServerRunning(char *name)
+{
+    afs_int32 code;
+    osi_socket sock;
+    struct sockaddr_in addr;
+    afs_int32 service;
+
+    service = afsconf_FindService(name);
+    if (service == -1) {
+       fprintf(stderr, "Unknown service name: %s\n", name);
+       exit(1);
+    }
+    sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
+    if (sock == OSI_NULLSOCKET) {
+       fprintf(stderr, "Failed to get socket file descriptor.\n");
+       exit(1);
+    }
+    addr.sin_family = AF_INET;
+    addr.sin_addr.s_addr = htonl(INADDR_ANY);
+    addr.sin_port = service; /* Already in network byte order. */
+#ifdef STRUCT_SOCKADDR_HAS_SA_LEN
+    addr.sin_len = sizeof(addr);
+#endif
+    code = bind(sock, (struct sockaddr *)&addr, sizeof(addr));
+    if (code < 0) {
+       if (errno == EADDRINUSE) {
+           skip_all("Service %s is already running.\n", name);
+       } else {
+           perror("bind");
+           exit(1);
+       }
+    }
+    close(sock);
+}
index ddad658..758535e 100644 (file)
@@ -106,6 +106,8 @@ main(int argc, char **argv)
     afstest_SkipTestsIfBadHostname();
     /* Skip all tests if the current hostname is on the loopback network */
     afstest_SkipTestsIfLoopbackNetIsDefault();
+    /* Skip all tests if a vlserver is already running on this system. */
+    afstest_SkipTestsIfServerRunning("afs3-vlserver");
 
     plan(6);