From 91de2dd08727f4cd1da124c4966d7a41a7ab99cf Mon Sep 17 00:00:00 2001 From: Simon Wilkinson Date: Tue, 31 May 2011 09:27:57 +0100 Subject: [PATCH] tests: Use a real IP address for the test cell When creating the test CellServDB, use the IP address of the machine that we are running on, rather than 127.0.0.1. This makes it possible to actually start up ubik servers using this CellServDB. Change-Id: Iec0be80921dd1f01825177562f8a3dcc59400b9a Reviewed-on: http://gerrit.openafs.org/4808 Tested-by: BuildBot Reviewed-by: Derrick Brashear --- tests/common/config.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/tests/common/config.c b/tests/common/config.c index 7574465..8f143b4 100644 --- a/tests/common/config.c +++ b/tests/common/config.c @@ -74,6 +74,9 @@ char * afstest_BuildTestConfig(void) { char *dir = NULL; FILE *file; + struct hostent *host; + char hostname[255]; + struct in_addr iaddr; if (asprintf(&dir, "%s/afs_XXXXXX", gettmpdir()) == -1) goto fail; @@ -81,10 +84,20 @@ afstest_BuildTestConfig(void) { if (mkdtemp(dir) == NULL) goto fail; - /* Create a CellServDB */ + /* Work out which IP address to use in our CellServDB. We figure this out + * according to the IP address which ubik is most likely to pick for one of + * our db servers */ + + gethostname(hostname, sizeof(hostname)); + host = gethostbyname(hostname); + if (!host) + return NULL; + + memcpy(&iaddr, host->h_addr, 4); + file = openConfigFile(dir, "CellServDB"); fprintf(file, ">example.org # An example cell\n"); - fprintf(file, "127.0.0.1 #test.example.org\n"); + fprintf(file, "%s #test.example.org\n", inet_ntoa(iaddr)); fclose(file); /* Create a ThisCell file */ -- 1.9.4