Change in vdsm[master]: tests: Move virt storage tests to new module

nsoffer at redhat.com nsoffer at redhat.com
Wed Feb 4 23:53:36 UTC 2015


Nir Soffer has uploaded a new change for review.

Change subject: tests: Move virt storage tests to new module
......................................................................

tests: Move virt storage tests to new module

This patch moves virt.vmdevices.storage.Drive.getXML tests to new
vmStorageTests module. Future patches will move the rest of the Drive
releated tests.

Moved tests were refactored to make them more reliable, readable and
easier to modify.

- Each test case has its own test method, so failure of one test case
  does not effect others.
- Device configuration was indented and sorted
- Unneeded logic was eliminated

Change-Id: I79babde8a7a12544f18bb450cc9c81accb77b72e
Signed-off-by: Nir Soffer <nsoffer at redhat.com>
---
M tests/Makefile.am
A tests/vmStorageTests.py
M tests/vmTests.py
3 files changed, 170 insertions(+), 92 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/32/37532/1

diff --git a/tests/Makefile.am b/tests/Makefile.am
index a4261d6..8ab3ad3 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -88,8 +88,9 @@
 	vdsClientTests.py \
 	vmApiTests.py \
 	vmMigrationTests.py \
-	vmTestsData.py \
+	vmStorageTests.py \
 	vmTests.py \
+	vmTestsData.py \
 	vmXmlTests.py \
 	volumeTests.py \
 	v2vTests.py \
diff --git a/tests/vmStorageTests.py b/tests/vmStorageTests.py
new file mode 100644
index 0000000..95a1180
--- /dev/null
+++ b/tests/vmStorageTests.py
@@ -0,0 +1,168 @@
+#
+# Copyright 2015 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
+#
+# Refer to the README and COPYING files for full details of the license
+#
+
+from virt.vmdevices.storage import Drive
+from testlib import XMLTestCase
+
+
+class TestDriveXML(XMLTestCase):
+
+    def test_cdrom(self):
+        conf = {
+            'device': 'cdrom',
+            'format': 'raw',
+            'iface': 'ide',
+            'index': '2',
+            'name': 'hdc',
+            'path': '/path/to/fedora.iso',
+            'propagateErrors': 'off',
+            'readonly': 'True',
+            'serial': '54-a672-23e5b495a9ea',
+            'shared': 'none',
+            'type': 'disk',
+        }
+        xml = """
+            <disk device="cdrom" snapshot="no" type="file">
+                <source file="/path/to/fedora.iso" startupPolicy="optional"/>
+                <target bus="ide" dev="hdc"/>
+                <readonly/>
+                <serial>54-a672-23e5b495a9ea</serial>
+            </disk>
+            """
+        self.check({}, conf, xml, is_block_device=False)
+
+    def test_disk_virtio_cache(self):
+        conf = {
+            'device': 'disk',
+            'format': 'cow',
+            'iface': 'virtio',
+            'index': '0',
+            'name': 'vda',
+            'path': '/path/to/volume',
+            'propagateErrors': 'on',
+            'readonly': 'False',
+            'serial': '54-a672-23e5b495a9ea',
+            'shared': 'shared',
+            'specParams': {
+                'ioTune': {
+                    'read_bytes_sec': 6120000,
+                    'total_iops_sec': 800,
+                }
+            },
+            'type': 'disk',
+        }
+        xml = """
+            <disk device="disk" snapshot="no" type="file">
+                <source file="/path/to/volume"/>
+                <target bus="virtio" dev="vda"/>
+                <shareable/>
+                <serial>54-a672-23e5b495a9ea</serial>
+                <driver cache="writethrough" error_policy="enospace"
+                        io="threads" name="qemu" type="qcow2"/>
+                <iotune>
+                    <read_bytes_sec>6120000</read_bytes_sec>
+                    <total_iops_sec>800</total_iops_sec>
+                </iotune>
+            </disk>
+            """
+        vm_conf = {'custom': {'viodiskcache': 'writethrough'}}
+        self.check(vm_conf, conf, xml, is_block_device=False)
+
+    def test_disk_block(self):
+        conf = {
+            'device': 'disk',
+            'format': 'raw',
+            'iface': 'virtio',
+            'index': '0',
+            'name': 'vda',
+            'path': '/path/to/volume',
+            'propagateErrors': 'off',
+            'readonly': 'False',
+            'serial': '54-a672-23e5b495a9ea',
+            'shared': 'none',
+            'type': 'disk',
+        }
+        xml = """
+            <disk device="disk" snapshot="no" type="block">
+                <source dev="/path/to/volume"/>
+                <target bus="virtio" dev="vda"/>
+                <serial>54-a672-23e5b495a9ea</serial>
+                <driver cache="none" error_policy="stop"
+                        io="native" name="qemu" type="raw"/>
+            </disk>
+            """
+        self.check({}, conf, xml, is_block_device=True)
+
+    def test_disk_file(self):
+        conf = {
+            'device': 'disk',
+            'format': 'raw',
+            'iface': 'scsi',
+            'index': '0',
+            'name': 'sda',
+            'path': '/path/to/volume',
+            'propagateErrors': 'off',
+            'readonly': 'False',
+            'serial': '54-a672-23e5b495a9ea',
+            'shared': 'exclusive',
+            'type': 'disk',
+        }
+        xml = """
+            <disk device="disk" snapshot="no" type="file">
+                <source file="/path/to/volume"/>
+                <target bus="scsi" dev="sda"/>
+                <serial>54-a672-23e5b495a9ea</serial>
+                <driver cache="none" error_policy="stop"
+                        io="threads" name="qemu" type="raw"/>
+            </disk>
+            """
+        self.check({}, conf, xml, is_block_device=False)
+
+    def test_lun(self):
+        conf = {
+            'device': 'lun',
+            'format': 'raw',
+            'iface': 'scsi',
+            'index': '0',
+            'name': 'sda',
+            'path': '/dev/mapper/lun1',
+            'propagateErrors': 'off',
+            'readonly': 'False',
+            'serial': '54-a672-23e5b495a9ea',
+            'sgio': 'unfiltered',
+            'shared': 'none',
+            'type': 'disk',
+        }
+        xml = """
+            <disk device="lun" sgio="unfiltered" snapshot="no" type="block">
+                <source dev="/dev/mapper/lun1"/>
+                <target bus="scsi" dev="sda"/>
+                <serial>54-a672-23e5b495a9ea</serial>
+                <driver cache="none" error_policy="stop"
+                        io="native" name="qemu" type="raw"/>
+            </disk>
+            """
+        self.check({}, conf, xml, is_block_device=True)
+
+    def check(self, vm_conf, device_conf, xml, is_block_device=False):
+        drive = Drive(vm_conf, self.log, **device_conf)
+        # Patch to skip the block device checking.
+        drive._blockDev = is_block_device
+        self.assertXMLEqual(drive.getXML().toxml(), xml)
diff --git a/tests/vmTests.py b/tests/vmTests.py
index 2b96dd8..088340e 100644
--- a/tests/vmTests.py
+++ b/tests/vmTests.py
@@ -692,97 +692,6 @@
         with self.assertRaises(ValueError):
             drive = vmdevices.storage.Drive({}, self.log, **driveInput)
 
-    def testDriveXML(self):
-        SERIAL = '54-a672-23e5b495a9ea'
-        devConfs = [
-            {'index': '2', 'propagateErrors': 'off', 'iface': 'ide',
-             'name': 'hdc', 'format': 'raw', 'device': 'cdrom',
-             'path': '/tmp/fedora.iso', 'type': 'disk', 'readonly': 'True',
-             'shared': 'none', 'serial': SERIAL},
-
-            {'index': '0', 'propagateErrors': 'on', 'iface': 'virtio',
-             'name': 'vda', 'format': 'cow', 'device': 'disk',
-             'path': '/tmp/disk1.img', 'type': 'disk', 'readonly': 'False',
-             'shared': 'shared', 'serial': SERIAL,
-             'specParams': {'ioTune': {'read_bytes_sec': 6120000,
-                                       'total_iops_sec': 800}}},
-
-            {'index': '0', 'propagateErrors': 'off', 'iface': 'virtio',
-             'name': 'vda', 'format': 'raw', 'device': 'disk',
-             'path': '/dev/mapper/lun1', 'type': 'disk', 'readonly': 'False',
-             'shared': 'none', 'serial': SERIAL},
-
-            {'index': '0', 'propagateErrors': 'off', 'iface': 'scsi',
-             'name': 'sda', 'format': 'raw', 'device': 'disk',
-             'path': '/tmp/disk1.img', 'type': 'disk', 'readonly': 'False',
-             'shared': 'exclusive', 'serial': SERIAL},
-
-            {'index': '0', 'propagateErrors': 'off', 'iface': 'scsi',
-             'name': 'sda', 'format': 'raw', 'device': 'lun',
-             'path': '/dev/mapper/lun1', 'type': 'disk', 'readonly': 'False',
-             'shared': 'none', 'serial': SERIAL, 'sgio': 'unfiltered'}]
-
-        expectedXMLs = [
-            """
-            <disk device="cdrom" snapshot="no" type="file">
-                <source file="/tmp/fedora.iso" startupPolicy="optional"/>
-                <target bus="ide" dev="hdc"/>
-                <readonly/>
-                <serial>%s</serial>
-            </disk>""",
-
-            """
-            <disk device="disk" snapshot="no" type="file">
-                <source file="/tmp/disk1.img"/>
-                <target bus="virtio" dev="vda"/>
-                <shareable/>
-                <serial>%s</serial>
-                <driver cache="writethrough" error_policy="enospace"
-                        io="threads" name="qemu" type="qcow2"/>
-                <iotune>
-                    <read_bytes_sec>6120000</read_bytes_sec>
-                    <total_iops_sec>800</total_iops_sec>
-                </iotune>
-            </disk>""",
-
-            """
-            <disk device="disk" snapshot="no" type="block">
-                <source dev="/dev/mapper/lun1"/>
-                <target bus="virtio" dev="vda"/>
-                <serial>%s</serial>
-                <driver cache="none" error_policy="stop"
-                        io="native" name="qemu" type="raw"/>
-            </disk>""",
-
-            """
-            <disk device="disk" snapshot="no" type="file">
-                <source file="/tmp/disk1.img"/>
-                <target bus="scsi" dev="sda"/>
-                <serial>%s</serial>
-                <driver cache="none" error_policy="stop"
-                        io="threads" name="qemu" type="raw"/>
-            </disk>""",
-
-            """
-            <disk device="lun" sgio="unfiltered" snapshot="no" type="block">
-                <source dev="/dev/mapper/lun1"/>
-                <target bus="scsi" dev="sda"/>
-                <serial>%s</serial>
-                <driver cache="none" error_policy="stop"
-                        io="native" name="qemu" type="raw"/>
-            </disk>"""]
-
-        blockDevs = [False, False, True, False, True]
-        vmConfs = [{}, {'custom': {'viodiskcache': 'writethrough'}},
-                   {}, {}, {}]
-
-        for (devConf, xml, blockDev, vmConf) in \
-                zip(devConfs, expectedXMLs, blockDevs, vmConfs):
-            drive = vmdevices.storage.Drive(vmConf, self.log, **devConf)
-            # Patch Drive.blockDev to skip the block device checking.
-            drive._blockDev = blockDev
-            self.assertXMLEqual(drive.getXML().toxml(), xml % SERIAL)
-
     def testIoTuneException(self):
         SERIAL = '54-a672-23e5b495a9ea'
         basicConf = {'index': '0', 'propagateErrors': 'on', 'iface': 'virtio',


-- 
To view, visit http://gerrit.ovirt.org/37532
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I79babde8a7a12544f18bb450cc9c81accb77b72e
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Nir Soffer <nsoffer at redhat.com>


More information about the vdsm-patches mailing list