Adds:
- Get and Set Metadata functions to the test driver.
Signed-off-by: K Shiva <shiva_kr(a)riseup.net>
---
src/driver-network.h | 16 +++++++++
src/test/test_driver.c | 74 ++++++++++++++++++++++++++++++++++++++++++
2 files changed, 90 insertions(+)
diff --git a/src/driver-network.h b/src/driver-network.h
index 99efd4c8aa..1d19b013c9 100644
--- a/src/driver-network.h
+++ b/src/driver-network.h
@@ -161,6 +161,20 @@ typedef int
virNetworkPortPtr **ports,
unsigned int flags);
+typedef int
+(*virDrvNetworkSetMetadata)(virNetworkPtr network,
+ int type,
+ const char *metadata,
+ const char *key,
+ const char *uri,
+ unsigned int flags);
+
+typedef char *
+(*virDrvNetworkGetMetadata)(virNetworkPtr network,
+ int type,
+ const char *uri,
+ unsigned int flags);
+
typedef struct _virNetworkDriver virNetworkDriver;
/**
@@ -202,4 +216,6 @@ struct _virNetworkDriver {
virDrvNetworkPortGetParameters networkPortGetParameters;
virDrvNetworkPortDelete networkPortDelete;
virDrvNetworkListAllPorts networkListAllPorts;
+ virDrvNetworkSetMetadata networkSetMetadata;
+ virDrvNetworkGetMetadata networkGetMetadata;
};
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index e7fce053b4..7294766d6e 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -633,6 +633,25 @@ static int testStoragePoolObjSetDefaults(virStoragePoolObj *obj);
static int testNodeGetInfo(virConnectPtr conn, virNodeInfoPtr info);
static virNetworkObj *testNetworkObjFindByName(testDriver *privconn, const char *name);
+static virNetworkObj *
+testNetworkObjFromNetwork(virNetworkPtr network)
+{
+ virNetworkObj *net;
+ testDriver *driver = network->conn->privateData;
+ char uuidstr[VIR_UUID_STRING_BUFLEN];
+
+ net = virNetworkObjFindByUUID(driver->networks, network->uuid);
+ if (!net) {
+ virUUIDFormat(network->uuid, uuidstr);
+ virReportError(VIR_ERR_NO_NETWORK,
+ _("no network with matching uuid '%1$s'
(%2$s)"),
+ uuidstr, network->name);
+ }
+
+ return net;
+}
+
+
static virDomainObj *
testDomObjFromDomain(virDomainPtr domain)
{
@@ -9948,6 +9967,59 @@ testConnectGetAllDomainStats(virConnectPtr conn,
return ret;
}
+static char *
+testNetworkGetMetadata(virNetworkPtr net,
+ int type,
+ const char *uri,
+ unsigned int flags)
+{
+ virNetworkObj *privnet;
+ char *ret;
+
+ virCheckFlags(VIR_NETWORK_UPDATE_AFFECT_LIVE |
+ VIR_NETWORK_UPDATE_AFFECT_CONFIG, NULL);
+
+ if (!(privnet = testNetworkObjFromNetwork(net)))
+ return NULL;
+
+ ret = virNetworkObjGetMetadata(privnet, type, uri, flags);
+
+ virNetworkObjEndAPI(&privnet);
+ return ret;
+}
+
+static int
+testNetworkSetMetadata(virNetworkPtr net,
+ int type,
+ const char *metadata,
+ const char *key,
+ const char *uri,
+ unsigned int flags)
+{
+ testDriver *privconn = net->conn->privateData;
+ virNetworkObj *privnet;
+ int ret;
+
+ virCheckFlags(VIR_NETWORK_UPDATE_AFFECT_LIVE |
+ VIR_NETWORK_UPDATE_AFFECT_CONFIG, -1);
+
+ if (!(privnet = testNetworkObjFromNetwork(net)))
+ return -1;
+
+ ret = virNetworkObjSetMetadata(privnet, type, metadata,
+ key, uri, NULL,
+ NULL, NULL, flags);
+
+ if (ret == 0) {
+ virObjectEvent *ev = NULL;
+ ev = virNetworkEventMetadataChangeNewFromObj(privnet, type, uri);
+ virObjectEventStateQueue(privconn->eventState, ev);
+ }
+
+ virNetworkObjEndAPI(&privnet);
+ return ret;
+}
+
/*
* Test driver
*/
@@ -10141,6 +10213,8 @@ static virNetworkDriver testNetworkDriver = {
.networkSetAutostart = testNetworkSetAutostart, /* 0.3.2 */
.networkIsActive = testNetworkIsActive, /* 0.7.3 */
.networkIsPersistent = testNetworkIsPersistent, /* 0.7.3 */
+ .networkSetMetadata = testNetworkSetMetadata, /* 9.5.0 */
+ .networkGetMetadata = testNetworkGetMetadata, /* 9.5.0 */
};
static virInterfaceDriver testInterfaceDriver = {
--
2.41.0