Re: [test-API][PATCH] Add the volume clone case

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 01/14/2013 05:36 PM, Wayne Sun wrote:
This is for volume clone testing by using createXMLFrom API
* add the vol_clone case under storage
   it is general for all pool types
* add cases into confs:
   cases/storage_dir.conf
   cases/storage_logical.conf
   cases/storage_netfs.conf
* add variable 'defaultvolclonename' in global.cfg

Signed-off-by: Wayne Sun <gsun@xxxxxxxxxx>
---
  cases/storage_dir.conf     |   14 +++++++
  cases/storage_logical.conf |   14 +++++++
  cases/storage_netfs.conf   |   14 +++++++
  global.cfg                 |    2 +
  repos/storage/vol_clone.py |   81 ++++++++++++++++++++++++++++++++++++++++++++
  5 files changed, 125 insertions(+), 0 deletions(-)
  create mode 100644 repos/storage/vol_clone.py

diff --git a/cases/storage_dir.conf b/cases/storage_dir.conf
index dcac700..38b349d 100644
--- a/cases/storage_dir.conf
+++ b/cases/storage_dir.conf
@@ -20,6 +20,20 @@ storage:create_dir_volume
      capacity
          $defaultvolumesize
+storage:vol_clone
+    poolname
+        $defaultpoolname
+    volname
+        $defaultvolumename
+    clonevolname
+        $defaultvolclonename
+
+storage:delete_dir_volume
+    poolname
+        $defaultpoolname
+    volname
+        $defaultvolclonename
+
  storage:delete_dir_volume
      poolname
          $defaultpoolname
diff --git a/cases/storage_logical.conf b/cases/storage_logical.conf
index 3334abd..d374dfa 100644
--- a/cases/storage_logical.conf
+++ b/cases/storage_logical.conf
@@ -22,6 +22,20 @@ storage:create_logical_volume
      capacity
          $defaultvolumesize
+storage:vol_clone
+    poolname
+        $defaultpoolname
+    volname
+        $defaultvolumename
+    clonevolname
+        $defaultvolclonename
+
+storage:delete_logical_volume
+    poolname
+        $defaultpoolname
+    volname
+        $defaultvolclonename
+
  storage:delete_logical_volume
      poolname
          $defaultpoolname
diff --git a/cases/storage_netfs.conf b/cases/storage_netfs.conf
index e764813..f486ff4 100644
--- a/cases/storage_netfs.conf
+++ b/cases/storage_netfs.conf
@@ -24,6 +24,20 @@ storage:create_netfs_volume
      capacity
          $defaultvolumesize
+storage:vol_clone
+    poolname
+        $defaultpoolname
+    volname
+        $defaultvolumename
+    clonevolname
+        $defaultvolclonename
+
+storage:delete_netfs_volume
+    poolname
+        $defaultpoolname
+    volname
+        $defaultvolclonename
+
  storage:delete_netfs_volume
      poolname
          $defaultpoolname
diff --git a/global.cfg b/global.cfg
index 9e28614..182acbd 100644
--- a/global.cfg
+++ b/global.cfg
@@ -156,6 +156,8 @@ defaultpoolname = test_api_pool
  defaultpoolpath = /var/lib/libvirt/images/dir_pool
  # default volume name for creating new volume
  defaultvolumename = test_api_volume
+# default clone volume name for clone a volume
+defaultvolclonename = test_clone_volume
  # default volume type for creating a new volume
  defaultvolumetype = raw
  # default volume capacity for creating a new volume
diff --git a/repos/storage/vol_clone.py b/repos/storage/vol_clone.py
new file mode 100644
index 0000000..abf5644
--- /dev/null
+++ b/repos/storage/vol_clone.py
@@ -0,0 +1,81 @@
+#!/usr/bin/env python
+# volume clone testing
+
+import os
+from xml.dom import minidom
+
+import libvirt
+from libvirt import libvirtError
+
+from src import sharedmod
+
+required_params = ('poolname', 'volname', 'clonevolname',)
+optional_params = {}
+
+def prepare_clone_xml(xmlstr, volname):
+    """prepare clone xmldesc by replace name element
+       with clone souce volume xml
+    """
+    doc = minidom.parseString(xmlstr)
+    oldname = doc.getElementsByTagName("name")[0]
+
+    newname = doc.createElement('name')
+    newnameval = doc.createTextNode(volname)
+    newname.appendChild(newnameval)
+
+    volume = doc.getElementsByTagName('volume')[0]
+
+    volume.replaceChild(newname, oldname)
+    newxmlstr = doc.toxml()
+
+    return newxmlstr
+
+def vol_clone(params):
+    """volume clone testing"""
+
+    global logger
+    logger = params['logger']
+    poolname = params['poolname']
+    volname = params['volname']
+    clonevolname = params['clonevolname']
+
+    logger.info("the poolname is %s, volname is %s" % (poolname, volname))
+    logger.info("the clone volume name is %s" % clonevolname)
+
+    conn = sharedmod.libvirtobj['conn']
+    try:
+        poolobj = conn.storagePoolLookupByName(poolname)
+        old_vol = poolobj.storageVolLookupByName(volname)
+
+        xmlstr = old_vol.XMLDesc(0)
+        newxmlstr = prepare_clone_xml(xmlstr, clonevolname)
+        logger.debug("volume xml:\n%s" % newxmlstr)
+
+        logger.info("clone volume %s from source volume %s" %
+                    (clonevolname, volname))
+
+        old_volnum = poolobj.numOfVolumes()
+
+        new_vol = poolobj.createXMLFrom(newxmlstr, old_vol, 0)
+        poolobj.refresh(0)
+
+        new_volnum = poolobj.numOfVolumes()
+
+        logger.debug("new cloned volume path is: %s" % new_vol.path())
+        if os.access(new_vol.path(), os.R_OK):
+            logger.info("cloned volume path exist")
+        else:
+            logger.error("cloned volume path not exist")
+            return 1
+
+        if new_volnum > old_volnum:
+            logger.info("clone succeed")
+        else:
+            logger.error("clone failed")
+            return 1
+
+    except libvirtError, e:
+        logger.error("libvirt call failed: " + str(e))
+        return 1
+
+    return 0

   ACK and pushed
   Thanks.

   Guannan

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


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]