Change in vdsm[master]: tests: add negative tests for setNumberOfVcpus

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 negative tests for setNumberOfVcpus
......................................................................

tests: add negative tests for setNumberOfVcpus

Failures are more cumbersome to tests, due to need
to inject errors or to cause them.
Add tests to do basic sanity tests, and to help
verification of the upcoming response.error() transition
patches.

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


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/52/39052/1

diff --git a/tests/vmTests.py b/tests/vmTests.py
index 2784e06..ab26135 100644
--- a/tests/vmTests.py
+++ b/tests/vmTests.py
@@ -37,6 +37,7 @@
 from virt import vmstatus
 from vdsm import constants
 from vdsm import define
+from vdsm import response
 from testlib import VdsmTestCase as TestCaseBase
 from testlib import permutations, expandPermutations
 from testlib import find_xml_element
@@ -1065,6 +1066,25 @@
             self.assertEqual(period + offset,
                              testvm._vcpuTuneInfo['vcpu_period'])
 
+    @permutations([[libvirt.VIR_ERR_OPERATION_DENIED, 'setNumberOfCpusErr',
+                    'Failed to set the number of cpus'],
+                   [libvirt.VIR_ERR_NO_DOMAIN, 'noVM', None]])
+    def testSetNumberOfVcpusFailed(self, virt_error, vdsm_error,
+                                   error_message):
+        def _fail(*args):
+            raise_libvirt_error(virt_error, error_message)
+
+        with MonkeyPatchScope([(hooks, 'before_set_num_of_cpus',
+                                lambda: None)]):
+            with fake.VM() as testvm:
+                dom = fake.Domain()
+                dom.setVcpusFlags = _fail
+                testvm._dom = dom
+
+                res = testvm.setNumberOfCpus(4)  # random value
+
+                self.assertEqual(res, response.error(vdsm_error))
+
 
 class ChangingSchedulerDomain(object):
 
@@ -1414,3 +1434,9 @@
 
                 expected_status = define.errCode['changeDisk']['status']
                 self.assertEqual(res['status'], expected_status)
+
+
+def raise_libvirt_error(code, message):
+    err = libvirt.libvirtError(defmsg=message)
+    err.err = [code]
+    raise err


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

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