listAllVolumes is a new API in RHEL7, so add a new case for it.
And add the case to releated conf to check the volumes list.
modified: cases/storage_dir.conf
modified: cases/storage_dir_vol_resize_delta.conf
modified: cases/storage_logical.conf
modified: cases/storage_netfs.conf
new file: repos/storage/list_volumes.py
---
cases/storage_dir.conf | 16 +++++
cases/storage_dir_vol_resize_delta.conf | 8 +++
cases/storage_logical.conf | 16 +++++
cases/storage_netfs.conf | 16 +++++
repos/storage/list_volumes.py | 97 +++++++++++++++++++++++++++++++
5 files changed, 153 insertions(+), 0 deletions(-)
create mode 100644 repos/storage/list_volumes.py
diff --git a/cases/storage_dir.conf b/cases/storage_dir.conf
index 38b349d..393d34f 100644
--- a/cases/storage_dir.conf
+++ b/cases/storage_dir.conf
@@ -20,6 +20,10 @@ storage:create_dir_volume
capacity
$defaultvolumesize
+storage:list_volumes
+ poolname
+ $defaultpoolname
+
storage:vol_clone
poolname
$defaultpoolname
@@ -28,18 +32,30 @@ storage:vol_clone
clonevolname
$defaultvolclonename
+storage:list_volumes
+ poolname
+ $defaultpoolname
+
storage:delete_dir_volume
poolname
$defaultpoolname
volname
$defaultvolclonename
+storage:list_volumes
+ poolname
+ $defaultpoolname
+
storage:delete_dir_volume
poolname
$defaultpoolname
volname
$defaultvolumename
+storage:list_volumes
+ poolname
+ $defaultpoolname
+
storage:destroy_pool
poolname
$defaultpoolname
diff --git a/cases/storage_dir_vol_resize_delta.conf
b/cases/storage_dir_vol_resize_delta.conf
index 58e15bf..22d3b47 100644
--- a/cases/storage_dir_vol_resize_delta.conf
+++ b/cases/storage_dir_vol_resize_delta.conf
@@ -12,6 +12,10 @@ storage:create_dir_volume
capacity
$defaultvolumesize
+storage:list_volumes
+ poolname
+ $defaultpoolname
+
storage:vol_resize_delta
poolname
$defaultpoolname
@@ -42,6 +46,10 @@ storage:delete_dir_volume
volname
$defaultvolumename
+storage:list_volumes
+ poolname
+ $defaultpoolname
+
storage:destroy_pool
poolname
$defaultpoolname
diff --git a/cases/storage_logical.conf b/cases/storage_logical.conf
index d374dfa..a0fdad6 100644
--- a/cases/storage_logical.conf
+++ b/cases/storage_logical.conf
@@ -22,6 +22,10 @@ storage:create_logical_volume
capacity
$defaultvolumesize
+storage:list_volumes
+ poolname
+ $defaultpoolname
+
storage:vol_clone
poolname
$defaultpoolname
@@ -30,18 +34,30 @@ storage:vol_clone
clonevolname
$defaultvolclonename
+storage:list_volumes
+ poolname
+ $defaultpoolname
+
storage:delete_logical_volume
poolname
$defaultpoolname
volname
$defaultvolclonename
+storage:list_volumes
+ poolname
+ $defaultpoolname
+
storage:delete_logical_volume
poolname
$defaultpoolname
volname
$defaultvolumename
+storage:list_volumes
+ poolname
+ $defaultpoolname
+
storage:destroy_pool
poolname
$defaultpoolname
diff --git a/cases/storage_netfs.conf b/cases/storage_netfs.conf
index f486ff4..6880763 100644
--- a/cases/storage_netfs.conf
+++ b/cases/storage_netfs.conf
@@ -24,6 +24,10 @@ storage:create_netfs_volume
capacity
$defaultvolumesize
+storage:list_volumes
+ poolname
+ $defaultpoolname
+
storage:vol_clone
poolname
$defaultpoolname
@@ -32,18 +36,30 @@ storage:vol_clone
clonevolname
$defaultvolclonename
+storage:list_volumes
+ poolname
+ $defaultpoolname
+
storage:delete_netfs_volume
poolname
$defaultpoolname
volname
$defaultvolclonename
+storage:list_volumes
+ poolname
+ $defaultpoolname
+
storage:delete_netfs_volume
poolname
$defaultpoolname
volname
$defaultvolumename
+storage:list_volumes
+ poolname
+ $defaultpoolname
+
storage:destroy_pool
poolname
$defaultpoolname
diff --git a/repos/storage/list_volumes.py b/repos/storage/list_volumes.py
new file mode 100644
index 0000000..9555720
--- /dev/null
+++ b/repos/storage/list_volumes.py
@@ -0,0 +1,97 @@
+#!/usr/bin/evn python
+
+import libvirt
+from libvirt import libvirtError
+from xml.dom import minidom
+
+from utils import utils
+
+from src import sharedmod
+
+required_params = ('poolname',)
+optional_params = {}
+
+
+def get_pool_path(pool_obj):
+ """
+ Get the pool path
+ """
+ poolxml = pool_obj.XMLDesc(0)
+ logger.debug("the xml description of pool is %s" % poolxml)
+
+ doc = minidom.parseString(poolxml)
+ path_element = doc.getElementsByTagName('path')[0]
+ textnode = path_element.childNodes[0]
+ path_value = textnode.data
+
+ return path_value
+
+
+def check_list_volumes(pool_obj, vol_name_list):
+ """
+ Check the result of listAllVolumes
+ """
+
+ vol_poolobj_list = pool_obj.listVolumes()
+ logger.debug("get volumes from listVolumes is %s" % vol_poolobj_list)
+
+ poolpath = get_pool_path(pool_obj)
+ logger.info("the pool path is %s" % poolpath)
+ vol_ls_cmd = "ls -a " + poolpath
+
+ (status, vol_cmd_list) = utils.exec_cmd(vol_ls_cmd, shell=True)
+ if status:
+ logger.error("Executing " + vol_ls_cmd + " failed")
+ logger.error(vol_ls_cmd)
+ return False
+ else:
+ logger.debug("get volumes from poolpath is %s" % vol_cmd_list)
+ logger.info("compare the volume list under poolpath and list from
API")
+ vol_cmd_list = vol_cmd_list[2:]
+ vol_name_list.sort()
+ vol_poolobj_list.sort()
+ vol_cmd_list.sort()
+ if (cmp(vol_poolobj_list, vol_name_list) == 0) and \
+ (cmp(vol_name_list, vol_cmd_list) == 0):
+
+ return True
+ else:
+ return False
+
+
+def list_volumes(params):
+ """List all the volumes of a storage pool
+ """
+ global logger
+ logger = params['logger']
+ poolname = params['poolname']
+ vol_name_list = []
+
+ logger.info("the poolname is %s" % (poolname))
+ conn = sharedmod.libvirtobj['conn']
+ storage_pool_list = conn.listStoragePools()
+
+ if poolname not in storage_pool_list:
+ logger.error("pool %s doesn't exist or not running" % poolname)
+ return 1
+
+ pool_obj = conn.storagePoolLookupByName(poolname)
+
+ try:
+ vol_obj_list = pool_obj.listAllVolumes()
+ for vol_obj in vol_obj_list:
+ vol_name_list.append(vol_obj.name())
+ logger.info("the volume list is %s" % vol_name_list)
+
+ if check_list_volumes(pool_obj, vol_name_list):
+ logger.info("get the right volumes list successfully")
+ else:
+ logger.error("fail to get the right volumes list")
+ return 1
+
+ except libvirtError as e:
+ logger.error("API error message: %s, error code is %s"
+ % (e.message, e.get_error_code()))
+ return 1
+
+ return 0
--
1.7.1