Change in vdsm[master]: tests: bootstrap changeBlockDev tests

fromani at redhat.com fromani at redhat.com
Wed Mar 4 17:57:29 UTC 2015


Francesco Romani has uploaded a new change for review.

Change subject: tests: bootstrap changeBlockDev tests
......................................................................

tests: bootstrap changeBlockDev tests

add very basic tests, to be used in followup patch.

Change-Id: I906ae55f6582833f5f023ce64bdd28c02ede33b2
Signed-off-by: Francesco Romani <fromani at redhat.com>
---
M tests/vmTests.py
M tests/vmfakelib.py
2 files changed, 45 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/91/38391/1

diff --git a/tests/vmTests.py b/tests/vmTests.py
index a855467..73ee763 100644
--- a/tests/vmTests.py
+++ b/tests/vmTests.py
@@ -20,6 +20,7 @@
 #
 
 from itertools import product
+import logging
 import re
 import threading
 import time
@@ -1296,3 +1297,43 @@
     def testSmpByParameters(self, cpus):
         with fake.VM({'smp': cpus}) as testvm:
             self.assertEqual(int(testvm.conf['smp']), cpus)
+
+
+# we need a different ClientIF Fake because we need to
+# fake
+# prepareVolumePath
+# and
+# teardownVolumePath
+
+class FakeClientIF(object):
+    def __init__(self):
+        # the bare minimum initialization for our test needs.
+        self.irs = None  # just to make sure nothing ever happens
+        self.log = logging.getLogger('fake.ClientIF')
+        self.channelListener = None
+        self.vmContainerLock = threading.Lock()
+        self.vmContainer = {}
+
+    def prepareVolumePath(self, drivespec):
+        pass
+
+    def teardownVolumePath(self, drivespec):
+        pass
+
+
+class ChangeBlockDevTests(TestCaseBase):
+
+    def test_change_cd_failure(self):
+        cif = FakeClientIF()
+        # no specific meaning, actually any error != None is good
+        with fake.VM(cif=cif) as fakevm:
+            fakevm._dom = fake.Domain(
+                virtError=libvirt.VIR_ERR_ACCESS_DENIED)
+
+            res = fakevm.changeCD({})
+
+            expected_error = define.errCode['changeDisk']['status']
+            self.assertEqual(res['status']['code'],
+                             expected_error['code'])
+            self.assertEqual(res['status']['message'],
+                             expected_error['message'])
diff --git a/tests/vmfakelib.py b/tests/vmfakelib.py
index a1b56c5..6919351 100644
--- a/tests/vmfakelib.py
+++ b/tests/vmfakelib.py
@@ -94,6 +94,7 @@
         return self._xml
 
     def updateDeviceFlags(self, devXml, unused):
+        self._failIfRequested()
         self.devXml = devXml
 
     def vcpusFlags(self, flags):
@@ -181,13 +182,14 @@
 
 @contextmanager
 def VM(params=None, devices=None, runCpu=False,
-       arch=caps.Architecture.X86_64, status=None):
+       arch=caps.Architecture.X86_64, status=None,
+       cif=None):
     with namedTemporaryDir() as tmpDir:
         with MonkeyPatchScope([(constants, 'P_VDSM_RUN', tmpDir + '/'),
                                (libvirtconnection, 'get', Connection)]):
             vmParams = {'vmId': 'TESTING'}
             vmParams.update({} if params is None else params)
-            cif = ClientIF()
+            cif = ClientIF() if cif is None else cif
             fake = vm.Vm(cif, vmParams)
             cif.vmContainer[fake.id] = fake
             fake.arch = arch


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

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