tests: validate private data / pre / post exec hooks for RPC APIs

Validate that the virNetServer(Client) RPC APIs are processing the
private data callbacks correctly by passing in non-NULL pointers.

Reviewed-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
Daniel P. Berrangé 2018-02-01 15:32:49 +00:00
parent 4d83a6722f
commit 72874b2d11
21 changed files with 192 additions and 57 deletions

View File

@ -46,7 +46,8 @@
"errfd": -1,
"pid": -1,
"isClient": true
}
},
"privateData": 1729
},
{
"auth": 2,
@ -57,7 +58,8 @@
"errfd": -1,
"pid": -1,
"isClient": true
}
},
"privateData": 1729
}
]
},
@ -107,7 +109,8 @@
"errfd": -1,
"pid": -1,
"isClient": true
}
},
"privateData": 1729
},
{
"auth": 2,
@ -118,7 +121,8 @@
"errfd": -1,
"pid": -1,
"isClient": true
}
},
"privateData": 1729
}
]
}

View File

@ -48,7 +48,8 @@
"errfd": -1,
"pid": -1,
"isClient": true
}
},
"privateData": 1729
},
{
"auth": 2,
@ -59,7 +60,8 @@
"errfd": -1,
"pid": -1,
"isClient": true
}
},
"privateData": 1729
}
]
},
@ -110,7 +112,8 @@
"errfd": -1,
"pid": -1,
"isClient": true
}
},
"privateData": 1729
},
{
"auth": 2,
@ -121,7 +124,8 @@
"errfd": -1,
"pid": -1,
"isClient": true
}
},
"privateData": 1729
}
]
}

View File

@ -45,7 +45,8 @@
"errfd": -1,
"pid": -1,
"isClient": true
}
},
"privateData": 1729
},
{
"auth": 2,
@ -56,7 +57,8 @@
"errfd": -1,
"pid": -1,
"isClient": true
}
},
"privateData": 1729
}
]
}

View File

@ -36,7 +36,8 @@
"errfd": -1,
"pid": -1,
"isClient": true
}
},
"privateData": 1729
},
]
}

View File

@ -49,7 +49,8 @@
"errfd": -1,
"pid": -1,
"isClient": true
}
},
"privateData": 1729
},
{
"id": 3,
@ -62,7 +63,8 @@
"errfd": -1,
"pid": -1,
"isClient": true
}
},
"privateData": 1729
}
]
}

View File

@ -48,7 +48,8 @@
"errfd": -1,
"pid": -1,
"isClient": true
}
},
"privateData": 1729
},
{
"id": 3,
@ -60,7 +61,8 @@
"errfd": -1,
"pid": -1,
"isClient": true
}
},
"privateData": 1729
}
]
}

View File

@ -49,7 +49,8 @@
"errfd": -1,
"pid": -1,
"isClient": true
}
},
"privateData": 1729
},
{
"id": 2,
@ -62,7 +63,8 @@
"errfd": -1,
"pid": -1,
"isClient": true
}
},
"privateData": 1729
}
]
}

View File

@ -44,7 +44,8 @@
"errfd": -1,
"pid": -1,
"isClient": true
}
},
"privateData": 1729
},
{
"auth": 2,
@ -55,7 +56,8 @@
"errfd": -1,
"pid": -1,
"isClient": true
}
},
"privateData": 1729
}
]
}

View File

@ -45,7 +45,8 @@
"errfd": -1,
"pid": -1,
"isClient": true
}
},
"privateData": 1729
},
{
"auth": 2,
@ -56,7 +57,8 @@
"errfd": -1,
"pid": -1,
"isClient": true
}
},
"privateData": 1729
}
]
}

View File

@ -45,7 +45,8 @@
"errfd": -1,
"pid": -1,
"isClient": true
}
},
"privateData": 1729
},
{
"auth": 2,
@ -56,7 +57,8 @@
"errfd": -1,
"pid": -1,
"isClient": true
}
},
"privateData": 1729
}
]
},
@ -105,7 +107,8 @@
"errfd": -1,
"pid": -1,
"isClient": true
}
},
"privateData": 1729
},
{
"auth": 2,
@ -116,7 +119,8 @@
"errfd": -1,
"pid": -1,
"isClient": true
}
},
"privateData": 1729
}
]
}

View File

@ -49,7 +49,8 @@
"errfd": -1,
"pid": -1,
"isClient": true
}
},
"privateData": 1729
},
{
"id": 2,
@ -62,7 +63,8 @@
"errfd": -1,
"pid": -1,
"isClient": true
}
},
"privateData": 1729
}
]
},
@ -115,7 +117,8 @@
"errfd": -1,
"pid": -1,
"isClient": true
}
},
"privateData": 1729
},
{
"id": 2,
@ -128,7 +131,8 @@
"errfd": -1,
"pid": -1,
"isClient": true
}
},
"privateData": 1729
}
]
}

View File

@ -49,7 +49,8 @@
"errfd": -1,
"pid": -1,
"isClient": true
}
},
"privateData": 1729
},
{
"id": 2,
@ -62,7 +63,8 @@
"errfd": -1,
"pid": -1,
"isClient": true
}
},
"privateData": 1729
}
]
},
@ -115,7 +117,8 @@
"errfd": -1,
"pid": -1,
"isClient": true
}
},
"privateData": 1729
},
{
"id": 2,
@ -128,7 +131,8 @@
"errfd": -1,
"pid": -1,
"isClient": true
}
},
"privateData": 1729
}
]
}

View File

@ -49,7 +49,8 @@
"errfd": -1,
"pid": -1,
"isClient": true
}
},
"privateData": 1729
},
{
"id": 2,
@ -62,7 +63,8 @@
"errfd": -1,
"pid": -1,
"isClient": true
}
},
"privateData": 1729
}
]
}

View File

@ -49,7 +49,8 @@
"errfd": -1,
"pid": -1,
"isClient": true
}
},
"privateData": 1729
},
{
"id": 3,
@ -62,7 +63,8 @@
"errfd": -1,
"pid": -1,
"isClient": true
}
},
"privateData": 1729
}
]
}

View File

@ -49,7 +49,8 @@
"errfd": -1,
"pid": -1,
"isClient": true
}
},
"privateData": 1729
},
{
"id": 3,
@ -62,7 +63,8 @@
"errfd": -1,
"pid": -1,
"isClient": true
}
},
"privateData": 1729
}
]
}

View File

@ -50,7 +50,8 @@
"errfd": -1,
"pid": -1,
"isClient": true
}
},
"privateData": 1729
},
{
"id": 2,
@ -64,7 +65,8 @@
"errfd": -1,
"pid": -1,
"isClient": true
}
},
"privateData": 1729
}
]
}

View File

@ -49,7 +49,8 @@
"errfd": -1,
"pid": -1,
"isClient": true
}
},
"privateData": 1729
},
{
"id": 2,
@ -62,7 +63,8 @@
"errfd": -1,
"pid": -1,
"isClient": true
}
},
"privateData": 1729
}
]
}

View File

@ -50,7 +50,8 @@
"errfd": -1,
"pid": -1,
"isClient": true
}
},
"privateData": 1729
},
{
"id": 2,
@ -63,7 +64,8 @@
"errfd": -1,
"pid": -1,
"isClient": true
}
},
"privateData": 1729
}
]
}

View File

@ -49,7 +49,8 @@
"errfd": -1,
"pid": -1,
"isClient": true
}
},
"privateData": 1729
},
{
"id": 2,
@ -62,7 +63,8 @@
"errfd": -1,
"pid": -1,
"isClient": true
}
},
"privateData": 1729
}
]
},
@ -115,7 +117,8 @@
"errfd": -1,
"pid": -1,
"isClient": true
}
},
"privateData": 1729
},
{
"id": 2,
@ -128,7 +131,8 @@
"errfd": -1,
"pid": -1,
"isClient": true
}
},
"privateData": 1729
}
]
}

View File

@ -27,6 +27,60 @@
#define VIR_FROM_THIS VIR_FROM_RPC
#if defined(HAVE_SOCKETPAIR) && defined(WITH_YAJL)
struct testClientPriv {
int magic;
};
static void *
testClientNew(virNetServerClientPtr client ATTRIBUTE_UNUSED,
void *opaque ATTRIBUTE_UNUSED)
{
struct testClientPriv *priv;
if (VIR_ALLOC(priv) < 0)
return NULL;
priv->magic = 1729;
return priv;
}
static virJSONValuePtr
testClientPreExec(virNetServerClientPtr client ATTRIBUTE_UNUSED,
void *data)
{
struct testClientPriv *priv = data;
return virJSONValueNewNumberInt(priv->magic);
}
static void *
testClientNewPostExec(virNetServerClientPtr client,
virJSONValuePtr object,
void *opaque)
{
int magic;
if (virJSONValueGetNumberInt(object, &magic) < 0)
return NULL;
if (magic != 1729)
return NULL;
return testClientNew(client, opaque);
}
static void
testClientFree(void *opaque)
{
VIR_FREE(opaque);
}
static virNetServerPtr
testCreateServer(const char *server_name, const char *host, int family)
{
@ -53,9 +107,9 @@ testCreateServer(const char *server_name, const char *host, int family)
10, 50, 5, 100, 10,
120, 5,
mdns_group,
NULL,
NULL,
NULL,
testClientNew,
testClientPreExec,
testClientFree,
NULL)))
goto error;
@ -101,7 +155,10 @@ testCreateServer(const char *server_name, const char *host, int family)
# ifdef WITH_GNUTLS
NULL,
# endif
NULL, NULL, NULL, NULL)))
testClientNew,
testClientPreExec,
testClientFree,
NULL)))
goto error;
if (!(cln2 = virNetServerClientNew(virNetServerNextClientID(srv),
@ -112,7 +169,10 @@ testCreateServer(const char *server_name, const char *host, int family)
# ifdef WITH_GNUTLS
NULL,
# endif
NULL, NULL, NULL, NULL)))
testClientNew,
testClientPreExec,
testClientFree,
NULL)))
goto error;
if (virNetServerAddClient(srv, cln1) < 0)
@ -206,8 +266,11 @@ testNewServerPostExecRestart(virNetDaemonPtr dmn ATTRIBUTE_UNUSED,
if (STREQ(data->serverNames[i], name)) {
return virNetServerNewPostExecRestart(object,
name,
NULL, NULL, NULL,
NULL, NULL);
testClientNew,
testClientNewPostExec,
testClientPreExec,
testClientFree,
NULL);
}
}

View File

@ -27,6 +27,26 @@
#define VIR_FROM_THIS VIR_FROM_RPC
#ifdef HAVE_SOCKETPAIR
static void *
testClientNew(virNetServerClientPtr client ATTRIBUTE_UNUSED,
void *opaque ATTRIBUTE_UNUSED)
{
char *dummy;
if (VIR_ALLOC(dummy) < 0)
return NULL;
return dummy;
}
static void
testClientFree(void *opaque)
{
VIR_FREE(opaque);
}
static int testIdentity(const void *opaque ATTRIBUTE_UNUSED)
{
int sv[2];
@ -56,7 +76,10 @@ static int testIdentity(const void *opaque ATTRIBUTE_UNUSED)
# ifdef WITH_GNUTLS
NULL,
# endif
NULL, NULL, NULL, NULL))) {
testClientNew,
NULL,
testClientFree,
NULL))) {
virDispatchError(NULL);
goto cleanup;
}