Change in vdsm[master]: move kernelBootImages to a new file functionalUtils.py
shaohef at linux.vnet.ibm.com
shaohef at linux.vnet.ibm.com
Thu Jan 24 19:31:04 UTC 2013
ShaoHe Feng has uploaded a new change for review.
Change subject: move kernelBootImages to a new file functionalUtils.py
......................................................................
move kernelBootImages to a new file functionalUtils.py
There is already a good functional test for xmlrpc test.
The jsonrpc test should benefit from the xmlrpc test.
So move some kernelBootImages to new file, jsonrpc test
can share with xmlrpc test.
Change-Id: If38afd417e5bb32066b13de4ff8f7b1f766f8215
Signed-off-by: ShaoHe Feng <shaohef at linux.vnet.ibm.com>
---
M tests/functional/Makefile.am
A tests/functional/functionalUtils.py
M tests/functional/xmlrpcTests.py
3 files changed, 77 insertions(+), 53 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/85/11385/1
diff --git a/tests/functional/Makefile.am b/tests/functional/Makefile.am
index e3374e8..98f0a60 100644
--- a/tests/functional/Makefile.am
+++ b/tests/functional/Makefile.am
@@ -21,6 +21,7 @@
vdsmfunctestsdir = ${vdsmtestsdir}/functional
dist_vdsmfunctests_PYTHON = \
+ functionalUtils.py \
jsonrpcSeverClient.py \
momTests.py \
sosPluginTests.py \
diff --git a/tests/functional/functionalUtils.py b/tests/functional/functionalUtils.py
new file mode 100644
index 0000000..78cdb50
--- /dev/null
+++ b/tests/functional/functionalUtils.py
@@ -0,0 +1,74 @@
+#
+# 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
+#
+
+import os
+import tempfile
+from contextlib import contextmanager
+
+from nose.plugins.skip import SkipTest
+
+from vdsm.constants import QEMU_PROCESS_USER, EXT_SUDO
+from storage.misc import execCmd
+from vdsm.utils import CommandPath
+
+_mkinitrd = CommandPath("mkinird", "/usr/bin/mkinitrd")
+
+
+def readableBy(filePath, user):
+ rc, out, err = execCmd([EXT_SUDO, '-u', user, 'head', '-c', '0', filePath])
+ return rc == 0
+
+
+ at contextmanager
+def kernelBootImages():
+ kernelVer = os.uname()[2]
+ kernelPath = "/boot/vmlinuz-" + kernelVer
+ initramfsPath = "/boot/initramfs-%s.img" % kernelVer
+
+ if not os.path.isfile(kernelPath):
+ raise SkipTest("Can not locate kernel image for release %s" %
+ kernelVer)
+ if not readableBy(kernelPath, QEMU_PROCESS_USER):
+ raise SkipTest("qemu process can not read the file %s" % kernelPath)
+
+ if os.path.isfile(initramfsPath):
+ # There is an initramfs shipped with the distro, try use it
+ if not readableBy(initramfsPath, QEMU_PROCESS_USER):
+ raise SkipTest("qemu process can not read the file %s" %
+ initramfsPath)
+ try:
+ yield (kernelPath, initramfsPath)
+ finally:
+ pass
+ else:
+ # Generate an initramfs on demand, use it, delete it
+ initramfsPath = genInitramfs(kernelVer)
+ try:
+ yield (kernelPath, initramfsPath)
+ finally:
+ os.unlink(initramfsPath)
+
+
+def genInitramfs(kernelVer):
+ fd, path = tempfile.mkstemp()
+ cmd = [_mkinitrd.cmd, "-f", path, kernelVer]
+ rc, out, err = execCmd(cmd, sudo=False)
+ os.chmod(path, 0644)
+ return path
diff --git a/tests/functional/xmlrpcTests.py b/tests/functional/xmlrpcTests.py
index a898539..1ba00d3 100644
--- a/tests/functional/xmlrpcTests.py
+++ b/tests/functional/xmlrpcTests.py
@@ -23,9 +23,7 @@
import pwd
import grp
import shutil
-from contextlib import contextmanager
from functools import partial, wraps
-
from testrunner import VdsmTestCase as TestCaseBase
from testrunner import permutations, expandPermutations
from nose.plugins.skip import SkipTest
@@ -35,61 +33,12 @@
pass
from vdsm.config import config
-from vdsm.constants import VDSM_USER, VDSM_GROUP, QEMU_PROCESS_USER, EXT_SUDO
+from vdsm.constants import VDSM_USER, VDSM_GROUP
import storage.sd
import storage.volume
-from storage.misc import execCmd
from storage.misc import RollbackContext
-from vdsm.utils import CommandPath
from vdsm import vdscli
-
-if not config.getboolean('vars', 'xmlrpc_enable'):
- raise SkipTest("XML-RPC Bindings are disabled")
-
-_mkinitrd = CommandPath("mkinird", "/usr/bin/mkinitrd")
-
-
-def readableBy(filePath, user):
- rc, out, err = execCmd([EXT_SUDO, '-u', user, 'head', '-c', '0', filePath])
- return rc == 0
-
-
- at contextmanager
-def kernelBootImages():
- kernelVer = os.uname()[2]
- kernelPath = "/boot/vmlinuz-" + kernelVer
- initramfsPath = "/boot/initramfs-%s.img" % kernelVer
-
- if not os.path.isfile(kernelPath):
- raise SkipTest("Can not locate kernel image for release %s" %
- kernelVer)
- if not readableBy(kernelPath, QEMU_PROCESS_USER):
- raise SkipTest("qemu process can not read the file %s" % kernelPath)
-
- if os.path.isfile(initramfsPath):
- # There is an initramfs shipped with the distro, try use it
- if not readableBy(initramfsPath, QEMU_PROCESS_USER):
- raise SkipTest("qemu process can not read the file %s" %
- initramfsPath)
- try:
- yield (kernelPath, initramfsPath)
- finally:
- pass
- else:
- # Generate an initramfs on demand, use it, delete it
- initramfsPath = genInitramfs(kernelVer)
- try:
- yield (kernelPath, initramfsPath)
- finally:
- os.unlink(initramfsPath)
-
-
-def genInitramfs(kernelVer):
- fd, path = tempfile.mkstemp()
- cmd = [_mkinitrd.cmd, "-f", path, kernelVer]
- rc, out, err = execCmd(cmd, sudo=False)
- os.chmod(path, 0644)
- return path
+from functionalUtils import kernelBootImages
def skipNoKVM(method):
--
To view, visit http://gerrit.ovirt.org/11385
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: If38afd417e5bb32066b13de4ff8f7b1f766f8215
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