Since the daemon can manage and add (at fresh start) multiple servers, we also should be able to add them from a JSON state file in case of a daemon restart. This patch introduces virNetDaemonAddServersPostExec method which harvests the data about servers from a JSON file supporting both old format with a single server and a new one storing an array of servers. The method makes use of the original virNetDaemonAddServerPostExec, declaring the latter as static. Patch also updates virnetdaemontest accordingly. --- src/locking/lock_daemon.c | 1 + src/logging/log_daemon.c | 1 + src/rpc/virnetdaemon.c | 2 + src/rpc/virnetdaemon.h | 1 + src/rpc/virnetserver.c | 6 +- src/rpc/virnetserver.h | 1 + .../input-data-admin-server-names.json | 128 +++++++++++++++++++++ .../virnetdaemondata/output-data-admin-nomdns.json | 2 + .../output-data-admin-server-names.json | 128 +++++++++++++++++++++ .../virnetdaemondata/output-data-anon-clients.json | 1 + .../output-data-initial-nomdns.json | 1 + tests/virnetdaemondata/output-data-initial.json | 1 + tests/virnetdaemontest.c | 40 +++---- 13 files changed, 288 insertions(+), 25 deletions(-) create mode 100644 tests/virnetdaemondata/input-data-admin-server-names.json create mode 100644 tests/virnetdaemondata/output-data-admin-server-names.json diff --git a/src/locking/lock_daemon.c b/src/locking/lock_daemon.c index 568b657..5ebb972 100644 --- a/src/locking/lock_daemon.c +++ b/src/locking/lock_daemon.c @@ -267,6 +267,7 @@ virLockDaemonNewPostExecRestart(virJSONValuePtr object, bool privileged) goto error; if (!(srv = virNetDaemonAddServerPostExec(lockd->dmn, + "virtlockd", virLockDaemonClientNew, virLockDaemonClientNewPostExecRestart, virLockDaemonClientPreExecRestart, diff --git a/src/logging/log_daemon.c b/src/logging/log_daemon.c index ea7bfcf..9b7be3c 100644 --- a/src/logging/log_daemon.c +++ b/src/logging/log_daemon.c @@ -209,6 +209,7 @@ virLogDaemonNewPostExecRestart(virJSONValuePtr object, bool privileged) goto error; if (!(logd->srv = virNetDaemonAddServerPostExec(logd->dmn, + "virtlogd", virLogDaemonClientNew, virLogDaemonClientNewPostExecRestart, virLogDaemonClientPreExecRestart, diff --git a/src/rpc/virnetdaemon.c b/src/rpc/virnetdaemon.c index 910f266..5324873 100644 --- a/src/rpc/virnetdaemon.c +++ b/src/rpc/virnetdaemon.c @@ -206,6 +206,7 @@ virNetDaemonGetServer(virNetDaemonPtr dmn, virNetServerPtr virNetDaemonAddServerPostExec(virNetDaemonPtr dmn, + const char *serverName, virNetServerClientPrivNew clientPrivNew, virNetServerClientPrivNewPostExecRestart clientPrivNewPostExecRestart, virNetServerClientPrivPreExecRestart clientPrivPreExecRestart, @@ -236,6 +237,7 @@ virNetDaemonAddServerPostExec(virNetDaemonPtr dmn, } srv = virNetServerNewPostExecRestart(object, + serverName, clientPrivNew, clientPrivNewPostExecRestart, clientPrivPreExecRestart, diff --git a/src/rpc/virnetdaemon.h b/src/rpc/virnetdaemon.h index bb32053..bb7de29 100644 --- a/src/rpc/virnetdaemon.h +++ b/src/rpc/virnetdaemon.h @@ -40,6 +40,7 @@ virNetDaemonPtr virNetDaemonNew(void); int virNetDaemonAddServer(virNetDaemonPtr dmn, virNetServerPtr); virNetServerPtr virNetDaemonAddServerPostExec(virNetDaemonPtr dmn, + const char *serverName, virNetServerClientPrivNew clientPrivNew, virNetServerClientPrivNewPostExecRestart clientPrivNewPostExecRestart, virNetServerClientPrivPreExecRestart clientPrivPreExecRestart, diff --git a/src/rpc/virnetserver.c b/src/rpc/virnetserver.c index d4dc41f..2e06dcc 100644 --- a/src/rpc/virnetserver.c +++ b/src/rpc/virnetserver.c @@ -363,6 +363,7 @@ virNetServerPtr virNetServerNew(size_t min_workers, virNetServerPtr virNetServerNewPostExecRestart(virJSONValuePtr object, + const char *serverName, virNetServerClientPrivNew clientPrivNew, virNetServerClientPrivNewPostExecRestart clientPrivNewPostExecRestart, virNetServerClientPrivPreExecRestart clientPrivPreExecRestart, @@ -382,7 +383,10 @@ virNetServerPtr virNetServerNewPostExecRestart(virJSONValuePtr object, unsigned int keepaliveInterval; unsigned int keepaliveCount; const char *mdnsGroupName = NULL; - const char *serverName = NULL; + const char *srvName = NULL; + + if (!(srvName = virJSONValueObjectGetString(object, "name"))) + srvName = serverName; if (virJSONValueObjectGetNumberUint(object, "min_workers", &min_workers) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", diff --git a/src/rpc/virnetserver.h b/src/rpc/virnetserver.h index fb04aa3..60707d1 100644 --- a/src/rpc/virnetserver.h +++ b/src/rpc/virnetserver.h @@ -49,6 +49,7 @@ virNetServerPtr virNetServerNew(size_t min_workers, void *clientPrivOpaque); virNetServerPtr virNetServerNewPostExecRestart(virJSONValuePtr object, + const char *serverName, virNetServerClientPrivNew clientPrivNew, virNetServerClientPrivNewPostExecRestart clientPrivNewPostExecRestart, virNetServerClientPrivPreExecRestart clientPrivPreExecRestart, diff --git a/tests/virnetdaemondata/input-data-admin-server-names.json b/tests/virnetdaemondata/input-data-admin-server-names.json new file mode 100644 index 0000000..608023f --- /dev/null +++ b/tests/virnetdaemondata/input-data-admin-server-names.json @@ -0,0 +1,128 @@ +{ + "servers": [ + { + "name": "testServer0", + "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 + } + } + ] + }, + { + "name": "testServer1", + "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/virnetdaemondata/output-data-admin-nomdns.json b/tests/virnetdaemondata/output-data-admin-nomdns.json index a814aeb..4b09311 100644 --- a/tests/virnetdaemondata/output-data-admin-nomdns.json +++ b/tests/virnetdaemondata/output-data-admin-nomdns.json @@ -1,6 +1,7 @@ { "servers": [ { + "name": "testServer0", "min_workers": 10, "max_workers": 50, "priority_workers": 5, @@ -62,6 +63,7 @@ ] }, { + "name": "testServer1", "min_workers": 2, "max_workers": 50, "priority_workers": 5, diff --git a/tests/virnetdaemondata/output-data-admin-server-names.json b/tests/virnetdaemondata/output-data-admin-server-names.json new file mode 100644 index 0000000..4b09311 --- /dev/null +++ b/tests/virnetdaemondata/output-data-admin-server-names.json @@ -0,0 +1,128 @@ +{ + "servers": [ + { + "name": "testServer0", + "min_workers": 10, + "max_workers": 50, + "priority_workers": 5, + "max_clients": 100, + "max_anonymous_clients": 100, + "keepaliveInterval": 120, + "keepaliveCount": 5, + "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 + } + } + ] + }, + { + "name": "testServer1", + "min_workers": 2, + "max_workers": 50, + "priority_workers": 5, + "max_clients": 100, + "max_anonymous_clients": 100, + "keepaliveInterval": 120, + "keepaliveCount": 5, + "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 index 05fc0ae..043f072 100644 --- a/tests/virnetdaemondata/output-data-anon-clients.json +++ b/tests/virnetdaemondata/output-data-anon-clients.json @@ -1,6 +1,7 @@ { "servers": [ { + "name": "testServer0", "min_workers": 10, "max_workers": 50, "priority_workers": 5, diff --git a/tests/virnetdaemondata/output-data-initial-nomdns.json b/tests/virnetdaemondata/output-data-initial-nomdns.json index 400e47b..00bebc3 100644 --- a/tests/virnetdaemondata/output-data-initial-nomdns.json +++ b/tests/virnetdaemondata/output-data-initial-nomdns.json @@ -1,6 +1,7 @@ { "servers": [ { + "name": "testServer0", "min_workers": 10, "max_workers": 50, "priority_workers": 5, diff --git a/tests/virnetdaemondata/output-data-initial.json b/tests/virnetdaemondata/output-data-initial.json index e875cff..63a4872 100644 --- a/tests/virnetdaemondata/output-data-initial.json +++ b/tests/virnetdaemondata/output-data-initial.json @@ -1,6 +1,7 @@ { "servers": [ { + "name": "testServer0", "min_workers": 10, "max_workers": 50, "priority_workers": 5, diff --git a/tests/virnetdaemontest.c b/tests/virnetdaemontest.c index 754b6fb..b487235 100644 --- a/tests/virnetdaemontest.c +++ b/tests/virnetdaemontest.c @@ -28,7 +28,7 @@ #ifdef HAVE_SOCKETPAIR static virNetServerPtr -testCreateServer(const char *host, int family) +testCreateServer(const char *host, int family, const char *name) { virNetServerPtr srv = NULL; virNetServerServicePtr svc1 = NULL, svc2 = NULL; @@ -51,7 +51,7 @@ testCreateServer(const char *host, int family) if (!(srv = virNetServerNew(10, 50, 5, 100, 10, 120, 5, - mdns_group, "test-server", + mdns_group, name, NULL, NULL, NULL, @@ -135,7 +135,7 @@ testCreateServer(const char *host, int family) goto cleanup; } -static char *testGenerateJSON(void) +static char *testGenerateJSON(const char *server_name) { virNetDaemonPtr dmn = NULL; virNetServerPtr srv = NULL; @@ -157,7 +157,7 @@ static char *testGenerateJSON(void) if (!(srv = testCreateServer( has_ipv4 ? "127.0.0.1" : "::1", - has_ipv4 ? AF_INET : AF_INET6))) + has_ipv4 ? AF_INET : AF_INET6, server_name))) goto cleanup; if (!(dmn = virNetDaemonNew())) @@ -186,8 +186,8 @@ static char *testGenerateJSON(void) struct testExecRestartData { const char *jsonfile; + const char **serverNames; int nservers; - bool pass; }; static int testExecRestart(const void *opaque) @@ -241,7 +241,7 @@ static int testExecRestart(const void *opaque) goto cleanup; for (i = 0; i < data->nservers; i++) { - if (!(srv = virNetDaemonAddServerPostExec(dmn, + if (!(srv = virNetDaemonAddServerPostExec(dmn, data->serverNames[i], NULL, NULL, NULL, NULL, NULL))) goto cleanup; @@ -257,19 +257,11 @@ static int testExecRestart(const void *opaque) if (virtTestCompareToFile(outjsonstr, outfile) < 0) goto cleanup; - if (!data->pass) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", "Test should've failed"); - goto cleanup; - } - ret = 0; cleanup: - if (ret < 0) { - if (!data->pass) - ret = 0; - else - virDispatchError(NULL); - } + if (ret < 0) + virDispatchError(NULL); + VIR_FREE(infile); VIR_FREE(outfile); VIR_FREE(injsonstr); @@ -289,6 +281,7 @@ static int mymain(void) { int ret = 0; + const char *server_names[] = { "testServer0", "testServer1" }; if (virInitialize() < 0 || virEventRegisterDefaultImpl() < 0) { @@ -302,7 +295,7 @@ mymain(void) * numbers with 100, 101, 102, 103. */ if (getenv("VIR_GENERATE_JSON")) { - char *json = testGenerateJSON(); + char *json = testGenerateJSON(server_names[0]); if (!json) return EXIT_FAILURE; @@ -311,26 +304,25 @@ mymain(void) return ret; } -# define EXEC_RESTART_TEST_FULL(file, servers, pass) \ +# define EXEC_RESTART_TEST_FULL(file, nservers) \ do { \ struct testExecRestartData data = { \ - file, servers, pass \ + file, server_names, nservers \ }; \ if (virtTestRun("ExecRestart " file, \ testExecRestart, &data) < 0) \ ret = -1; \ } while (0) -# define EXEC_RESTART_TEST(file) EXEC_RESTART_TEST_FULL(file, 1, true) +# define EXEC_RESTART_TEST(file) EXEC_RESTART_TEST_FULL(file, 1) # 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); + EXEC_RESTART_TEST_FULL("admin-nomdns", 2); + EXEC_RESTART_TEST_FULL("admin-server-names", 2); return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; } -- 2.4.3 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list