提交 1f12580a 编写于 作者: J Jovanka Gulicoska 提交者: Cole Robinson

test: implement node device lifecycle event APIs

Also includes unittests for node device lifecycle events API
上级 9806ae04
......@@ -51,6 +51,7 @@
#include "storage_conf.h"
#include "storage_event.h"
#include "node_device_conf.h"
#include "node_device_event.h"
#include "virxml.h"
#include "virthread.h"
#include "virlog.h"
......@@ -5427,6 +5428,7 @@ testNodeDeviceCreateXML(virConnectPtr conn,
int parent_host = -1;
virNodeDevicePtr dev = NULL;
virNodeDevCapsDefPtr caps;
virObjectEventPtr event = NULL;
virCheckFlags(0, NULL);
......@@ -5470,11 +5472,16 @@ testNodeDeviceCreateXML(virConnectPtr conn,
goto cleanup;
virNodeDeviceObjUnlock(obj);
event = virNodeDeviceEventLifecycleNew(def->name,
VIR_NODE_DEVICE_EVENT_CREATED,
0);
dev = virGetNodeDevice(conn, def->name);
def = NULL;
cleanup:
testDriverUnlock(driver);
virNodeDeviceDefFree(def);
testObjectEventQueue(driver, event);
VIR_FREE(wwnn);
VIR_FREE(wwpn);
return dev;
......@@ -5488,6 +5495,7 @@ testNodeDeviceDestroy(virNodeDevicePtr dev)
virNodeDeviceObjPtr obj = NULL;
char *parent_name = NULL, *wwnn = NULL, *wwpn = NULL;
int parent_host = -1;
virObjectEventPtr event = NULL;
testDriverLock(driver);
obj = virNodeDeviceFindByName(&driver->devs, dev->name);
......@@ -5521,12 +5529,17 @@ testNodeDeviceDestroy(virNodeDevicePtr dev)
goto out;
}
event = virNodeDeviceEventLifecycleNew(dev->name,
VIR_NODE_DEVICE_EVENT_DELETED,
0);
virNodeDeviceObjLock(obj);
virNodeDeviceObjRemove(&driver->devs, obj);
out:
if (obj)
virNodeDeviceObjUnlock(obj);
testObjectEventQueue(driver, event);
VIR_FREE(parent_name);
VIR_FREE(wwnn);
VIR_FREE(wwpn);
......@@ -5667,6 +5680,39 @@ testConnectStoragePoolEventDeregisterAny(virConnectPtr conn,
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,
virDomainPtr **domains,
unsigned int flags)
......@@ -6809,6 +6855,8 @@ static virStorageDriver testStorageDriver = {
};
static virNodeDeviceDriver testNodeDeviceDriver = {
.connectNodeDeviceEventRegisterAny = testConnectNodeDeviceEventRegisterAny, /* 2.2.0 */
.connectNodeDeviceEventDeregisterAny = testConnectNodeDeviceEventDeregisterAny, /* 2.2.0 */
.nodeNumOfDevices = testNodeNumOfDevices, /* 0.7.2 */
.nodeListDevices = testNodeListDevices, /* 0.7.2 */
.nodeDeviceLookupByName = testNodeDeviceLookupByName, /* 0.7.2 */
......
......@@ -61,12 +61,25 @@ static const char storagePoolDef[] =
" </target>\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 {
int startEvents;
int stopEvents;
int defineEvents;
int undefineEvents;
int unexpectedEvents;
int createdEvents;
int deletedEvents;
} lifecycleEventCounter;
static void
......@@ -77,12 +90,15 @@ lifecycleEventCounter_reset(lifecycleEventCounter *counter)
counter->defineEvents = 0;
counter->undefineEvents = 0;
counter->unexpectedEvents = 0;
counter->createdEvents = 0;
counter->deletedEvents = 0;
}
typedef struct {
virConnectPtr conn;
virNetworkPtr net;
virStoragePoolPtr pool;
virNodeDevicePtr dev;
} objecteventTest;
......@@ -163,6 +179,21 @@ storagePoolRefreshCb(virConnectPtr conn ATTRIBUTE_UNUSED,
(*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
testDomainCreateXMLOld(const void *data)
{
......@@ -691,6 +722,42 @@ testStoragePoolStartStopEvent(const void *data)
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
timeout(int id ATTRIBUTE_UNUSED, void *opaque ATTRIBUTE_UNUSED)
{
......@@ -765,6 +832,11 @@ mymain(void)
testStoragePoolStartStopEvent, &test) < 0)
ret = EXIT_FAILURE;
/* Node device event tests */
if (virTestRun("Node device createXML add event ",
testNodeDeviceCreateXML, &test) < 0)
ret = EXIT_FAILURE;
/* Cleanup */
if (test.pool) {
virStoragePoolUndefine(test.pool);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册