#include "snapshot_conf.h"
#include "fdstream.h"
#include "storage_conf.h"
+#include "storage_event.h"
#include "node_device_conf.h"
#include "virxml.h"
#include "virthread.h"
testDriverPtr privconn = pool->conn->privateData;
virStoragePoolObjPtr privpool;
int ret = -1;
+ virObjectEventPtr event = NULL;
virCheckFlags(0, -1);
}
privpool->active = 1;
+
+ event = virStoragePoolEventLifecycleNew(pool->name, pool->uuid,
+ VIR_STORAGE_POOL_EVENT_STARTED,
+ 0);
ret = 0;
cleanup:
+ testObjectEventQueue(privconn, event);
if (privpool)
virStoragePoolObjUnlock(privpool);
return ret;
virStoragePoolDefPtr def;
virStoragePoolObjPtr pool = NULL;
virStoragePoolPtr ret = NULL;
+ virObjectEventPtr event = NULL;
virCheckFlags(0, NULL);
}
pool->active = 1;
+ event = virStoragePoolEventLifecycleNew(pool->def->name, pool->def->uuid,
+ VIR_STORAGE_POOL_EVENT_STARTED,
+ 0);
+
ret = virGetStoragePool(conn, pool->def->name, pool->def->uuid,
NULL, NULL);
cleanup:
virStoragePoolDefFree(def);
+ testObjectEventQueue(privconn, event);
if (pool)
virStoragePoolObjUnlock(pool);
testDriverUnlock(privconn);
virStoragePoolDefPtr def;
virStoragePoolObjPtr pool = NULL;
virStoragePoolPtr ret = NULL;
+ virObjectEventPtr event = NULL;
virCheckFlags(0, NULL);
goto cleanup;
def = NULL;
+ event = virStoragePoolEventLifecycleNew(pool->def->name, pool->def->uuid,
+ VIR_STORAGE_POOL_EVENT_DEFINED,
+ 0);
+
if (testStoragePoolObjSetDefaults(pool) == -1) {
virStoragePoolObjRemove(&privconn->pools, pool);
pool = NULL;
cleanup:
virStoragePoolDefFree(def);
+ testObjectEventQueue(privconn, event);
if (pool)
virStoragePoolObjUnlock(pool);
testDriverUnlock(privconn);
testDriverPtr privconn = pool->conn->privateData;
virStoragePoolObjPtr privpool;
int ret = -1;
+ virObjectEventPtr event = NULL;
testDriverLock(privconn);
privpool = virStoragePoolObjFindByName(&privconn->pools,
goto cleanup;
}
+ event = virStoragePoolEventLifecycleNew(pool->name, pool->uuid,
+ VIR_STORAGE_POOL_EVENT_UNDEFINED,
+ 0);
+
virStoragePoolObjRemove(&privconn->pools, privpool);
privpool = NULL;
ret = 0;
cleanup:
if (privpool)
virStoragePoolObjUnlock(privpool);
+ testObjectEventQueue(privconn, event);
testDriverUnlock(privconn);
return ret;
}
testDriverPtr privconn = pool->conn->privateData;
virStoragePoolObjPtr privpool;
int ret = -1;
+ virObjectEventPtr event = NULL;
testDriverLock(privconn);
privpool = virStoragePoolObjFindByName(&privconn->pools,
}
privpool->active = 0;
+ event = virStoragePoolEventLifecycleNew(privpool->def->name, privpool->def->uuid,
+ VIR_STORAGE_POOL_EVENT_STOPPED,
+ 0);
if (privpool->configFile == NULL) {
virStoragePoolObjRemove(&privconn->pools, privpool);
ret = 0;
cleanup:
+ testObjectEventQueue(privconn, event);
if (privpool)
virStoragePoolObjUnlock(privpool);
testDriverUnlock(privconn);
testDriverPtr privconn = pool->conn->privateData;
virStoragePoolObjPtr privpool;
int ret = -1;
+ virObjectEventPtr event = NULL;
virCheckFlags(0, -1);
_("storage pool '%s' is not active"), pool->name);
goto cleanup;
}
+
+ event = virStoragePoolEventLifecycleNew(pool->name, pool->uuid,
+ VIR_STORAGE_POOL_EVENT_REFRESHED,
+ 0);
ret = 0;
cleanup:
+ testObjectEventQueue(privconn, event);
if (privpool)
virStoragePoolObjUnlock(privpool);
return ret;
return ret;
}
+static int
+testConnectStoragePoolEventRegisterAny(virConnectPtr conn,
+ virStoragePoolPtr pool,
+ int eventID,
+ virConnectStoragePoolEventGenericCallback callback,
+ void *opaque,
+ virFreeCallback freecb)
+{
+ testDriverPtr driver = conn->privateData;
+ int ret;
+
+ if (virStoragePoolEventStateRegisterID(conn, driver->eventState,
+ pool, eventID, callback,
+ opaque, freecb, &ret) < 0)
+ ret = -1;
+
+ return ret;
+}
+
+static int
+testConnectStoragePoolEventDeregisterAny(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)
.connectListDefinedStoragePools = testConnectListDefinedStoragePools, /* 0.5.0 */
.connectListAllStoragePools = testConnectListAllStoragePools, /* 0.10.2 */
.connectFindStoragePoolSources = testConnectFindStoragePoolSources, /* 0.5.0 */
+ .connectStoragePoolEventRegisterAny = testConnectStoragePoolEventRegisterAny, /* 2.0.0 */
+ .connectStoragePoolEventDeregisterAny = testConnectStoragePoolEventDeregisterAny, /* 2.0.0 */
.storagePoolLookupByName = testStoragePoolLookupByName, /* 0.5.0 */
.storagePoolLookupByUUID = testStoragePoolLookupByUUID, /* 0.5.0 */
.storagePoolLookupByVolume = testStoragePoolLookupByVolume, /* 0.5.0 */
" </ip>\n"
"</network>\n";
+static const char storagePoolDef[] =
+"<pool type='dir'>\n"
+" <name>P</name>\n"
+" <target>\n"
+" <path>/target-path</path>\n"
+" </target>\n"
+"</pool>\n";
+
typedef struct {
int startEvents;
int stopEvents;
int defineEvents;
int undefineEvents;
int unexpectedEvents;
+ int refreshEvents;
} lifecycleEventCounter;
static void
counter->defineEvents = 0;
counter->undefineEvents = 0;
counter->unexpectedEvents = 0;
+ counter->refreshEvents = 0;
}
typedef struct {
virConnectPtr conn;
virNetworkPtr net;
+ virStoragePoolPtr pool;
} objecteventTest;
counter->undefineEvents++;
}
+static void
+storagePoolLifecycleCb(virConnectPtr conn ATTRIBUTE_UNUSED,
+ virStoragePoolPtr pool ATTRIBUTE_UNUSED,
+ int event,
+ int detail ATTRIBUTE_UNUSED,
+ void* opaque)
+{
+ lifecycleEventCounter *counter = opaque;
+
+ if (event == VIR_STORAGE_POOL_EVENT_STARTED)
+ counter->startEvents++;
+ else if (event == VIR_STORAGE_POOL_EVENT_STOPPED)
+ counter->stopEvents++;
+ else if (event == VIR_STORAGE_POOL_EVENT_DEFINED)
+ counter->defineEvents++;
+ else if (event == VIR_STORAGE_POOL_EVENT_UNDEFINED)
+ counter->undefineEvents++;
+ else if (event == VIR_STORAGE_POOL_EVENT_REFRESHED)
+ counter->refreshEvents++;
+}
static int
testDomainCreateXMLOld(const void *data)
return ret;
}
+static int
+testStoragePoolCreateXML(const void *data)
+{
+ const objecteventTest *test = data;
+ lifecycleEventCounter counter;
+ virStoragePoolPtr pool;
+ int id;
+ int ret = 0;
+
+ lifecycleEventCounter_reset(&counter);
+
+ id = virConnectStoragePoolEventRegisterAny(test->conn, NULL,
+ VIR_STORAGE_POOL_EVENT_ID_LIFECYCLE,
+ VIR_STORAGE_POOL_EVENT_CALLBACK(&storagePoolLifecycleCb),
+ &counter, NULL);
+ pool = virStoragePoolCreateXML(test->conn, storagePoolDef, 0);
+
+ if (!pool || virEventRunDefaultImpl() < 0) {
+ ret = -1;
+ goto cleanup;
+ }
+
+ if (counter.startEvents != 1 || counter.unexpectedEvents > 0) {
+ ret = -1;
+ goto cleanup;
+ }
+
+ cleanup:
+ virConnectStoragePoolEventDeregisterAny(test->conn, id);
+ if (pool) {
+ virStoragePoolDestroy(pool);
+ virStoragePoolFree(pool);
+ }
+ return ret;
+}
+
+static int
+testStoragePoolDefine(const void *data)
+{
+ const objecteventTest *test = data;
+ lifecycleEventCounter counter;
+ virStoragePoolPtr pool;
+ int id;
+ int ret = 0;
+
+ lifecycleEventCounter_reset(&counter);
+
+ id = virConnectStoragePoolEventRegisterAny(test->conn, NULL,
+ VIR_STORAGE_POOL_EVENT_ID_LIFECYCLE,
+ VIR_STORAGE_POOL_EVENT_CALLBACK(&storagePoolLifecycleCb),
+ &counter, NULL);
+
+ /* Make sure the define event is triggered */
+ pool = virStoragePoolDefineXML(test->conn, storagePoolDef, 0);
+
+ if (!pool || virEventRunDefaultImpl() < 0) {
+ ret = -1;
+ goto cleanup;
+ }
+
+ if (counter.defineEvents != 1 || counter.unexpectedEvents > 0) {
+ ret = -1;
+ goto cleanup;
+ }
+
+ /* Make sure the undefine event is triggered */
+ virStoragePoolUndefine(pool);
+
+ if (virEventRunDefaultImpl() < 0) {
+ ret = -1;
+ goto cleanup;
+ }
+
+ if (counter.undefineEvents != 1 || counter.unexpectedEvents > 0) {
+ ret = -1;
+ goto cleanup;
+ }
+
+
+ cleanup:
+ virConnectStoragePoolEventDeregisterAny(test->conn, id);
+ if (pool)
+ virStoragePoolFree(pool);
+
+ return ret;
+}
+
+static int
+testStoragePoolStartStopEvent(const void *data)
+{
+ const objecteventTest *test = data;
+ lifecycleEventCounter counter;
+ int id;
+ int ret = 0;
+
+ if (!test->pool)
+ return -1;
+
+ lifecycleEventCounter_reset(&counter);
+
+ id = virConnectStoragePoolEventRegisterAny(test->conn, test->pool,
+ VIR_STORAGE_POOL_EVENT_ID_LIFECYCLE,
+ VIR_STORAGE_POOL_EVENT_CALLBACK(&storagePoolLifecycleCb),
+ &counter, NULL);
+ virStoragePoolCreate(test->pool, 0);
+ virStoragePoolRefresh(test->pool, 0);
+ virStoragePoolDestroy(test->pool);
+
+ if (virEventRunDefaultImpl() < 0) {
+ ret = -1;
+ goto cleanup;
+ }
+
+ if (counter.startEvents != 1 || counter.stopEvents != 1 ||
+ counter.refreshEvents != 1 || counter.unexpectedEvents > 0) {
+ ret = -1;
+ goto cleanup;
+ }
+
+ cleanup:
+ virConnectStoragePoolEventDeregisterAny(test->conn, id);
+ return ret;
+}
+
static void
timeout(int id ATTRIBUTE_UNUSED, void *opaque ATTRIBUTE_UNUSED)
{
virNetworkUndefine(test.net);
virNetworkFree(test.net);
}
+
+ /* Storage pool event tests */
+ if (virTestRun("Storage pool createXML start event ",
+ testStoragePoolCreateXML, &test) < 0)
+ ret = EXIT_FAILURE;
+ if (virTestRun("Storage pool (un)define events",
+ testStoragePoolDefine, &test) < 0)
+ ret = EXIT_FAILURE;
+
+ /* Define a test storage pool */
+ if (!(test.pool = virStoragePoolDefineXML(test.conn, storagePoolDef, 0)))
+ ret = EXIT_FAILURE;
+ if (virTestRun("Storage pool start stop events ",
+ testStoragePoolStartStopEvent, &test) < 0)
+ ret = EXIT_FAILURE;
+
+ /* Cleanup */
+ if (test.pool) {
+ virStoragePoolUndefine(test.pool);
+ virStoragePoolFree(test.pool);
+ }
+
virConnectClose(test.conn);
virEventRemoveTimeout(timer);