summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Kletzander <mkletzan@redhat.com>2015-06-11 14:02:30 +0200
committerMartin Kletzander <mkletzan@redhat.com>2015-06-16 13:46:20 +0200
commita47461145829b54fc993f469d7e4efd49154ddb8 (patch)
tree48e20814a7f475a7a50875070cd9b7bdb5065baa
parentfa14207368820b264123ba8429927b62258f996e (diff)
downloadlibvirt-a47461145829b54fc993f469d7e4efd49154ddb8.tar.gz
tests: Adapt virnetservertest to daemon refactor
Rename the test to virnetdaemontest and use virNetDaemon objects instead of virNetServer inside. Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
-rw-r--r--tests/Makefile.am10
-rw-r--r--tests/virnetdaemondata/README (renamed from tests/virnetserverdata/README)0
-rw-r--r--tests/virnetdaemondata/input-data-admin-nomdns.json126
-rw-r--r--tests/virnetdaemondata/input-data-anon-clients.json (renamed from tests/virnetserverdata/input-data-anon-clients.json)0
-rw-r--r--tests/virnetdaemondata/input-data-initial-nomdns.json (renamed from tests/virnetserverdata/output-data-anon-clients.json)1
-rw-r--r--tests/virnetdaemondata/input-data-initial.json (renamed from tests/virnetserverdata/input-data-initial.json)0
-rw-r--r--tests/virnetdaemondata/output-data-admin-nomdns.json128
-rw-r--r--tests/virnetdaemondata/output-data-anon-clients.json66
-rw-r--r--tests/virnetdaemondata/output-data-initial-nomdns.json66
-rw-r--r--tests/virnetdaemondata/output-data-initial.json67
-rw-r--r--tests/virnetdaemontest.c (renamed from tests/virnetservertest.c)70
-rw-r--r--tests/virnetserverdata/output-data-initial.json63
12 files changed, 511 insertions, 86 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index b3a0e4b2c8..cefe8b3cf9 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -189,7 +189,7 @@ if WITH_REMOTE
test_programs += \
virnetmessagetest \
virnetsockettest \
- virnetservertest \
+ virnetdaemontest \
virnetserverclienttest \
$(NULL)
if WITH_GNUTLS
@@ -923,11 +923,11 @@ virnetsockettest_SOURCES = \
virnetsockettest.c testutils.h testutils.c
virnetsockettest_LDADD = $(LDADDS)
-virnetservertest_SOURCES = \
- virnetservertest.c \
+virnetdaemontest_SOURCES = \
+ virnetdaemontest.c \
testutils.h testutils.c
-virnetservertest_CFLAGS = $(XDR_CFLAGS) $(AM_CFLAGS)
-virnetservertest_LDADD = $(LDADDS)
+virnetdaemontest_CFLAGS = $(XDR_CFLAGS) $(AM_CFLAGS)
+virnetdaemontest_LDADD = $(LDADDS)
virnetserverclienttest_SOURCES = \
virnetserverclienttest.c \
diff --git a/tests/virnetserverdata/README b/tests/virnetdaemondata/README
index d6d79d27d5..d6d79d27d5 100644
--- a/tests/virnetserverdata/README
+++ b/tests/virnetdaemondata/README
diff --git a/tests/virnetdaemondata/input-data-admin-nomdns.json b/tests/virnetdaemondata/input-data-admin-nomdns.json
new file mode 100644
index 0000000000..59bc4714a6
--- /dev/null
+++ b/tests/virnetdaemondata/input-data-admin-nomdns.json
@@ -0,0 +1,126 @@
+{
+ "servers": [
+ {
+ "min_workers": 10,
+ "max_workers": 50,
+ "priority_workers": 5,
+ "max_clients": 100,
+ "keepaliveInterval": 120,
+ "keepaliveCount": 5,
+ "keepaliveRequired": true,
+ "services": [
+ {
+ "auth": 0,
+ "readonly": true,
+ "nrequests_client_max": 2,
+ "socks": [
+ {
+ "fd": 100,
+ "errfd": -1,
+ "pid": 0,
+ "isClient": false
+ }
+ ]
+ },
+ {
+ "auth": 2,
+ "readonly": false,
+ "nrequests_client_max": 5,
+ "socks": [
+ {
+ "fd": 101,
+ "errfd": -1,
+ "pid": 0,
+ "isClient": false
+ }
+ ]
+ }
+ ],
+ "clients": [
+ {
+ "auth": 1,
+ "readonly": true,
+ "nrequests_max": 15,
+ "sock": {
+ "fd": 102,
+ "errfd": -1,
+ "pid": -1,
+ "isClient": true
+ }
+ },
+ {
+ "auth": 2,
+ "readonly": true,
+ "nrequests_max": 66,
+ "sock": {
+ "fd": 103,
+ "errfd": -1,
+ "pid": -1,
+ "isClient": true
+ }
+ }
+ ]
+ },
+ {
+ "min_workers": 2,
+ "max_workers": 50,
+ "priority_workers": 5,
+ "max_clients": 100,
+ "keepaliveInterval": 120,
+ "keepaliveCount": 5,
+ "keepaliveRequired": true,
+ "services": [
+ {
+ "auth": 0,
+ "readonly": true,
+ "nrequests_client_max": 2,
+ "socks": [
+ {
+ "fd": 100,
+ "errfd": -1,
+ "pid": 0,
+ "isClient": false
+ }
+ ]
+ },
+ {
+ "auth": 2,
+ "readonly": false,
+ "nrequests_client_max": 5,
+ "socks": [
+ {
+ "fd": 101,
+ "errfd": -1,
+ "pid": 0,
+ "isClient": false
+ }
+ ]
+ }
+ ],
+ "clients": [
+ {
+ "auth": 1,
+ "readonly": true,
+ "nrequests_max": 15,
+ "sock": {
+ "fd": 102,
+ "errfd": -1,
+ "pid": -1,
+ "isClient": true
+ }
+ },
+ {
+ "auth": 2,
+ "readonly": true,
+ "nrequests_max": 66,
+ "sock": {
+ "fd": 103,
+ "errfd": -1,
+ "pid": -1,
+ "isClient": true
+ }
+ }
+ ]
+ }
+ ]
+}
diff --git a/tests/virnetserverdata/input-data-anon-clients.json b/tests/virnetdaemondata/input-data-anon-clients.json
index 8a51ff53d6..8a51ff53d6 100644
--- a/tests/virnetserverdata/input-data-anon-clients.json
+++ b/tests/virnetdaemondata/input-data-anon-clients.json
diff --git a/tests/virnetserverdata/output-data-anon-clients.json b/tests/virnetdaemondata/input-data-initial-nomdns.json
index 8a51ff53d6..02bb427487 100644
--- a/tests/virnetserverdata/output-data-anon-clients.json
+++ b/tests/virnetdaemondata/input-data-initial-nomdns.json
@@ -3,7 +3,6 @@
"max_workers": 50,
"priority_workers": 5,
"max_clients": 100,
- "max_anonymous_clients": 10,
"keepaliveInterval": 120,
"keepaliveCount": 5,
"keepaliveRequired": true,
diff --git a/tests/virnetserverdata/input-data-initial.json b/tests/virnetdaemondata/input-data-initial.json
index 795622535b..795622535b 100644
--- a/tests/virnetserverdata/input-data-initial.json
+++ b/tests/virnetdaemondata/input-data-initial.json
diff --git a/tests/virnetdaemondata/output-data-admin-nomdns.json b/tests/virnetdaemondata/output-data-admin-nomdns.json
new file mode 100644
index 0000000000..5df71a0d88
--- /dev/null
+++ b/tests/virnetdaemondata/output-data-admin-nomdns.json
@@ -0,0 +1,128 @@
+{
+ "servers": [
+ {
+ "min_workers": 10,
+ "max_workers": 50,
+ "priority_workers": 5,
+ "max_clients": 100,
+ "max_anonymous_clients": 100,
+ "keepaliveInterval": 120,
+ "keepaliveCount": 5,
+ "keepaliveRequired": true,
+ "services": [
+ {
+ "auth": 0,
+ "readonly": true,
+ "nrequests_client_max": 2,
+ "socks": [
+ {
+ "fd": 100,
+ "errfd": -1,
+ "pid": 0,
+ "isClient": false
+ }
+ ]
+ },
+ {
+ "auth": 2,
+ "readonly": false,
+ "nrequests_client_max": 5,
+ "socks": [
+ {
+ "fd": 101,
+ "errfd": -1,
+ "pid": 0,
+ "isClient": false
+ }
+ ]
+ }
+ ],
+ "clients": [
+ {
+ "auth": 1,
+ "readonly": true,
+ "nrequests_max": 15,
+ "sock": {
+ "fd": 102,
+ "errfd": -1,
+ "pid": -1,
+ "isClient": true
+ }
+ },
+ {
+ "auth": 2,
+ "readonly": true,
+ "nrequests_max": 66,
+ "sock": {
+ "fd": 103,
+ "errfd": -1,
+ "pid": -1,
+ "isClient": true
+ }
+ }
+ ]
+ },
+ {
+ "min_workers": 2,
+ "max_workers": 50,
+ "priority_workers": 5,
+ "max_clients": 100,
+ "max_anonymous_clients": 100,
+ "keepaliveInterval": 120,
+ "keepaliveCount": 5,
+ "keepaliveRequired": true,
+ "services": [
+ {
+ "auth": 0,
+ "readonly": true,
+ "nrequests_client_max": 2,
+ "socks": [
+ {
+ "fd": 100,
+ "errfd": -1,
+ "pid": 0,
+ "isClient": false
+ }
+ ]
+ },
+ {
+ "auth": 2,
+ "readonly": false,
+ "nrequests_client_max": 5,
+ "socks": [
+ {
+ "fd": 101,
+ "errfd": -1,
+ "pid": 0,
+ "isClient": false
+ }
+ ]
+ }
+ ],
+ "clients": [
+ {
+ "auth": 1,
+ "readonly": true,
+ "nrequests_max": 15,
+ "sock": {
+ "fd": 102,
+ "errfd": -1,
+ "pid": -1,
+ "isClient": true
+ }
+ },
+ {
+ "auth": 2,
+ "readonly": true,
+ "nrequests_max": 66,
+ "sock": {
+ "fd": 103,
+ "errfd": -1,
+ "pid": -1,
+ "isClient": true
+ }
+ }
+ ]
+ }
+ ]
+}
diff --git a/tests/virnetdaemondata/output-data-anon-clients.json b/tests/virnetdaemondata/output-data-anon-clients.json
new file mode 100644
index 0000000000..4e4332691a
--- /dev/null
+++ b/tests/virnetdaemondata/output-data-anon-clients.json
@@ -0,0 +1,66 @@
+{
+ "servers": [
+ {
+ "min_workers": 10,
+ "max_workers": 50,
+ "priority_workers": 5,
+ "max_clients": 100,
+ "max_anonymous_clients": 10,
+ "keepaliveInterval": 120,
+ "keepaliveCount": 5,
+ "keepaliveRequired": true,
+ "services": [
+ {
+ "auth": 0,
+ "readonly": true,
+ "nrequests_client_max": 2,
+ "socks": [
+ {
+ "fd": 100,
+ "errfd": -1,
+ "pid": 0,
+ "isClient": false
+ }
+ ]
+ },
+ {
+ "auth": 2,
+ "readonly": false,
+ "nrequests_client_max": 5,
+ "socks": [
+ {
+ "fd": 101,
+ "errfd": -1,
+ "pid": 0,
+ "isClient": false
+ }
+ ]
+ }
+ ],
+ "clients": [
+ {
+ "auth": 1,
+ "readonly": true,
+ "nrequests_max": 15,
+ "sock": {
+ "fd": 102,
+ "errfd": -1,
+ "pid": -1,
+ "isClient": true
+ }
+ },
+ {
+ "auth": 2,
+ "readonly": true,
+ "nrequests_max": 66,
+ "sock": {
+ "fd": 103,
+ "errfd": -1,
+ "pid": -1,
+ "isClient": true
+ }
+ }
+ ]
+ }
+ ]
+}
diff --git a/tests/virnetdaemondata/output-data-initial-nomdns.json b/tests/virnetdaemondata/output-data-initial-nomdns.json
new file mode 100644
index 0000000000..bef54bf94a
--- /dev/null
+++ b/tests/virnetdaemondata/output-data-initial-nomdns.json
@@ -0,0 +1,66 @@
+{
+ "servers": [
+ {
+ "min_workers": 10,
+ "max_workers": 50,
+ "priority_workers": 5,
+ "max_clients": 100,
+ "max_anonymous_clients": 100,
+ "keepaliveInterval": 120,
+ "keepaliveCount": 5,
+ "keepaliveRequired": true,
+ "services": [
+ {
+ "auth": 0,
+ "readonly": true,
+ "nrequests_client_max": 2,
+ "socks": [
+ {
+ "fd": 100,
+ "errfd": -1,
+ "pid": 0,
+ "isClient": false
+ }
+ ]
+ },
+ {
+ "auth": 2,
+ "readonly": false,
+ "nrequests_client_max": 5,
+ "socks": [
+ {
+ "fd": 101,
+ "errfd": -1,
+ "pid": 0,
+ "isClient": false
+ }
+ ]
+ }
+ ],
+ "clients": [
+ {
+ "auth": 1,
+ "readonly": true,
+ "nrequests_max": 15,
+ "sock": {
+ "fd": 102,
+ "errfd": -1,
+ "pid": -1,
+ "isClient": true
+ }
+ },
+ {
+ "auth": 2,
+ "readonly": true,
+ "nrequests_max": 66,
+ "sock": {
+ "fd": 103,
+ "errfd": -1,
+ "pid": -1,
+ "isClient": true
+ }
+ }
+ ]
+ }
+ ]
+}
diff --git a/tests/virnetdaemondata/output-data-initial.json b/tests/virnetdaemondata/output-data-initial.json
new file mode 100644
index 0000000000..9afa791d91
--- /dev/null
+++ b/tests/virnetdaemondata/output-data-initial.json
@@ -0,0 +1,67 @@
+{
+ "servers": [
+ {
+ "min_workers": 10,
+ "max_workers": 50,
+ "priority_workers": 5,
+ "max_clients": 100,
+ "max_anonymous_clients": 100,
+ "keepaliveInterval": 120,
+ "keepaliveCount": 5,
+ "keepaliveRequired": true,
+ "mdnsGroupName": "libvirtTest",
+ "services": [
+ {
+ "auth": 0,
+ "readonly": true,
+ "nrequests_client_max": 2,
+ "socks": [
+ {
+ "fd": 100,
+ "errfd": -1,
+ "pid": 0,
+ "isClient": false
+ }
+ ]
+ },
+ {
+ "auth": 2,
+ "readonly": false,
+ "nrequests_client_max": 5,
+ "socks": [
+ {
+ "fd": 101,
+ "errfd": -1,
+ "pid": 0,
+ "isClient": false
+ }
+ ]
+ }
+ ],
+ "clients": [
+ {
+ "auth": 1,
+ "readonly": true,
+ "nrequests_max": 15,
+ "sock": {
+ "fd": 102,
+ "errfd": -1,
+ "pid": -1,
+ "isClient": true
+ }
+ },
+ {
+ "auth": 2,
+ "readonly": true,
+ "nrequests_max": 66,
+ "sock": {
+ "fd": 103,
+ "errfd": -1,
+ "pid": -1,
+ "isClient": true
+ }
+ }
+ ]
+ }
+ ]
+}
diff --git a/tests/virnetservertest.c b/tests/virnetdaemontest.c
index d546f87764..ef45018f58 100644
--- a/tests/virnetservertest.c
+++ b/tests/virnetdaemontest.c
@@ -22,7 +22,7 @@
#include "testutils.h"
#include "virerror.h"
-#include "rpc/virnetserver.h"
+#include "rpc/virnetdaemon.h"
#define VIR_FROM_THIS VIR_FROM_RPC
@@ -135,6 +135,7 @@ testCreateServer(const char *host, int family)
static char *testGenerateJSON(void)
{
+ virNetDaemonPtr dmn = NULL;
virNetServerPtr srv = NULL;
virJSONValuePtr json = NULL;
char *jsonstr = NULL;
@@ -157,27 +158,41 @@ static char *testGenerateJSON(void)
has_ipv4 ? AF_INET : AF_INET6)))
goto cleanup;
- if (!(json = virNetServerPreExecRestart(srv)))
+ if (!(dmn = virNetDaemonNew()))
+ goto cleanup;
+
+ if (virNetDaemonAddServer(dmn, srv) < 0)
+ goto cleanup;
+
+ if (!(json = virNetDaemonPreExecRestart(dmn)))
goto cleanup;
if (!(jsonstr = virJSONValueToString(json, true)))
goto cleanup;
+
fprintf(stderr, "%s\n", jsonstr);
cleanup:
virNetServerClose(srv);
virObjectUnref(srv);
+ virObjectUnref(dmn);
virJSONValueFree(json);
+ if (!jsonstr)
+ virDispatchError(NULL);
return jsonstr;
}
struct testExecRestartData {
const char *jsonfile;
+ int nservers;
+ bool pass;
};
static int testExecRestart(const void *opaque)
{
+ size_t i;
int ret = -1;
+ virNetDaemonPtr dmn = NULL;
virNetServerPtr srv = NULL;
const struct testExecRestartData *data = opaque;
char *infile = NULL, *outfile = NULL;
@@ -206,11 +221,11 @@ static int testExecRestart(const void *opaque)
dup2(fdclient[0], 102);
dup2(fdclient[1], 103);
- if (virAsprintf(&infile, "%s/virnetserverdata/input-data-%s.json",
+ if (virAsprintf(&infile, "%s/virnetdaemondata/input-data-%s.json",
abs_srcdir, data->jsonfile) < 0)
goto cleanup;
- if (virAsprintf(&outfile, "%s/virnetserverdata/output-data-%s.json",
+ if (virAsprintf(&outfile, "%s/virnetdaemondata/output-data-%s.json",
abs_srcdir, data->jsonfile) < 0)
goto cleanup;
@@ -220,33 +235,46 @@ static int testExecRestart(const void *opaque)
if (!(injson = virJSONValueFromString(injsonstr)))
goto cleanup;
- if (!(srv = virNetServerNewPostExecRestart(injson,
- NULL, NULL, NULL,
- NULL, NULL)))
+ if (!(dmn = virNetDaemonNewPostExecRestart(injson)))
goto cleanup;
- if (!(outjson = virNetServerPreExecRestart(srv)))
+ for (i = 0; i < data->nservers; i++) {
+ if (!(srv = virNetDaemonAddServerPostExec(dmn,
+ NULL, NULL, NULL,
+ NULL, NULL)))
+ goto cleanup;
+ srv = NULL;
+ }
+
+ if (!(outjson = virNetDaemonPreExecRestart(dmn)))
goto cleanup;
if (!(outjsonstr = virJSONValueToString(outjson, true)))
goto cleanup;
if (virtTestCompareToFile(outjsonstr, outfile) < 0)
- goto fail;
+ goto cleanup;
- ret = 0;
+ if (!data->pass) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s", "Test should've failed");
+ goto cleanup;
+ }
+ ret = 0;
cleanup:
- if (ret < 0)
- virDispatchError(NULL);
- fail:
+ if (ret < 0) {
+ if (!data->pass)
+ ret = 0;
+ else
+ virDispatchError(NULL);
+ }
VIR_FREE(infile);
VIR_FREE(outfile);
VIR_FREE(injsonstr);
VIR_FREE(outjsonstr);
virJSONValueFree(injson);
virJSONValueFree(outjson);
- virObjectUnref(srv);
+ virObjectUnref(dmn);
VIR_FORCE_CLOSE(fdserver[0]);
VIR_FORCE_CLOSE(fdserver[1]);
VIR_FORCE_CLOSE(fdclient[0]);
@@ -273,27 +301,35 @@ mymain(void)
*/
if (getenv("VIR_GENERATE_JSON")) {
char *json = testGenerateJSON();
+ if (!json)
+ return EXIT_FAILURE;
+
fprintf(stdout, "%s\n", json);
VIR_FREE(json);
- return EXIT_SUCCESS;
+ return ret;
}
-# define EXEC_RESTART_TEST(file) \
+# define EXEC_RESTART_TEST_FULL(file, servers, pass) \
do { \
struct testExecRestartData data = { \
- file \
+ file, servers, pass \
}; \
if (virtTestRun("ExecRestart " file, \
testExecRestart, &data) < 0) \
ret = -1; \
} while (0)
+# define EXEC_RESTART_TEST(file) EXEC_RESTART_TEST_FULL(file, 1, true)
+
# ifdef WITH_AVAHI
EXEC_RESTART_TEST("initial");
# endif
EXEC_RESTART_TEST("initial-nomdns");
EXEC_RESTART_TEST("anon-clients");
+ EXEC_RESTART_TEST_FULL("anon-clients", 2, false);
+ EXEC_RESTART_TEST_FULL("admin-nomdns", 2, true);
+
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
}
#else
diff --git a/tests/virnetserverdata/output-data-initial.json b/tests/virnetserverdata/output-data-initial.json
deleted file mode 100644
index da02aac0aa..0000000000
--- a/tests/virnetserverdata/output-data-initial.json
+++ /dev/null
@@ -1,63 +0,0 @@
-{
- "min_workers": 10,
- "max_workers": 50,
- "priority_workers": 5,
- "max_clients": 100,
- "max_anonymous_clients": 100,
- "keepaliveInterval": 120,
- "keepaliveCount": 5,
- "keepaliveRequired": true,
- "mdnsGroupName": "libvirtTest",
- "services": [
- {
- "auth": 0,
- "readonly": true,
- "nrequests_client_max": 2,
- "socks": [
- {
- "fd": 100,
- "errfd": -1,
- "pid": 0,
- "isClient": false
- }
- ]
- },
- {
- "auth": 2,
- "readonly": false,
- "nrequests_client_max": 5,
- "socks": [
- {
- "fd": 101,
- "errfd": -1,
- "pid": 0,
- "isClient": false
- }
- ]
- }
- ],
- "clients": [
- {
- "auth": 1,
- "readonly": true,
- "nrequests_max": 15,
- "sock": {
- "fd": 102,
- "errfd": -1,
- "pid": -1,
- "isClient": true
- }
- },
- {
- "auth": 2,
- "readonly": true,
- "nrequests_max": 66,
- "sock": {
- "fd": 103,
- "errfd": -1,
- "pid": -1,
- "isClient": true
- }
- }
- ]
-}