Francesco Romani has uploaded a new change for review.

Change subject: tests: vm: add unit tests for setBalloonTarget
......................................................................

tests: vm: add unit tests for setBalloonTarget

This patch add unit tests for the setBalloonTarget API call.

Change-Id: I97d4667204560a372d10ab3ed0aa69b3407e671a
Signed-off-by: Francesco Romani <[email protected]>
---
M tests/vmTests.py
1 file changed, 38 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/90/29390/1

diff --git a/tests/vmTests.py b/tests/vmTests.py
index 7ee2eb8..8a4b90a 100644
--- a/tests/vmTests.py
+++ b/tests/vmTests.py
@@ -54,9 +54,11 @@
 
 
 class FakeDomain:
-    def __init__(self, xml=''):
+    def __init__(self, xml='', fail=False):
         self._xml = xml
         self.devXml = ''
+        self._fail = fail
+        self.calls = {}
 
     def info(self):
         raise libvirt.libvirtError(defmsg='')
@@ -76,6 +78,11 @@
     def schedulerParameters(self):
         return {'vcpu_quota': vm._NO_CPU_QUOTA,
                 'vcpu_period': vm._NO_CPU_PERIOD}
+
+    def setMemory(self, target):
+        if self._fail:
+            raise libvirt.libvirtError(defmsg='')
+        self.calls['setMemory'] = (target,)
 
 
 class TestVm(TestCaseBase):
@@ -1239,3 +1246,33 @@
                    {'type': 'graphics', 'device': devType}]
         with FakeVM(self.conf, devices) as fake:
             self.assertRaises(ValueError, fake.buildConfDevices)
+
+
+class TestVmBalloon(TestCaseBase):
+    def assertAPIFailed(self, res, specificErr=None):
+        if specificErr is None:
+            self.assertNotEqual(res['status']['code'], 0)
+        else:
+            self.assertEqual(res['status']['code'],
+                             define.errCode[specificErr]['status']['code'])
+
+    def testSucceed(self):
+        with FakeVM() as vm:
+            vm._dom = FakeDomain(fail=False)
+            target = 256
+            self.assertEqual(vm.setBalloonTarget(target)['status']['code'], 0)
+            self.assertEqual(vm._dom.calls['setMemory'][0], target)
+
+    def testVmWithoutDom(self):
+        with FakeVM() as vm:
+            self.assertTrue(vm._dom is None)
+            self.assertAPIFailed(vm.setBalloonTarget(128))
+
+    def testTargetValueNotInteger(self):
+        with FakeVM() as vm:
+            self.assertAPIFailed(vm.setBalloonTarget('foobar'))
+
+    def testLibvirtFailure(self):
+        with FakeVM() as vm:
+            vm._dom = FakeDomain(fail=True)
+            self.assertAPIFailed(vm.setBalloonTarget(256), 'balloonErr')


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

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

Reply via email to