Change in vdsm[master]: hostdev: add basic unit tests for XML

mpolednik at redhat.com mpolednik at redhat.com
Wed Jul 1 09:28:15 UTC 2015


Martin Polednik has uploaded a new change for review.

Change subject: hostdev: add basic unit tests for XML
......................................................................

hostdev: add basic unit tests for XML

Now VDSM has the needed tools to unit test the creation of host
devices. This patch adds first batch of tests, that verify PCI and USB
devices without supplied address. Future patches will expand the
possibilities of test cases.

Change-Id: I723a8876382f778441b015c7c0f453d0888d7f6b
Signed-off-by: Martin Polednik <mpolednik at redhat.com>
---
M tests/hostdevTests.py
1 file changed, 94 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/88/43088/1

diff --git a/tests/hostdevTests.py b/tests/hostdevTests.py
index d87bb99..1d8dfe5 100644
--- a/tests/hostdevTests.py
+++ b/tests/hostdevTests.py
@@ -22,7 +22,9 @@
 import hostdev
 import vmfakelib as fake
 
-from testlib import VdsmTestCase as TestCaseBase
+from virt.vmdevices import hostdevice
+
+from testlib import VdsmTestCase as TestCaseBase, XMLTestCase
 from testlib import permutations, expandPermutations
 from monkeypatch import MonkeyClass
 
@@ -36,6 +38,77 @@
 _SRIOV_VF = 'pci_0000_05_10_7'
 _ADDITIONAL_DEVICE = 'pci_0000_00_09_0'
 _NET_DEVICE = 'net_em1_28_d2_44_55_66_88'
+
+_DEVICE_XML = {
+    'pci_0000_00_02_0':
+    '''
+    <hostdev managed="no" mode="subsystem" type="pci">
+            <source>
+                    <address bus="0" domain="0" function="0" slot="2"
+                    type="pci"/>
+            </source>
+    </hostdev>
+    ''',
+    'pci_0000_00_19_0':
+    '''
+    <hostdev managed="no" mode="subsystem" type="pci">
+            <source>
+                    <address bus="0" domain="0" function="0" slot="25"
+                    type="pci"/>
+            </source>
+    </hostdev>
+    ''',
+    'pci_0000_00_1a_0':
+    '''
+    <hostdev managed="no" mode="subsystem" type="pci">
+            <source>
+                    <address bus="0" domain="0" function="0" slot="26"
+                    type="pci"/>
+            </source>
+    </hostdev>
+    ''',
+    'pci_0000_00_1b_0':
+    '''
+    <hostdev managed="no" mode="subsystem" type="pci">
+            <source>
+                    <address bus="0" domain="0" function="0" slot="27"
+                    type="pci"/>
+            </source>
+    </hostdev>
+    ''',
+    'pci_0000_00_1f_2':
+    '''
+    <hostdev managed="no" mode="subsystem" type="pci">
+            <source>
+                    <address bus="0" domain="0" function="2" slot="31"
+                    type="pci"/>
+            </source>
+    </hostdev>
+    ''',
+    'usb_1_1':
+    '''
+    <hostdev managed="no" mode="subsystem" type="usb">
+            <source>
+                    <address bus="1" device="2" type="usb"/>
+            </source>
+    </hostdev>
+    ''',
+    'usb_1_1_4':
+    '''
+    <hostdev managed="no" mode="subsystem" type="usb">
+            <source>
+                    <address bus="1" device="10" type="usb"/>
+            </source>
+    </hostdev>
+    ''',
+    'usb_usb1':
+    '''
+    <hostdev managed="no" mode="subsystem" type="usb">
+            <source>
+                    <address bus="1" device="1" type="usb"/>
+            </source>
+    </hostdev>
+    '''}
 
 DEVICES_PARSED = {u'pci_0000_00_1b_0': {'product': '6 Series/C200 Series '
                                         'Chipset Family High Definition '
@@ -278,3 +351,23 @@
         for cap in caps:
             self.assertTrue(set(DEVICES_BY_CAPS[cap].keys()).
                             issubset(devices.keys()))
+
+
+ at expandPermutations
+ at MonkeyClass(libvirtconnection, 'get', Connection)
+class HostdevCreationTests(XMLTestCase):
+
+    def setUp(self):
+        self.conf = {
+            'vmName': 'testVm',
+            'vmId': '9ffe28b6-6134-4b1e-8804-1185f49c436f',
+            'smp': '8', 'maxVCpus': '160',
+            'memSize': '1024', 'memGuaranteedSize': '512'}
+
+    @permutations(map(lambda device_name: [device_name],
+                      _PCI_DEVICES + _USB_DEVICES))
+    def testCreateHostDevice(self, device_name):
+        dev_spec = {'type': 'hostdev', 'device': device_name}
+        device = hostdevice.HostDevice(self.conf, self.log, **dev_spec)
+        print device.getXML().toprettyxml()
+        self.assertXMLEqual(device.getXML().toxml(), _DEVICE_XML[device_name])


-- 
To view, visit https://gerrit.ovirt.org/43088
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I723a8876382f778441b015c7c0f453d0888d7f6b
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Martin Polednik <mpolednik at redhat.com>


More information about the vdsm-patches mailing list