mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-27 19:11:16 +00:00
test: implement node device lifecycle event APIs
Also includes unittests for node device lifecycle events API
This commit is contained in:
parent
9806ae04dd
commit
1f12580a64
@ -51,6 +51,7 @@
|
|||||||
#include "storage_conf.h"
|
#include "storage_conf.h"
|
||||||
#include "storage_event.h"
|
#include "storage_event.h"
|
||||||
#include "node_device_conf.h"
|
#include "node_device_conf.h"
|
||||||
|
#include "node_device_event.h"
|
||||||
#include "virxml.h"
|
#include "virxml.h"
|
||||||
#include "virthread.h"
|
#include "virthread.h"
|
||||||
#include "virlog.h"
|
#include "virlog.h"
|
||||||
@ -5427,6 +5428,7 @@ testNodeDeviceCreateXML(virConnectPtr conn,
|
|||||||
int parent_host = -1;
|
int parent_host = -1;
|
||||||
virNodeDevicePtr dev = NULL;
|
virNodeDevicePtr dev = NULL;
|
||||||
virNodeDevCapsDefPtr caps;
|
virNodeDevCapsDefPtr caps;
|
||||||
|
virObjectEventPtr event = NULL;
|
||||||
|
|
||||||
virCheckFlags(0, NULL);
|
virCheckFlags(0, NULL);
|
||||||
|
|
||||||
@ -5470,11 +5472,16 @@ testNodeDeviceCreateXML(virConnectPtr conn,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
virNodeDeviceObjUnlock(obj);
|
virNodeDeviceObjUnlock(obj);
|
||||||
|
|
||||||
|
event = virNodeDeviceEventLifecycleNew(def->name,
|
||||||
|
VIR_NODE_DEVICE_EVENT_CREATED,
|
||||||
|
0);
|
||||||
|
|
||||||
dev = virGetNodeDevice(conn, def->name);
|
dev = virGetNodeDevice(conn, def->name);
|
||||||
def = NULL;
|
def = NULL;
|
||||||
cleanup:
|
cleanup:
|
||||||
testDriverUnlock(driver);
|
testDriverUnlock(driver);
|
||||||
virNodeDeviceDefFree(def);
|
virNodeDeviceDefFree(def);
|
||||||
|
testObjectEventQueue(driver, event);
|
||||||
VIR_FREE(wwnn);
|
VIR_FREE(wwnn);
|
||||||
VIR_FREE(wwpn);
|
VIR_FREE(wwpn);
|
||||||
return dev;
|
return dev;
|
||||||
@ -5488,6 +5495,7 @@ testNodeDeviceDestroy(virNodeDevicePtr dev)
|
|||||||
virNodeDeviceObjPtr obj = NULL;
|
virNodeDeviceObjPtr obj = NULL;
|
||||||
char *parent_name = NULL, *wwnn = NULL, *wwpn = NULL;
|
char *parent_name = NULL, *wwnn = NULL, *wwpn = NULL;
|
||||||
int parent_host = -1;
|
int parent_host = -1;
|
||||||
|
virObjectEventPtr event = NULL;
|
||||||
|
|
||||||
testDriverLock(driver);
|
testDriverLock(driver);
|
||||||
obj = virNodeDeviceFindByName(&driver->devs, dev->name);
|
obj = virNodeDeviceFindByName(&driver->devs, dev->name);
|
||||||
@ -5521,12 +5529,17 @@ testNodeDeviceDestroy(virNodeDevicePtr dev)
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
event = virNodeDeviceEventLifecycleNew(dev->name,
|
||||||
|
VIR_NODE_DEVICE_EVENT_DELETED,
|
||||||
|
0);
|
||||||
|
|
||||||
virNodeDeviceObjLock(obj);
|
virNodeDeviceObjLock(obj);
|
||||||
virNodeDeviceObjRemove(&driver->devs, obj);
|
virNodeDeviceObjRemove(&driver->devs, obj);
|
||||||
|
|
||||||
out:
|
out:
|
||||||
if (obj)
|
if (obj)
|
||||||
virNodeDeviceObjUnlock(obj);
|
virNodeDeviceObjUnlock(obj);
|
||||||
|
testObjectEventQueue(driver, event);
|
||||||
VIR_FREE(parent_name);
|
VIR_FREE(parent_name);
|
||||||
VIR_FREE(wwnn);
|
VIR_FREE(wwnn);
|
||||||
VIR_FREE(wwpn);
|
VIR_FREE(wwpn);
|
||||||
@ -5667,6 +5680,39 @@ testConnectStoragePoolEventDeregisterAny(virConnectPtr conn,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
testConnectNodeDeviceEventRegisterAny(virConnectPtr conn,
|
||||||
|
virNodeDevicePtr dev,
|
||||||
|
int eventID,
|
||||||
|
virConnectNodeDeviceEventGenericCallback callback,
|
||||||
|
void *opaque,
|
||||||
|
virFreeCallback freecb)
|
||||||
|
{
|
||||||
|
testDriverPtr driver = conn->privateData;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
if (virNodeDeviceEventStateRegisterID(conn, driver->eventState,
|
||||||
|
dev, eventID, callback,
|
||||||
|
opaque, freecb, &ret) < 0)
|
||||||
|
ret = -1;
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
testConnectNodeDeviceEventDeregisterAny(virConnectPtr conn,
|
||||||
|
int callbackID)
|
||||||
|
{
|
||||||
|
testDriverPtr driver = conn->privateData;
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
|
if (virObjectEventStateDeregisterID(conn, driver->eventState,
|
||||||
|
callbackID) < 0)
|
||||||
|
ret = -1;
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
static int testConnectListAllDomains(virConnectPtr conn,
|
static int testConnectListAllDomains(virConnectPtr conn,
|
||||||
virDomainPtr **domains,
|
virDomainPtr **domains,
|
||||||
unsigned int flags)
|
unsigned int flags)
|
||||||
@ -6809,6 +6855,8 @@ static virStorageDriver testStorageDriver = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static virNodeDeviceDriver testNodeDeviceDriver = {
|
static virNodeDeviceDriver testNodeDeviceDriver = {
|
||||||
|
.connectNodeDeviceEventRegisterAny = testConnectNodeDeviceEventRegisterAny, /* 2.2.0 */
|
||||||
|
.connectNodeDeviceEventDeregisterAny = testConnectNodeDeviceEventDeregisterAny, /* 2.2.0 */
|
||||||
.nodeNumOfDevices = testNodeNumOfDevices, /* 0.7.2 */
|
.nodeNumOfDevices = testNodeNumOfDevices, /* 0.7.2 */
|
||||||
.nodeListDevices = testNodeListDevices, /* 0.7.2 */
|
.nodeListDevices = testNodeListDevices, /* 0.7.2 */
|
||||||
.nodeDeviceLookupByName = testNodeDeviceLookupByName, /* 0.7.2 */
|
.nodeDeviceLookupByName = testNodeDeviceLookupByName, /* 0.7.2 */
|
||||||
|
@ -61,12 +61,25 @@ static const char storagePoolDef[] =
|
|||||||
" </target>\n"
|
" </target>\n"
|
||||||
"</pool>\n";
|
"</pool>\n";
|
||||||
|
|
||||||
|
static const char nodeDeviceDef[] =
|
||||||
|
"<device>\n"
|
||||||
|
" <parent>test-scsi-host-vport</parent>\n"
|
||||||
|
" <capability type='scsi_host'>\n"
|
||||||
|
" <capability type='fc_host'>\n"
|
||||||
|
" <wwpn>1111222233334444</wwpn>\n"
|
||||||
|
" <wwnn>5555666677778888</wwnn>\n"
|
||||||
|
" </capability>\n"
|
||||||
|
" </capability>\n"
|
||||||
|
"</device>\n";
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int startEvents;
|
int startEvents;
|
||||||
int stopEvents;
|
int stopEvents;
|
||||||
int defineEvents;
|
int defineEvents;
|
||||||
int undefineEvents;
|
int undefineEvents;
|
||||||
int unexpectedEvents;
|
int unexpectedEvents;
|
||||||
|
int createdEvents;
|
||||||
|
int deletedEvents;
|
||||||
} lifecycleEventCounter;
|
} lifecycleEventCounter;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -77,12 +90,15 @@ lifecycleEventCounter_reset(lifecycleEventCounter *counter)
|
|||||||
counter->defineEvents = 0;
|
counter->defineEvents = 0;
|
||||||
counter->undefineEvents = 0;
|
counter->undefineEvents = 0;
|
||||||
counter->unexpectedEvents = 0;
|
counter->unexpectedEvents = 0;
|
||||||
|
counter->createdEvents = 0;
|
||||||
|
counter->deletedEvents = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
virConnectPtr conn;
|
virConnectPtr conn;
|
||||||
virNetworkPtr net;
|
virNetworkPtr net;
|
||||||
virStoragePoolPtr pool;
|
virStoragePoolPtr pool;
|
||||||
|
virNodeDevicePtr dev;
|
||||||
} objecteventTest;
|
} objecteventTest;
|
||||||
|
|
||||||
|
|
||||||
@ -163,6 +179,21 @@ storagePoolRefreshCb(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|||||||
(*counter)++;
|
(*counter)++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
nodeDeviceLifecycleCb(virConnectPtr conn ATTRIBUTE_UNUSED,
|
||||||
|
virNodeDevicePtr dev ATTRIBUTE_UNUSED,
|
||||||
|
int event,
|
||||||
|
int detail ATTRIBUTE_UNUSED,
|
||||||
|
void* opaque)
|
||||||
|
{
|
||||||
|
lifecycleEventCounter *counter = opaque;
|
||||||
|
|
||||||
|
if (event == VIR_NODE_DEVICE_EVENT_CREATED)
|
||||||
|
counter->createdEvents++;
|
||||||
|
else if (event == VIR_NODE_DEVICE_EVENT_DELETED)
|
||||||
|
counter->deletedEvents++;
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
testDomainCreateXMLOld(const void *data)
|
testDomainCreateXMLOld(const void *data)
|
||||||
{
|
{
|
||||||
@ -691,6 +722,42 @@ testStoragePoolStartStopEvent(const void *data)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
testNodeDeviceCreateXML(const void *data)
|
||||||
|
{
|
||||||
|
const objecteventTest *test = data;
|
||||||
|
lifecycleEventCounter counter;
|
||||||
|
virNodeDevicePtr dev;
|
||||||
|
int id;
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
|
lifecycleEventCounter_reset(&counter);
|
||||||
|
|
||||||
|
id = virConnectNodeDeviceEventRegisterAny(test->conn, NULL,
|
||||||
|
VIR_NODE_DEVICE_EVENT_ID_LIFECYCLE,
|
||||||
|
VIR_NODE_DEVICE_EVENT_CALLBACK(&nodeDeviceLifecycleCb),
|
||||||
|
&counter, NULL);
|
||||||
|
dev = virNodeDeviceCreateXML(test->conn, nodeDeviceDef, 0);
|
||||||
|
virNodeDeviceDestroy(dev);
|
||||||
|
|
||||||
|
if (!dev || virEventRunDefaultImpl() < 0) {
|
||||||
|
ret = -1;
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (counter.createdEvents != 1 || counter.deletedEvents != 1 ||
|
||||||
|
counter.unexpectedEvents > 0) {
|
||||||
|
ret = -1;
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
virConnectNodeDeviceEventDeregisterAny(test->conn, id);
|
||||||
|
if (dev)
|
||||||
|
virNodeDeviceFree(dev);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
timeout(int id ATTRIBUTE_UNUSED, void *opaque ATTRIBUTE_UNUSED)
|
timeout(int id ATTRIBUTE_UNUSED, void *opaque ATTRIBUTE_UNUSED)
|
||||||
{
|
{
|
||||||
@ -765,6 +832,11 @@ mymain(void)
|
|||||||
testStoragePoolStartStopEvent, &test) < 0)
|
testStoragePoolStartStopEvent, &test) < 0)
|
||||||
ret = EXIT_FAILURE;
|
ret = EXIT_FAILURE;
|
||||||
|
|
||||||
|
/* Node device event tests */
|
||||||
|
if (virTestRun("Node device createXML add event ",
|
||||||
|
testNodeDeviceCreateXML, &test) < 0)
|
||||||
|
ret = EXIT_FAILURE;
|
||||||
|
|
||||||
/* Cleanup */
|
/* Cleanup */
|
||||||
if (test.pool) {
|
if (test.pool) {
|
||||||
virStoragePoolUndefine(test.pool);
|
virStoragePoolUndefine(test.pool);
|
||||||
|
Loading…
Reference in New Issue
Block a user