Change in vdsm[master]: add a json rpc funtional test which sets up a VM
shaohef at linux.vnet.ibm.com
shaohef at linux.vnet.ibm.com
Thu Jan 24 19:41:28 UTC 2013
ShaoHe Feng has uploaded a new change for review.
Change subject: add a json rpc funtional test which sets up a VM
......................................................................
add a json rpc funtional test which sets up a VM
This test create a VM and destroy it.
It take full advantage of xml test.
Change-Id: I734614fdc9515e2883004aceafb36291ee44e59a
Signed-off-by: ShaoHe Feng <shaohef at linux.vnet.ibm.com>
---
M tests/functional/Makefile.am
A tests/functional/jsonrpcTests.py
2 files changed, 140 insertions(+), 0 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/86/11386/1
diff --git a/tests/functional/Makefile.am b/tests/functional/Makefile.am
index 98f0a60..80b1752 100644
--- a/tests/functional/Makefile.am
+++ b/tests/functional/Makefile.am
@@ -23,6 +23,7 @@
dist_vdsmfunctests_PYTHON = \
functionalUtils.py \
jsonrpcSeverClient.py \
+ jsonrpcTests.py \
momTests.py \
sosPluginTests.py \
xmlrpcTests.py \
diff --git a/tests/functional/jsonrpcTests.py b/tests/functional/jsonrpcTests.py
new file mode 100644
index 0000000..64c5bc8
--- /dev/null
+++ b/tests/functional/jsonrpcTests.py
@@ -0,0 +1,139 @@
+#
+# Copyright 2012 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 vdsm.config import config
+from jsonrpcSeverClient import jsonRpcServerClient as jrpcClient
+from functionalUtils import kernelBootImages
+from functools import wraps
+from testrunner import VdsmTestCase as TestCaseBase
+from nose.plugins.skip import SkipTest
+
+if not config.getboolean('vars', 'jsonrpc_enable'):
+ raise SkipTest("JSON-RPC Bindings are disabled")
+
+ip = "127.0.0.1"
+port = config.getint('addresses', 'json_port')
+
+
+def skipNoKVM(method):
+ @wraps(method)
+ def wrapped(self, *args, **kwargs):
+ r = self.s.Host.getCapabilities()
+ self.assertVdsOK(r)
+ if r['result']['kvmEnabled'] != 'true':
+ raise SkipTest('KVM is not enabled')
+ return method(self, *args, **kwargs)
+ return wrapped
+
+
+class jsonRPCTest(TestCaseBase):
+ UPSTATES = frozenset(('Up', 'Powering up', 'Running'))
+
+ def setUp(self):
+ self.s = jrpcClient(ip, port)
+
+ def testHostPing(self):
+ r = self.s.Host.ping()
+ self.assertVdsOK(r)
+
+ def assertVmUp(self, vmid):
+ r = self.s.VM.getStats(vmid)
+ self.assertVdsOK(r)
+ self.myAssertIn(r['result'][0]['status'], self.UPSTATES)
+
+ def assertGuestUp(self, vmid):
+ r = self.s.VM.getStats(vmid)
+ self.assertVdsOK(r)
+ self.assertEquals(r['result'][0]['status'], 'Up')
+
+ def myAssertIn(self, member, container, msg=None):
+ "Poor man's reimplementation of Python2.7's unittest.assertIn"
+
+ if hasattr(self, 'assertIn'):
+ return self.assertIn(member, container, msg)
+
+ if msg is None:
+ msg = '%r not found in %r' % (member, container)
+
+ self.assertTrue(member in container, msg)
+
+ def assertVdsOK(self, vdsResult):
+ # according to json-rpc standard,
+ # either 'error' or 'result' can appear in the response but not both
+ # So success should be measured by the absence of the 'error' element
+ self.assertFalse('error' in vdsResult)
+
+ @skipNoKVM
+ def testStartEmptyVM(self):
+ VMID = '66666666-ffff-4444-bbbb-333333333333'
+ vmParams = {'memSize': '100', 'display': 'vnc',
+ 'vmId': VMID, 'vmName': 'foo'}
+ r = self.s.VM.create(VMID, vmParams)
+ self.assertVdsOK(r)
+ try:
+ self.retryAssert(lambda: self.assertVmUp(VMID), timeout=20)
+ finally:
+ # FIXME: if the server dies now, we end up with a leaked VM.
+ r = self.s.VM.destroy(VMID)
+ self.assertVdsOK(r)
+
+ @skipNoKVM
+ def testStartSmallVM(self):
+ customization = {'vmId': '77777777-ffff-3333-bbbb-222222222222',
+ 'vmName': 'vdsm_testSmallVM'}
+
+ self._runVMKernelBootTemplate(customization)
+
+ def _runVMKernelBootTemplate(self, vmDef={}, distro='fedora'):
+ kernelArgsDistro = {
+ # Fedora: The initramfs is generated by dracut. The following
+ # arguments will be interpreted by init scripts created by dracut.
+ 'fedora': 'rd.break=cmdline rd.shell rd.skipfsck'}
+ kernelArgsDistro['rhel'] = kernelArgsDistro['fedora']
+ if distro.lower() not in kernelArgsDistro:
+ raise SkipTest("Don't know how to perform direct kernel boot for "
+ "%s" % distro)
+
+ template = {'vmId': '11111111-abcd-2222-ffff-333333333333',
+ 'vmName': 'vdsmKernelBootVM',
+ 'display': 'vnc',
+ 'kvmEnable': 'true',
+ 'memSize': '256',
+ 'vmType': 'kvm',
+ 'kernelArgs': kernelArgsDistro[distro]}
+ template.update(vmDef)
+ vmid = template['vmId']
+
+ def assertVMAndGuestUp():
+ self.assertVmUp(vmid)
+ self.assertGuestUp(vmid)
+
+ with kernelBootImages() as (kernelPath, initramfsPath):
+ template.update(
+ {'kernel': kernelPath,
+ 'initrd': initramfsPath})
+ try:
+ self.assertVdsOK(self.s.VM.create(vmid, template))
+ # wait 65 seconds for VM to come up until timeout
+ self.retryAssert(assertVMAndGuestUp, timeout=65)
+ finally:
+ destroyResult = self.s.VM.destroy(vmid)
+
+ self.assertVdsOK(destroyResult)
--
To view, visit http://gerrit.ovirt.org/11386
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I734614fdc9515e2883004aceafb36291ee44e59a
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: ShaoHe Feng <shaohef at linux.vnet.ibm.com>
More information about the vdsm-patches
mailing list