aboutsummaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorJohn Snow <jsnow@redhat.com>2020-05-14 01:54:00 -0400
committerPhilippe Mathieu-Daudé <philmd@redhat.com>2020-05-31 18:25:31 +0200
commitc95dddce4910c9cd5315b942180b03ca4e48a6a6 (patch)
treeb91ed748056c060d45638cda74a47a7ac818be2a /python
parentde210ec53c842fa67aa10110a7a351d64f91c487 (diff)
downloadqemu-c95dddce4910c9cd5315b942180b03ca4e48a6a6.zip
qemu-c95dddce4910c9cd5315b942180b03ca4e48a6a6.tar.gz
qemu-c95dddce4910c9cd5315b942180b03ca4e48a6a6.tar.bz2
python/qemu/qtest: Check before accessing _qtest
It can be None; so add assertions or exceptions where appropriate to guard the access accordingly. Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> Message-Id: <20200514055403.18902-30-jsnow@redhat.com> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Diffstat (limited to 'python')
-rw-r--r--python/qemu/qtest.py14
1 files changed, 11 insertions, 3 deletions
diff --git a/python/qemu/qtest.py b/python/qemu/qtest.py
index 4c88590..888c8bd 100644
--- a/python/qemu/qtest.py
+++ b/python/qemu/qtest.py
@@ -121,7 +121,8 @@ class QEMUQtestMachine(QEMUMachine):
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()
@@ -129,6 +130,13 @@ class QEMUQtestMachine(QEMUMachine):
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)