Francesco Romani has uploaded a new change for review.

Change subject: tests: split API schema conformancy tests
......................................................................

tests: split API schema conformancy tests

this patch splits the VM API schema tests from the main unit tests body
with no functional changes.

Change-Id: I38d1d68ee1a556a9a1f484f436217a463c8705aa
Signed-off-by: Francesco Romani <from...@redhat.com>
---
M tests/Makefile.am
A tests/vmApiTests.py
M tests/vmTests.py
3 files changed, 81 insertions(+), 51 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/00/28800/1

diff --git a/tests/Makefile.am b/tests/Makefile.am
index 0d696e9..156e1da 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -74,6 +74,7 @@
        transportWrapperTests.py \
        utilsTests.py \
        vdsClientTests.py \
+       vmApiTests.py \
        vmTestsData.py \
        vmTests.py \
        volumeTests.py \
diff --git a/tests/vmApiTests.py b/tests/vmApiTests.py
new file mode 100644
index 0000000..a616d45
--- /dev/null
+++ b/tests/vmApiTests.py
@@ -0,0 +1,80 @@
+#
+# Copyright 2014 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
+#
+# Refer to the README and COPYING files for full details of the license
+#
+
+from contextlib import contextmanager
+import os
+import os.path
+
+from virt import vmexitreason
+from vdsm import define
+from testrunner import VdsmTestCase as TestCaseBase
+from vdsm import utils
+from rpc import vdsmapi
+
+from vmTests import FakeVM
+
+
+@contextmanager
+def ensureVmStats(vm):
+    vm._initVmStats()
+    try:
+        yield vm
+    finally:
+        vm._vmStats.stop()
+
+
+class TestVmStats(TestCaseBase):
+    @utils.memoized
+    def _getAPI(self):
+        testPath = os.path.realpath(__file__)
+        dirName = os.path.split(testPath)[0]
+        apiPath = os.path.join(
+            dirName, '..', 'vdsm', 'rpc', 'vdsmapi-schema.json')
+        return vdsmapi.get_api(apiPath)
+
+    def assertVmStatsSchemaCompliancy(self, schema, stats):
+        api = self._getAPI()
+        ref = api['types'][schema]['data']
+        for apiItem, apiType in ref.items():
+            if apiItem[0] == '*':
+                # optional, may be absent and it is fine
+                self.assertTrue(stats.get(apiItem[1:], True))
+            else:
+                # mandatory
+                self.assertIn(apiItem, stats)
+        # TODO: type checking
+
+    def testDownStats(self):
+        with FakeVM() as fake:
+            fake.setDownStatus(define.ERROR, vmexitreason.GENERIC_ERROR)
+            self.assertVmStatsSchemaCompliancy('ExitedVmStats',
+                                               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 ensureVmStats(fake):
+                self.assertVmStatsSchemaCompliancy('RunningVmStats',
+                                                   fake.getStats())
diff --git a/tests/vmTests.py b/tests/vmTests.py
index b142661..483a270 100644
--- a/tests/vmTests.py
+++ b/tests/vmTests.py
@@ -21,7 +21,6 @@
 
 from contextlib import contextmanager
 from itertools import product
-import os.path
 import re
 import shutil
 import tempfile
@@ -38,7 +37,6 @@
 import caps
 from vdsm import utils
 from vdsm import libvirtconnection
-from rpc import vdsmapi
 from monkeypatch import MonkeyPatch, MonkeyPatchScope
 from vmTestsData import CONF_TO_DOMXML_X86_64
 from vmTestsData import CONF_TO_DOMXML_PPC64
@@ -1081,55 +1079,6 @@
                             libvirt.VIR_DOMAIN_EVENT_IO_ERROR_NONE)
             self.assertTrue(fake._guestCpuRunning)
             self.assertNotIn('pauseCode', fake.conf)  # no error recorded
-
-
-@contextmanager
-def ensureVmStats(vm):
-    vm._initVmStats()
-    try:
-        yield vm
-    finally:
-        vm._vmStats.stop()
-
-
-class TestVmStats(TestCaseBase):
-    @utils.memoized
-    def _getAPI(self):
-        testPath = os.path.realpath(__file__)
-        dirName = os.path.split(testPath)[0]
-        apiPath = os.path.join(
-            dirName, '..', 'vdsm', 'rpc', 'vdsmapi-schema.json')
-        return vdsmapi.get_api(apiPath)
-
-    def assertVmStatsSchemaCompliancy(self, schema, stats):
-        api = self._getAPI()
-        ref = api['types'][schema]['data']
-        for apiItem, apiType in ref.items():
-            if apiItem[0] == '*':
-                # optional, may be absent and it is fine
-                self.assertTrue(stats.get(apiItem[1:], True))
-            else:
-                # mandatory
-                self.assertIn(apiItem, stats)
-        # TODO: type checking
-
-    def testDownStats(self):
-        with FakeVM() as fake:
-            fake.setDownStatus(define.ERROR, vmexitreason.GENERIC_ERROR)
-            self.assertVmStatsSchemaCompliancy('ExitedVmStats',
-                                               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 ensureVmStats(fake):
-                self.assertVmStatsSchemaCompliancy('RunningVmStats',
-                                                   fake.getStats())
 
 
 @expandPermutations


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I38d1d68ee1a556a9a1f484f436217a463c8705aa
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Francesco Romani <from...@redhat.com>
_______________________________________________
vdsm-patches mailing list
vdsm-patches@lists.fedorahosted.org
https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches

Reply via email to