]> xenbits.xensource.com Git - libvirt.git/commitdiff
tests: validate private data / pre / post exec hooks for RPC APIs
authorDaniel P. Berrangé <berrange@redhat.com>
Thu, 1 Feb 2018 15:32:49 +0000 (15:32 +0000)
committerDaniel P. Berrangé <berrange@redhat.com>
Fri, 2 Feb 2018 13:00:48 +0000 (13:00 +0000)
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>
21 files changed:
tests/virnetdaemondata/input-data-admin-nomdns.json
tests/virnetdaemondata/input-data-admin-server-names.json
tests/virnetdaemondata/input-data-anon-clients.json
tests/virnetdaemondata/input-data-client-auth-pending-failure.json
tests/virnetdaemondata/input-data-client-auth-pending.json
tests/virnetdaemondata/input-data-client-ids.json
tests/virnetdaemondata/input-data-client-timestamp.json
tests/virnetdaemondata/input-data-initial-nomdns.json
tests/virnetdaemondata/input-data-initial.json
tests/virnetdaemondata/input-data-no-keepalive-required.json
tests/virnetdaemondata/output-data-admin-nomdns.json
tests/virnetdaemondata/output-data-admin-server-names.json
tests/virnetdaemondata/output-data-anon-clients.json
tests/virnetdaemondata/output-data-client-auth-pending.json
tests/virnetdaemondata/output-data-client-ids.json
tests/virnetdaemondata/output-data-client-timestamp.json
tests/virnetdaemondata/output-data-initial-nomdns.json
tests/virnetdaemondata/output-data-initial.json
tests/virnetdaemondata/output-data-no-keepalive-required.json
tests/virnetdaemontest.c
tests/virnetserverclienttest.c

index 449bcc9b259c25b94b84c166aa3991a57b919223..985ea4b434833822b4d3d7ea68c59f9baa6360c2 100644 (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
         }
         ]
     },
             "errfd": -1,
             "pid": -1,
             "isClient": true
-            }
+            },
+            "privateData": 1729
         },
         {
             "auth": 2,
             "errfd": -1,
             "pid": -1,
             "isClient": true
-            }
+            },
+            "privateData": 1729
         }
         ]
     }
index 3afe16fad08cdc929bc55590d1fcf332601aaa68..99515c5f122646967b75de437de2aea36a96466c 100644 (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
         }
             ]
     },
             "errfd": -1,
             "pid": -1,
             "isClient": true
-            }
+            },
+           "privateData": 1729
         },
         {
             "auth": 2,
             "errfd": -1,
             "pid": -1,
             "isClient": true
-            }
+            },
+           "privateData": 1729
         }
             ]
     }
index 8a51ff53d6cfa7796439d5024f54290e4fc1c1bc..8058fe0a43d1bd0299160b00479ab36ed200fa67 100644 (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
         }
     ]
 }
index 7d4ef6438deac97f3e1bca630d4dc88e898b275e..9c33d92e082436ed8e2c751fbdc28db2aa845b63 100644 (file)
@@ -36,7 +36,8 @@
                         "errfd": -1,
                         "pid": -1,
                         "isClient": true
-                    }
+                    },
+                   "privateData": 1729
                 },
             ]
         }
index ae85253b5332d9e780712f3823f4e45626f8760d..56dd2d85d6c7f3d41195630486f46968bc6ae9ae 100644 (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
                 }
             ]
         }
index 7caa2ccd5729764360820b87dfd8ce124a686db2..c94a538b130a52f55db9dd9a7097335d9df944e0 100644 (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
                 }
             ]
         }
index d069997a14bfd8df9d97776bdef70ff65d0f1423..ee2b2357beaac934fa320b06e3532814a7d032bd 100644 (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
                 }
             ]
         }
index 02bb42748774560f6ace3929137587b5d949a2dd..6cf70d96e8de592f91a8b165398d20c56af0cedf 100644 (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
         }
     ]
 }
index 795622535b88e384cd4cf520541daad5ec416bbd..5bb09ed36b31bc9fac43524f2e4a0efee7157899 100644 (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
         }
     ]
 }
index df282edd6ef8575fb7957343557c7fea1a0843a1..1ed9ac2c7c25035bed457429c6fbb66769385373 100644 (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
         }
         ]
     },
             "errfd": -1,
             "pid": -1,
             "isClient": true
-            }
+            },
+           "privateData": 1729
         },
         {
             "auth": 2,
             "errfd": -1,
             "pid": -1,
             "isClient": true
-            }
+            },
+           "privateData": 1729
         }
         ]
     }
index d6d02163e282471b442f1db2878240d4682da4cf..04cb5e6bb397146c341ffb62672d48e7a09234f5 100644 (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
         }
       ]
     },
             "errfd": -1,
             "pid": -1,
             "isClient": true
-          }
+          },
+          "privateData": 1729
         },
         {
           "id": 2,
             "errfd": -1,
             "pid": -1,
             "isClient": true
-          }
+          },
+          "privateData": 1729
         }
       ]
     }
index d6d02163e282471b442f1db2878240d4682da4cf..04cb5e6bb397146c341ffb62672d48e7a09234f5 100644 (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
         }
       ]
     },
             "errfd": -1,
             "pid": -1,
             "isClient": true
-          }
+          },
+          "privateData": 1729
         },
         {
           "id": 2,
             "errfd": -1,
             "pid": -1,
             "isClient": true
-          }
+          },
+          "privateData": 1729
         }
       ]
     }
index cb6005bfe68c895469b61670800df9c569a75f7d..49fe89be48308cf8862dc89871d0a0f789d0716d 100644 (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
         }
       ]
     }
index 5720ea9b71c4803eafd660c4958f4fd362cf85e7..0675404e6c75609830ec621ea9220e8d202fd301 100644 (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
         }
       ]
     }
index 2b1663d4f8c652da42afdc9149724e7b5fb21a87..90c3383a93c0986e2692a116b41ef2f94cd9a30e 100644 (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
         }
       ]
     }
index e8c8e9a991d910924f25897a6ca53e615b3b7047..9cfb069793542fe42181b5e92e7b2f9f8233ce0c 100644 (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
         }
       ]
     }
index 167aef8d295eaf8c40215dbd8d661bf68d99776a..916297c59dd33754df01cf3166ce2c06a22cb79d 100644 (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
         }
       ]
     }
index 3281e868d7aa25ad2b5893d859998f5ec10346da..5ed03472d6c05b4120200df85964516cd037bd92 100644 (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
         }
       ]
     }
index d6d02163e282471b442f1db2878240d4682da4cf..04cb5e6bb397146c341ffb62672d48e7a09234f5 100644 (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
         }
       ]
     },
             "errfd": -1,
             "pid": -1,
             "isClient": true
-          }
+          },
+          "privateData": 1729
         },
         {
           "id": 2,
             "errfd": -1,
             "pid": -1,
             "isClient": true
-          }
+          },
+          "privateData": 1729
         }
       ]
     }
index 435513d314a65195a9b80c447ec7e9933db22940..ef869b16e36337ac7c0ca5d7938eb700b0b45756 100644 (file)
 #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);
         }
     }
 
index 96b69b3e45ea3e137b573fad49cee812b4dd6e67..398b46928cd7aa9b3e8f8d85ca929f83a8c58e37 100644 (file)
 #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;
     }