[dts] [PATCH V1 1/2] QMP: optimization file qemu-ga-client and qmp.py

Xie, WeiX weix.xie at intel.com
Fri Jun 5 09:48:26 CEST 2020


Tested-by:  Xie,WeiX < weix.xie at intel.com>

Regards,
Xie Wei


-----Original Message-----
From: Ma, LihongX 
Sent: Thursday, June 4, 2020 9:38 AM
To: dts at dpdk.org; Xie, WeiX <weix.xie at intel.com>
Cc: Ma, LihongX <lihongx.ma at intel.com>
Subject: [dts][PATCH V1 1/2] QMP: optimization file qemu-ga-client and qmp.py

1. modify code to support python3
2. return None string if file not exist when use cat command

Signed-off-by: lihong <lihongx.ma at intel.com>
---
 dep/QMP/qemu-ga-client | 10 ++++++----
 dep/QMP/qmp.py         |  4 ++--
 2 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/dep/QMP/qemu-ga-client b/dep/QMP/qemu-ga-client index 46676c3..caf44b1 100755
--- a/dep/QMP/qemu-ga-client
+++ b/dep/QMP/qemu-ga-client
@@ -68,7 +68,7 @@ class QemuGuestAgentClient:
 
     def __file_read_all(self, handle):
         eof = False
-        data = ''
+        data = b''
         while not eof:
             ret = self.qga.file_read(handle=handle, count=1024)
             _data = base64.b64decode(ret['buf-b64']) @@ -77,7 +77,10 @@ class QemuGuestAgentClient:
         return data
 
     def read(self, path):
-        handle = self.qga.file_open(path=path)
+        try:
+            handle = self.qga.file_open(path=path)
+        except:
+            return ''
         try:
             data = self.__file_read_all(handle)
         finally:
@@ -162,7 +165,6 @@ class QemuGuestAgentClient:
         except self.qga.timeout:
             return
 
-
 def _cmd_cat(client, args):
     if len(args) != 1:
         print('Invalid argument')
@@ -259,7 +261,7 @@ def main(address, cmd, args):
 
     try:
         client = QemuGuestAgentClient(address)
-    except QemuGuestAgent.error, e:
+    except QemuGuestAgent.error as e:
         import errno
 
         print(e)
diff --git a/dep/QMP/qmp.py b/dep/QMP/qmp.py index 9e6f4cf..430887d 100755
--- a/dep/QMP/qmp.py
+++ b/dep/QMP/qmp.py
@@ -108,7 +108,7 @@ class QEMUMonitorProtocol:
                 been closed
         """
         try:
-            self.__sock.sendall(json.dumps(qmp_cmd))
+            self.__sock.sendall(str.encode(json.dumps(qmp_cmd)))
         except socket.error as err:
             if err[0] == errno.EPIPE:
                 return
@@ -135,7 +135,7 @@ class QEMUMonitorProtocol:
         if not ret:
             return
         else:
-            if 'error' in ret:
+            if 'error' in ret.keys():
                 raise Exception(ret['error']['desc'])
             return ret['return']
 
--
2.7.4

-------------- next part --------------
A non-text attachment was scrubbed...
Name: TestVmHotplug.log
Type: application/octet-stream
Size: 7263124 bytes
Desc: TestVmHotplug.log
URL: <http://mails.dpdk.org/archives/dts/attachments/20200605/1343ce1c/attachment-0001.obj>


More information about the dts mailing list