Change in vdsm[ovirt-3.5]: tests: add test case for getAllVmStats

fromani at redhat.com fromani at redhat.com
Wed Jan 14 13:37:31 UTC 2015


Francesco Romani has uploaded a new change for review.

Change subject: tests: add test case for getAllVmStats
......................................................................

tests: add test case for getAllVmStats

bootstrap test case for Host.getAllVmStats
external API.

Change-Id: I7288b3a224d6be608b52c3bad183be4f02b55b67
Signed-off-by: Francesco Romani <fromani at redhat.com>
---
M tests/clientifTests.py
M tests/vmApiTests.py
M tests/vmTests.py
3 files changed, 39 insertions(+), 9 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/03/36903/1

diff --git a/tests/clientifTests.py b/tests/clientifTests.py
index 64138fb..debe8fc 100644
--- a/tests/clientifTests.py
+++ b/tests/clientifTests.py
@@ -20,6 +20,7 @@
 
 import logging
 import os.path
+import threading
 from testrunner import VdsmTestCase as TestCaseBase
 from testrunner import temporaryPath
 from monkeypatch import MonkeyPatch
@@ -56,6 +57,8 @@
         # the bare minimum initialization for our test needs.
         self.irs = None  # just to make sure nothing ever happens
         self.log = logging.getLogger('ClientIFTests')
+        self.vmContainerLock = threading.Lock()
+        self.vmContainer = {}
 
 
 def fakeDrive():
diff --git a/tests/vmApiTests.py b/tests/vmApiTests.py
index bc68c6d..c7e1ca1 100644
--- a/tests/vmApiTests.py
+++ b/tests/vmApiTests.py
@@ -28,7 +28,13 @@
 from vdsm import utils
 from rpc import vdsmapi
 
+from clientifTests import FakeClientIF
 from vmTests import FakeVM
+
+import API
+from clientIF import clientIF
+
+from monkeypatch import MonkeyPatchScope
 
 
 class TestSchemaCompliancyBase(TestCaseBase):
@@ -63,6 +69,14 @@
         vm._vmStats.stop()
 
 
+_VM_PARAMS = {
+    'displayPort': -1, 'displaySecurePort': -1, 'display': 'qxl',
+    'displayIp': '127.0.0.1', 'vmType': 'kvm', 'devices': {},
+    'memSize': 1024,
+    # HACKs
+    'pauseCode': 'NOERR'}
+
+
 class TestVmStats(TestSchemaCompliancyBase):
     def testDownStats(self):
         with FakeVM() as fake:
@@ -71,13 +85,25 @@
                                                fake.getStats())
 
     def testRunningStats(self):
-        vmParams = {
-            'displayPort': -1, 'displaySecurePort': -1, 'display': 'qxl',
-            'displayIp': '127.0.0.1', 'vmType': 'kvm', 'devices': {},
-            'memSize': 1024,
-            # HACKs
-            'pauseCode': 'NOERR'}
-        with FakeVM(vmParams) as fake:
+        with FakeVM(_VM_PARAMS) as fake:
             with ensureVmStats(fake):
                 self.assertVmStatsSchemaCompliancy('RunningVmStats',
                                                    fake.getStats())
+
+
+class TestApiAllVm(TestSchemaCompliancyBase):
+    def testAllVmStats(self):
+        cif = FakeClientIF()
+        with FakeVM(_VM_PARAMS, clientIFInst=cif) as testvm:
+            with ensureVmStats(testvm):
+                with MonkeyPatchScope([(clientIF, 'getInstance',
+                                        lambda _: cif)]):
+                    api = API.Global()
+
+                    response = api.getAllVmStats()
+
+                    self.assertEqual(response['status']['code'], 0)
+
+                    for stat in response['statsList']:
+                        self.assertVmStatsSchemaCompliancy(
+                            'RunningVmStats', stat)
diff --git a/tests/vmTests.py b/tests/vmTests.py
index a4067c4..3b92956 100644
--- a/tests/vmTests.py
+++ b/tests/vmTests.py
@@ -1356,13 +1356,14 @@
 
 @contextmanager
 def FakeVM(params=None, devices=None, runCpu=False,
-           arch=caps.Architecture.X86_64, status=None):
+           arch=caps.Architecture.X86_64, status=None,
+           clientIFInst=None):
     with namedTemporaryDir() as tmpDir:
         with MonkeyPatchScope([(constants, 'P_VDSM_RUN', tmpDir + '/'),
                                (libvirtconnection, 'get', ConnectionMock)]):
             vmParams = {'vmId': 'TESTING'}
             vmParams.update({} if params is None else params)
-            cif = FakeClientIF()
+            cif = clientIFInst if clientIFInst is not None else FakeClientIF()
             fake = vm.Vm(cif, vmParams)
             cif.vmContainer[fake.id] = fake
             fake.arch = arch


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

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


More information about the vdsm-patches mailing list