Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
libvirt
提交
edc1a27a
L
libvirt
项目概览
openeuler
/
libvirt
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
L
libvirt
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
edc1a27a
编写于
6月 15, 2016
作者:
J
Jovanka Gulicoska
提交者:
Cole Robinson
6月 16, 2016
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
test: implement storage lifecycle event APIs
Also includes unittests for storage pool lifecycle events API
上级
dc7b849a
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
248 addition
and
0 deletion
+248
-0
src/test/test_driver.c
src/test/test_driver.c
+71
-0
tests/objecteventtest.c
tests/objecteventtest.c
+177
-0
未找到文件。
src/test/test_driver.c
浏览文件 @
edc1a27a
...
...
@@ -49,6 +49,7 @@
#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"
...
...
@@ -4114,6 +4115,7 @@ testStoragePoolCreate(virStoragePoolPtr pool,
testDriverPtr
privconn
=
pool
->
conn
->
privateData
;
virStoragePoolObjPtr
privpool
;
int
ret
=
-
1
;
virObjectEventPtr
event
=
NULL
;
virCheckFlags
(
0
,
-
1
);
...
...
@@ -4134,9 +4136,14 @@ testStoragePoolCreate(virStoragePoolPtr pool,
}
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
;
...
...
@@ -4204,6 +4211,7 @@ testStoragePoolCreateXML(virConnectPtr conn,
virStoragePoolDefPtr
def
;
virStoragePoolObjPtr
pool
=
NULL
;
virStoragePoolPtr
ret
=
NULL
;
virObjectEventPtr
event
=
NULL
;
virCheckFlags
(
0
,
NULL
);
...
...
@@ -4231,11 +4239,16 @@ testStoragePoolCreateXML(virConnectPtr conn,
}
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
);
...
...
@@ -4251,6 +4264,7 @@ testStoragePoolDefineXML(virConnectPtr conn,
virStoragePoolDefPtr
def
;
virStoragePoolObjPtr
pool
=
NULL
;
virStoragePoolPtr
ret
=
NULL
;
virObjectEventPtr
event
=
NULL
;
virCheckFlags
(
0
,
NULL
);
...
...
@@ -4266,6 +4280,10 @@ testStoragePoolDefineXML(virConnectPtr conn,
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
;
...
...
@@ -4277,6 +4295,7 @@ testStoragePoolDefineXML(virConnectPtr conn,
cleanup:
virStoragePoolDefFree
(
def
);
testObjectEventQueue
(
privconn
,
event
);
if
(
pool
)
virStoragePoolObjUnlock
(
pool
);
testDriverUnlock
(
privconn
);
...
...
@@ -4289,6 +4308,7 @@ testStoragePoolUndefine(virStoragePoolPtr pool)
testDriverPtr
privconn
=
pool
->
conn
->
privateData
;
virStoragePoolObjPtr
privpool
;
int
ret
=
-
1
;
virObjectEventPtr
event
=
NULL
;
testDriverLock
(
privconn
);
privpool
=
virStoragePoolObjFindByName
(
&
privconn
->
pools
,
...
...
@@ -4305,6 +4325,10 @@ testStoragePoolUndefine(virStoragePoolPtr pool)
goto
cleanup
;
}
event
=
virStoragePoolEventLifecycleNew
(
pool
->
name
,
pool
->
uuid
,
VIR_STORAGE_POOL_EVENT_UNDEFINED
,
0
);
virStoragePoolObjRemove
(
&
privconn
->
pools
,
privpool
);
privpool
=
NULL
;
ret
=
0
;
...
...
@@ -4312,6 +4336,7 @@ testStoragePoolUndefine(virStoragePoolPtr pool)
cleanup:
if
(
privpool
)
virStoragePoolObjUnlock
(
privpool
);
testObjectEventQueue
(
privconn
,
event
);
testDriverUnlock
(
privconn
);
return
ret
;
}
...
...
@@ -4356,6 +4381,7 @@ testStoragePoolDestroy(virStoragePoolPtr pool)
testDriverPtr
privconn
=
pool
->
conn
->
privateData
;
virStoragePoolObjPtr
privpool
;
int
ret
=
-
1
;
virObjectEventPtr
event
=
NULL
;
testDriverLock
(
privconn
);
privpool
=
virStoragePoolObjFindByName
(
&
privconn
->
pools
,
...
...
@@ -4373,6 +4399,9 @@ testStoragePoolDestroy(virStoragePoolPtr pool)
}
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
);
...
...
@@ -4381,6 +4410,7 @@ testStoragePoolDestroy(virStoragePoolPtr pool)
ret
=
0
;
cleanup:
testObjectEventQueue
(
privconn
,
event
);
if
(
privpool
)
virStoragePoolObjUnlock
(
privpool
);
testDriverUnlock
(
privconn
);
...
...
@@ -4430,6 +4460,7 @@ testStoragePoolRefresh(virStoragePoolPtr pool,
testDriverPtr
privconn
=
pool
->
conn
->
privateData
;
virStoragePoolObjPtr
privpool
;
int
ret
=
-
1
;
virObjectEventPtr
event
=
NULL
;
virCheckFlags
(
0
,
-
1
);
...
...
@@ -4448,9 +4479,14 @@ testStoragePoolRefresh(virStoragePoolPtr pool,
_
(
"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
;
...
...
@@ -5644,6 +5680,39 @@ testConnectNetworkEventDeregisterAny(virConnectPtr conn,
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
)
...
...
@@ -6751,6 +6820,8 @@ static virStorageDriver testStorageDriver = {
.
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 */
...
...
tests/objecteventtest.c
浏览文件 @
edc1a27a
...
...
@@ -53,12 +53,21 @@ static const char networkDef[] =
" </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
...
...
@@ -69,11 +78,13 @@ lifecycleEventCounter_reset(lifecycleEventCounter *counter)
counter
->
defineEvents
=
0
;
counter
->
undefineEvents
=
0
;
counter
->
unexpectedEvents
=
0
;
counter
->
refreshEvents
=
0
;
}
typedef
struct
{
virConnectPtr
conn
;
virNetworkPtr
net
;
virStoragePoolPtr
pool
;
}
objecteventTest
;
...
...
@@ -125,6 +136,26 @@ networkLifecycleCb(virConnectPtr conn ATTRIBUTE_UNUSED,
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
)
...
...
@@ -523,6 +554,130 @@ testNetworkStartStopEvent(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
)
{
...
...
@@ -581,6 +736,28 @@ mymain(void)
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
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录