Change in vdsm[master]: tests: Add drive_config helper

nsoffer at redhat.com nsoffer at redhat.com
Thu Feb 5 15:10:16 UTC 2015


Nir Soffer has uploaded a new change for review.

Change subject: tests: Add drive_config helper
......................................................................

tests: Add drive_config helper

Instead of repeating all drive options for each test, add a helper
function to create drive configuration specifying only the interesting
options for the specific test.

Change-Id: I7b1d1fd263324d3e376606c97be7ab54059b7f17
Signed-off-by: Nir Soffer <nsoffer at redhat.com>
---
M tests/vmStorageTests.py
1 file changed, 41 insertions(+), 69 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/47/37547/1

diff --git a/tests/vmStorageTests.py b/tests/vmStorageTests.py
index a3c4107..603d974 100644
--- a/tests/vmStorageTests.py
+++ b/tests/vmStorageTests.py
@@ -27,19 +27,13 @@
 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',
-        }
+        conf = drive_config(
+            device='cdrom',
+            iface='ide',
+            index='2',
+            path='/path/to/fedora.iso',
+            readonly='True',
+        )
         xml = """
             <disk device="cdrom" snapshot="no" type="file">
                 <source file="/path/to/fedora.iso" startupPolicy="optional"/>
@@ -51,25 +45,17 @@
         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': {
+        conf = drive_config(
+            format='cow',
+            propagateErrors='on',
+            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"/>
@@ -88,19 +74,7 @@
         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',
-        }
+        conf = drive_config()
         xml = """
             <disk device="disk" snapshot="no" type="block">
                 <source dev="/path/to/volume"/>
@@ -113,23 +87,11 @@
         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',
-        }
+        conf = drive_config()
         xml = """
             <disk device="disk" snapshot="no" type="file">
                 <source file="/path/to/volume"/>
-                <target bus="scsi" dev="sda"/>
+                <target bus="virtio" dev="vda"/>
                 <serial>54-a672-23e5b495a9ea</serial>
                 <driver cache="none" error_policy="stop"
                         io="threads" name="qemu" type="raw"/>
@@ -138,20 +100,12 @@
         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',
-        }
+        conf = drive_config(
+            device='lun',
+            iface='scsi',
+            path='/dev/mapper/lun1',
+            sgio='unfiltered',
+        )
         xml = """
             <disk device="lun" sgio="unfiltered" snapshot="no" type="block">
                 <source dev="/dev/mapper/lun1"/>
@@ -192,8 +146,26 @@
         self.check(shared, 'none')
 
     def check(self, shared, expected):
-        conf = {'index': '0', 'iface': 'virtio', 'device': 'disk'}
+        conf = drive_config()
         if shared:
             conf['shared'] = shared
         drive = Drive({}, self.log, **conf)
         self.assertEqual(drive.extSharedState, expected)
+
+
+def drive_config(**kw):
+    """ Reutrn drive configuration updated from **kw """
+    conf = {
+        'device': 'disk',
+        'format': 'raw',
+        'iface': 'virtio',
+        'index': '0',
+        'path': '/path/to/volume',
+        'propagateErrors': 'off',
+        'readonly': 'False',
+        'serial': '54-a672-23e5b495a9ea',
+        'shared': 'none',
+        'type': 'disk',
+    }
+    conf.update(kw)
+    return conf


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I7b1d1fd263324d3e376606c97be7ab54059b7f17
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