Martin Polednik has uploaded a new change for review.

Change subject: tests: add way to easily mock host devices
......................................................................

tests: add way to easily mock host devices

Currently, trying to use host device in unit test will result in an
explotion (for good reason - we want to avoid touching the real
hardware).

This patch replaces host device's access to libvirt with access to
file that specified the XML of the device.

Change-Id: Id154b390811a7c9d81da09f60d9414423925136a
Signed-off-by: Martin Polednik <[email protected]>
---
M tests/vmfakelib.py
1 file changed, 21 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/60/40860/1

diff --git a/tests/vmfakelib.py b/tests/vmfakelib.py
index 995508c..11fde9a 100644
--- a/tests/vmfakelib.py
+++ b/tests/vmfakelib.py
@@ -21,6 +21,7 @@
 
 from contextlib import contextmanager
 import logging
+import os
 import threading
 import xml.etree.ElementTree as etree
 
@@ -48,6 +49,26 @@
     def listAllNetworks(self, *args):
         return []
 
+    def nodeDeviceLookupByName(self, device_xml_filename):
+        """
+        This is a method that allows us to access hostdev XML in a test.
+        Normally, libvirt holds the device XML but in case of unit testing,
+        we cannot access the libvirt.
+
+        If we want to use hostdev in a test, the XML itself must be supplied
+        in tests/devices/data/${device address passed}.
+        """
+        fakelib_path = os.path.realpath(__file__)
+        dir_name = os.path.split(fakelib_path)[0]
+        xml_path = os.path.join(
+            dir_name, 'devices', 'data', device_xml_filename)
+
+        device_xml = None
+        with open(xml_path, 'r') as device_xml_file:
+            device_xml = device_xml_file.read()
+
+        return VirNodeDeviceStub(device_xml)
+
 
 class ClientIF(clientIF.clientIF):
     def __init__(self):


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

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