Change in vdsm[master]: tests: add tests for disk hotplug/hotunplug

fromani at redhat.com fromani at redhat.com
Mon Mar 23 13:43:48 UTC 2015


Francesco Romani has uploaded a new change for review.

Change subject: tests: add tests for disk hotplug/hotunplug
......................................................................

tests: add tests for disk hotplug/hotunplug

Add tests for negative flows.
Negative flows are tested less often because
of the need to cause or inject faults.
Moreover, we want this test to help verify the upcoming
switch to response.error().

Change-Id: Idd8b467d49c183c81f6a11494d38984246f5b527
Signed-off-by: Francesco Romani <fromani at redhat.com>
---
M tests/vmTests.py
1 file changed, 74 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/53/39053/1

diff --git a/tests/vmTests.py b/tests/vmTests.py
index ab26135..9ca6655 100644
--- a/tests/vmTests.py
+++ b/tests/vmTests.py
@@ -53,6 +53,7 @@
 from vmTestsData import CONF_TO_DOMXML_PPC64
 from vmTestsData import CONF_TO_DOMXML_NO_VDSM
 import vmfakelib as fake
+from vmStorageTests import drive_config
 
 from testValidation import slowtest
 
@@ -1417,6 +1418,7 @@
             self.assertEqual(NAME, testvm.getStats()['vmName'])
 
 
+ at expandPermutations
 class ChangeBlockDevTests(TestCaseBase):
 
     def test_change_cd_failure(self):
@@ -1431,12 +1433,82 @@
                     virtError=libvirt.VIR_ERR_GET_FAILED)
 
                 res = fakevm.changeCD({})
+                self.assertEqual(res, response.error('changeDisk'))
 
-                expected_status = define.errCode['changeDisk']['status']
-                self.assertEqual(res['status'], expected_status)
+    # TODO: need a way to pass message through fake.Domain failIfRequested
+    @permutations([[libvirt.VIR_ERR_OPERATION_DENIED, 'hotplugDisk', ''],
+                   [libvirt.VIR_ERR_NO_DOMAIN, 'noVM', '']])
+    def test_hotplug_disk_failure(self, virtError, vdsmError, customMessage):
+        # caveat emptor: in this test we DON't
+        # overwrite the message, thus will be the default one; but for
+        # errors != 'noVM', it can change.
+        PATH = '/this/path/does/not/exists'
+
+        def _fail(*args):
+            # no specific meaning, actually any error != None is good
+            raise_libvirt_error(libvirt.VIR_ERR_ACCESS_DENIED,
+                                'Failed to hotplug disk')
+
+        dom = fake.Domain()
+        dom.updateDeviceFlags = _fail
+        dom.attachDevice = _fail
+
+        cif = fake.ClientIF()
+
+        with MonkeyPatchScope([(cif, 'prepareVolumePath',
+                                lambda _: PATH),
+                               (cif, 'teardownVolumePath',
+                                lambda _: None),
+                               (hooks, 'before_disk_hotplug',
+                                _fake_disk_hook),
+                               (utils, 'isBlockDevice',
+                                lambda path: True)]):
+            with fake.VM(devices=[drive_config()],
+                         cif=cif) as fakevm:
+                fakevm._dom = dom
+
+                res = fakevm.hotplugDisk({
+                    'drive': drive_config(
+                        path=PATH,
+                        serial='65-a561-23e5b495b9bc')})
+
+                self.assertEqual(res,
+                                 response.error('hotplugDisk', customMessage))
+
+    def test_hotunplug_inexistent_disk(self):
+        PATH = '/this/path/does/not/exists'
+
+        def _fail(*args):
+            raise_libvirt_error(libvirt.VIR_ERR_ACCESS_DENIED, '')
+
+        dom = fake.Domain()
+        dom.updateDeviceFlags = _fail
+
+        cif = fake.ClientIF()
+        with MonkeyPatchScope([(cif, 'prepareVolumePath',
+                                lambda _: PATH),
+                               (cif, 'teardownVolumePath',
+                                lambda _: None),
+                               (hooks, 'before_disk_hotunplug',
+                                _fake_disk_hook),
+                               (utils, 'isBlockDevice',
+                                lambda path: True)]):
+            with fake.VM(cif=cif) as fakevm:
+                # no specific meaning, actually any error != None is good
+                fakevm._dom = dom
+
+                res = fakevm.hotunplugDisk({})
+
+                self.assertEqual(res,
+                                 response.error('hotunplugDisk',
+                                                'Disk not found'))
 
 
 def raise_libvirt_error(code, message):
     err = libvirt.libvirtError(defmsg=message)
     err.err = [code]
     raise err
+
+
+def _fake_disk_hook(driveXml, conf, params):
+    return driveXml


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Idd8b467d49c183c81f6a11494d38984246f5b527
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Francesco Romani <fromani at redhat.com>


More information about the vdsm-patches mailing list