qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Damien Hedde <damien.hedde@greensocs.com>
To: qemu-devel@nongnu.org
Cc: Damien Hedde <damien.hedde@greensocs.com>,
	Eduardo Habkost <eduardo@habkost.net>,
	John Snow <jsnow@redhat.com>, Cleber Rosa <crosa@redhat.com>
Subject: [PATCH 3/5] python: qmp_shell: refactor disconnection handling
Date: Mon, 21 Feb 2022 16:55:17 +0100	[thread overview]
Message-ID: <20220221155519.2367-4-damien.hedde@greensocs.com> (raw)
In-Reply-To: <20220221155519.2367-1-damien.hedde@greensocs.com>

Introduce QMPShellConnectError (subclass of QMPShellError)
to handle disconnection in read_exec_command().

Signed-off-by: Damien Hedde <damien.hedde@greensocs.com>
---
 python/qemu/aqmp/qmp_shell.py | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/python/qemu/aqmp/qmp_shell.py b/python/qemu/aqmp/qmp_shell.py
index a1bd7d5630..cce7732ba2 100644
--- a/python/qemu/aqmp/qmp_shell.py
+++ b/python/qemu/aqmp/qmp_shell.py
@@ -142,6 +142,12 @@ class QMPShellParseError(QMPShellError):
     """
 
 
+class QMPShellConnectError(QMPShellError):
+    """
+    QMP Shell Connect error class.
+    """
+
+
 class FuzzyJSON(ast.NodeTransformer):
     """
     This extension of ast.NodeTransformer filters literal "true/false/null"
@@ -347,8 +353,7 @@ def _execute_cmd(self, cmdline: str) -> bool:
             self._print(qmpcmd)
         resp = self.cmd_obj(qmpcmd)
         if resp is None:
-            print('Disconnected')
-            return False
+            raise QMPShellConnectError('Disconnected')
         self._print(resp)
         return True
 
@@ -400,6 +405,9 @@ def read_exec_command(self) -> bool:
             return self._execute_cmd(cmdline)
         except QMPShellParseError as err:
             self._print_parse_error(err)
+        except QMPShellConnectError as err:
+            print(f"{err!s}");
+            return False
         return True
 
     def repl(self) -> Iterator[None]:
@@ -481,8 +489,7 @@ def _execute_cmd(self, cmdline: str) -> bool:
                 raise QMPShellParseError('cpu command takes an integer argument')
         resp = self._cmd_passthrough(cmdline, self._cpu_index)
         if resp is None:
-            print('Disconnected')
-            return False
+            raise QMPShellConnectError('Disconnected')
         assert 'return' in resp or 'error' in resp
         if 'return' in resp:
             # Success
-- 
2.35.1



  parent reply	other threads:[~2022-02-21 16:12 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-21 15:55 [PATCH 0/5] qmp-shell modifications for non-interactive use Damien Hedde
2022-02-21 15:55 ` [PATCH 1/5] python: qmp_shell: don't prompt when stdin is non-interactive Damien Hedde
2022-02-21 15:55 ` [PATCH 2/5] python: qmp_shell: refactor the parsing error handling Damien Hedde
2022-02-21 15:55 ` Damien Hedde [this message]
2022-02-21 15:55 ` [PATCH 4/5] python: qmp_shell: add -e/--exit-on-error option Damien Hedde
2022-02-23 15:22   ` John Snow
2022-02-23 15:27     ` Daniel P. Berrangé
2022-02-23 15:41       ` John Snow
2022-02-23 15:44         ` Daniel P. Berrangé
2022-02-23 16:18           ` John Snow
2022-02-23 17:09             ` Damien Hedde
2022-02-23 18:20               ` John Snow
2022-02-24 11:20                 ` Damien Hedde
2022-02-23 17:50             ` Daniel P. Berrangé
2022-02-23 16:43           ` Damien Hedde
2022-02-23 16:46             ` Damien Hedde
2022-02-21 15:55 ` [PATCH 5/5] python: qmp_shell: handle comment lines and escaped eol Damien Hedde
2022-02-22  6:10 ` [PATCH 0/5] qmp-shell modifications for non-interactive use Markus Armbruster
2022-02-22  7:57   ` Damien Hedde
2022-02-22  9:21     ` Daniel P. Berrangé
2022-02-22  9:38       ` Damien Hedde
2022-02-22 10:31         ` Daniel P. Berrangé
2022-02-23  9:57           ` Damien Hedde
2022-02-23 11:13             ` Daniel P. Berrangé
2022-02-23 15:01               ` John Snow
2022-02-23 15:08                 ` Daniel P. Berrangé
2022-02-22  9:52     ` Markus Armbruster
2022-02-25 20:40 ` John Snow

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220221155519.2367-4-damien.hedde@greensocs.com \
    --to=damien.hedde@greensocs.com \
    --cc=crosa@redhat.com \
    --cc=eduardo@habkost.net \
    --cc=jsnow@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).