summaryrefslogtreecommitdiffstats
path: root/python/qemu/machine.py
Commit message (Collapse)AuthorAgeFilesLines
* Python: close the log file kept by QEMUMachine before reading itCleber Rosa2021-02-161-2/+2
| | | | | | | | | | | | Closing a file that is open for writing, and then reading from it sounds like a better idea than the opposite, given that the content will be flushed. Reference: https://docs.python.org/3/library/io.html#io.IOBase.close Signed-off-by: Cleber Rosa <crosa@redhat.com> Message-Id: <20210211220146.2525771-2-crosa@redhat.com> Reviewed-by: John Snow <jsnow@redhat.com> Signed-off-by: Cleber Rosa <crosa@redhat.com>
* treewide: do not use short-form boolean optionsPaolo Bonzini2020-12-101-1/+1
| | | | | | | They are going to be deprecated, avoid warnings on stdout while the tests run. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
* tests: add prefixes to the bare mkdtemp callsAlex Bennée2020-11-231-1/+2
| | | | | | | | | | | | The first step to debug a thing is to know what created the thing in the first place. Add some prefixes so random tmpdir's have something grep in the code. Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> Reviewed-by: Wainer dos Santos Moschetta <wainersm@redhat.com> Reviewed-by: Thomas Huth <thuth@redhat.com> Message-Id: <20201117173635.29101-3-alex.bennee@linaro.org>
* python/qemu: Add mypy type annotationsJohn Snow2020-10-201-42/+56
| | | | | | | | | | | | These should all be purely annotations with no changes in behavior at all. You need to be in the python folder, but you should be able to confirm that these annotations are correct (or at least self-consistent) by running `mypy --strict qemu`. Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Kevin Wolf <kwolf@redhat.com> Message-id: 20201006235817.3280413-12-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
* python/qemu: make 'args' style arguments immutableJohn Snow2020-10-201-13/+17
| | | | | | | | | | | | | | | | | These arguments don't need to be mutable and aren't really used as such. Clarify their types as immutable and adjust code to match where necessary. In general, It's probably best not to accept a user-defined mutable object and store it as internal object state unless there's a strong justification for doing so. Instead, try to use generic types as input with empty tuples as the default, and coerce to list where necessary. Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> Message-id: 20201006235817.3280413-10-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
* python/machine.py: fix _popen accessJohn Snow2020-10-201-5/+11
| | | | | | | | | | | As always, Optional[T] causes problems with unchecked access. Add a helper that asserts the pipe is present before we attempt to talk with it. Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Kevin Wolf <kwolf@redhat.com> Message-id: 20201006235817.3280413-9-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
* python/machine.py: Add _qmp access shimJohn Snow2020-10-201-11/+13
| | | | | | | | | | | Like many other Optional[] types, it's not always a given that this object will be set. Wrap it in a type-shim that raises a meaningful error and will always return a concrete type. Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Kevin Wolf <kwolf@redhat.com> Message-id: 20201006235817.3280413-8-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
* python/machine.py: use qmp.commandJohn Snow2020-10-201-12/+20
| | | | | | | | | | | machine.py and qmp.py both do the same thing here; refactor machine.py to use qmp.py's functionality more directly. Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> Message-id: 20201006235817.3280413-7-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
* python/machine.py: Handle None events in events_waitJohn Snow2020-10-201-7/+20
| | | | | | | | | If the timeout is 0, we can get None back. Handle this explicitly. Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Kevin Wolf <kwolf@redhat.com> Message-id: 20201006235817.3280413-6-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
* python/machine.py: Don't modify state in _base_args()John Snow2020-10-201-7/+10
| | | | | | | | | | | | | | Don't append to the _remove_files list during _base_args; instead do so during _launch. Rework _base_args as a @property to help facilitate this impression. This has the additional benefit of making the type of _console_address easier to analyze statically. Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Kevin Wolf <kwolf@redhat.com> Message-id: 20201006235817.3280413-5-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
* python/machine.py: reorder __init__John Snow2020-10-201-19/+25
| | | | | | | | | | | | Put the init arg handling all at the top, and mostly in order (deviating when one is dependent on another), and put what is effectively runtime state declaration at the bottom. Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> Reviewed-by: Kevin Wolf <kwolf@redhat.com> Message-id: 20201006235817.3280413-4-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
* python/machine.py: Fix monitor address typingJohn Snow2020-10-201-15/+25
| | | | | | | | | | | | | | | | | Prior to this, it's difficult for mypy to intuit what the concrete type of the monitor address is; it has difficulty inferring the type across two variables. Create _monitor_address as a property that always returns a valid address to simplify static type analysis. To preserve our ability to clean up, use a simple boolean to indicate whether or not we should try to clean up the sock file after execution. Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Kevin Wolf <kwolf@redhat.com> Message-id: 20201006235817.3280413-3-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
* python/qemu: use isort to lay out importsJohn Snow2020-10-201-4/+4
| | | | | | | | | | | Borrowed from the QAPI cleanup series, use the same configuration to standardize the way we write and sort imports. Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> Reviewed-by: Kevin Wolf <kwolf@redhat.com> Message-id: 20201006235817.3280413-2-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
* python/qemu: Change ConsoleSocket to optionally drain socket.Robert Foley2020-07-271-9/+4Star
| | | | | | | | | | | | | | | The primary purpose of this change is to clean up machine.py's console_socket property to return a single type, a ConsoleSocket. ConsoleSocket now derives from a socket, which means that in the default case (of not draining), machine.py will see the same behavior as it did prior to ConsoleSocket. Signed-off-by: Robert Foley <robert.foley@linaro.org> Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Message-Id: <20200717203041.9867-3-robert.foley@linaro.org> Message-Id: <20200724064509.331-16-alex.bennee@linaro.org>
* python/qemu: Cleanup changes to ConsoleSocketRobert Foley2020-07-271-3/+4
| | | | | | | | | | | | The changes to console_socket.py and machine.py are to cleanup for pylint and flake8. Signed-off-by: Robert Foley <robert.foley@linaro.org> Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Reviewed-by: Alex Bennée <alex.bennee@linaro.org> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Message-Id: <20200717203041.9867-2-robert.foley@linaro.org> Message-Id: <20200724064509.331-15-alex.bennee@linaro.org>
* python/machine: Change default timeout to 30 secondsJohn Snow2020-07-251-15/+15
| | | | | | | | | | | 3 seconds is too short for some tests running inside busy VMs. Build it out to a rather generous 30 seconds to find out conclusively if there are more severe problems in the merge/CI tests. Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Eduardo Habkost <ehabkost@redhat.com> Message-id: 20200720160252.104139-2-jsnow@redhat.com Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
* python/qmp.py: re-absorb MonitorResponseErrorJohn Snow2020-07-141-14/+1Star
| | | | | | | | | | | | | | When I initially split this out, I considered this more of a machine error than a QMP protocol error, but I think that's misguided. Move this back to qmp.py and name it QMPResponseError. Convert qmp.command() to use this exception type. Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> Reviewed-by: Kevin Wolf <kwolf@redhat.com> Message-Id: <20200710052220.3306-4-jsnow@redhat.com> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
* python/machine.py: change default wait timeout to 3 secondsJohn Snow2020-07-141-2/+2
| | | | | | | | | | | | | | Machine.wait() does not appear to be used except in the acceptance tests, and an infinite timeout by default in a test suite is not the most helpful. Change it to 3 seconds, like the default shutdown timeout. Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> Reviewed-by: Cleber Rosa <crosa@redhat.com> Tested-by: Cleber Rosa <crosa@redhat.com> Message-Id: <20200710050649.32434-13-jsnow@redhat.com> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
* python/machine.py: re-add sigkill warning suppressionJohn Snow2020-07-141-1/+6
| | | | | | | | | | | If the user kills QEMU on purpose, we don't need to warn them about that having happened: they know already. Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> Reviewed-by: Cleber Rosa <crosa@redhat.com> Message-Id: <20200710050649.32434-12-jsnow@redhat.com> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
* python/machine.py: split shutdown into hard and soft flavorsJohn Snow2020-07-141-15/+83
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is done primarily to avoid the 'bare except' pattern, which suppresses all exceptions during shutdown and can obscure errors. Replace this with a pattern that isolates the different kind of shutdown paradigms (_hard_shutdown and _soft_shutdown), and a new fallback shutdown handler (_do_shutdown) that gracefully attempts one before the other. This split now also ensures that no matter what happens, _post_shutdown() is always invoked. shutdown() changes in behavior such that if it attempts to do a graceful shutdown and is unable to, it will now always raise an exception to indicate this. This can be avoided by the test writer in three ways: 1. If the VM is expected to have already exited or is in the process of exiting, wait() can be used instead of shutdown() to clean up resources instead. This helps avoid race conditions in shutdown. 2. If a test writer is expecting graceful shutdown to fail, shutdown should be called in a try...except block. 3. If the test writer has no interest in performing a graceful shutdown at all, kill() can be used instead. Handling shutdown in this way makes it much more explicit which type of shutdown we want and allows the library to report problems with this process. Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> Reviewed-by: Cleber Rosa <crosa@redhat.com> Tested-by: Cleber Rosa <crosa@redhat.com> Message-Id: <20200710050649.32434-11-jsnow@redhat.com> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
* python/machine.py: Make wait() call shutdown()John Snow2020-07-141-8/+9
| | | | | | | | | | | | | | | At this point, shutdown(has_quit=True) and wait() do essentially the same thing; they perform cleanup without actually instructing QEMU to quit. Define one in terms of the other. Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> Reviewed-by: Cleber Rosa <crosa@redhat.com> Tested-by: Cleber Rosa <crosa@redhat.com> Message-Id: <20200710050649.32434-8-jsnow@redhat.com> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
* python/machine.py: Add a configurable timeout to shutdown()John Snow2020-07-141-3/+5
| | | | | | | | | | | Three seconds is hardcoded. Use it as a default parameter instead, and use that value for both waits that may occur in the function. Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> Reviewed-by: Cleber Rosa <crosa@redhat.com> Message-Id: <20200710050649.32434-7-jsnow@redhat.com> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
* python/machine.py: Prohibit multiple shutdown() callsJohn Snow2020-07-141-1/+13
| | | | | | | | | | | | | | | If the VM is not launched, don't try to shut it down. As a change, _post_shutdown now unconditionally also calls _early_cleanup in order to offer comprehensive object cleanup in failure cases. As a courtesy, treat it as a NOP instead of rejecting it as an error. This is slightly nicer for acceptance tests where vm.shutdown() is issued unconditionally in tearDown callbacks. Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> Message-Id: <20200710050649.32434-6-jsnow@redhat.com> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
* python/machine.py: Perform early cleanup for wait() calls, tooJohn Snow2020-07-141-0/+1
| | | | | | | | | | | | | This is primarily for consistency, and is a step towards wait() and shutdown() sharing the same implementation so that the two cleanup paths cannot diverge. Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> Reviewed-by: Cleber Rosa <crosa@redhat.com> Tested-by: Cleber Rosa <crosa@redhat.com> Message-Id: <20200710050649.32434-5-jsnow@redhat.com> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
* python/machine.py: Add _early_cleanup hookJohn Snow2020-07-141-6/+12
| | | | | | | | | | | | Some parts of cleanup need to occur prior to shutdown, otherwise shutdown might break. Move this into a suitably named method/callback. Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> Reviewed-by: Cleber Rosa <crosa@redhat.com> Tested-by: Cleber Rosa <crosa@redhat.com> Message-Id: <20200710050649.32434-4-jsnow@redhat.com> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
* python/machine.py: Close QMP socket in cleanupJohn Snow2020-07-141-3/+4
| | | | | | | | | | | | It's not important to do this before waiting for the process to exit, so it can be done during generic post-shutdown cleanup. Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> Reviewed-by: Cleber Rosa <crosa@redhat.com> Tested-by: Cleber Rosa <crosa@redhat.com> Message-Id: <20200710050649.32434-3-jsnow@redhat.com> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
* python/machine.py: consolidate _post_shutdown()John Snow2020-07-141-14/+13Star
| | | | | | | | | | | | | | | Move more cleanup actions into _post_shutdown. As a change, if QEMU should so happen to be terminated during a call to wait(), that event will now be logged. This is not likely to occur during normative use. Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Cleber Rosa <crosa@redhat.com> Tested-by: Cleber Rosa <crosa@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> Message-Id: <20200710050649.32434-2-jsnow@redhat.com> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
* python/qemu: Add ConsoleSocket for optional use in QEMUMachineRobert Foley2020-07-111-4/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | We add the ConsoleSocket object, which has a socket interface and which will consume all arriving characters on the socket, placing them into an in memory buffer. This will also provide those chars via recv() as would a regular socket. ConsoleSocket also has the option of dumping the console bytes to a log file. We also give QEMUMachine the option of using ConsoleSocket to drain and to use for logging console to a file. By default QEMUMachine does not use ConsoleSocket. This is added in preparation for use by basevm.py in a later commit. This is a workaround we found was needed for basevm.py since there is a known issue where QEMU will hang waiting for console characters to be consumed. Cc: Eduardo Habkost <ehabkost@redhat.com> Cc: Cleber Rosa <crosa@redhat.com> Signed-off-by: Robert Foley <robert.foley@linaro.org> Reviewed-by: Peter Puhov <peter.puhov@linaro.org> Acked-by: Alex Bennée <alex.bennee@linaro.org> Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com> Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Message-Id: <20200601211421.1277-9-robert.foley@linaro.org> Message-Id: <20200701135652.1366-13-alex.bennee@linaro.org>
* python/qemu: Adjust traceback typingJohn Snow2020-05-311-2/+6
| | | | | | | | | | | | | | | | | mypy considers it incorrect to use `bool` to statically return false, because it will assume that it could conceivably return True, and gives different analysis in that case. Use a None return to achieve the same effect, but make mypy happy. Note: Pylint considers function signatures as code that might trip the duplicate-code checker. I'd rather not disable this as it does not trigger often in practice, so I'm disabling it as a one-off and filed a change request; see https://github.com/PyCQA/pylint/issues/3619 Signed-off-by: John Snow <jsnow@redhat.com> Acked-by: Philippe Mathieu-Daudé <philmd@redhat.com> Message-Id: <20200514055403.18902-14-jsnow@redhat.com> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
* python/qemu: remove Python2 style super() callsJohn Snow2020-05-311-1/+1
| | | | | | | | | Use the Python3 style instead. Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> Message-Id: <20200514055403.18902-12-jsnow@redhat.com> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
* python/qemu: delint; add flake8 configJohn Snow2020-05-311-4/+9
| | | | | | | | | | | Mostly, ignore the "no bare except" rule, because flake8 is not contextual and cannot determine if we re-raise. Pylint can, though, so always prefer pylint for that. Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> Message-Id: <20200528222129.23826-5-jsnow@redhat.com> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
* python/qemu: delint and add pylintrcJohn Snow2020-05-311-3/+3
| | | | | | | | | | | | | | | Bring our these files up to speed with pylint 2.5.0. Add a pylintrc file to formalize which pylint subset we are targeting. The similarity ignore is there to suppress similarity reports across imports, which for typing constants, are going to trigger this report erroneously. Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> Message-Id: <20200528222129.23826-4-jsnow@redhat.com> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
* python/qemu/machine: remove logging configurationJohn Snow2020-05-311-3/+0Star
| | | | | | | | | | | Python 3.5 and above do not print a warning when logging is not configured. As a library, it's best practice to leave logging configuration to the client executable. Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> Message-Id: <20200514055403.18902-22-jsnow@redhat.com> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
* python/qemu/machine: add kill() methodVladimir Sementsov-Ogievskiy2020-05-311-3/+9
| | | | | | | | | Add method to hard-kill vm, without any quit commands. Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> Reviewed-by: Andrey Shinkevich <andrey.shinkevich@virtuozzo.com> Message-Id: <20200217150246.29180-19-vsementsov@virtuozzo.com> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
* python/qemu: Kill QEMU process if 'quit' doesn't workKevin Wolf2020-03-211-0/+1
| | | | | | | | | | | | | | | | | | | | With a QEMU bug, it can happen that the QEMU process doesn't react to a 'quit' QMP command. If we got an exception during previous QMP communication (e.g. iotests Timeout expiring), we could also be in an inconsistent state where after sending 'quit' we immediately read an old response and close the socket even though the 'quit' command wasn't processed yet. Both cases would lead to a hanging test. Fix this by waiting for the QEMU process to exit after sending 'quit' with a timeout, and if it doesn't happen within three seconds, send SIGKILL. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: John Snow <jsnow@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com> Message-id: 20200313083617.8326-3-kwolf@redhat.com Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
* python/qemu/qmp.py: QMP debug with VM labelOksana Vohchana2020-03-171-1/+2
| | | | | | | | | | | | | | QEMUMachine writes some messages to the default logger. But it sometimes hard to read the output if we have requests to more than one VM. This patch adds a label to the logger in the debug mode. Signed-off-by: Oksana Vohchana <ovoshcha@redhat.com> Reviewed-by: John Snow <jsnow@redhat.com> Reviewed-by: Wainer dos Santos Moschetta <wainersm@redhat.com> Reviewed-by: Cleber Rosa <crosa@redhat.com> Message-Id: <20200316103203.10046-1-ovoshcha@redhat.com> Signed-off-by: Cleber Rosa <crosa@redhat.com>
* python/qemu/machine: Allow to use other serial consoles than defaultPhilippe Mathieu-Daudé2020-02-071-1/+9
| | | | | | | | | | | | | | | | | | | | | | | Currently the QEMU Python module limits the QEMUMachine class to use the first serial console. Some machines/guest might use another console than the first one as the 'boot console'. For example the Raspberry Pi uses the second (AUX) console. To be able to use the Nth console as default, we simply need to connect all the N - 1 consoles to the null chardev. Add an index argument, so we can use a specific serial console as default. Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Reviewed-by: Liam Merwick <liam.merwick@oracle.com> Tested-by: Liam Merwick <liam.merwick@oracle.com> Reviewed-by: Wainer dos Santos Moschetta <wainersm@redhat.com> Message-Id: <20200120235159.18510-5-f4bug@amsat.org> [PMD: zero-initialize _console_index in __init__()] Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
* python/qemu: Add set_qmp_monitor() to QEMUMachineWainer dos Santos Moschetta2019-12-161-25/+45
| | | | | | | | | | | | | | | | | | | | | The QEMUMachine VM has a monitor setup on which an QMP connection is always attempted on _post_launch() (executed by launch()). In case the QEMU process immediatly exits then the qmp.accept() (used to establish the connection) stalls until it reaches timeout and consequently an exception raises. That behavior is undesirable when, for instance, it needs to gather information from the QEMU binary ($ qemu -cpu list) or a test which launches the VM expecting its failure. This patch adds the set_qmp_monitor() method to QEMUMachine that allows turn off the creation of the monitor machinery on VM launch. Signed-off-by: Wainer dos Santos Moschetta <wainersm@redhat.com> Reviewed-by: Cleber Rosa <crosa@redhat.com> Message-Id: <20191211185536.16962-2-wainersm@redhat.com> [Cleber: trivial indentation fix] Signed-off-by: Cleber Rosa <crosa@redhat.com>
* Python libs: close console sockets before shutting down the VMsCleber Rosa2019-10-291-4/+7
| | | | | | | | | | | | | Currently, the console socket on QEMUMachine is closed after the QMP command to gracefully exit QEMU is executed. Because of a possible deadlock (QEMU waiting for the socket to become writable) let's close the console socket earlier. Reference: <20190607034214.GB22416@habkost.net> Reference: https://bugs.launchpad.net/qemu/+bug/1829779 From: Eduardo Habkost <ehabkost@redhat.com> Signed-off-by: Cleber Rosa <crosa@redhat.com> Message-Id: <20190911023558.4880-2-crosa@redhat.com>
* iotests.py: Store socket files in $SOCK_DIRMax Reitz2019-10-281-3/+12
| | | | | | | | | | | | iotests.py itself does not store socket files, but machine.py and qtest.py do. iotests.py needs to pass the respective path to them, and they need to adhere to it. Signed-off-by: Max Reitz <mreitz@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Reviewed-by: Thomas Huth <thuth@redhat.com> Message-id: 20191017133155.5327-3-mreitz@redhat.com Signed-off-by: Max Reitz <mreitz@redhat.com>
* iotests: Add @has_quit to vm.shutdown()Max Reitz2019-07-191-2/+3
| | | | | | | | | | | If a test has issued a quit command already (which may be useful to do explicitly because the test wants to show its effects), QEMUMachine.shutdown() should not do so again. Otherwise, the VM may well return an ECONNRESET which will lead QEMUMachine.shutdown() to killing it, which then turns into a "qemu received signal 9" line. Signed-off-by: Max Reitz <mreitz@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* machine.py: minor delintingJohn Snow2019-07-021-11/+22
| | | | | | | | | Since we're out in a new module, do a quick cursory pass of some of the more obvious style issues. Signed-off-by: John Snow <jsnow@redhat.com> Message-Id: <20190627212816.27298-3-jsnow@redhat.com> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
* python/qemu: split QEMUMachine out from underneath __init__.pyJohn Snow2019-07-021-0/+520
It's not obvious that something named __init__.py actually houses important code that isn't relevant to python packaging glue. Move the QEMUMachine and related error classes out into their own module. Adjust users to the new import location. Signed-off-by: John Snow <jsnow@redhat.com> Message-Id: <20190627212816.27298-2-jsnow@redhat.com> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>