[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH RFC 29/32] python//qtest.py: Check before accessing _qtest
From: |
Philippe Mathieu-Daudé |
Subject: |
Re: [PATCH RFC 29/32] python//qtest.py: Check before accessing _qtest |
Date: |
Sun, 31 May 2020 12:04:26 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 |
On 5/14/20 7:54 AM, John Snow wrote:
> It can be None; so add assertions or exceptions where appropriate to
> guard the access accordingly.
>
> Signed-off-by: John Snow <jsnow@redhat.com>
> ---
> python/qemu/lib/qtest.py | 14 +++++++++++---
> 1 file changed, 11 insertions(+), 3 deletions(-)
>
> diff --git a/python/qemu/lib/qtest.py b/python/qemu/lib/qtest.py
> index a8be0c782f..05c63a1d58 100644
> --- a/python/qemu/lib/qtest.py
> +++ b/python/qemu/lib/qtest.py
> @@ -126,7 +126,8 @@ def _pre_launch(self):
> super()._pre_launch()
> self._qtest = QEMUQtestProtocol(self._qtest_path, server=True)
>
> - def _post_launch(self):
> + def _post_launch(self) -> None:
> + assert self._qtest is not None
> super()._post_launch()
> self._qtest.accept()
>
> @@ -134,6 +135,13 @@ def _post_shutdown(self):
> super()._post_shutdown()
> self._remove_if_exists(self._qtest_path)
>
> - def qtest(self, cmd):
> - '''Send a qtest command to guest'''
> + def qtest(self, cmd: str) -> str:
> + """
> + Send a qtest command to the guest.
> +
> + :param cmd: qtest command to send
> + :return: qtest server response
> + """
> + if self._qtest is None:
> + raise RuntimeError("qtest socket not available")
> return self._qtest.cmd(cmd)
>
Thanks, applied to my python-next tree:
https://gitlab.com/philmd/qemu/commits/python-next
- [PATCH RFC 23/32] python//machine.py: reorder __init__, (continued)
- [PATCH RFC 23/32] python//machine.py: reorder __init__, John Snow, 2020/05/14
- [PATCH RFC 24/32] python//machine.py: Don't modify state in _base_args(), John Snow, 2020/05/14
- [PATCH RFC 25/32] python//machine.py: Handle None events in event_wait, John Snow, 2020/05/14
- [PATCH RFC 26/32] python//machine.py: use qmp.command, John Snow, 2020/05/14
- [PATCH RFC 28/32] python//machine.py: fix _popen access, John Snow, 2020/05/14
- [PATCH RFC 27/32] python//machine.py: Add _qmp access shim, John Snow, 2020/05/14
- [PATCH RFC 29/32] python//qtest.py: Check before accessing _qtest, John Snow, 2020/05/14
- [PATCH RFC 12/32] python/qemu/lib: fix socket.makefile() typing, John Snow, 2020/05/14
- [PATCH RFC 31/32] python/qemu: add mypy to Pipfile, John Snow, 2020/05/14
- [PATCH RFC 19/32] python//qmp.py: add QMPProtocolError, John Snow, 2020/05/14
- [PATCH RFC 13/32] python/qemu/lib: Adjust traceback typing, John Snow, 2020/05/14
- [PATCH RFC 30/32] python/qemu/lib: make 'args' style arguments immutable, John Snow, 2020/05/14
- [PATCH RFC 32/32] python/qemu/lib: Add mypy type annotations, John Snow, 2020/05/14