提交 a4746114 编写于 作者: M Martin Kletzander

tests: Adapt virnetservertest to daemon refactor

Rename the test to virnetdaemontest and use virNetDaemon objects instead
of virNetServer inside.
Signed-off-by: NMartin Kletzander <mkletzan@redhat.com>
上级 fa142073
...@@ -189,7 +189,7 @@ if WITH_REMOTE ...@@ -189,7 +189,7 @@ if WITH_REMOTE
test_programs += \ test_programs += \
virnetmessagetest \ virnetmessagetest \
virnetsockettest \ virnetsockettest \
virnetservertest \ virnetdaemontest \
virnetserverclienttest \ virnetserverclienttest \
$(NULL) $(NULL)
if WITH_GNUTLS if WITH_GNUTLS
...@@ -923,11 +923,11 @@ virnetsockettest_SOURCES = \ ...@@ -923,11 +923,11 @@ virnetsockettest_SOURCES = \
virnetsockettest.c testutils.h testutils.c virnetsockettest.c testutils.h testutils.c
virnetsockettest_LDADD = $(LDADDS) virnetsockettest_LDADD = $(LDADDS)
virnetservertest_SOURCES = \ virnetdaemontest_SOURCES = \
virnetservertest.c \ virnetdaemontest.c \
testutils.h testutils.c testutils.h testutils.c
virnetservertest_CFLAGS = $(XDR_CFLAGS) $(AM_CFLAGS) virnetdaemontest_CFLAGS = $(XDR_CFLAGS) $(AM_CFLAGS)
virnetservertest_LDADD = $(LDADDS) virnetdaemontest_LDADD = $(LDADDS)
virnetserverclienttest_SOURCES = \ virnetserverclienttest_SOURCES = \
virnetserverclienttest.c \ virnetserverclienttest.c \
......
{
"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
}
}
]
}
]
}
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
"max_workers": 50, "max_workers": 50,
"priority_workers": 5, "priority_workers": 5,
"max_clients": 100, "max_clients": 100,
"max_anonymous_clients": 10,
"keepaliveInterval": 120, "keepaliveInterval": 120,
"keepaliveCount": 5, "keepaliveCount": 5,
"keepaliveRequired": true, "keepaliveRequired": true,
......
{
"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
}
}
]
}
]
}
{
"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
}
}
]
}
]
}
{
"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
}
}
]
}
]
}
{
"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
}
}
]
}
]
}
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
#include "testutils.h" #include "testutils.h"
#include "virerror.h" #include "virerror.h"
#include "rpc/virnetserver.h" #include "rpc/virnetdaemon.h"
#define VIR_FROM_THIS VIR_FROM_RPC #define VIR_FROM_THIS VIR_FROM_RPC
...@@ -135,6 +135,7 @@ testCreateServer(const char *host, int family) ...@@ -135,6 +135,7 @@ testCreateServer(const char *host, int family)
static char *testGenerateJSON(void) static char *testGenerateJSON(void)
{ {
virNetDaemonPtr dmn = NULL;
virNetServerPtr srv = NULL; virNetServerPtr srv = NULL;
virJSONValuePtr json = NULL; virJSONValuePtr json = NULL;
char *jsonstr = NULL; char *jsonstr = NULL;
...@@ -157,27 +158,41 @@ static char *testGenerateJSON(void) ...@@ -157,27 +158,41 @@ static char *testGenerateJSON(void)
has_ipv4 ? AF_INET : AF_INET6))) has_ipv4 ? AF_INET : AF_INET6)))
goto cleanup; goto cleanup;
if (!(json = virNetServerPreExecRestart(srv))) if (!(dmn = virNetDaemonNew()))
goto cleanup;
if (virNetDaemonAddServer(dmn, srv) < 0)
goto cleanup;
if (!(json = virNetDaemonPreExecRestart(dmn)))
goto cleanup; goto cleanup;
if (!(jsonstr = virJSONValueToString(json, true))) if (!(jsonstr = virJSONValueToString(json, true)))
goto cleanup; goto cleanup;
fprintf(stderr, "%s\n", jsonstr); fprintf(stderr, "%s\n", jsonstr);
cleanup: cleanup:
virNetServerClose(srv); virNetServerClose(srv);
virObjectUnref(srv); virObjectUnref(srv);
virObjectUnref(dmn);
virJSONValueFree(json); virJSONValueFree(json);
if (!jsonstr)
virDispatchError(NULL);
return jsonstr; return jsonstr;
} }
struct testExecRestartData { struct testExecRestartData {
const char *jsonfile; const char *jsonfile;
int nservers;
bool pass;
}; };
static int testExecRestart(const void *opaque) static int testExecRestart(const void *opaque)
{ {
size_t i;
int ret = -1; int ret = -1;
virNetDaemonPtr dmn = NULL;
virNetServerPtr srv = NULL; virNetServerPtr srv = NULL;
const struct testExecRestartData *data = opaque; const struct testExecRestartData *data = opaque;
char *infile = NULL, *outfile = NULL; char *infile = NULL, *outfile = NULL;
...@@ -206,11 +221,11 @@ static int testExecRestart(const void *opaque) ...@@ -206,11 +221,11 @@ static int testExecRestart(const void *opaque)
dup2(fdclient[0], 102); dup2(fdclient[0], 102);
dup2(fdclient[1], 103); 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) abs_srcdir, data->jsonfile) < 0)
goto cleanup; 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) abs_srcdir, data->jsonfile) < 0)
goto cleanup; goto cleanup;
...@@ -220,33 +235,46 @@ static int testExecRestart(const void *opaque) ...@@ -220,33 +235,46 @@ static int testExecRestart(const void *opaque)
if (!(injson = virJSONValueFromString(injsonstr))) if (!(injson = virJSONValueFromString(injsonstr)))
goto cleanup; goto cleanup;
if (!(srv = virNetServerNewPostExecRestart(injson, if (!(dmn = virNetDaemonNewPostExecRestart(injson)))
goto cleanup;
for (i = 0; i < data->nservers; i++) {
if (!(srv = virNetDaemonAddServerPostExec(dmn,
NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL))) NULL, NULL)))
goto cleanup; goto cleanup;
srv = NULL;
}
if (!(outjson = virNetServerPreExecRestart(srv))) if (!(outjson = virNetDaemonPreExecRestart(dmn)))
goto cleanup; goto cleanup;
if (!(outjsonstr = virJSONValueToString(outjson, true))) if (!(outjsonstr = virJSONValueToString(outjson, true)))
goto cleanup; goto cleanup;
if (virtTestCompareToFile(outjsonstr, outfile) < 0) 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: cleanup:
if (ret < 0) if (ret < 0) {
if (!data->pass)
ret = 0;
else
virDispatchError(NULL); virDispatchError(NULL);
fail: }
VIR_FREE(infile); VIR_FREE(infile);
VIR_FREE(outfile); VIR_FREE(outfile);
VIR_FREE(injsonstr); VIR_FREE(injsonstr);
VIR_FREE(outjsonstr); VIR_FREE(outjsonstr);
virJSONValueFree(injson); virJSONValueFree(injson);
virJSONValueFree(outjson); virJSONValueFree(outjson);
virObjectUnref(srv); virObjectUnref(dmn);
VIR_FORCE_CLOSE(fdserver[0]); VIR_FORCE_CLOSE(fdserver[0]);
VIR_FORCE_CLOSE(fdserver[1]); VIR_FORCE_CLOSE(fdserver[1]);
VIR_FORCE_CLOSE(fdclient[0]); VIR_FORCE_CLOSE(fdclient[0]);
...@@ -273,27 +301,35 @@ mymain(void) ...@@ -273,27 +301,35 @@ mymain(void)
*/ */
if (getenv("VIR_GENERATE_JSON")) { if (getenv("VIR_GENERATE_JSON")) {
char *json = testGenerateJSON(); char *json = testGenerateJSON();
if (!json)
return EXIT_FAILURE;
fprintf(stdout, "%s\n", json); fprintf(stdout, "%s\n", json);
VIR_FREE(json); VIR_FREE(json);
return EXIT_SUCCESS; return ret;
} }
# define EXEC_RESTART_TEST(file) \ # define EXEC_RESTART_TEST_FULL(file, servers, pass) \
do { \ do { \
struct testExecRestartData data = { \ struct testExecRestartData data = { \
file \ file, servers, pass \
}; \ }; \
if (virtTestRun("ExecRestart " file, \ if (virtTestRun("ExecRestart " file, \
testExecRestart, &data) < 0) \ testExecRestart, &data) < 0) \
ret = -1; \ ret = -1; \
} while (0) } while (0)
# define EXEC_RESTART_TEST(file) EXEC_RESTART_TEST_FULL(file, 1, true)
# ifdef WITH_AVAHI # ifdef WITH_AVAHI
EXEC_RESTART_TEST("initial"); EXEC_RESTART_TEST("initial");
# endif # endif
EXEC_RESTART_TEST("initial-nomdns"); EXEC_RESTART_TEST("initial-nomdns");
EXEC_RESTART_TEST("anon-clients"); 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; return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
} }
#else #else
......
{
"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
}
}
]
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册