On 01/06/2013 05:40 PM, Wayne Sun wrote:
* add dir volume wipe and wipe pattern cases
* wipe case compare wiped volume with zero volume file with same
capacity
* wipe pattern cases support algorithms in:
zero|nnsa|dod|bsi|gutmann|schneier|pfitzner7|pfitzner33|random,
Besides zero, other algorithms are patterns supported by scrub,
some algorithm might fail due to scrub version.
* the check method in wipe pattern case for each algorithm is the
same, only to make sure digest before and after wipe is
different.
Signed-off-by: Wayne Sun <gsun(a)redhat.com>
---
cases/storage_dir_vol_wipe.conf | 132 ++++++++++++++++++++++++++++++++
repos/storage/dir_vol_wipe.py | 136 +++++++++++++++++++++++++++++++++
repos/storage/dir_vol_wipe_pattern.py | 123 +++++++++++++++++++++++++++++
3 files changed, 391 insertions(+), 0 deletions(-)
create mode 100644 cases/storage_dir_vol_wipe.conf
create mode 100644 repos/storage/dir_vol_wipe.py
create mode 100644 repos/storage/dir_vol_wipe_pattern.py
diff --git a/cases/storage_dir_vol_wipe.conf b/cases/storage_dir_vol_wipe.conf
new file mode 100644
index 0000000..aa39415
--- /dev/null
+++ b/cases/storage_dir_vol_wipe.conf
@@ -0,0 +1,132 @@
+storage:create_dir_pool
+ poolname
+ $defaultpoolname
+
+storage:dir_vol_wipe
+ poolname
+ $defaultpoolname
+ volname
+ $defaultvolumename
+ capacity
+ 2M
+ volformat
+ raw
+clean
+
+storage:dir_vol_wipe
+ poolname
+ $defaultpoolname
+ volname
+ $defaultvolumename
+ capacity
+ 50M
+ volformat
+ qcow2
+clean
+
+storage:dir_vol_wipe
+ poolname
+ $defaultpoolname
+ volname
+ $defaultvolumename
+ capacity
+ 30M
+ volformat
+ qed
+clean
+
+storage:dir_vol_wipe_pattern
+ poolname
+ $defaultpoolname
+ volname
+ $defaultvolumename
+ capacity
+ 2M
+ volformat
+ raw
+ algorithm
+ zero
+clean
+
+storage:dir_vol_wipe_pattern
+ poolname
+ $defaultpoolname
+ volname
+ $defaultvolumename
+ capacity
+ 50M
+ volformat
+ qcow2
+ algorithm
+ nnsa
+clean
+
+storage:dir_vol_wipe_pattern
+ poolname
+ $defaultpoolname
+ volname
+ $defaultvolumename
+ capacity
+ 30M
+ volformat
+ qed
+ algorithm
+ pfitzner7
+clean
+
+storage:dir_vol_wipe_pattern
+ poolname
+ $defaultpoolname
+ volname
+ $defaultvolumename
+ capacity
+ 1K
+ volformat
+ raw
+ algorithm
+ random
+clean
+
+storage:dir_vol_wipe_pattern
+ poolname
+ $defaultpoolname
+ volname
+ $defaultvolumename
+ capacity
+ 1K
+ volformat
+ raw
+ algorithm
+ dod
+clean
+
+storage:dir_vol_wipe_pattern
+ poolname
+ $defaultpoolname
+ volname
+ $defaultvolumename
+ capacity
+ 1K
+ volformat
+ raw
+ algorithm
+ bsi
+clean
+
+storage:dir_vol_wipe_pattern
+ poolname
+ $defaultpoolname
+ volname
+ $defaultvolumename
+ capacity
+ 1K
+ volformat
+ raw
+ algorithm
+ gutmann
+clean
+
+
+storage:destroy_pool
+ poolname
+ $defaultpoolname
diff --git a/repos/storage/dir_vol_wipe.py b/repos/storage/dir_vol_wipe.py
new file mode 100644
index 0000000..c020b43
--- /dev/null
+++ b/repos/storage/dir_vol_wipe.py
@@ -0,0 +1,136 @@
+#!/usr/bin/env python
+# volume wipe testing
+
+import os
+import string
+from xml.dom import minidom
+
+import libvirt
+from libvirt import libvirtError
+
+from src import sharedmod
+from utils import utils
+
+required_params = ('poolname', 'volname', 'volformat',
'capacity',)
+optional_params = {'xml' : 'xmls/dir_volume.xml',
+ }
+
+def get_pool_path(poolobj):
+ """ get pool xml description
+ """
+ poolxml = poolobj.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 write_file(path, capacity):
+ """write test data to file
+ """
+ logger.info("write %s data into file %s" % (capacity, path))
+ out = utils.get_capacity_suffix_size(capacity)
+ f = open(path, 'w')
+ datastr = ''.join(string.lowercase + string.uppercase
+ + string.digits + '.' + '\n')
+ repeat = out['capacity_byte'] / 64
+ data = ''.join(repeat * datastr)
+ f.write(data)
+ f.close()
+
+def dir_vol_wipe(params):
+ """test volume download and check"""
+
+ global logger
+ logger = params['logger']
+ poolname = params['poolname']
+ volname = params['volname']
+ volformat = params['volformat']
+ capacity = params['capacity']
+ xmlstr = params['xml']
+
+ logger.info("the poolname is %s, volname is %s, volformat is %s" %
+ (poolname, volname, volformat))
+
+ conn = sharedmod.libvirtobj['conn']
+ try:
+ poolobj = conn.storagePoolLookupByName(poolname)
+ path_value = get_pool_path(poolobj)
+ volume_path = path_value + "/" + volname
+
+ xmlstr = xmlstr.replace('VOLPATH', volume_path)
+ xmlstr = xmlstr.replace('SUFFIX', capacity[-1])
+ xmlstr = xmlstr.replace('CAP', capacity[:-1])
+ logger.debug("volume xml:\n%s" % xmlstr)
+
+ logger.info("create %s %s volume" % (volname, volformat))
+ vol = poolobj.createXML(xmlstr, 0)
+
+ write_file(volume_path, capacity)
+
+ poolobj.refresh(0)
+
+ origdigest = utils.digest(volume_path, 0, 0)
+ logger.debug("the md5 hex digest of data read from %s is: %s" %
+ (volume_path, origdigest))
+
+ test_path = path_value + "/" + "vol_test"
+ out = utils.get_capacity_suffix_size(capacity)
+ count = out['capacity_byte'] / 1024
+ logger.info("write %s zero to test volume %s" % (capacity,
test_path))
+ cmd = "dd if=/dev/zero of=%s bs=1024 count=%s" % (test_path, count)
+ utils.exec_cmd(cmd, shell=True)
+ cmpdigest = utils.digest(test_path, 0, 0)
+ logger.debug("the compare volume digest is: %s" % cmpdigest)
+
+ logger.info("wipe volume %s" % volume_path)
+ vol.wipe(0)
+
+ newdigest = utils.digest(volume_path, 0, 0)
+ logger.debug("the volum digest of data read from %s after wipe is:
%s"
+ % (volume_path, newdigest))
+
+ logger.info("check the digest before and after wipe")
+ if newdigest == origdigest:
+ logger.error("wipe failed, digest did not change")
+ return 1
+ else:
+ logger.info("digest is different before and after wipe")
+
+ logger.info("compare the digest after wipe with digest of volume %s"
%
+ test_path)
+ if not newdigest == cmpdigest:
+ logger.error("wipe failed, digest is different")
+ return 1
+ else:
+ logger.info("digest is same with zero volume %s" % test_path)
+
+ logger.info("wipe succeed")
+
+ except libvirtError, e:
+ logger.error("libvirt call failed: " + str(e))
+ return 1
+
+ return 0
+
+def dir_vol_wipe_clean(params):
+ """clean testing environment"""
+ poolname = params['poolname']
+ volname = params['volname']
+
+ conn = sharedmod.libvirtobj['conn']
+ poolobj = conn.storagePoolLookupByName(poolname)
+ path_value = get_pool_path(poolobj)
+ test_path = path_value + "/" + "vol_test"
+
+ vol = poolobj.storageVolLookupByName(volname)
+ vol.delete(0)
+
+ if os.path.exists(test_path):
+ os.unlink(test_path)
+
+ return 0
diff --git a/repos/storage/dir_vol_wipe_pattern.py
b/repos/storage/dir_vol_wipe_pattern.py
new file mode 100644
index 0000000..86e3ea2
--- /dev/null
+++ b/repos/storage/dir_vol_wipe_pattern.py
@@ -0,0 +1,123 @@
+#!/usr/bin/env python
+# volume wipe with pattern testing, the supported algorithm are
+# zero and algorithm patterns supported by 'scrub' command which
+# are nnsa|dod|bsi|gutmann|schneier|pfitzner7|pfitzner33|random
+
+import os
+import string
+from xml.dom import minidom
+
+import libvirt
+from libvirt import libvirtError
+
+from src import sharedmod
+from utils import utils
+
+required_params = ('poolname', 'volname', 'volformat',
'capacity', 'algorithm',)
+optional_params = {'xml' : 'xmls/dir_volume.xml',
+ }
+
+def get_pool_path(poolobj):
+ """ get pool xml description
+ """
+ poolxml = poolobj.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 write_file(path, capacity):
+ """write test data to file
+ """
+ logger.info("write %s data into file %s" % (capacity, path))
+ out = utils.get_capacity_suffix_size(capacity)
+ f = open(path, 'w')
+ datastr = ''.join(string.lowercase + string.uppercase
+ + string.digits + '.' + '\n')
+ repeat = out['capacity_byte'] / 64
+ data = ''.join(repeat * datastr)
+ f.write(data)
+ f.close()
+
+def dir_vol_wipe_pattern(params):
+ """test volume download and check"""
+
+ global logger
+ logger = params['logger']
+ poolname = params['poolname']
+ volname = params['volname']
+ volformat = params['volformat']
+ capacity = params['capacity']
+ algorithm = params['algorithm']
+ xmlstr = params['xml']
+
+ logger.info("the poolname is %s, volname is %s, volformat is %s" %
+ (poolname, volname, volformat))
+
+ logger.info("the wipe algorithm given is %s" % algorithm)
+ alg_str = 'libvirt.VIR_STORAGE_VOL_WIPE_ALG_%s' % algorithm.upper()
+ alg_val = eval(alg_str)
+ logger.info("the correspond algorithm value is %s" % alg_val)
+
+ conn = sharedmod.libvirtobj['conn']
+ try:
+ poolobj = conn.storagePoolLookupByName(poolname)
+ path_value = get_pool_path(poolobj)
+ volume_path = path_value + "/" + volname
+
+ xmlstr = xmlstr.replace('VOLPATH', volume_path)
+ xmlstr = xmlstr.replace('SUFFIX', capacity[-1])
+ xmlstr = xmlstr.replace('CAP', capacity[:-1])
+ logger.debug("volume xml:\n%s" % xmlstr)
+
+ logger.info("create %s %s volume" % (volname, volformat))
+ vol = poolobj.createXML(xmlstr, 0)
+
+ write_file(volume_path, capacity)
+
+ poolobj.refresh(0)
+
+ origdigest = utils.digest(volume_path, 0, 0)
+ logger.debug("the md5 hex digest of data read from %s is: %s" %
+ (volume_path, origdigest))
+
+ logger.info("wipe volume %s with algorithm value %s" %
+ (volume_path, alg_val))
+ vol.wipePattern(alg_val, 0)
+
+ newdigest = utils.digest(volume_path, 0, 0)
+ logger.debug("the volum digest of data read from %s after wipe is:
%s"
+ % (volume_path, newdigest))
+
+ logger.info("check the digest before and after wipe")
+ if newdigest == origdigest:
+ logger.error("wipe with algorithm %s failed, digest is the same"
+ % algorithm)
+ return 1
+ else:
+ logger.info("digest is different before and after wipe")
+
+ logger.info("wipe with algorithm %s succeed" % algorithm)
+
+ except libvirtError, e:
+ logger.error("libvirt call failed: " + str(e))
+ return 1
+
+ return 0
+
+def dir_vol_wipe_pattern_clean(params):
+ """clean testing environment"""
+ poolname = params['poolname']
+ volname = params['volname']
+
+ conn = sharedmod.libvirtobj['conn']
+ poolobj = conn.storagePoolLookupByName(poolname)
+ vol = poolobj.storageVolLookupByName(volname)
+ vol.delete(0)
+
+ return 0
ACK and pushed
Thanks
Guannan