Add cases for testing findStoragePoolSources API
* add 3 cases for storage type 'netfs', 'iscsi' and 'logical'
* add 2 xmls for 'netfs' and 'iscsi'
  find 'logical' storage pool sources did not require xml start with
  source tag and xml could be empty
* add test conf for find storage pool sources

Signed-off-by: Wayne Sun <g...@redhat.com>
---
 cases/find_storage_pool_sources.conf       |   31 +++++++++++
 repos/storage/find_iscsi_pool_sources.py   |   72 ++++++++++++++++++++++++
 repos/storage/find_logical_pool_sources.py |   82 ++++++++++++++++++++++++++++
 repos/storage/find_netfs_pool_sources.py   |   71 ++++++++++++++++++++++++
 repos/storage/xmls/iscsi_pool_source.xml   |    3 +
 repos/storage/xmls/netfs_pool_source.xml   |    4 ++
 6 files changed, 263 insertions(+), 0 deletions(-)
 create mode 100644 cases/find_storage_pool_sources.conf
 create mode 100644 repos/storage/find_iscsi_pool_sources.py
 create mode 100644 repos/storage/find_logical_pool_sources.py
 create mode 100644 repos/storage/find_netfs_pool_sources.py
 create mode 100644 repos/storage/xmls/iscsi_pool_source.xml
 create mode 100644 repos/storage/xmls/netfs_pool_source.xml

diff --git a/cases/find_storage_pool_sources.conf 
b/cases/find_storage_pool_sources.conf
new file mode 100644
index 0000000..d2e86db
--- /dev/null
+++ b/cases/find_storage_pool_sources.conf
@@ -0,0 +1,31 @@
+storage:find_iscsi_pool_sources
+    sourcehost
+        $iscsi_server
+
+storage:find_netfs_pool_sources
+    sourcehost
+        $nfs_server
+
+storage:define_logical_pool
+    poolname
+        $defaultpoolname
+    sourcename
+        $defaultpoolname
+    sourcepath
+        $defaultpartition
+
+storage:build_logical_pool
+    poolname
+        $defaultpoolname
+
+storage:find_logical_pool_sources
+    sourcepath
+        $defaultpartition
+
+storage:delete_logical_pool
+    poolname
+        $defaultpoolname
+
+storage:undefine_pool
+    poolname
+        $defaultpoolname
diff --git a/repos/storage/find_iscsi_pool_sources.py 
b/repos/storage/find_iscsi_pool_sources.py
new file mode 100644
index 0000000..4b758d2
--- /dev/null
+++ b/repos/storage/find_iscsi_pool_sources.py
@@ -0,0 +1,72 @@
+#!/usr/bin/env python
+# Test finding storage pool source of 'iscsi' type
+
+from xml.dom import minidom
+
+import libvirt
+from libvirt import libvirtError
+
+from src import sharedmod
+from utils import utils
+
+required_params = ('sourcehost',)
+optional_params = {'xml' : 'xmls/iscsi_pool_source.xml',
+                  }
+
+def check_pool_sources(host, xmlstr):
+    """check the iscsi sources with command:
+       iscsiadm --mode discovery --type sendtargets --portal
+    """
+    source_val = []
+
+    doc = minidom.parseString(xmlstr)
+    for diskTag in doc.getElementsByTagName("source"):
+        device_element = diskTag.getElementsByTagName("device")[0]
+        attr = device_element.getAttributeNode('path')
+        path_val = attr.nodeValue
+
+        source_val.append(path_val)
+
+    logger.debug("pool source info list is: %s" % source_val)
+
+    cmd = "iscsiadm --mode discovery --type sendtargets --portal %s:3260,1 |\
+           awk -F' ' '{print $2}'" % host
+    ret, path_list = utils.exec_cmd(cmd, shell=True)
+
+    logger.debug("iscsiadm command output list is: %s" % path_list)
+
+    if source_val == path_list:
+        logger.info("source list matched with iscsiadm command output")
+        return 0
+    else:
+        logger.error("source list did not match with iscsiadm command output")
+        return 1
+
+def find_iscsi_pool_sources(params):
+    """Find iscsi type storage pool sources from xml"""
+    global logger
+    logger = params['logger']
+    sourcehost = params['sourcehost']
+    xmlstr = params['xml']
+
+    conn = sharedmod.libvirtobj['conn']
+    try:
+
+        logger.debug("storage source spec xml:\n%s" % xmlstr)
+
+        logger.info("find pool sources of iscsi type")
+        source_xml = conn.findStoragePoolSources('iscsi', xmlstr, 0)
+        logger.info("pool sources xml description is:\n %s" % source_xml)
+
+        ret = check_pool_sources(sourcehost, source_xml)
+        if ret:
+            logger.error("pool sources check failed")
+            return 1
+        else:
+            logger.info("pool sources check succeed")
+
+    except libvirtError, e:
+        logger.error("libvirt call failed: " + str(e))
+        return 1
+
+    return 0
diff --git a/repos/storage/find_logical_pool_sources.py 
b/repos/storage/find_logical_pool_sources.py
new file mode 100644
index 0000000..255d879
--- /dev/null
+++ b/repos/storage/find_logical_pool_sources.py
@@ -0,0 +1,82 @@
+#!/usr/bin/env python
+# Test finding storage pool source of 'logical' type
+
+from xml.dom import minidom
+
+import libvirt
+from libvirt import libvirtError
+
+from src import sharedmod
+from utils import utils
+
+required_params = ('sourcepath',)
+optional_params = {'xml' : 'xmls/logical_pool.xml',
+                  }
+
+def check_pool_sources(xmlstr):
+    """check the logical sources with command:
+       pvs --noheadings -o pv_name,vg_name
+    """
+    source_val = {}
+    source_cmp = {}
+
+    doc = minidom.parseString(xmlstr)
+    for diskTag in doc.getElementsByTagName("source"):
+        device_element = diskTag.getElementsByTagName("device")[0]
+        attr = device_element.getAttributeNode('path')
+        path_val = attr.nodeValue
+
+        name_element = diskTag.getElementsByTagName("name")[0]
+        textnode = name_element.childNodes[0]
+        name_val = textnode.data
+
+        source_val.update({path_val: name_val, })
+
+    logger.debug("pool source info dict is: %s" % source_val)
+
+    cmd = "pvs --noheadings -o pv_name,vg_name | awk -F' ' '{print $1}'"
+    ret, path_list = utils.exec_cmd(cmd, shell=True)
+
+    cmd = "pvs --noheadings -o pv_name,vg_name | awk -F' ' '{print $2}'"
+    ret, name_list = utils.exec_cmd(cmd, shell=True)
+
+    for i in range(len(path_list)):
+        source_cmp.update({path_list[i]: name_list[i]})
+
+    logger.debug("pvs command output dict is: %s" % source_cmp)
+
+    if source_val == source_cmp:
+        logger.info("source dict match with pvs command output")
+        return 0
+    else:
+        logger.error("source dict did not match with pvs command output")
+        return 1
+
+def find_logical_pool_sources(params):
+    """Find logical type storage pool sources from xml"""
+    global logger
+    logger = params['logger']
+    sourcepath = params['sourcepath']
+    xmlstr = params['xml']
+
+    conn = sharedmod.libvirtobj['conn']
+    try:
+
+        logger.debug("storage source spec xml:\n%s" % xmlstr)
+
+        logger.info("find pool sources of logical type")
+        source_xml = conn.findStoragePoolSources('logical', xmlstr, 0)
+        logger.info("pool sources xml description is:\n %s" % source_xml)
+
+        ret = check_pool_sources(source_xml)
+        if ret:
+            logger.error("pool sources check failed")
+            return 1
+        else:
+            logger.info("pool sources check succeed")
+
+    except libvirtError, e:
+        logger.error("libvirt call failed: " + str(e))
+        return 1
+
+    return 0
diff --git a/repos/storage/find_netfs_pool_sources.py 
b/repos/storage/find_netfs_pool_sources.py
new file mode 100644
index 0000000..bc71233
--- /dev/null
+++ b/repos/storage/find_netfs_pool_sources.py
@@ -0,0 +1,71 @@
+#!/usr/bin/env python
+# Test finding storage pool source of 'netfs' type
+
+from xml.dom import minidom
+
+import libvirt
+from libvirt import libvirtError
+
+from src import sharedmod
+from utils import utils
+
+required_params = ('sourcehost',)
+optional_params = {'xml' : 'xmls/netfs_pool_source.xml',
+                  }
+
+def check_pool_sources(host, xmlstr):
+    """check the netfs sources with command:
+       showmount --no-headers -e HOSTNAME
+    """
+    source_val = []
+
+    doc = minidom.parseString(xmlstr)
+    for diskTag in doc.getElementsByTagName("source"):
+        device_element = diskTag.getElementsByTagName("dir")[0]
+        attr = device_element.getAttributeNode('path')
+        path_val = attr.nodeValue
+
+        source_val.append(path_val)
+
+    logger.debug("pool source info list is: %s" % source_val)
+
+    cmd = "showmount --no-headers -e %s | awk -F' ' '{print $1}'" % host
+    ret, path_list = utils.exec_cmd(cmd, shell=True)
+
+    logger.debug("showmount command output list is: %s" % path_list)
+
+    if source_val == path_list:
+        logger.info("source list matched with showmount command output")
+        return 0
+    else:
+        logger.error("source list did not match with showmount command output")
+        return 1
+
+def find_netfs_pool_sources(params):
+    """Find netfs type storage pool sources from xml"""
+    global logger
+    logger = params['logger']
+    sourcehost = params['sourcehost']
+    xmlstr = params['xml']
+
+    conn = sharedmod.libvirtobj['conn']
+    try:
+
+        logger.debug("storage source spec xml:\n%s" % xmlstr)
+
+        logger.info("find pool sources of netfs type")
+        source_xml = conn.findStoragePoolSources('netfs', xmlstr, 0)
+        logger.info("pool sources xml description is:\n %s" % source_xml)
+
+        ret = check_pool_sources(sourcehost, source_xml)
+        if ret:
+            logger.error("pool sources check failed")
+            return 1
+        else:
+            logger.info("pool sources check succeed")
+
+    except libvirtError, e:
+        logger.error("libvirt call failed: " + str(e))
+        return 1
+
+    return 0
diff --git a/repos/storage/xmls/iscsi_pool_source.xml 
b/repos/storage/xmls/iscsi_pool_source.xml
new file mode 100644
index 0000000..93216c5
--- /dev/null
+++ b/repos/storage/xmls/iscsi_pool_source.xml
@@ -0,0 +1,3 @@
+<source>
+  <host name="SOURCEHOST"/>
+</source>
diff --git a/repos/storage/xmls/netfs_pool_source.xml 
b/repos/storage/xmls/netfs_pool_source.xml
new file mode 100644
index 0000000..6a2aeea
--- /dev/null
+++ b/repos/storage/xmls/netfs_pool_source.xml
@@ -0,0 +1,4 @@
+<source>
+  <host name="SOURCEHOST"/>
+  <format type="nfs"/>
+</source>
-- 
1.7.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Reply via email to