libvirt-cim-bounces@redhat.com wrote on 2008-11-03
16:40:49:
> # HG changeset patch
> # User Guolian Yun <yunguol@cn.ibm.com>
> # Date 1225701642 28800
> # Node ID 636e060429738891aae9d1c5ca43e12d1508773c
> # Parent d1614c101c281b57bd2bc98dfb6625f790748e54
> [TEST] Move some functions from utils.py to xm_virt_util.py
>
> I will do below on the next:
> 1) Update common_util.py
> 2) Delete these functions in utils.py
> 3) Update all related tc
>
> Signed-off-by: Guolian Yun <yunguol@cn.ibm.com>
>
> diff -r d1614c101c28 -r 636e06042973 suites/libvirt-
> cim/lib/XenKvmLib/test_doms.py
> --- a/suites/libvirt-cim/lib/XenKvmLib/test_doms.py Wed Oct
29 20:
> 11:47 2008 -0700
> +++ b/suites/libvirt-cim/lib/XenKvmLib/test_doms.py Mon Nov
03 00:
> 40:42 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 d1614c101c28 -r 636e06042973 suites/libvirt-
> cim/lib/XenKvmLib/test_xml.py
> --- a/suites/libvirt-cim/lib/XenKvmLib/test_xml.py Wed Oct
29 20:
> 11:47 2008 -0700
> +++ b/suites/libvirt-cim/lib/XenKvmLib/test_xml.py Mon Nov
03 00:
> 40:42 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 d1614c101c28 -r 636e06042973 suites/libvirt-
> cim/lib/XenKvmLib/xm_virt_util.py
> --- a/suites/libvirt-cim/lib/XenKvmLib/xm_virt_util.py Wed
Oct 29
> 20:11:47 2008 -0700
> +++ b/suites/libvirt-cim/lib/XenKvmLib/xm_virt_util.py Mon
Nov 03
> 00:40:42 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,70 @@
> 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 run_remote_guest(ip, domain, command):
> + """ Execute commands on remote guest
console.
> + """
> +
> + cmd = 'python %s %s "%s"' % (CONSOLE_APP_PATH,
domain, command)
> +
> + return run_remote(ip, cmd)
> +
> +
Kaitlin,
I think we can remove run_remote_guest
to xm_virt_util.py under ../libvirt-cim/lib/XenKvmLib,
because it have to be used by live.py
under lib/VirtLib. We have to make it stay in utils.py.
Thoughts?
If you agree to make it stay in utils.py,
I will rework on this patch.
Thanks!
> +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 d1614c101c28 -r 636e06042973 suites/libvirt-cim/main.py
> --- a/suites/libvirt-cim/main.py Wed Oct 29 20:11:47 2008 -0700
> +++ b/suites/libvirt-cim/main.py Mon Nov 03 00:40:42 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
>
> _______________________________________________
> Libvirt-cim mailing list
> Libvirt-cim@redhat.com
> https://www.redhat.com/mailman/listinfo/libvirt-cim