summaryrefslogtreecommitdiffstats
path: root/python
Commit message (Collapse)AuthorAgeFilesLines
* python, iotests: remove socket_scm_helperJohn Snow2021-10-122-5/+0Star
| | | | | | | | | | It's not used anymore, now. Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Hanna Reitz <hreitz@redhat.com> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Message-id: 20210923004938.3999963-11-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
* python/qmp: add send_fd_scm directly to QEMUMonitorProtocolJohn Snow2021-10-122-47/+18Star
| | | | | | | | | | | | | | | | | It turns out you can do this directly from Python ... and because of this, you don't need to worry about setting the inheritability of the fds or spawning another process. Doing this is helpful because it allows QEMUMonitorProtocol to keep its file descriptor and socket object as private implementation details. /that/ is helpful in turn because it allows me to write a compatible, alternative implementation. Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Hanna Reitz <hreitz@redhat.com> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Message-id: 20210923004938.3999963-10-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
* python/qmp: clear events on get_events() callJohn Snow2021-10-123-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | All callers in the tree *already* clear the events after a call to get_events(). Do it automatically instead and update callsites to remove the manual clear call. These semantics are quite a bit easier to emulate with async QMP, and nobody appears to be abusing some emergent properties of what happens if you decide not to clear them, so let's dial down to the dumber, simpler thing. Specifically: callers of clear() right after a call to get_events() are more likely expressing their desire to not see any events they just retrieved, whereas callers of clear_events() not in relation to a recent call to pull_event/get_events are likely expressing their desire to simply drop *all* pending events straight onto the floor. In the sync world, this is safe enough; in the async world it's nearly impossible to promise that nothing happens between getting and clearing the events. Making the retrieval also clear the queue is vastly simpler. Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Hanna Reitz <hreitz@redhat.com> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Message-id: 20210923004938.3999963-9-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
* python/aqmp: Disable logging messages by defaultJohn Snow2021-10-121-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | AQMP is a library, and ideally it should not print error diagnostics unless a user opts into seeing them. By default, Python will print all WARNING, ERROR or CRITICAL messages to screen if no logging configuration has been created by a client application. In AQMP's case, ERROR logging statements are used to report additional detail about runtime failures that will also eventually be reported to the client library via an Exception, so these messages should not be rendered by default. (Why bother to have them at all, then? In async contexts, there may be multiple Exceptions and we are only able to report one of them back to the client application. It is not reasonably easy to predict ahead of time if one or more of these Exceptions will be squelched. Therefore, it's useful to log intermediate failures to help make sense of the ultimate, resulting failure.) Add a NullHandler that will suppress these messages until a client application opts into logging via logging.basicConfig or similar. Note that upon calling basicConfig(), this handler will *not* suppress these messages from being displayed by the client's configuration. Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Message-id: 20210923004938.3999963-8-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
* python/aqmp: Reduce severity of EOFError-caused loop terminationsJohn Snow2021-10-121-2/+5
| | | | | | | | | | | | | | When we encounter an EOFError, we don't know if it's an "error" in the perspective of the user of the library yet. Therefore, we should not log it as an error. Reduce the severity of this logging message to "INFO" to indicate that it's something that we expect to occur during the normal operation of the library. Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Message-id: 20210923004938.3999963-7-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
* python/aqmp: Add dict conversion method to Greeting objectJohn Snow2021-10-121-0/+13
| | | | | | | | | | | The iotests interface expects to return the greeting as a dict; AQMP offers it as a rich object. Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Message-id: 20210923004938.3999963-6-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
* python/aqmp: add send_fd_scmJohn Snow2021-10-121-0/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add an implementation for send_fd_scm to the async QMP implementation. Like socket_scm_helper mentions, a non-empty payload is required for QEMU to process the ancillary data. A space is most useful because it does not disturb the parsing of subsequent JSON objects. A note on "voiding the warranty": Python 3.11 removes support for calling sendmsg directly from a transport's socket. There is no other interface for doing this, our use case is, I suspect, "quite unique". As far as I can tell, this is safe to do -- send_fd_scm is a synchronous function and we can be guaranteed that the async coroutines will *not* be running when it is invoked. In testing, it works correctly. I investigated quite thoroughly the possibility of creating my own asyncio Transport (The class that ultimately manages the raw socket object) so that I could manage the socket myself, but this is so wildly invasive and unportable I scrapped the idea. It would involve a lot of copy-pasting of various python utilities and classes just to re-create the same infrastructure, and for extremely little benefit. Nah. Just boldly void the warranty instead, while I try to follow up on https://bugs.python.org/issue43232 Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Message-id: 20210923004938.3999963-5-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
* python/aqmp: Return cleared events from EventListener.clear()John Snow2021-10-121-2/+7
| | | | | | | | | | | | | | | | This serves two purposes: (1) It is now possible to discern whether or not clear() removed any event(s) from the queue with absolute certainty, and (2) It is now very easy to get a List of all pending events in one chunk, which is useful for the sync bridge. Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Hanna Reitz <hreitz@redhat.com> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Message-id: 20210923004938.3999963-4-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
* python/aqmp: add .empty() method to EventListenerJohn Snow2021-10-121-0/+6
| | | | | | | | | | | | | Synchronous clients may want to know if they're about to block waiting for an event or not. A method such as this is necessary to implement a compatible interface for the old QEMUMonitorProtocol using the new async internals. Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Hanna Reitz <hreitz@redhat.com> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Message-id: 20210923004938.3999963-3-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
* python/aqmp: add greeting property to QMPClientJohn Snow2021-10-121-0/+5
| | | | | | | | | | | Expose the greeting as a read-only property of QMPClient so it can be retrieved at-will. Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Hanna Reitz <hreitz@redhat.com> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Message-id: 20210923004938.3999963-2-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
* python/aqmp-tui: Add syntax highlightingG S Niteesh Babu2021-09-271-2/+34
| | | | | | | | | | | | | | | Add syntax highlighting for the incoming and outgoing QMP messages. This is achieved using the pygments module which was added in a previous commit. The current implementation is a really simple one which doesn't allow for any configuration. In future this has to be improved to allow for easier theme config using an external config of some sort. Signed-off-by: G S Niteesh Babu <niteesh.gs@gmail.com> Message-Id: <20210823220746.28295-6-niteesh.gs@gmail.com> Signed-off-by: John Snow <jsnow@redhat.com>
* python: add optional pygments dependencyG S Niteesh Babu2021-09-272-0/+13
| | | | | | | | | | | | | | Added pygments as optional dependency for AQMP TUI. This is required for the upcoming syntax highlighting feature in AQMP TUI. The dependency has also been added in the devel optional group. Added mypy 'ignore_missing_imports' for pygments since it does not have any type stubs. Signed-off-by: G S Niteesh Babu <niteesh.gs@gmail.com> Message-Id: <20210823220746.28295-5-niteesh.gs@gmail.com> Signed-off-by: John Snow <jsnow@redhat.com>
* python: Add entry point for aqmp-tuiG S Niteesh Babu2021-09-271-0/+1
| | | | | | | | | | Add an entry point for aqmp-tui. This will allow it to be run from the command line using "aqmp-tui localhost:1234" More options available in the TUI can be found using "aqmp-tui -h" Signed-off-by: G S Niteesh Babu <niteesh.gs@gmail.com> Message-Id: <20210823220746.28295-4-niteesh.gs@gmail.com> Signed-off-by: John Snow <jsnow@redhat.com>
* python/aqmp-tui: Add AQMP TUIG S Niteesh Babu2021-09-272-1/+632
| | | | | | | | | | | | | | | | Added AQMP TUI. Implements the follwing basic features: 1) Command transmission/reception. 2) Shows events asynchronously. 3) Shows server status in the bottom status bar. 4) Automatic retries on disconnects and error conditions. Also added type annotations and necessary pylint/mypy configurations. Signed-off-by: G S Niteesh Babu <niteesh.gs@gmail.com> Message-Id: <20210823220746.28295-3-niteesh.gs@gmail.com> Signed-off-by: John Snow <jsnow@redhat.com>
* python: Add dependencies for AQMP TUIG S Niteesh Babu2021-09-272-0/+20
| | | | | | | | | | | | | Added dependencies for the upcoming AQMP TUI under the optional 'tui' group. The same dependencies have also been added under the devel group since no work around has been found for optional groups to imply other optional groups. Signed-off-by: G S Niteesh Babu <niteesh.gs@gmail.com> Message-Id: <20210823220746.28295-2-niteesh.gs@gmail.com> Signed-off-by: John Snow <jsnow@redhat.com>
* python/aqmp: Add Coverage.py supportJohn Snow2021-09-274-0/+27
| | | | | | | | | | | | | I'm not exposing this via the Makefile help, it's not likely to be useful to passersby. Switch the avocado runner to the 'legacy' runner for now, as the new runner seems to obscure coverage reports, again. Usage is to enter your venv of choice and then: `make check-coverage && xdg-open htmlcov/index.html`. Signed-off-by: John Snow <jsnow@redhat.com> Message-id: 20210915162955.333025-28-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
* python/aqmp: add LineProtocol testsJohn Snow2021-09-271-0/+48
| | | | | | | | | | | Tests a real connect, a real accept, and really sending and receiving a message over a UNIX socket. Brings coverage of protocol.py up to ~93%. Signed-off-by: John Snow <jsnow@redhat.com> Message-id: 20210915162955.333025-27-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
* python/aqmp: add AsyncProtocol unit testsJohn Snow2021-09-271-0/+535
| | | | | | | | | | This tests most of protocol.py -- From a hacked up Coverage.py run, it's at about 86%. There's a few error cases that aren't very well tested yet, they're hard to induce artificially so far. I'm working on it. Signed-off-by: John Snow <jsnow@redhat.com> Message-id: 20210915162955.333025-26-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
* python: bump avocado to v90.0John Snow2021-09-272-5/+5
| | | | | | | | | | | Avocado v90 includes improved support for running async unit tests. The workaround that existed prior to v90 causes the unit tests to fail afterwards, however, so upgrade our minimum version pin to the very latest and greatest. Signed-off-by: John Snow <jsnow@redhat.com> Message-id: 20210915162955.333025-25-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
* python/aqmp: add scary messageJohn Snow2021-09-271-0/+14
| | | | | | | | | Add a warning whenever AQMP is used to steer people gently away from using it for the time-being. Signed-off-by: John Snow <jsnow@redhat.com> Message-id: 20210915162955.333025-24-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
* python/aqmp: add asyncio_run compatibility wrapperJohn Snow2021-09-271-0/+19
| | | | | | | | | | As a convenience. It isn't used by the library itself, but it is used by the test suite. It will also come in handy for users of the library still on Python 3.6. Signed-off-by: John Snow <jsnow@redhat.com> Message-id: 20210915162955.333025-23-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
* python/aqmp: add _raw() execution interfaceJohn Snow2021-09-271-0/+51
| | | | | | | | | | | | | | This is added in anticipation of wanting it for a synchronous wrapper for the iotest interface. Normally, execute() and execute_msg() both raise QMP errors in the form of Python exceptions. Many iotests expect the entire reply as-is. To reduce churn there, add a private execution interface that will ease transition churn. However, I do not wish to encourage its use, so it will remain a private interface. Signed-off-by: John Snow <jsnow@redhat.com> Message-id: 20210915162955.333025-22-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
* python/aqmp: add execute() interfacesJohn Snow2021-09-272-8/+198
| | | | | | | | | | | | | | | | Add execute() and execute_msg(). _execute() is split into _issue() and _reply() halves so that hypothetical subclasses of QMP that want to support different execution paradigms can do so. I anticipate a synchronous interface may have need of separating the send/reply phases. However, I do not wish to expose that interface here and want to actively discourage it, so they remain private interfaces. Signed-off-by: John Snow <jsnow@redhat.com> Message-id: 20210915162955.333025-21-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
* python/aqmp: Add message routing to QMP protocolJohn Snow2021-09-271-2/+120
| | | | | | | | | | Add the ability to handle and route messages in qmp_protocol.py. The interface for actually sending anything still isn't added until next commit. Signed-off-by: John Snow <jsnow@redhat.com> Message-id: 20210915162955.333025-20-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
* python/pylint: disable no-member checkJohn Snow2021-09-271-0/+1
| | | | | | | | | | | | mypy handles this better -- but we only need the workaround because pylint under Python 3.6 does not understand that a MutableMapping really does have a .get() method attached. We could remove this again once 3.7 is our minimum. Signed-off-by: John Snow <jsnow@redhat.com> Message-id: 20210915162955.333025-19-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
* python/aqmp: add QMP protocol supportJohn Snow2021-09-272-0/+266
| | | | | | | | | | | The star of our show! Add most of the QMP protocol, sans support for actually executing commands. No problem, that happens in the next several commits. Signed-off-by: John Snow <jsnow@redhat.com> Message-id: 20210915162955.333025-18-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
* python/pylint: disable too-many-function-argsJohn Snow2021-09-271-0/+1
| | | | | | | | | | | | | too-many-function-args seems prone to failure when considering things like Method Resolution Order, which mypy gets correct. When dealing with multiple inheritance, pylint doesn't seem to understand which method will actually get called, while mypy does. Remove the less powerful, redundant check. Signed-off-by: John Snow <jsnow@redhat.com> Message-id: 20210915162955.333025-17-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
* python/aqmp: add QMP event supportJohn Snow2021-09-272-0/+708
| | | | | | | | | | | This class was designed as a "mix-in" primarily so that the feature could be given its own treatment in its own python module. It gets quite a bit too long otherwise. Signed-off-by: John Snow <jsnow@redhat.com> Message-id: 20210915162955.333025-16-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
* python/aqmp: add well-known QMP object modelsJohn Snow2021-09-271-0/+133
| | | | | | | | | | The QMP spec doesn't define very many objects that are iron-clad in their format, but there are a few. This module makes it trivial to validate them without relying on an external third-party library. Signed-off-by: John Snow <jsnow@redhat.com> Message-id: 20210915162955.333025-15-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
* python/aqmp: add QMP Message formatJohn Snow2021-09-272-1/+212
| | | | | | | | | | | | | The Message class is here primarily to serve as a solid type to use for mypy static typing for unambiguous annotation and documentation. We can also stuff JSON serialization and deserialization into this class itself so it can be re-used even outside this infrastructure. Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Message-id: 20210915162955.333025-14-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
* python/aqmp: add AsyncProtocol._readline() methodJohn Snow2021-09-271-0/+29
| | | | | | | | | | | | | | This is added as a courtesy: many protocols are line-based, including QMP. Putting it in AsyncProtocol lets us keep the QMP class implementation just a pinch more abstract. (And, if we decide to add a QTEST implementation later, it will need this, too. (Yes, I have a QTEST implementation.)) Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Message-id: 20210915162955.333025-13-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
* python/aqmp: add _cb_inbound and _cb_outbound logging hooksJohn Snow2021-09-271-4/+46
| | | | | | | | | | | | | | | Add hooks designed to log/filter incoming/outgoing messages. The primary intent for these is to be able to support iotests which may want to log messages with specific filters for reproducible output. Another use is for plugging into Urwid frameworks; all messages in/out can be automatically added to a rendering list for the purposes of a qmp-shell like tool. Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Message-id: 20210915162955.333025-12-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
* python/aqmp: add configurable read buffer limitJohn Snow2021-09-271-2/+16
| | | | | | | | | | | QMP can transmit some pretty big messages, and the default limit of 64KB isn't sufficient. Make sure that we can configure it. Reported-by: G S Niteesh Babu <niteesh.gs@gmail.com> Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Message-id: 20210915162955.333025-11-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
* python/aqmp: add AsyncProtocol.accept() methodJohn Snow2021-09-271-4/+85
| | | | | | | | | | It's a little messier than connect, because it wasn't designed to accept *precisely one* connection. Such is life. Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Message-id: 20210915162955.333025-10-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
* python/aqmp: add logging to AsyncProtocolJohn Snow2021-09-271-9/+73
| | | | | | | | | | Give the connection and the reader/writer tasks nicknames, and add logging statements throughout. Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Message-id: 20210915162955.333025-9-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
* python/aqmp: Add logging utility helpersJohn Snow2021-09-271-0/+56
| | | | | | | Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Message-id: 20210915162955.333025-8-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
* python/aqmp: add runstate state machine to AsyncProtocolJohn Snow2021-09-272-5/+160
| | | | | | | | | | | | | | This serves a few purposes: 1. Protect interfaces when it's not safe to call them (via @require) 2. Add an interface by which an async client can determine if the state has changed, for the purposes of connection management. Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Message-id: 20210915162955.333025-7-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
* python/aqmp: add generic async message-based protocol supportJohn Snow2021-09-273-1/+577
| | | | | | | | | | | | | | | | | This is the bare minimum that you need to establish a full-duplex async message-based protocol with Python's asyncio. The features to be added in forthcoming commits are: - Runstate tracking - Logging - Support for incoming connections via accept() - _cb_outbound, _cb_inbound message hooks - _readline() method Signed-off-by: John Snow <jsnow@redhat.com> Message-id: 20210915162955.333025-6-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
* python/aqmp: add asyncio compatibility wrappersJohn Snow2021-09-271-0/+89
| | | | | | | | | | | | Python 3.6 does not have all of the goodies that Python 3.7 does, and we need to support both. Add some compatibility wrappers needed for this purpose. (Note: Python 3.6 is EOL December 2021.) Signed-off-by: John Snow <jsnow@redhat.com> Message-id: 20210915162955.333025-5-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
* python/pylint: Add exception for TypeVar names ('T')John Snow2021-09-271-0/+1
| | | | | | | | | | | | | 'T' is a common TypeVar name, allow its use. See also https://github.com/PyCQA/pylint/issues/3401 -- In the future, we might be able to have a separate list of acceptable names for TypeVars exclusively. Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Message-id: 20210915162955.333025-4-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
* python/aqmp: add error classesJohn Snow2021-09-272-0/+54
| | | | | | | Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Message-id: 20210915162955.333025-3-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
* python/aqmp: add asynchronous QMP (AQMP) subpackageJohn Snow2021-09-273-0/+28
| | | | | | | | | For now, it's empty! Soon, it won't be. Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Message-id: 20210915162955.333025-2-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
* python: pylint 2.11 supportJohn Snow2021-09-161-1/+1
| | | | | | | | | | | We're not ready to enforce f-strings everywhere, so just silence this new warning. Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Eduardo Habkost <ehabkost@redhat.com> Reviewed-by: Willian Rampazzo <willianr@redhat.com> Message-id: 20210916182248.721529-3-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
* python: Update for pylint 2.10John Snow2021-09-162-1/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | A few new annoyances. Of note is the new warning for an unspecified encoding when opening a text file, which actually does indicate a potentially real problem; see https://www.python.org/dev/peps/pep-0597/#motivation Use LC_CTYPE to determine an encoding to use for interpreting QEMU's terminal output. Note that Python states: "language code and encoding may be None if their values cannot be determined" -- use a platform default as a backup. Notes: Passing encoding=None will generate a suppressed warning on Python 3.10+ that 'None' should not be passed as the encoding argument. This behavior may be deprecated in the future and the default switched to be a ubiquitous UTF-8. Opting in to the locale default will be done by passing the encoding 'locale', but that isn't available in 3.6 through 3.9. Presumably this warning will be unsuppressed some time prior to the actual switch and we can re-investigate these issues at that time if necessary. Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Eduardo Habkost <ehabkost@redhat.com> Reviewed-by: Willian Rampazzo <willianr@redhat.com> Message-id: 20210916182248.721529-2-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
* python:QEMUMachine: template typing for self returning methodsVladimir Sementsov-Ogievskiy2021-09-011-3/+7
| | | | | | | | | | | mypy thinks that return value of these methods in subclusses is QEMUMachine, which is wrong. So, make typing smarter. Suggested-by: John Snow <jsnow@redhat.com> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> Message-Id: <20210824083856.17408-26-vsementsov@virtuozzo.com> Reviewed-by: Hanna Reitz <hreitz@redhat.com> Signed-off-by: Hanna Reitz <hreitz@redhat.com>
* python/qemu/machine: QEMUMachine: improve qmp() methodVladimir Sementsov-Ogievskiy2021-09-011-1/+11
| | | | | | | | | | | | | | | | We often call qmp() with unpacking dict, like qmp('foo', **{...}). mypy don't really like it, it thinks that passed unpacked dict is a positional argument and complains that it type should be bool (because second argument of qmp() is conv_keys: bool). Allow passing dict directly, simplifying interface, and giving a way to satisfy mypy. Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> Reviewed-by: Max Reitz <mreitz@redhat.com> Reviewed-by: John Snow <jsnow@redhat.com> Message-Id: <20210824083856.17408-25-vsementsov@virtuozzo.com> Signed-off-by: Hanna Reitz <hreitz@redhat.com>
* python/qemu/machine.py: refactor _qemu_args()Vladimir Sementsov-Ogievskiy2021-09-011-10/+8Star
| | | | | | | | | | | | | - use shorter construction - don't create new dict if not needed - drop extra unpacking key-val arguments - drop extra default values Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> Reviewed-by: Max Reitz <mreitz@redhat.com> Reviewed-by: John Snow <jsnow@redhat.com> Message-Id: <20210824083856.17408-24-vsementsov@virtuozzo.com> Signed-off-by: Hanna Reitz <hreitz@redhat.com>
* qemu-iotests: add option to show qemu binary logs on stdoutEmanuele Giuseppe Esposito2021-09-011-3/+6
| | | | | | | | | | | | | | Using the flag -p, allow the qemu binary to print to stdout. Also create the common function _close_qemu_log_file() to avoid accessing machine.py private fields directly and have duplicate code. Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com> Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> Reviewed-by: Max Reitz <mreitz@redhat.com> Message-Id: <20210809090114.64834-16-eesposit@redhat.com> Signed-off-by: Hanna Reitz <hreitz@redhat.com>
* python: qemu: pass the wrapper field from QEMUQtestmachine to QEMUMachineEmanuele Giuseppe Esposito2021-09-011-1/+3
| | | | | | | | | | Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com> Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> Reviewed-by: John Snow <jsnow@redhat.com> Reviewed-by: Max Reitz <mreitz@redhat.com> Acked-by: John Snow <jsnow@redhat.com> Message-Id: <20210809090114.64834-4-eesposit@redhat.com> Signed-off-by: Hanna Reitz <hreitz@redhat.com>
* python: Reduce strictness of pylint's duplicate-code checkJohn Snow2021-09-011-0/+5
| | | | | | | | | | | | | | | | | | | | | | Pylint prior to 2.8.3 (We pin at >= 2.8.0) includes function and method signatures as part of its duplicate checking algorithm. This check does not listen to pragmas, so the only way to disable it is to turn it off completely or increase the minimum duplicate lines so that it doesn't trigger for functions with long, multi-line signatures. When we decide to upgrade to pylint 2.8.3 or greater, we will be able to use 'ignore-signatures = true' to the config instead. I'd prefer not to keep us on the very bleeding edge of pylint if I can help it -- 2.8.3 came out only three days ago at time of writing. See: https://github.com/PyCQA/pylint/pull/4474 Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> Acked-by: John Snow <jsnow@redhat.com> Reviewed-by: Max Reitz <mreitz@redhat.com> Message-Id: <20210809090114.64834-3-eesposit@redhat.com> Signed-off-by: Hanna Reitz <hreitz@redhat.com>