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

Merge pull request #1335 from luckyh/qemu-python3-replace-commands

[qemu] Python 3: Replace commands
import logging
import commands
import os
import re
......@@ -32,7 +31,8 @@ def run(test, params, env):
if "guest" in test_type:
(s, o) = session.cmd_status_output(cmd, timeout=timeout)
else:
(s, o) = commands.getstatusoutput(cmd)
cmd_result = process.run(cmd, ignore_status=True, shell=True)
(s, o) = cmd_result.exit_status, cmd_result.stdout
return (s, o)
def check_ept():
......
......@@ -2,11 +2,12 @@ import logging
import time
import random
import os
import commands
import re
import aexpect
from avocado.utils import process
from virttest import data_dir
from virttest import error_context
from virttest import utils_misc
......@@ -99,7 +100,8 @@ def run(test, params, env):
query_cmd = re.sub("QEMU_PID", str(vm.process.get_pid()), query_cmd)
_, sharing_page_0 = commands.getstatusoutput(query_cmd)
sharing_page_0 = process.system_output(query_cmd, verbose=False,
ignore_status=True, shell=True)
if query_regex:
sharing_page_0 = re.findall(query_regex, sharing_page_0)[0]
......@@ -112,7 +114,8 @@ def run(test, params, env):
_execute_allocator(cmd, vm, session, fill_timeout)
time.sleep(120)
_, sharing_page_1 = commands.getstatusoutput(query_cmd)
sharing_page_1 = process.system_output(query_cmd, verbose=False,
ignore_status=True, shell=True)
if query_regex:
sharing_page_1 = re.findall(query_regex, sharing_page_1)[0]
......@@ -127,7 +130,8 @@ def run(test, params, env):
_execute_allocator(cmd, vm, session, fill_timeout)
time.sleep(120)
_, sharing_page_2 = commands.getstatusoutput(query_cmd)
sharing_page_2 = process.system_output(query_cmd, verbose=False,
ignore_status=True, shell=True)
if query_regex:
sharing_page_2 = re.findall(query_regex, sharing_page_2)[0]
......
import os
import re
import commands
import shutil
import shelve
import threading
......@@ -31,12 +30,14 @@ def cmd_runner_monitor(test, vm, monitor_cmd, test_cmd,
"""
def thread_kill(cmd, p_file):
fd = shelve.open(p_file)
o = commands.getoutput("pstree -p %s" % fd["pid"])
o = process.system_output("pstree -p %s" % fd["pid"], verbose=False,
ignore_status=True)
tmp = re.split(r"\s+", cmd)[0]
pid = re.findall(r"%s.(\d+)" % tmp, o)[0]
s, o = commands.getstatusoutput("kill -9 %s" % pid)
cmd_result = process.run("kill -9 %s" % pid, verbose=False,
ignore_status=True)
fd.close()
return (s, o)
return (cmd_result.exit_status, cmd_result.stdout)
def monitor_thread(m_cmd, p_file, r_file):
fd = shelve.open(p_file)
......
......@@ -2,7 +2,6 @@ import os
import time
import re
import logging
import commands
import shutil
import tempfile
......@@ -343,13 +342,15 @@ def run(test, params, env):
image_name,
crtcmd)
error_context.context(msg, logging.info)
status, output = commands.getstatusoutput(crtcmd)
cmd_result = process.run(crtcmd, verbose=False, ignore_status=True)
status, output = cmd_result.exit_status, cmd_result.stdout
if status != 0:
test.fail("Create snapshot failed via command: %s;"
"Output is: %s" % (crtcmd, output))
listcmd = cmd
listcmd += " -l %s" % image_name
status, out = commands.getstatusoutput(listcmd)
cmd_result = process.run(listcmd, verbose=False, ignore_status=True)
status, out = cmd_result.exit_status, cmd_result.stdout
if not ("snapshot0" in out and "snapshot1" in out and status == 0):
test.fail("Snapshot created failed or missed;"
"snapshot list is: \n%s" % out)
......@@ -359,7 +360,8 @@ def run(test, params, env):
delcmd += " -d %s %s" % (sn_name, image_name)
msg = "Delete snapshot '%s' by command %s" % (sn_name, delcmd)
error_context.context(msg, logging.info)
status, output = commands.getstatusoutput(delcmd)
cmd_result = process.run(delcmd, verbose=False, ignore_status=True)
status, output = cmd_result.exit_status, cmd_result.stdout
if status != 0:
test.fail("Delete snapshot '%s' failed: %s" %
(sn_name, output))
......
import logging
import time
import commands
from functools import partial
from avocado.utils import process
from virttest import utils_misc
_system_output = partial(process.system_output, shell=True)
def run(test, params, env):
"""
Test qmp event notification function:
......@@ -28,7 +33,7 @@ def run(test, params, env):
qmp_monitor = list(filter(lambda x: x.protocol == "qmp", vm.monitors))[0]
humam_monitor = list(
filter(lambda x: x.protocol == "human", vm.monitors))[0]
callback = {"host_cmd": commands.getoutput,
callback = {"host_cmd": _system_output,
"guest_cmd": session.cmd,
"monitor_cmd": humam_monitor.send_args_cmd,
"qmp_cmd": qmp_monitor.send_args_cmd}
......
......@@ -9,13 +9,14 @@ Step file creator/editor.
import time
import os
import commands
import logging
import pygtk
import gtk
import gobject
from avocado.utils import process
from virttest import utils_misc
from virttest import ppm_utils
from virttest import step_editor
......@@ -63,7 +64,7 @@ class StepMaker(step_editor.StepMakerWindow):
self.steps_file.write("# Generated by Step Maker\n")
self.steps_file.write("# Generated on %s\n" % time.asctime())
self.steps_file.write("# uname -a: %s\n" %
commands.getoutput("uname -a"))
process.system_output("uname -a", verbose=False))
self.steps_file.flush()
self.vars_file.write("# This file lists the vars used during recording"
......
import logging
import time
import commands
import aexpect
from avocado.utils import process
from virttest import utils_test
......@@ -35,13 +37,16 @@ def run(test, params, env):
:param mask: The CPU affinity mask.
:return: A dict containing the previous mask for each thread.
"""
tids = commands.getoutput("ps -L --pid=%s -o lwp=" % pid).split()
tids = process.system_output("ps -L --pid=%s -o lwp=" % pid,
verbose=False).split()
prev_masks = {}
for tid in tids:
prev_mask = commands.getoutput("taskset -p %s" % tid).split()[-1]
prev_mask = process.system_output("taskset -p %s" % tid,
verbose=False).split()[-1]
prev_masks[tid] = prev_mask
commands.getoutput("taskset -p %s %s" % (mask, tid))
children = commands.getoutput("ps --ppid=%s -o pid=" % pid).split()
process.system("taskset -p %s %s" % (mask, tid), verbose=False)
children = process.system_output("ps --ppid=%s -o pid=" % pid,
verbose=False).split()
for child in children:
prev_masks.update(set_cpu_affinity(child, mask))
return prev_masks
......@@ -53,7 +58,7 @@ def run(test, params, env):
:param prev_masks: A dict containing TIDs as keys and masks as values.
"""
for tid, mask in prev_masks.items():
commands.getoutput("taskset -p %s %s" % (mask, tid))
process.system("taskset -p %s %s" % (mask, tid), verbose=False)
vm = env.get_vm(params["main_vm"])
vm.verify_alive()
......
import time
import os
import logging
import commands
import re
from avocado.utils import cpu
from avocado.utils import process
from virttest import data_dir
......@@ -40,7 +41,8 @@ def run(test, params, env):
tsc_cmd = tsc_cmd_host
cmd = "taskset %s %s" % (1 << i, tsc_cmd)
if machine == "host":
s, o = commands.getstatusoutput(cmd)
result = process.run(cmd, ignore_status=True)
s, o = result.exit_status, result.stdout
else:
s, o = session.cmd_status_output(cmd)
if s != 0:
......@@ -54,7 +56,7 @@ def run(test, params, env):
session = vm.wait_for_login(timeout=int(params.get("login_timeout", 360)))
if not os.path.exists(tsc_cmd_guest):
commands.getoutput("gcc %s" % tsc_freq_path)
process.run("gcc %s" % tsc_freq_path)
ncpu = cpu.online_cpus_count()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册