# HG changeset patch
# User Kaitlin Rupert <karupert(a)us.ibm.com>
# Date 1259878320 28800
# Node ID c19371e7fb585e64291dafc2b7f84dc1f1d8255e
# Parent e9de3634a25633777e40bd80cc400a07ed42c6e1
[TEST] Fix calls to virsh to handle potiential extra debug messages from virsh
Occasionally, virsh will return additional debug or error messages. This
change makes it so our virsh command only returns stdout. We don't care about
the output of stderr, so might as well drop it. That way, it doesn't
interfere when we parse the output.
diff -r e9de3634a256 -r c19371e7fb58 suites/libvirt-cim/lib/XenKvmLib/common_util.py
--- a/suites/libvirt-cim/lib/XenKvmLib/common_util.py Thu Dec 03 14:12:00 2009 -0800
+++ b/suites/libvirt-cim/lib/XenKvmLib/common_util.py Thu Dec 03 14:12:00 2009 -0800
@@ -246,12 +246,12 @@
return rc, out
def pre_check(ip, virt):
- cmd = "virsh -c %s list --all" % virt2uri(virt)
+ cmd = "virsh -c %s list --all 2>/dev/null" % 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" % virt2uri(virt)
+ cmd = "virsh -c %s version 2>/dev/null" % virt2uri(virt)
ret, out = utils.run_remote(ip, cmd)
if ret != 0:
# The above version cmd does not work for F10.
@@ -341,7 +341,8 @@
dpoolname=dpool_list[0]
if dpoolname == None:
- cmd = "virsh -c %s pool-info %s" % (virt2uri(virt), dpool)
+ cmd = "virsh -c %s pool-info %s 2>/dev/null" % \
+ (virt2uri(virt), dpool)
ret, out = utils.run_remote(server, cmd)
if ret == 0:
logger.error("Disk pool with name '%s' already exists",
dpool)
@@ -403,7 +404,7 @@
test_network = vir_network[0]
if test_network == None:
- cmd = "virsh -c %s net-list --all | grep -w %s" % \
+ cmd = "virsh -c %s net-list --all 2>/dev/null | grep -w %s" % \
(virt2uri(virt), net_name)
ret, out = utils.run_remote(server, cmd)
# If success, network pool with name net_name already exists
diff -r e9de3634a256 -r c19371e7fb58 suites/libvirt-cim/lib/XenKvmLib/pool.py
--- a/suites/libvirt-cim/lib/XenKvmLib/pool.py Thu Dec 03 14:12:00 2009 -0800
+++ b/suites/libvirt-cim/lib/XenKvmLib/pool.py Thu Dec 03 14:12:00 2009 -0800
@@ -107,7 +107,7 @@
def enum_volumes(virt, server, pooln=default_pool_name):
volume = 0
- cmd = "virsh -c %s vol-list %s | sed -e '1,2 d' -e '$ d'" %
\
+ cmd = "virsh -c %s vol-list %s 2>/dev/null | sed -e '1,2 d' -e '$
d'" % \
(virt2uri(virt), pooln)
ret, out = run_remote(server ,cmd)
if ret != 0:
@@ -115,7 +115,8 @@
lines = out.split("\n")
for line in lines:
vol = line.split()[0]
- cmd = "virsh -c %s vol-info --pool %s %s" % (virt2uri(virt), pooln,
vol)
+ cmd = "virsh -c %s vol-info --pool %s %s 2>/dev/null" % \
+ (virt2uri(virt), pooln, vol)
ret, out = run_remote(server ,cmd)
if ret == 0:
volume = volume + 1
@@ -164,7 +165,7 @@
def net_undefine(network, server, virt="Xen"):
"""Function undefine a given virtual network"""
- cmd = "virsh -c %s net-undefine %s" % (virt2uri(virt), network)
+ cmd = "virsh -c %s net-undefine %s 2>/dev/null" % (virt2uri(virt),
network)
ret, out = run_remote(server, cmd)
return ret
@@ -186,7 +187,8 @@
if dp_name == None:
return FAIL
- cmd = "virsh -c %s pool-undefine %s" % (virt2uri(virt), dp_name)
+ cmd = "virsh -c %s pool-undefine %s 2>/dev/null" % \
+ (virt2uri(virt), dp_name)
ret, out = run_remote(server, cmd)
if ret != 0:
logger.error("Failed to undefine pool '%s'", dp_name)
diff -r e9de3634a256 -r c19371e7fb58 suites/libvirt-cim/lib/XenKvmLib/reporting.py
--- a/suites/libvirt-cim/lib/XenKvmLib/reporting.py Thu Dec 03 14:12:00 2009 -0800
+++ b/suites/libvirt-cim/lib/XenKvmLib/reporting.py Thu Dec 03 14:12:00 2009 -0800
@@ -42,7 +42,7 @@
def get_libvirt_ver(ip):
libvirt_ver = "Unknown"
hyp_ver = "Unknown"
- cmd = "virsh version"
+ cmd = "virsh version 2>/dev/null"
virsh_ver = get_cmd_val(cmd, ip)
if virsh_ver != "Unknown":
libvirt, tok1, tok2, hypervisor = virsh_ver.splitlines()
diff -r e9de3634a256 -r c19371e7fb58 suites/libvirt-cim/lib/XenKvmLib/test_doms.py
--- a/suites/libvirt-cim/lib/XenKvmLib/test_doms.py Thu Dec 03 14:12:00 2009 -0800
+++ b/suites/libvirt-cim/lib/XenKvmLib/test_doms.py Thu Dec 03 14:12:00 2009 -0800
@@ -47,19 +47,19 @@
f.write(xml)
f.close()
- cmd = "virsh -c %s define %s" % (virt2uri(virt), name)
+ cmd = "virsh -c %s define %s 2>/dev/null" % (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" % (virt2uri(virt), name)
+ cmd = "virsh -c %s undefine %s 2>/dev/null" % (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" % (virt2uri(virt), name)
+ cmd = "virsh -c %s start %s 2>/dev/null" % (virt2uri(virt), name)
s, o = utils.run_remote(server, cmd)
return s == 0
@@ -119,7 +119,7 @@
def destroy_and_undefine_domain(name, server, virt="Xen"):
"""Destroy and undefine a domain.
name could be domid or domname"""
- cmd = "virsh -c %s 'destroy %s ; undefine %s'" % \
+ cmd = "virsh -c %s 'destroy %s ; undefine %s' 2>/dev/null" % \
(virt2uri(virt), name, name)
utils.run_remote(server, cmd)
@@ -154,7 +154,7 @@
else:
name = xmlfile_domname
- vcmd = "virsh -c %s %s %s" % (virt2uri(virt), cmd, name)
+ vcmd = "virsh -c %s %s %s 2>/dev/null" % (virt2uri(virt), cmd, name)
s, o = utils.run_remote(server, vcmd)
if cmd == "define" or cmd == "create":
f.close()
@@ -164,7 +164,7 @@
"""
Get the vcpu lists. The input is either the domid or domname.
"""
- cmd = "virsh -c %s vcpuinfo %s | grep '^$' | wc -l" % \
+ cmd = "virsh -c %s vcpuinfo %s 2>/dev/null | grep '^$' | wc -l"
% \
(virt2uri(virt), name_id)
ret, out = utils.run_remote(server, cmd)
@@ -180,7 +180,7 @@
nf.write(net_xml)
nf.flush()
fname = nf.name
- cmd = "virsh -c %s net-create %s" % (virt2uri(virt), fname)
+ cmd = "virsh -c %s net-create %s 2>/dev/null" % (virt2uri(virt), fname)
ret, out = utils.run_remote(server, cmd)
nf.close()
if ret != 0:
diff -r e9de3634a256 -r c19371e7fb58 suites/libvirt-cim/lib/XenKvmLib/vxml.py
--- a/suites/libvirt-cim/lib/XenKvmLib/vxml.py Thu Dec 03 14:12:00 2009 -0800
+++ b/suites/libvirt-cim/lib/XenKvmLib/vxml.py Thu Dec 03 14:12:00 2009 -0800
@@ -176,7 +176,7 @@
" cmd on '%s'", vcmd, ip)
return 0
- cmd = 'virsh -c %s %s %s' % (self.vuri, vcmd, name)
+ cmd = 'virsh -c %s %s %s 2>/dev/null' % (self.vuri, vcmd, name)
s, o = utils.run_remote(ip, cmd)
if vcmd == 'define' or vcmd == 'create' or vcmd ==
'net-create' \
or vcmd == 'pool-create':
@@ -223,7 +223,7 @@
self.server = server
if is_new_net is False:
- cmd = "virsh net-dumpxml %s" % self.net_name
+ cmd = "virsh net-dumpxml %s 2>/dev/null" % self.net_name
s, net_xml = utils.run_remote(server, cmd)
if s != 0:
logger.error("Encounter error dump netxml")
@@ -245,7 +245,8 @@
n_list = net_list(server, virt)
for _net_name in n_list:
- cmd = "virsh net-dumpxml %s | awk '/ip address/ {print}' | \
+ cmd = "virsh net-dumpxml %s 2>/dev/null | \
+ awk '/ip address/ {print}' | \
cut -d ' ' -f 4 | sed 's/address=//'" % _net_name
s, in_use_addr = utils.run_remote(server, cmd)
in_use_addr = in_use_addr.strip("'")
@@ -302,7 +303,7 @@
self.server = server
if is_new_pool is False:
- cmd = "virsh pool-dumpxml %s" % self.pool_name
+ cmd = "virsh pool-dumpxml %s 2>/dev/null" % self.pool_name
s, disk_xml = utils.run_remote(server, cmd)
if s != 0:
logger.error("Encounter error dump netxml")
@@ -516,7 +517,7 @@
return networkStr
def dumpxml(self, ip):
- cmd = 'virsh -c %s dumpxml %s' % (self.vuri, self.dname)
+ cmd = 'virsh -c %s dumpxml %s 2>/dev/null' % (self.vuri, self.dname)
s, o = utils.run_remote(ip, cmd)
if s == 0:
self.xml_string = o
diff -r e9de3634a256 -r c19371e7fb58 suites/libvirt-cim/lib/XenKvmLib/xm_virt_util.py
--- a/suites/libvirt-cim/lib/XenKvmLib/xm_virt_util.py Thu Dec 03 14:12:00 2009 -0800
+++ b/suites/libvirt-cim/lib/XenKvmLib/xm_virt_util.py Thu Dec 03 14:12:00 2009 -0800
@@ -97,7 +97,7 @@
if virt == "XenFV":
virt = "Xen"
- cmd = "virsh -c %s destroy %s" % (virt2uri(virt), dom)
+ cmd = "virsh -c %s destroy %s 2>/dev/null" % (virt2uri(virt), dom)
ret, out = utils.run_remote(server, cmd)
print cmd, ret, out
@@ -108,7 +108,7 @@
if virt == "XenFV":
virt = "Xen"
- cmd = "virsh -c %s list --all | sed -e '1,2 d' -e '$ d'" %
\
+ cmd = "virsh -c %s list --all 2>/dev/null | sed -e '1,2 d' -e '$
d'" % \
virt2uri(virt)
ret, out = utils.run_remote(server, cmd)
@@ -128,7 +128,7 @@
if virt == "XenFV":
virt = "Xen"
- cmd = "virsh -c %s list | sed -e '1,2 d' -e '$ d'" % \
+ cmd = "virsh -c %s list 2>/dev/null | sed -e '1,2 d' -e '$
d'" % \
virt2uri(virt)
ret, out = utils.run_remote(server, cmd)
@@ -175,7 +175,7 @@
def net_list(server, virt="Xen"):
"""Function to list active network"""
names = []
- cmd = "virsh -c %s net-list | sed -e '1,2 d' -e '$ d'" % \
+ cmd = "virsh -c %s net-list 2>/dev/null | sed -e '1,2 d' -e '$
d'" % \
virt2uri(virt)
ret, out = utils.run_remote(server, cmd)
@@ -192,8 +192,8 @@
def get_bridge_from_network_xml(network, server, virt="Xen"):
"""Function returns bridge name for a given virtual
network"""
- cmd = "virsh -c %s net-dumpxml %s | awk '/bridge name/ { print $2
}'" % \
- (virt2uri(virt), network)
+ cmd = "virsh -c %s net-dumpxml %s 2>/dev/null | \
+ awk '/bridge name/ { print $2 }'" % (virt2uri(virt), network)
ret, out = utils.run_remote(server, cmd)
if ret != 0:
@@ -205,7 +205,7 @@
def net_destroy(network, server, virt="Xen"):
"""Function destroys a given virtual network"""
- cmd = "virsh -c %s net-destroy %s" % (virt2uri(virt), network)
+ cmd = "virsh -c %s net-destroy %s 2>/dev/null" % (virt2uri(virt),
network)
ret, out = utils.run_remote(server, cmd)
return ret
@@ -224,7 +224,7 @@
return None
def virsh_version(server, virt="KVM"):
- cmd = "virsh -c %s -v " % virt2uri(virt)
+ cmd = "virsh -c %s -v 2>/dev/null" % virt2uri(virt)
ret, out = utils.run_remote(server, cmd)
if ret != 0:
return None
@@ -233,7 +233,7 @@
def diskpool_list(server, virt="KVM"):
"""Function to list active DiskPool list"""
names = []
- cmd = "virsh -c %s pool-list | sed -e '1,2 d' -e '$ d'" %
\
+ cmd = "virsh -c %s pool-list 2>/dev/null | sed -e '1,2 d' -e '$
d'" % \
virt2uri(virt)
ret, out = utils.run_remote(server, cmd)
@@ -251,7 +251,7 @@
def vol_list(server, virt="KVM", pool_name=None):
""" Function to list the volumes of a pool"""
- cmd = "virsh -c %s vol-list %s | sed -e '1,2 d' -e '$ d'"
\
+ cmd = "virsh -c %s vol-list %s 2>/dev/null | sed -e '1,2 d' -e '$
d'" \
% (virt2uri(virt), pool_name)
ret, out = utils.run_remote(server, cmd)
if ret != 0:
@@ -262,7 +262,7 @@
def vol_delete(server, virt="KVM", vol_name=None, pool_name=None):
""" Function to delete the volume of a pool"""
- cmd = "virsh -c %s vol-delete %s --pool %s"\
+ cmd = "virsh -c %s vol-delete %s --pool %s 2>/dev/null" \
% (virt2uri(virt), vol_name, pool_name)
ret, out = utils.run_remote(server, cmd)
if ret != 0:
@@ -272,19 +272,19 @@
def virsh_vcpuinfo(server, dom, virt="Xen"):
- cmd = "virsh -c %s vcpuinfo %s | grep VCPU | wc -l" % (virt2uri(virt),
- dom)
+ cmd = "virsh -c %s vcpuinfo %s 2>/dev/null | grep VCPU | wc -l" \
+ % (virt2uri(virt), dom)
ret, out = utils.run_remote(server, cmd)
if out.isdigit():
return out
return None
def get_hv_ver(server, virt="Xen"):
- cmd = "virsh -c %s version" %virt2uri(virt)
+ cmd = "virsh -c %s version 2>/dev/null" %virt2uri(virt)
ret, out = utils.run_remote(server, cmd)
if ret == 0:
- cmd = "virsh -c %s version | grep ^Running | cut -d ' ' -f 3,4"
\
- %virt2uri(virt)
+ cmd = "virsh -c %s version 2>/dev/null | grep ^Running | \
+ cut -d ' ' -f 3,4" % virt2uri(virt)
# This is a workaround work for F10.
# The version option does not seem to work on F10.