From 091776545f759f379fa9ae5b67ce5b2a6153a010 Mon Sep 17 00:00:00 2001 From: Eduardo Habkost Date: Thu, 5 Oct 2017 14:20:12 -0300 Subject: scripts: Remove debug parameter from QEMUMonitorProtocol MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use logging module for the QMP debug messages. The only scripts that set debug=True are iotests.py and guestperf/engine.py, and they already call logging.basicConfig() to set up logging. Scripts that don't configure logging are safe as long as they don't need debugging output, because debug messages don't trigger the "No handlers could be found for logger" message from the Python logging module. Scripts that already configure logging but don't use debug=True (e.g. scripts/vm/basevm.py) will get QMP debugging enabled for free. Cc: "Alex Bennée" Cc: Fam Zheng Cc: "Philippe Mathieu-Daudé" Signed-off-by: Eduardo Habkost Message-Id: <20171005172013.3098-3-ehabkost@redhat.com> Reviewed-by: Lukáš Doktor Signed-off-by: Eduardo Habkost --- scripts/qemu.py | 3 +-- scripts/qmp/qmp.py | 16 +++++++--------- 2 files changed, 8 insertions(+), 11 deletions(-) (limited to 'scripts') diff --git a/scripts/qemu.py b/scripts/qemu.py index c9a106f..f6d2e68 100644 --- a/scripts/qemu.py +++ b/scripts/qemu.py @@ -177,8 +177,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() diff --git a/scripts/qmp/qmp.py b/scripts/qmp/qmp.py index ef12e8a..07c9632 100644 --- a/scripts/qmp/qmp.py +++ b/scripts/qmp/qmp.py @@ -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): -- cgit v1.1 From 1a6d3757107181dc0b9baf3dd8ff40fb2a242b66 Mon Sep 17 00:00:00 2001 From: Eduardo Habkost Date: Thu, 5 Oct 2017 14:20:13 -0300 Subject: scripts: Remove debug parameter from QEMUMachine MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit All scripts that use the QEMUMachine and QEMUQtestMachine classes (device-crash-test, tests/migration/*, iotests.py, basevm.py) already configure logging. The basicConfig() call inside QEMUMachine.__init__() is being kept just to make sure a script would still work if it didn't configure logging. Signed-off-by: Eduardo Habkost Message-Id: <20171005172013.3098-4-ehabkost@redhat.com> Reviewed-by: Lukáš Doktor Signed-off-by: Eduardo Habkost --- scripts/qemu.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'scripts') diff --git a/scripts/qemu.py b/scripts/qemu.py index f6d2e68..9bfdf6d 100644 --- a/scripts/qemu.py +++ b/scripts/qemu.py @@ -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 -- cgit v1.1