Martin Polednik has uploaded a new change for review.

Change subject: vdsm: add tests for hostdev mapper
......................................................................

vdsm: add tests for hostdev mapper

unit tests for hostdev mapper module

Change-Id: I15ba986c77ec710f6becd0244e86d27ec2023e27
Signed-off-by: Martin Polednik <[email protected]>
---
A tests/hostdevTests.py
1 file changed, 284 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/66/31766/1

diff --git a/tests/hostdevTests.py b/tests/hostdevTests.py
new file mode 100644
index 0000000..6d984f3
--- /dev/null
+++ b/tests/hostdevTests.py
@@ -0,0 +1,284 @@
+#
+# Copyright 2008-2014 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 xml.dom.minidom import parseString
+
+import hostdev
+from testlib import VdsmTestCase as TestCaseBase
+from vdsm import libvirtconnection
+from monkeypatch import MonkeyPatch
+
+
+class ifMock(object):
+
+    def __init__(self):
+        self.vmContainer = {}
+
+
+class virNodeDevice(object):
+
+    def __init__(self, xml):
+        self.xml = xml
+        self._name = parseString(self.XMLDesc(0)).\
+            getElementsByTagName('name')[0].firstChild.nodeValue
+
+    def XMLDesc(self, flags=0):
+        return self.xml
+
+    def name(self):
+        return self._name
+
+    # unfortunately, in real environment these are the most problematic calls
+    # but in order to test them, we would put host in danger of removing
+    # device needed to run properly (such as nic)
+    def dettach(self):
+        pass
+
+    def reAttach(self):
+        pass
+
+
+class ConnectionMock:
+
+    PCI_DEVICE_XML = ["""
+                      <device>
+                          <name>pci_0000_00_1a_0</name>
+                          <path>/sys/devices/pci0000:00/0000:00:1a.0</path>
+                          <parent>computer</parent>
+                          <driver>
+                          <name>ehci-pci</name>
+                          </driver>
+                          <capability type='pci'>
+                          <domain>0</domain>
+                          <bus>0</bus>
+                          <slot>26</slot>
+                          <function>0</function>
+                          <product id='0x1c2d'>6 Series/C200 Series Chipset 
Family USB Enhanced Host Controller #2</product>
+                          <vendor id='0x8086'>Intel Corporation</vendor>
+                          </capability>
+                      </device>
+                      """,
+                      """
+                      <device>
+                          <name>pci_0000_00_1f_2</name>
+                          <path>/sys/devices/pci0000:00/0000:00:1f.2</path>
+                          <parent>computer</parent>
+                          <driver>
+                          <name>ahci</name>
+                          </driver>
+                          <capability type='pci'>
+                          <domain>0</domain>
+                          <bus>0</bus>
+                          <slot>31</slot>
+                          <function>2</function>
+                          <product id='0x1c03'>6 Series/C200 Series Chipset 
Family 6 port SATA AHCI Controller</product>
+                          <vendor id='0x8086'>Intel Corporation</vendor>
+                          </capability>
+                      </device>
+                      """,
+                      """
+                      <device>
+                          <name>pci_0000_00_02_0</name>
+                          <path>/sys/devices/pci0000:00/0000:00:02.0</path>
+                          <parent>computer</parent>
+                          <driver>
+                          <name>i915</name>
+                          </driver>
+                          <capability type='pci'>
+                          <domain>0</domain>
+                          <bus>0</bus>
+                          <slot>2</slot>
+                          <function>0</function>
+                          <product id='0x0126'>2nd Generation Core Processor 
Family Integrated Graphics Controller</product>
+                          <vendor id='0x8086'>Intel Corporation</vendor>
+                          </capability>
+                      </device>
+                      """,
+                      # in reality, the device above would be unavailable for 
passthrough,
+                      # but in case of tests that does not really matter as we 
can't
+                      # call real release()
+                      """
+                      <device>
+                          <name>pci_0000_00_19_0</name>
+                          <path>/sys/devices/pci0000:00/0000:00:19.0</path>
+                          <parent>computer</parent>
+                          <driver>
+                          <name>e1000e</name>
+                          </driver>
+                          <capability type='pci'>
+                          <domain>0</domain>
+                          <bus>0</bus>
+                          <slot>25</slot>
+                          <function>0</function>
+                          <product id='0x1502'>82579LM Gigabit Network 
Connection</product>
+                          <vendor id='0x8086'>Intel Corporation</vendor>
+                          </capability>
+                      </device>
+                      """,
+                      """
+                      <device>
+                          <name>pci_0000_00_1b_0</name>
+                          <path>/sys/devices/pci0000:00/0000:00:1b.0</path>
+                          <parent>computer</parent>
+                          <driver>
+                          <name>snd_hda_intel</name>
+                          </driver>
+                          <capability type='pci'>
+                          <domain>0</domain>
+                          <bus>0</bus>
+                          <slot>27</slot>
+                          <function>0</function>
+                          <product id='0x1c20'>6 Series/C200 Series Chipset 
Family High Definition Audio Controller</product>
+                          <vendor id='0x8086'>Intel Corporation</vendor>
+                      </capability>
+                      </device>
+                      """]
+
+    USB_DEVICE_XML = ["""
+                      <device>
+                          <name>usb_usb1</name>
+                          
<path>/sys/devices/pci0000:00/0000:00:1a.0/usb1</path>
+                          <parent>pci_0000_00_1a_0</parent>
+                          <driver>
+                          <name>usb</name>
+                          </driver>
+                          <capability type='usb_device'>
+                          <bus>1</bus>
+                          <device>1</device>
+                          <product id='0x0002'>EHCI Host Controller</product>
+                          <vendor id='0x1d6b'>Linux 3.10.0-123.6.3.el7.x86_64 
ehci_hcd</vendor>
+                          </capability>
+                      </device>
+                      """,
+                      """
+                      <device>
+                          <name>usb_1_1</name>
+                          
<path>/sys/devices/pci0000:00/0000:00:1a.0/usb1/1-1</path>
+                          <parent>usb_usb1</parent>
+                          <driver>
+                          <name>usb</name>
+                          </driver>
+                          <capability type='usb_device'>
+                          <bus>1</bus>
+                          <device>2</device>
+                          <product id='0x0024' />
+                          <vendor id='0x8087' />
+                          </capability>
+                      </device>
+                      """,
+                      """
+                      <device>
+                          <name>usb_1_1</name>
+                          
<path>/sys/devices/pci0000:00/0000:00:1a.0/usb1/1-1</path>
+                          <parent>usb_usb1</parent>
+                          <driver>
+                          <name>usb</name>
+                          </driver>
+                          <capability type='usb_device'>
+                          <bus>1</bus>
+                          <device>2</device>
+                          <product id='0x0024' />
+                          <vendor id='0x8087' />
+                          </capability>
+                      </device>
+                      """,
+                      """
+                      <device>
+                          <name>usb_1_1_4</name>
+                          
<path>/sys/devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.4</path>
+                          <parent>usb_1_1</parent>
+                          <driver>
+                          <name>usb</name>
+                          </driver>
+                          <capability type='usb_device'>
+                          <bus>1</bus>
+                          <device>10</device>
+                          <product id='0x217f'>Broadcom Bluetooth 
Device</product>
+                          <vendor id='0x0a5c'>Broadcom Corp</vendor>
+                          </capability>
+                      </device>
+                      """]
+
+    SCSI_DEVICE_XML = ["""
+                       <device>
+                           <name>scsi_host0</name>
+                           
<path>/sys/devices/pci0000:00/0000:00:1f.2/ata1/host0</path>
+                           <parent>pci_0000_00_1f_2</parent>
+                           <capability type='scsi_host'>
+                           <host>0</host>
+                           </capability>
+                       </device>
+                       """,
+                       """
+                       <device>
+                           <name>scsi_target0_0_0</name>
+                           
<path>/sys/devices/pci0000:00/0000:00:1f.2/ata1/host0/target0:0:0</path>
+                           <parent>scsi_host0</parent>
+                           <capability type='scsi_target'>
+                           <target>target0:0:0</target>
+                           </capability>
+                       </device>
+                       """,
+                       """
+                       <device>
+                           <name>scsi_0_0_0_0</name>
+                           
<path>/sys/devices/pci0000:00/0000:00:1f.2/ata1/host0/target0:0:0/0:0:0:0</path>
+                           <parent>scsi_target0_0_0</parent>
+                           <driver>
+                           <name>sd</name>
+                           </driver>
+                           <capability type='scsi'>
+                           <host>0</host>
+                           <bus>0</bus>
+                           <target>0</target>
+                           <lun>0</lun>
+                           <type>disk</type>
+                           </capability>
+                       </device>
+                       """]
+
+    def __init__(self):
+        self._devices = []
+
+        for device in self.PCI_DEVICE_XML + self.USB_DEVICE_XML + \
+                self.SCSI_DEVICE_XML:
+
+            self._devices.append(virNodeDevice(device))
+
+    def listAllDevices(self, flags=0):
+        return self._devices
+
+
+class HostdevTests(TestCaseBase):
+
+    def setUp(self):
+        self.cif = ifMock()
+
+    @MonkeyPatch(libvirtconnection, 'get', ConnectionMock)
+    def testHostdevMapperInit(self):
+        """
+        Every device defined in ConnectionMock should exist in mapper's
+        internal map and have no VM assignment
+        """
+        mapper = hostdev.HostDeviceMapper(self.cif, self.log)
+
+        for device in libvirtconnection.get()._devices:
+            self.assertTrue(device.name() in mapper._map)
+            self.assertFalse(mapper._map[device.name()][1])


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I15ba986c77ec710f6becd0244e86d27ec2023e27
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Martin Polednik <[email protected]>
_______________________________________________
vdsm-patches mailing list
[email protected]
https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches

Reply via email to