未验证 提交 921b65f8 编写于 作者: X Xu Han 提交者: GitHub

Merge pull request #1312 from hereischen/add-shell-true

Added shell=True in process.run|system|system_output calls
......@@ -13,6 +13,6 @@ def run(test, params, env):
dropin_path = os.path.join(data_dir.get_root_dir(), "dropin",
dropin_path)
try:
process.system(dropin_path)
process.system(dropin_path, shell=True)
except process.CmdError:
test.fail("Drop in test %s failed" % dropin_path)
......@@ -139,7 +139,7 @@ def run(test, params, env):
tcpdump_cmd += " and dst %s" % guest_ip
copy_files_func = vm.copy_files_to
try:
process.system(dd_cmd)
process.system(dd_cmd, shell=True)
except process.CmdError, e:
return failure
......
......@@ -56,6 +56,6 @@ def run(test, params, env):
error_context.context("Detected cluster leaks, try to repair it",
logging.info)
restore_cmd = params.get("image_restore_cmd") % image.image_filename
cmd_status = process.system(restore_cmd)
cmd_status = process.system(restore_cmd, shell=True)
if cmd_status:
test.fail("Failed to repair cluster leaks on the image")
......@@ -56,7 +56,7 @@ def run(test, params, env):
:param ovs: Ovs bridge name
'''
cmd = "ovs-vsctl list-ports %s" % ovs
return set(process.system_output(cmd).splitlines())
return set(process.system_output(cmd, shell=True).splitlines())
host_mtu_cmd = "ifconfig %s mtu %s"
netdst = params.get("netdst", "switch")
......@@ -70,7 +70,7 @@ def run(test, params, env):
error_context.context("Change all Bridge NICs MTU to %s" %
mtu, logging.info)
for iface in target_ifaces:
process.run(host_mtu_cmd % (iface, mtu))
process.run(host_mtu_cmd % (iface, mtu), shell=True)
try:
error_context.context("Changing the MTU of guest", logging.info)
......@@ -113,13 +113,13 @@ def run(test, params, env):
# Before change macvtap mtu, must set the base interface mtu
if params.get("nettype") == "macvtap":
base_if = utils_net.get_macvtap_base_iface(params.get("netdst"))
process.run(host_mtu_cmd % (base_if, mtu))
process.run(host_mtu_cmd % (ifname, mtu))
process.run(host_mtu_cmd % (base_if, mtu), shell=True)
process.run(host_mtu_cmd % (ifname, mtu), shell=True)
error_context.context("Add a temporary static ARP entry ...",
logging.info)
arp_add_cmd = "arp -s %s %s -i %s" % (guest_ip, mac, ifname)
process.run(arp_add_cmd)
process.run(arp_add_cmd, shell=True)
def is_mtu_ok():
status, _ = utils_test.ping(guest_ip, 1,
......@@ -197,10 +197,10 @@ def run(test, params, env):
if session:
session.close()
grep_cmd = "grep '%s.*%s' /proc/net/arp" % (guest_ip, ifname)
if process.system(grep_cmd) == '0':
if process.system(grep_cmd, shell=True) == '0':
process.run("arp -d %s -i %s" % (guest_ip, ifname))
logging.info("Removing the temporary ARP entry successfully")
logging.info("Change back Bridge NICs MTU to %s" % mtu_default)
for iface in target_ifaces:
process.run(host_mtu_cmd % (iface, mtu_default))
process.run(host_mtu_cmd % (iface, mtu_default), shell=True)
......@@ -155,7 +155,7 @@ def crash_test(test, vm, vcpu, crash_cmd, timeout):
logging.info("Delete the vmcore file.")
if kdump_method == "ssh":
process.run(vmcore_rm_cmd)
process.run(vmcore_rm_cmd, shell=True)
else:
session.cmd_output(vmcore_rm_cmd)
......@@ -201,7 +201,7 @@ def check_vmcore(test, vm, session, timeout):
try:
if vm.params.get("kdump_method") == "ssh":
logging.info("Checking vmcore file on host")
process.run(vmcore_chk_cmd)
process.run(vmcore_chk_cmd, shell=True)
else:
logging.info("Checking vmcore file on guest")
session.cmd(vmcore_chk_cmd)
......
......@@ -140,7 +140,7 @@ def run(test, params, env):
top_cmd = r"top -n 1 -p %s -b" % ",".join(map(str,
vhost_threads))
top_info = process.system_output(top_cmd)
top_info = process.system_output(top_cmd, shell=True)
logging.info("%s", top_info)
vhost_re = re.compile(r"S(\s+0.0+){2}.*vhost-\d+[\d|+]")
sleep_vhost_thread = len(vhost_re.findall(top_info, re.I))
......
......@@ -34,7 +34,7 @@ def run(test, params, env):
def run_host_guest(cmd):
run_guest(cmd)
process.system(cmd, ignore_status=True)
process.system(cmd, ignore_status=True, shell=True)
# flush the firewall rules
cmd_flush = "iptables -F"
......
......@@ -138,7 +138,8 @@ def run(test, params, env):
error_context.context("Change all Bridge NICs MTU to %s"
% mtu, logging.info)
for iface in target_ifaces:
process.run(host_mtu_cmd % (iface, mtu), ignore_status=False)
process.run(host_mtu_cmd % (iface, mtu), ignore_status=False,
shell=True)
def _pin_vm_threads(vm, node):
if node:
......@@ -285,7 +286,7 @@ def run(test, params, env):
src = os.path.join(test.virtdir, params.get("log_hostinfo_script"))
path = os.path.join(test.resultsdir, "systeminfo")
process.system_output(
"bash %s %s &> %s" % (src, test.resultsdir, path))
"bash %s %s &> %s" % (src, test.resultsdir, path), shell=True)
if params.get("log_guestinfo_script") and params.get("log_guestinfo_exec"):
src = os.path.join(test.virtdir, params.get("log_guestinfo_script"))
......@@ -450,7 +451,7 @@ def ssh_cmd(session, cmd, timeout=120, ignore_status=False):
"""
if session == "localhost":
o = process.system_output(cmd, timeout=timeout,
ignore_status=ignore_status)
ignore_status=ignore_status, shell=True)
else:
o = session.cmd(cmd, timeout=timeout, ignore_all_errors=ignore_status)
return o
......
......@@ -55,7 +55,7 @@ def run(test, params, env):
firewall_flush = params.get("firewall_flush", "service iptables stop")
error_context.context("Stop firewall in guest and host.", logging.info)
try:
process.run(firewall_flush)
process.run(firewall_flush, shell=True)
except Exception:
logging.warning("Could not stop firewall in host")
......
......@@ -105,15 +105,16 @@ class NFSCorruptConfig(object):
self.start_service()
process.run("exportfs %s:%s -o rw,no_root_squash" %
(self.nfs_ip, self.nfs_dir))
(self.nfs_ip, self.nfs_dir), shell=True)
process.run("mount %s:%s %s -o rw,soft,timeo=30,retrans=1,vers=3" %
(self.nfs_ip, self.nfs_dir, self.mnt_dir))
(self.nfs_ip, self.nfs_dir, self.mnt_dir), shell=True)
@error_context.context_aware
def cleanup(self, force_stop=False):
error_context.context("Cleaning up test NFS share", logging.info)
process.run("umount %s" % self.mnt_dir)
process.run("exportfs -u %s:%s" % (self.nfs_ip, self.nfs_dir))
process.run("umount %s" % self.mnt_dir, shell=True)
process.run("exportfs -u %s:%s" % (self.nfs_ip, self.nfs_dir),
shell=True)
if force_stop:
self.stop_service()
......@@ -121,19 +122,19 @@ class NFSCorruptConfig(object):
"""
Starts the NFS server.
"""
process.run(self.start_cmd)
process.run(self.start_cmd, shell=True)
def stop_service(self):
"""
Stops the NFS server.
"""
process.run(self.stop_cmd)
process.run(self.stop_cmd, shell=True)
def restart_service(self):
"""
Restarts the NFS server.
"""
process.run(self.restart_cmd)
process.run(self.restart_cmd, shell=True)
def is_service_active(self):
"""
......@@ -142,7 +143,8 @@ class NFSCorruptConfig(object):
:param chk_re: Regular expression that tells whether NFS is running
or not.
"""
status = process.system_output(self.status_cmd, ignore_status=True)
status = process.system_output(self.status_cmd, ignore_status=True,
shell=True)
if re.findall(self.chk_re, status):
return True
else:
......
......@@ -157,7 +157,7 @@ def run(test, params, env):
err_info.append(err_msg % copied_file)
for copied_file in host_file_paths:
if process.system("md5sum %s | grep %s" %
(copied_file, file_checksum)):
(copied_file, file_checksum), shell=True):
err_msg = "Host file %s md5sum changed"
err_info.append(err_msg % copied_file)
if err_info:
......
......@@ -113,15 +113,15 @@ class NTPTest(object):
# Set the time zone to New_York
cmd = ('echo \'ZONE = "America/New_York"\' > /etc/sysconfig/clock;')
try:
process.run(cmd, ignore_status=False)
process.run(cmd, ignore_status=False, shell=True)
except process.CmdError, detail:
self.test.fail("set Zone on host failed.%s" % detail)
cmd_ln = 'ln -sf /usr/share/zoneinfo/America/New_York /etc/localtime'
process.run(cmd_ln, ignore_status=True)
process.run(cmd_ln, ignore_status=True, shell=True)
# Check the cpu info of constant_tsc
cmd = "cat /proc/cpuinfo | grep constant_tsc"
result = process.run(cmd)
result = process.run(cmd, shell=True)
if not result.stdout.strip():
self.test.fail("constant_tsc not available in this system!!")
......@@ -142,16 +142,17 @@ class NTPTest(object):
# Delete server of local clock
result = process.run("grep '^server %s' /etc/ntp.conf" %
self.local_clock, ignore_status=True)
self.local_clock, ignore_status=True, shell=True)
if result.stdout.strip():
process.run("sed -i '/%s/d' /etc/ntp.conf" % self.local_clock)
process.run("sed -i '/%s/d' /etc/ntp.conf" % self.local_clock,
shell=True)
# Check the ntp.conf and add server ip into it
cmd = "grep '^server %s' /etc/ntp.conf" % self.server_ip
result = process.run(cmd, ignore_status=True)
result = process.run(cmd, ignore_status=True, shell=True)
if not result.stdout.strip():
cmd = "echo 'server %s' >> /etc/ntp.conf" % self.server_ip
try:
process.run(cmd, ignore_status=False)
process.run(cmd, ignore_status=False, shell=True)
except process.CmdError, detail:
self.test.fail("config /etc/ntp.conf on host failed!!")
......@@ -218,8 +219,9 @@ class NTPTest(object):
cmd_name = ""
if self.server_hostname:
cmd_name = "ntpq -p | grep '^*%s'" % self.server_hostname
result_ntpq_ip = process.run(cmd_ip, ignore_status=True)
result_ntpq_name = process.run(cmd_name, ignore_status=True)
result_ntpq_ip = process.run(cmd_ip, ignore_status=True, shell=True)
result_ntpq_name = process.run(cmd_name, ignore_status=True,
shell=True)
if (not result_ntpq_ip.stdout.strip() and
not result_ntpq_name.stdout.strip()):
self.test.fail("ntpd setting failed of %s host !!" % self.vm_name)
......
......@@ -43,8 +43,10 @@ def run(test, params, env):
vm_receiver = None
receiver_addr = params.get("receiver_address")
logging.debug(process.system("numactl --hardware", ignore_status=True))
logging.debug(process.system("numactl --show", ignore_status=True))
logging.debug(process.system("numactl --hardware", ignore_status=True,
shell=True))
logging.debug(process.system("numactl --show", ignore_status=True,
shell=True))
# pin guest vcpus/memory/vhost threads to last numa node of host by default
if params.get('numa_node'):
numa_node = int(params.get('numa_node'))
......
......@@ -69,7 +69,7 @@ def run(test, params, env):
ext_host = params.get("ext_host", "")
ext_host_get_cmd = params.get("ext_host_get_cmd", "")
try:
ext_host = process.system_output(ext_host_get_cmd)
ext_host = process.system_output(ext_host_get_cmd, shell=True)
except process.CmdError:
logging.warn("Can't get specified host with cmd '%s',"
" Fallback to default host '%s'",
......
import logging
import os
import aexpect
import functools
from avocado.utils import process
......@@ -11,6 +12,9 @@ from virttest import utils_misc
from virttest import error_context
_system_output = functools.partial(process.system_output, shell=True)
def format_result(result, base="12", fbase="2"):
"""
Format the result to a fixed length string.
......@@ -124,7 +128,7 @@ def run(test, params, env):
pktgen_ip = host_nic.get_ip()
dsc = vm.wait_for_get_address(0, timeout=5)
pktgen_interface = vm.get_ifname(0)
runner = process.system_output
runner = _system_output
pkt_cate_r = run_test(session_serial, runner, remote_path,
pktgen_ip, dsc, pktgen_interface,
run_threads, size, timeout)
......
......@@ -12,7 +12,7 @@ def cleanup(debugfs_path, session):
Umount the debugfs and close the session
"""
if os.path.ismount(debugfs_path):
process.run("umount %s" % debugfs_path)
process.run("umount %s" % debugfs_path, shell=True)
if os.path.isdir(debugfs_path):
os.removedirs(debugfs_path)
session.close()
......@@ -53,7 +53,7 @@ def run(test, params, env):
if not os.path.ismount(debugfs_path):
if not os.path.isdir(debugfs_path):
os.makedirs(debugfs_path)
process.run("mount -t debugfs none %s" % debugfs_path)
process.run("mount -t debugfs none %s" % debugfs_path, shell=True)
vm = env.get_vm(params.get("main_vm"))
session = vm.wait_for_login(timeout=login_timeout)
......
......@@ -111,13 +111,13 @@ def run(test, params, env):
logging.info("Prepare tmpfs in host")
if not os.path.isdir(mem_path):
os.makedirs(mem_path)
process.run("mount -t tmpfs none %s" % mem_path)
process.run("mount -t tmpfs none %s" % mem_path, shell=True)
logging.info("Start using dd to fragment memory in guest")
cmd = ("for i in `seq 262144`; do dd if=/dev/urandom of=%s/$i "
"bs=4K count=1 & done" % mem_path)
process.run(cmd)
process.run(cmd, shell=True)
finally:
process.run("umount %s" % mem_path)
process.run("umount %s" % mem_path, shell=True)
test_config = test_setup.TransparentHugePageConfig(test, params)
logging.info("Defrag test start")
......
......@@ -30,7 +30,8 @@ def run(test, params, env):
if not os.path.isdir(debugfs_path):
os.makedirs(debugfs_path)
try:
process.system("mount -t debugfs none %s" % debugfs_path)
process.system("mount -t debugfs none %s" % debugfs_path,
shell=True)
except Exception:
debugfs_flag = 0
......@@ -74,6 +75,6 @@ def run(test, params, env):
fd.write("0")
fd.close()
if os.path.ismount(debugfs_path):
process.run("umount %s" % debugfs_path)
process.run("umount %s" % debugfs_path, shell=True)
if os.path.isdir(debugfs_path):
os.removedirs(debugfs_path)
......@@ -67,7 +67,7 @@ def run(test, params, env):
if not os.path.isdir(mem_path):
os.makedirs(mem_path)
process.run("mount -t tmpfs -o size=%sM none %s" %
(tmpfs_size, mem_path))
(tmpfs_size, mem_path), shell=True)
# Set the memory size of vm
# To ignore the oom killer set it to the free swap size
......@@ -91,7 +91,7 @@ def run(test, params, env):
error_context.context("making guest to swap memory")
cmd = ("dd if=/dev/zero of=%s/zero bs=%s000000 count=%s" %
(mem_path, hugepage_size, count))
process.run(cmd)
process.run(cmd, shell=True)
args_dict = get_args(args_dict_check)
swap_free.append(int(args_dict['swap_free']) / 1024)
......@@ -103,7 +103,7 @@ def run(test, params, env):
session.cmd("find / -name \"*\"", timeout=check_cmd_timeout)
finally:
if session is not None:
process.run("umount %s" % mem_path)
process.run("umount %s" % mem_path, shell=True)
logging.info("Swapping test succeed")
......
......@@ -49,7 +49,7 @@ def run(test, params, env):
if not os.path.exists(cdrom_whql_dir):
os.makedirs(cdrom_whql_dir)
cmd = "mkisofs -J -o %s %s" % (cdrom_whql, src_path)
process.system(cmd)
process.system(cmd, shell=True)
params["cdroms"] += " whql"
vm = "vm1"
......
import logging
import re
import time
import functools
from avocado.utils import process
from virttest import data_dir
......@@ -12,6 +13,9 @@ from virttest import funcatexit
from virttest import error_context
_system = functools.partial(process.system, shell=True)
@error_context.context_aware
def run(test, params, env):
"""
......@@ -50,7 +54,7 @@ def run(test, params, env):
error_context.context("Add some load on host", logging.info)
process.system(timerdevice_host_load_cmd, shell=True)
host_load_stop_cmd = params["timerdevice_host_load_stop_cmd"]
funcatexit.register(env, params["type"], process.system,
funcatexit.register(env, params["type"], _system,
host_load_stop_cmd)
error_context.context("Boot a guest with kvm-clock", logging.info)
......
......@@ -87,7 +87,7 @@ def run(test, params, env):
host_path = os.path.join(test.tmpdir, "tmp-%s" %
utils_misc.generate_random_string(8))
logging.info("Test setup: Creating %dMB file on host", filesize)
process.run(dd_cmd % (host_path, filesize))
process.run(dd_cmd % (host_path, filesize), shell=True)
try:
src_md5 = (crypto.hash_file(host_path, algorithm="md5"))
......
......@@ -22,7 +22,7 @@ def run(test, params, env):
cmd = "./kvmctl test/x86/bootstrap test/x86/%s.flat" % case
try:
results = process.system_output(cmd)
results = process.system_output(cmd, shell=True)
except process.CmdError:
test.fail("Unit test %s failed" % case)
......
......@@ -83,7 +83,7 @@ def run(test, params, env):
error_context.context("Check usb device %s on host" % device, logging.info)
try:
process.system(lsusb_cmd)
process.system(lsusb_cmd, shell=True)
except:
test.cancel("Device %s not present on host" % device)
......
......@@ -25,7 +25,7 @@ def run(test, params, env):
def valgrind_intall():
valgrind_install_cmd = params.get("valgrind_install_cmd")
s = process.system(valgrind_install_cmd, timeout=3600)
s = process.system(valgrind_install_cmd, timeout=3600, shell=True)
if s != 0:
test.error("Fail to install valgrind")
else:
......@@ -34,7 +34,8 @@ def run(test, params, env):
valgring_support_check_cmd = params.get("valgring_support_check_cmd")
error_context.context("Check valgrind installed in host", logging.info)
try:
process.system(valgring_support_check_cmd, timeout=interval)
process.system(valgring_support_check_cmd, timeout=interval,
shell=True)
except Exception:
valgrind_intall()
......
......@@ -53,7 +53,8 @@ def run(test, params, env):
cgroup.set_property("cpu.cfs_period_us", 100000, 0)
assign_vm_into_cgroup(vm, cgroup, 0)
vhost_pids = process.system_output("pidof vhost-%s" % vm.get_pid())
vhost_pids = process.system_output("pidof vhost-%s" % vm.get_pid(),
shell=True)
if not vhost_pids:
test.error("Vhost process not exise")
logging.info("Vhost have started with pid %s" % vhost_pids)
......
......@@ -36,7 +36,7 @@ def run(test, params, env):
params_subtest = params.object_params(subtest_tag)
cmd_timeout = int(params_subtest.get("cmd_timeout", 240))
cmd = params_subtest['cmd']
process.system(cmd, timeout=cmd_timeout)
process.system(cmd, timeout=cmd_timeout, shell=True)
subtests = params["subtests"].split()
......
......@@ -1799,7 +1799,7 @@ def run(test, params, env):
qemu_version_pattern = params["qemu_version_pattern"]
qemu_binary = utils_misc.get_qemu_binary(params)
output = str(process.run(qemu_binary + " --version"))
output = str(process.run(qemu_binary + " --version", shell=True))
re_comp = re.compile(r'\s\d+\.\d+\.\d+')
output_list = re_comp.findall(output)
# high version
......
......@@ -146,7 +146,8 @@ def run(test, params, env):
error_context.context("Checking whether or not the host support"
" WDT '%s'" % watchdog_device_type, logging.info)
watchdog_device = process.system_output("%s 2>&1" % qemu_cmd,
retain_output=True)
retain_output=True,
shell=True)
if watchdog_device:
if re.findall(watchdog_device_type, watchdog_device, re.I):
logging.info("The host support '%s' type watchdog device" %
......
......@@ -55,7 +55,7 @@ def run(test, params, env):
guest_receive = utils_misc.InterruptedThread(receive_data,
args)
guest_receive.start()
process.system(send_cmd, timeout=30)
process.system(send_cmd, timeout=30, shell=True)
finally:
if guest_receive:
guest_receive.join(10)
......
......@@ -76,7 +76,8 @@ def run(test, params, env):
download.get_file(url_virtio_win, pkg_path)
if re.findall("zip$", url_virtio_win):
process.system("cd /tmp/virtio_win; unzip *; rm -f *.zip")
process.system("cd /tmp/virtio_win; unzip *; rm -f *.zip",
shell=True)
virtio_iso = utils_misc.get_path(data_dir.get_data_dir(),
params.get("cdrom_virtio",
......
......@@ -41,7 +41,7 @@ def run(test, params, env):
cmd += "modprobe vhost-net experimental_zcopytx=1"
else:
cmd += "modprobe vhost-net experimental_zcopytx=0"
if process.system(cmd) or enable != zerocp_enable_status():
if process.system(cmd, shell=True) or enable != zerocp_enable_status():
test.cancel("Set vhost_net zcopytx failed")
error_context.context("Set host vhost_net experimental_zcopytx",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册