# HG changeset patch
# User Eduardo Lima (Etrunko) <eblima(a)br.ibm.com>
# Date 1306519808 10800
# Node ID fcce3eb554659cd76e020f3cb852c352e6a02218
# Parent 6397c0670c35acc78ac13d737b408bb90e30632e
[TEST] Don't send commands via ssh for localhost
Also changes python strings format in many other files. Some commands
required double quotes to work properly when executed locally.
Signed-off-by: Eduardo Lima (Etrunko) <eblima(a)br.ibm.com>
diff --git a/lib/VirtLib/live.py b/lib/VirtLib/live.py
--- a/lib/VirtLib/live.py
+++ b/lib/VirtLib/live.py
@@ -30,7 +30,7 @@
"""Return a list of the available bridges in the running dom0.
"""
- cmd = "brctl show | grep -v 'bridge name' | awk '/^[^\t]/ { print
\$1 }'"
+ cmd = 'brctl show | grep -v "bridge name" | awk "/^[^\\t]/ { print
\$1 }"'
rc, out = utils.run_remote(ip, cmd)
if rc != 0:
@@ -39,8 +39,8 @@
return out.splitlines()
def exclude_vir_bridge(ip):
- cmd = "brctl show | grep -v 'bridge name' | grep -v vir | \
- grep -v vif | awk '/^[^\t]/ { print \$1
}'"
+ cmd = 'brctl show | grep -v "bridge name" | grep -v vir | \
+ grep -v vif | awk "/^[^\\t]/ { print \$1 }"'
rc, out = utils.run_remote(ip, cmd)
if rc != 0:
return []
@@ -51,7 +51,7 @@
"""Return a list of the available virtual bridges in the running
dom0.
"""
- cmd = "brctl show | grep -v 'bridge name' | grep -v peth | awk
'/^[^\t]/ { print \$1 }'"
+ cmd = 'brctl show | grep -v "bridge name" | grep -v peth | awk
"/^[^\\t]/ { print \$1 }"'
rc, out = utils.run_remote(ip, cmd)
if rc != 0:
@@ -78,14 +78,14 @@
"""
xm_ret, mfm = utils.run_remote(server,
- "xm info | awk -F ': ' '/max_free_memory/ {print
\$2}'")
+ 'xm info | awk -F ": " "/max_free_memory/ {print
\$2}"')
if xm_ret != 0:
return None
return int(mfm)
def fv_cap(server):
- cmd = "egrep flags /proc/cpuinfo | uniq | egrep 'vmx|svm'"
+ cmd = 'egrep flags /proc/cpuinfo | uniq | egrep "vmx|svm"'
ret, out = utils.run_remote(server, cmd)
return ret == 0
diff --git a/lib/VirtLib/utils.py b/lib/VirtLib/utils.py
--- a/lib/VirtLib/utils.py
+++ b/lib/VirtLib/utils.py
@@ -31,15 +31,24 @@
SSH_KEY = os.path.join(root_dot_ssh, 'id_rsa')
AUTHED_KEYS = os.path.join(root_dot_ssh, 'authorized_keys')
+localhost = ["0.0.0.0", "127.0.0.1", "localhost"]
+
def run_remote(ip, cmd):
- cmd = 'ssh %s -i %s root@%s "%s"' % (SSH_PARMS, SSH_KEY, ip, cmd)
+ if ip not in localhost:
+ cmd = "ssh %s -i %s root@%s '%s'" % (SSH_PARMS, SSH_KEY, ip,
cmd)
return commands.getstatusoutput(cmd)
def copy_remote(ip, local, remote='/tmp'):
- cmd = 'scp -r %s -i %s %s root@%s:%s' % (SSH_PARMS,
- SSH_KEY, local, ip, remote)
+ if ip not in localhost:
+ cmd = 'scp -r %s -i %s %s root@%s:%s' % (SSH_PARMS,
+ SSH_KEY, local, ip, remote)
+ else:
+ if local == remote:
+ return (0, "")
+ cmd = 'cp -r %s %s' % (local, remote)
+
return commands.getstatusoutput(cmd)
def setup_ssh_key():
diff --git a/suites/libvirt-cim/lib/XenKvmLib/common_util.py
b/suites/libvirt-cim/lib/XenKvmLib/common_util.py
--- a/suites/libvirt-cim/lib/XenKvmLib/common_util.py
+++ b/suites/libvirt-cim/lib/XenKvmLib/common_util.py
@@ -243,7 +243,7 @@
rc, out = utils.run_remote(ip, cmd)
if rc == 0 :
- cmd = "%s | awk '{ print \$8 }' | uniq" % cmd
+ cmd = '%s | awk "{ print \$8 }" | uniq' % cmd
rc, out = utils.run_remote(ip, cmd)
return rc, out
@@ -252,7 +252,7 @@
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
+ return "The libvirt install on '%s' does not support %s" % (ip,
virt)
cmd = "virsh -c %s version 2>/dev/null" % virt2uri(virt)
ret, out = utils.run_remote(ip, cmd)
@@ -491,7 +491,7 @@
def get_nfs_bin(server):
- cmd = "cat /etc/issue | grep -v ^$ | egrep 'Red Hat|Fedora'"
+ cmd = 'cat /etc/issue | grep -v ^$ | egrep "Red Hat|Fedora"'
rc, out = utils.run_remote(server, cmd)
if rc != 0:
#SLES
diff --git a/suites/libvirt-cim/lib/XenKvmLib/const.py
b/suites/libvirt-cim/lib/XenKvmLib/const.py
--- a/suites/libvirt-cim/lib/XenKvmLib/const.py
+++ b/suites/libvirt-cim/lib/XenKvmLib/const.py
@@ -166,7 +166,7 @@
# This is a sloppy mechanism for detecting a distro defined revision value
distro = None
- cmd = "cat /etc/issue | grep 'SUSE Linux Enterprise Server 11'"
+ cmd = 'cat /etc/issue | grep "SUSE Linux Enterprise Server 11"'
rc, out = run_remote(ip, cmd)
if rc == 0:
distro = "sles11"
diff --git a/suites/libvirt-cim/lib/XenKvmLib/pool.py
b/suites/libvirt-cim/lib/XenKvmLib/pool.py
--- a/suites/libvirt-cim/lib/XenKvmLib/pool.py
+++ b/suites/libvirt-cim/lib/XenKvmLib/pool.py
@@ -107,7 +107,7 @@
def enum_volumes(virt, server, pooln=default_pool_name):
volume = 0
- cmd = "virsh -c %s vol-list %s 2>/dev/null | 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:
diff --git a/suites/libvirt-cim/lib/XenKvmLib/reporting.py
b/suites/libvirt-cim/lib/XenKvmLib/reporting.py
--- a/suites/libvirt-cim/lib/XenKvmLib/reporting.py
+++ b/suites/libvirt-cim/lib/XenKvmLib/reporting.py
@@ -87,7 +87,7 @@
def get_env_data(ip, virt):
- distro = get_cmd_val("cat /etc/issue | sed '/^$/d' | awk
'NR<=1'", ip)
+ distro = get_cmd_val('cat /etc/issue | sed "/^$/d" | awk
"NR<=1"', ip)
if 'SUSE' in distro:
distro = (distro.split('-'))[0].split('to')[1]
diff --git a/suites/libvirt-cim/lib/XenKvmLib/test_doms.py
b/suites/libvirt-cim/lib/XenKvmLib/test_doms.py
--- a/suites/libvirt-cim/lib/XenKvmLib/test_doms.py
+++ b/suites/libvirt-cim/lib/XenKvmLib/test_doms.py
@@ -67,7 +67,7 @@
def virdomid_list(server, virt="Xen"):
"""Get a list of domid from virsh"""
- cmd = "virsh -c %s list 2>/dev/null | sed '1,2 d; /^$/d'" % \
+ cmd = 'virsh -c %s list 2>/dev/null | sed "1,2 d; /^$/d"' % \
virt2uri(virt)
ret, out = utils.run_remote(server, cmd)
if ret != 0:
@@ -108,7 +108,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'" % \
+ cmd = 'virsh -c %s domuuid %s 2>/dev/null | sed "/^$/d"' % \
(virt2uri(virt), name)
ret, out = utils.run_remote(server, cmd)
if ret == 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' 2>/dev/null" % \
+ cmd = 'virsh -c %s "destroy %s ; undefine %s" 2>/dev/null' % \
(virt2uri(virt), name, name)
utils.run_remote(server, cmd)
@@ -164,7 +164,7 @@
"""
Get the vcpu lists. The input is either the domid or domname.
"""
- cmd = "virsh -c %s vcpuinfo %s 2>/dev/null | 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)
diff --git a/suites/libvirt-cim/lib/XenKvmLib/xm_virt_util.py
b/suites/libvirt-cim/lib/XenKvmLib/xm_virt_util.py
--- a/suites/libvirt-cim/lib/XenKvmLib/xm_virt_util.py
+++ b/suites/libvirt-cim/lib/XenKvmLib/xm_virt_util.py
@@ -50,7 +50,7 @@
specified bridge.
"""
- cmd = "brctl show %s | grep 'vif' | grep -v vif0.*" % bridge
+ cmd = 'brctl show %s | grep "vif" | grep -v vif0.*' % bridge
rc, out = utils.run_remote(ip, cmd)
if rc != 0:
@@ -71,7 +71,7 @@
"""Returns the list of disk of the specified VS
"""
- guest_cmd = "cat /proc/partitions | awk '/^ /{ print $4 } ' "
+ guest_cmd = 'cat /proc/partitions | awk "/^ /{ print $4 } " '
rc, out = run_remote_guest(ip, vs_name, guest_cmd)
if rc != 0:
@@ -86,7 +86,7 @@
"""
xm_ret, mfm = utils.run_remote(server,
- "xm info | awk -F ': ' '/max_free_memory/ {print
\$2}'")
+ 'xm info | awk -F ": " "/max_free_memory/ {print
\$2}"')
if xm_ret != 0:
return None
@@ -108,7 +108,7 @@
if virt == "XenFV":
virt = "Xen"
- cmd = "virsh -c %s list --all 2>/dev/null | 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 2>/dev/null | 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)
@@ -162,7 +162,7 @@
if fv_cap(server) and gtype == 1:
bootloader = "/usr/lib/xen/boot/hvmloader"
else:
- cmd = "cat /etc/issue | grep -v ^$ | egrep 'Red Hat|Fedora'"
+ cmd = 'cat /etc/issue | grep -v ^$ | egrep "Red Hat|Fedora"'
ret, out = utils.run_remote(server,cmd)
if ret != 0:
# For SLES
@@ -175,7 +175,7 @@
def net_list(server, virt="Xen"):
"""Function to list active network"""
names = []
- cmd = "virsh -c %s net-list 2>/dev/null | 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 2>/dev/null | \
- 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:
@@ -233,7 +233,7 @@
def diskpool_list(server, virt="KVM"):
"""Function to list active DiskPool list"""
names = []
- cmd = "virsh -c %s pool-list 2>/dev/null | 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 2>/dev/null | 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:
@@ -283,14 +283,14 @@
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 2>/dev/null | 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.
if ret != 0 and virt == 'KVM':
- cmd = "qemu-kvm --help | grep -i version | tr -s [:space:] |" \
- " cut -d ' ' -f 1,5"
+ cmd = 'qemu-kvm --help | grep -i version | tr -s [:space:] |' \
+ ' cut -d " " -f 1,5'
ret, out = utils.run_remote(server, cmd)
if ret == 0:
@@ -362,7 +362,7 @@
"""Returns the number of processors of the specified VS
"""
- guest_cmd = "grep '^$' /proc/cpuinfo | wc -l"
+ guest_cmd = 'grep "^$" /proc/cpuinfo | wc -l'
rc, out = run_remote_guest(ip, vs_name, guest_cmd)
if rc != 0: