提交 a0b261db 编写于 作者: P Peter Maydell

Merge remote-tracking branch 'remotes/ehabkost/tags/python-next-pull-request' into staging

Python queue, 2017-10-11

# gpg: Signature made Wed 11 Oct 2017 19:49:40 BST
# gpg:                using RSA key 0x2807936F984DC5A6
# gpg: Good signature from "Eduardo Habkost <ehabkost@redhat.com>"
# Primary key fingerprint: 5A32 2FD5 ABC4 D3DB ACCF  D1AA 2807 936F 984D C5A6

* remotes/ehabkost/tags/python-next-pull-request:
  scripts: Remove debug parameter from QEMUMachine
  scripts: Remove debug parameter from QEMUMonitorProtocol
  guestperf: Configure logging on all shell frontends
  basevm: Call logging.basicConfig()
  iotests: Set up Python logging
Signed-off-by: NPeter Maydell <peter.maydell@linaro.org>
......@@ -54,7 +54,7 @@ class QEMUMachine(object):
def __init__(self, binary, args=None, wrapper=None, name=None,
test_dir="/var/tmp", monitor_address=None,
socket_scm_helper=None, debug=False):
socket_scm_helper=None):
'''
Initialize a QEMUMachine
......@@ -65,7 +65,6 @@ class QEMUMachine(object):
@param test_dir: where to create socket and log file
@param monitor_address: address for QMP monitor
@param socket_scm_helper: helper program, required for send_fd_scm()"
@param debug: enable debug mode
@note: Qemu process is not started until launch() is used.
'''
if args is None:
......@@ -85,12 +84,11 @@ class QEMUMachine(object):
self._events = []
self._iolog = None
self._socket_scm_helper = socket_scm_helper
self._debug = debug
self._qmp = None
self._qemu_full_args = None
# just in case logging wasn't configured by the main script:
logging.basicConfig(level=(logging.DEBUG if debug else logging.WARN))
logging.basicConfig()
def __enter__(self):
return self
......@@ -177,8 +175,7 @@ class QEMUMachine(object):
def _pre_launch(self):
self._qmp = qmp.qmp.QEMUMonitorProtocol(self._monitor_address,
server=True,
debug=self._debug)
server=True)
def _post_launch(self):
self._qmp.accept()
......
......@@ -11,7 +11,7 @@
import json
import errno
import socket
import sys
import logging
class QMPError(Exception):
......@@ -32,12 +32,14 @@ class QMPTimeoutError(QMPError):
class QEMUMonitorProtocol(object):
#: Logger object for debugging messages
logger = logging.getLogger('QMP')
#: Socket's error class
error = socket.error
#: Socket's timeout
timeout = socket.timeout
def __init__(self, address, server=False, debug=False):
def __init__(self, address, server=False):
"""
Create a QEMUMonitorProtocol class.
......@@ -51,7 +53,6 @@ class QEMUMonitorProtocol(object):
"""
self.__events = []
self.__address = address
self._debug = debug
self.__sock = self.__get_sock()
self.__sockfile = None
if server:
......@@ -83,8 +84,7 @@ class QEMUMonitorProtocol(object):
return
resp = json.loads(data)
if 'event' in resp:
if self._debug:
print >>sys.stderr, "QMP:<<< %s" % resp
self.logger.debug("<<< %s", resp)
self.__events.append(resp)
if not only_event:
continue
......@@ -164,8 +164,7 @@ class QEMUMonitorProtocol(object):
@return QMP response as a Python dict or None if the connection has
been closed
"""
if self._debug:
print >>sys.stderr, "QMP:>>> %s" % qmp_cmd
self.logger.debug(">>> %s", qmp_cmd)
try:
self.__sock.sendall(json.dumps(qmp_cmd))
except socket.error as err:
......@@ -173,8 +172,7 @@ class QEMUMonitorProtocol(object):
return
raise socket.error(err)
resp = self.__json_read()
if self._debug:
print >>sys.stderr, "QMP:<<< %s" % resp
self.logger.debug("<<< %s", resp)
return resp
def cmd(self, name, args=None, cmd_id=None):
......
......@@ -388,15 +388,13 @@ class Engine(object):
args=self._get_src_args(hardware),
wrapper=self._get_src_wrapper(hardware),
name="qemu-src-%d" % os.getpid(),
monitor_address=srcmonaddr,
debug=self._debug)
monitor_address=srcmonaddr)
dst = qemu.QEMUMachine(self._binary,
args=self._get_dst_args(hardware, uri),
wrapper=self._get_dst_wrapper(hardware),
name="qemu-dst-%d" % os.getpid(),
monitor_address=dstmonaddr,
debug=self._debug)
monitor_address=dstmonaddr)
try:
src.launch()
......
......@@ -26,6 +26,7 @@ sys.path.append(os.path.join(os.path.dirname(__file__),
import argparse
import fnmatch
import platform
import logging
from guestperf.hardware import Hardware
from guestperf.engine import Engine
......@@ -147,6 +148,10 @@ class Shell(BaseShell):
def run(self, argv):
args = self._parser.parse_args(argv)
logging.basicConfig(level=(logging.DEBUG if args.debug else
logging.INFO if args.verbose else
logging.WARN))
engine = self.get_engine(args)
hardware = self.get_hardware(args)
......@@ -179,6 +184,10 @@ class BatchShell(BaseShell):
def run(self, argv):
args = self._parser.parse_args(argv)
logging.basicConfig(level=(logging.DEBUG if args.debug else
logging.INFO if args.verbose else
logging.WARN))
engine = self.get_engine(args)
hardware = self.get_hardware(args)
......@@ -231,6 +240,10 @@ class PlotShell(object):
def run(self, argv):
args = self._parser.parse_args(argv)
logging.basicConfig(level=(logging.DEBUG if args.debug else
logging.INFO if args.verbose else
logging.WARN))
if len(args.reports) == 0:
print >>sys.stderr, "At least one report required"
......
......@@ -28,6 +28,7 @@ import qtest
import struct
import json
import signal
import logging
# This will not work if arguments contain spaces but is necessary if we
......@@ -194,8 +195,6 @@ class VM(qtest.QEMUQtestMachine):
super(VM, self).__init__(qemu_prog, qemu_opts, name=name,
test_dir=test_dir,
socket_scm_helper=socket_scm_helper)
if debug:
self._debug = True
self._num_drives = 0
def add_device(self, opts):
......@@ -467,6 +466,8 @@ def main(supported_fmts=[], supported_oses=['linux']):
else:
output = StringIO.StringIO()
logging.basicConfig(level=(logging.DEBUG if debug else logging.WARN))
class MyTestRunner(unittest.TextTestRunner):
def __init__(self, stream=output, descriptions=True, verbosity=verbosity):
unittest.TextTestRunner.__init__(self, stream, descriptions, verbosity)
......
......@@ -227,8 +227,8 @@ def main(vmcls):
if not argv and not args.build_qemu and not args.build_image:
print "Nothing to do?"
return 1
if args.debug:
logging.getLogger().setLevel(logging.DEBUG)
logging.basicConfig(level=(logging.DEBUG if args.debug
else logging.WARN))
vm = vmcls(debug=args.debug, vcpus=args.jobs)
if args.build_image:
if os.path.exists(args.image) and not args.force:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册