# HG changeset patch
# User Guolian Yun <yunguol(a)cn.ibm.com>
# Date 1225767133 28800
# Node ID 388b8ffc2c4e11fde0ec8373161698b9215811a0
# Parent 8118a0e17d219b6886b34176423c45c855f08576
[TEST] #2 Move some functions from utils.py to xm_virt_util.py and update helper function
Updates from 1 to 2:
run_remote_guest() still stays in lib/VirtLib/utils.py.
If you think it has to be moved to xm_virt_util.py, follow up patch will do this.
Signed-off-by: Guolian Yun <yunguol(a)cn.ibm.com>
diff -r 8118a0e17d21 -r 388b8ffc2c4e suites/libvirt-cim/lib/XenKvmLib/common_util.py
--- a/suites/libvirt-cim/lib/XenKvmLib/common_util.py Sun Nov 02 19:16:33 2008 -0800
+++ b/suites/libvirt-cim/lib/XenKvmLib/common_util.py Mon Nov 03 18:52:13 2008 -0800
@@ -36,7 +36,8 @@
from CimTest.Globals import logger, CIM_ERROR_ENUMERATE, \
CIM_ERROR_GETINSTANCE
from CimTest.ReturnCodes import PASS, FAIL, XFAIL_RC
-from XenKvmLib.xm_virt_util import diskpool_list, virsh_version, net_list, domain_list
+from XenKvmLib.xm_virt_util import diskpool_list, virsh_version, net_list,\
+ domain_list, virt2uri
from XenKvmLib.vxml import PoolXML, NetXML
from VirtLib import utils
from XenKvmLib.const import default_pool_name, default_network_name
@@ -382,7 +383,7 @@
if dpoolname == None:
cmd = "virsh -c %s pool-list --all | grep %s" % \
- (utils.virt2uri(virt), dpool)
+ (virt2uri(virt), dpool)
ret, out = utils.run_remote(server, cmd)
if out != "":
logger.error("Disk pool with name '%s' already exists",
dpool)
@@ -444,7 +445,7 @@
if test_network == None:
cmd = "virsh -c %s net-list --all | grep -w %s" % \
- (utils.virt2uri(virt), net_name)
+ (virt2uri(virt), net_name)
ret, out = utils.run_remote(server, cmd)
# If success, network pool with name net_name already exists
if ret == 0:
diff -r 8118a0e17d21 -r 388b8ffc2c4e suites/libvirt-cim/lib/XenKvmLib/test_doms.py
--- a/suites/libvirt-cim/lib/XenKvmLib/test_doms.py Sun Nov 02 19:16:33 2008 -0800
+++ b/suites/libvirt-cim/lib/XenKvmLib/test_doms.py Mon Nov 03 18:52:13 2008 -0800
@@ -24,7 +24,7 @@
import tempfile
import os
from VirtLib import utils
-from XenKvmLib.xm_virt_util import domain_list
+from XenKvmLib.xm_virt_util import domain_list, virt2uri
from CimTest.Globals import CIM_FUUID
try:
@@ -47,19 +47,19 @@
f.write(xml)
f.close()
- cmd = "virsh -c %s define %s" % (utils.virt2uri(virt), name)
+ cmd = "virsh -c %s define %s" % (virt2uri(virt), name)
s, o = utils.run_remote(server, cmd)
return s == 0
def undefine_test_domain(name, server, virt="Xen"):
- cmd = "virsh -c %s undefine %s" % (utils.virt2uri(virt), name)
+ cmd = "virsh -c %s undefine %s" % (virt2uri(virt), name)
s, o = utils.run_remote(server, cmd)
return s == 0
def start_test_domain(name, server, virt="Xen"):
- cmd = "virsh -c %s start %s" % (utils.virt2uri(virt), name)
+ cmd = "virsh -c %s start %s" % (virt2uri(virt), name)
s, o = utils.run_remote(server, cmd)
return s == 0
@@ -68,7 +68,7 @@
"""Get a list of domid from virsh"""
cmd = "virsh -c %s list 2>/dev/null | sed '1,2 d; /^$/d'" % \
- utils.virt2uri(virt)
+ virt2uri(virt)
ret, out = utils.run_remote(server, cmd)
if ret != 0:
return None
@@ -109,7 +109,7 @@
def viruuid(name, server, virt="Xen"):
"""Return domain uuid given domid or domname"""
cmd = "virsh -c %s domuuid %s 2>/dev/null | sed '/^$/d'" % \
- (utils.virt2uri(virt), name)
+ (virt2uri(virt), name)
ret, out = utils.run_remote(server, cmd)
if ret == 0:
return out.strip(" \n")
@@ -120,7 +120,7 @@
"""Destroy and undefine a domain.
name could be domid or domname"""
cmd = "virsh -c %s 'destroy %s ; undefine %s'" % \
- (utils.virt2uri(virt), name, name)
+ (virt2uri(virt), name, name)
utils.run_remote(server, cmd)
def destroy_and_undefine_all(server, virt="Xen", aggressive = False):
@@ -154,7 +154,7 @@
else:
name = xmlfile_domname
- vcmd = "virsh -c %s %s %s" % (utils.virt2uri(virt), cmd, name)
+ vcmd = "virsh -c %s %s %s" % (virt2uri(virt), cmd, name)
s, o = utils.run_remote(server, vcmd)
if cmd == "define" or cmd == "create":
f.close()
@@ -165,7 +165,7 @@
Get the vcpu lists. The input is either the domid or domname.
"""
cmd = "virsh -c %s vcpuinfo %s | grep '^$' | wc -l" % \
- (utils.virt2uri(virt), name_id)
+ (virt2uri(virt), name_id)
ret, out = utils.run_remote(server, cmd)
if ret != 0:
@@ -180,7 +180,7 @@
nf.write(net_xml)
nf.flush()
fname = nf.name
- cmd = "virsh -c %s net-create %s" % (utils.virt2uri(virt), fname)
+ cmd = "virsh -c %s net-create %s" % (virt2uri(virt), fname)
ret, out = utils.run_remote(server, cmd)
nf.close()
if ret != 0:
diff -r 8118a0e17d21 -r 388b8ffc2c4e suites/libvirt-cim/lib/XenKvmLib/test_xml.py
--- a/suites/libvirt-cim/lib/XenKvmLib/test_xml.py Sun Nov 02 19:16:33 2008 -0800
+++ b/suites/libvirt-cim/lib/XenKvmLib/test_xml.py Mon Nov 03 18:52:13 2008 -0800
@@ -35,7 +35,7 @@
from XenKvmLib.test_doms import set_uuid, create_vnet
from VirtLib.live import available_bridges
from XenKvmLib.xm_virt_util import net_list, get_bridge_from_network_xml, \
- bootloader
+ bootloader, virt2uri
from CimTest.ReturnCodes import SKIP
image_dir = "/tmp"
@@ -201,7 +201,7 @@
def dumpxml(name, server, virt="Xen"):
- cmd = "virsh -c %s dumpxml %s" % (utils.virt2uri(virt), name)
+ cmd = "virsh -c %s dumpxml %s" % (virt2uri(virt), name)
s, o = utils.run_remote(server, cmd)
if s == 0:
return o
diff -r 8118a0e17d21 -r 388b8ffc2c4e suites/libvirt-cim/lib/XenKvmLib/xm_virt_util.py
--- a/suites/libvirt-cim/lib/XenKvmLib/xm_virt_util.py Sun Nov 02 19:16:33 2008 -0800
+++ b/suites/libvirt-cim/lib/XenKvmLib/xm_virt_util.py Mon Nov 03 18:52:13 2008 -0800
@@ -63,7 +63,7 @@
"""
guest_cmd = "cat /proc/partitions | awk '/^ /{ print $4 } ' "
- rc, out = utils.run_remote_guest(ip, vs_name, guest_cmd)
+ rc, out = run_remote_guest(ip, vs_name, guest_cmd)
if rc != 0:
return None
@@ -89,7 +89,7 @@
virt = "Xen"
cmd = "virsh -c %s list --all | sed -e '1,2 d' -e '$ d'" %
\
- utils.virt2uri(virt)
+ virt2uri(virt)
ret, out = utils.run_remote(server, cmd)
if ret != 0:
@@ -109,7 +109,7 @@
virt = "Xen"
cmd = "virsh -c %s list | sed -e '1,2 d' -e '$ d'" % \
- utils.virt2uri(virt)
+ virt2uri(virt)
ret, out = utils.run_remote(server, cmd)
if ret != 0:
@@ -156,7 +156,7 @@
"""Function to list active network"""
names = []
cmd = "virsh -c %s net-list | sed -e '1,2 d' -e '$ d'" % \
- utils.virt2uri(virt)
+ virt2uri(virt)
ret, out = utils.run_remote(server, cmd)
if ret != 0:
@@ -173,7 +173,7 @@
"""Function returns bridge name for a given virtual
network"""
cmd = "virsh -c %s net-dumpxml %s | awk '/bridge name/ { print $2
}'" % \
- (utils.virt2uri(virt), network)
+ (virt2uri(virt), network)
ret, out = utils.run_remote(server, cmd)
if ret != 0:
@@ -196,7 +196,7 @@
return None
def virsh_version(server, virt="KVM"):
- cmd = "virsh -c %s -v " % utils.virt2uri(virt)
+ cmd = "virsh -c %s -v " % virt2uri(virt)
ret, out = utils.run_remote(server, cmd)
if ret != 0:
return None
@@ -206,7 +206,7 @@
"""Function to list active DiskPool list"""
names = []
cmd = "virsh -c %s pool-list | sed -e '1,2 d' -e '$ d'" %
\
- utils.virt2uri(virt)
+ virt2uri(virt)
ret, out = utils.run_remote(server, cmd)
if ret != 0:
@@ -221,7 +221,7 @@
return names
def virsh_vcpuinfo(server, dom, virt="Xen"):
- cmd = "virsh -c %s vcpuinfo %s | grep VCPU | wc -l" %
(utils.virt2uri(virt),
+ cmd = "virsh -c %s vcpuinfo %s | grep VCPU | wc -l" % (virt2uri(virt),
dom)
ret, out = utils.run_remote(server, cmd)
if out.isdigit():
@@ -229,10 +229,61 @@
return None
def get_hv_ver(server, virt="Xen"):
- cmd = "virsh -c %s version | grep ^Running | cut -d ' ' -f 3,4" %
utils.virt2uri(virt)
+ cmd = "virsh -c %s version | grep ^Running | cut -d ' ' -f 3,4"
%virt2uri(virt)
ret, out = utils.run_remote(server, cmd)
if ret == 0:
return out
else:
return None
+def get_xmtest_files(ip, kernel):
+ # get the xm-test disk from morbo
+ rc, out = run_remote(ip,
+ "rm -rf /tmp/boot ; mkdir -p /tmp/boot /tmp/xmtest")
+ rc, out = run_remote(ip,
+ "cd /tmp/boot ; wget
http://morbo.linux.ibm.com/pub/xmtest.disk.gz")
+ if rc != 0:
+ return 2, "fetching xmtest.disk failed:\n%s" % out
+
+ # mount on /tmp/xmtest
+ rc, out = run_remote(ip,
+ "gzip -d /tmp/boot/xmtest.disk.gz ; mount -o loop /tmp/boot/xmtest.disk
/tmp/xmtest")
+ if rc != 0:
+ run_remote(ip, "umount /tmp/xmtest")
+ return 2, "mounting xmtest.disk failed:\n%s" % out
+
+ # We need "uname -r" to name the kernel correctly
+ rc, uname = run_remote(ip, "uname -r")
+ if rc != 0:
+ run_remote(ip, "umount /tmp/xmtest")
+ return 2, "uname failed:\n%s" % out
+
+ # get the kernel binary, put in /tmp/boot
+ rc, out = run_remote(ip,
+ "wget %s -O /tmp/boot/vmlinuz-\`uname -r\`" % kernel)
+ if rc != 0:
+ run_remote(ip, "umount /tmp/xmtest")
+ return 2, "fetching kernel failed:\n%s" % out
+
+ return 0, ""
+
+def customize_xmtest_ramdisk(ip):
+ # customize modules on xm-test ramdisk
+ # cd $xmtestdir/ramdisk ; bin/add_modules_to_initrd ; cd
+ rc, out = run_remote(ip,
+ "cd /tmp/xmtest/ramdisk ; bin/add_modules_to_initrd")
+ if rc != 0:
+ run_remote(ip, "umount /tmp/xmtest")
+ return 2, "customizing ramdisk failed:\n%s" % out
+
+ return 0, ""
+
+def virt2uri(virt):
+ # convert cimtest --virt param string to libvirt uri
+ if virt == "Xen" or virt == "XenFV":
+ return "xen:///"
+ if virt == "KVM":
+ return "qemu:///system"
+ if virt == "LXC":
+ return "lxc:///system"
+ return ""
diff -r 8118a0e17d21 -r 388b8ffc2c4e suites/libvirt-cim/main.py
--- a/suites/libvirt-cim/main.py Sun Nov 02 19:16:33 2008 -0800
+++ b/suites/libvirt-cim/main.py Mon Nov 03 18:52:13 2008 -0800
@@ -36,6 +36,7 @@
default_pool_name
from XenKvmLib.reporting import gen_report, send_report
from VirtLib import utils
+from XenKvmLib.xm_virt_util import virt2uri
from CimTest.ReturnCodes import PASS, FAIL
from XenKvmLib.common_util import create_netpool_conf, destroy_netpool, \
create_diskpool_conf, destroy_diskpool
@@ -90,12 +91,12 @@
print "Cleaned log files."
def pre_check(ip, virt):
- cmd = "virsh -c %s list --all" % utils.virt2uri(virt)
+ cmd = "virsh -c %s list --all" % virt2uri(virt)
ret, out = utils.run_remote(ip, cmd)
if ret != 0:
return "This libvirt install does not support %s" % virt
- cmd = "virsh -c %s version" % utils.virt2uri(virt)
+ cmd = "virsh -c %s version" % virt2uri(virt)
ret, out = utils.run_remote(ip, cmd)
if ret != 0:
return "Encountered an error querying libvirt with: %s" % cmd