Skip to contentSkip to conversation

python: Treat None-return of greeting cmd

PATCH Applied Lukáš Doktor 3 participants 4 messages Jan 20, 2020 – Jan 30, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 python: Treat None-return of greeting cmd

In case qemu process dies the "monitor.cmd" returns None which gets passed to the "__negotiate_capabilities" and leads to unhandled exception. Let's only check the resp in case it has a value.

---
 python/qemu/qmp.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
python/qemu/qmp.py +1 -1
index 5c8cf6a056..a3e5de718a 100644
@@ -73,7 +73,7 @@ class QEMUMonitorProtocol(object):
             raise QMPConnectError
         # Greeting seems ok, negotiate capabilities
         resp = self.cmd('qmp_capabilities')
-        if "return" in resp:
+        if resp and "return" in resp:
             return greeting
         raise QMPCapabilitiesError
 
Signature · 1 line
2.21.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 15 lines · Lukáš Doktor

In case qemu process dies the "monitor.cmd" returns None which gets passed to the "__negotiate_capabilities" and leads to unhandled exception. Let's only check the resp in case it has a value.

---
  python/qemu/qmp.py | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
python/qemu/qmp.py +0 -0
index 5c8cf6a056..a3e5de718a 100644

python/qemu/qmp.py class QEMUMonitorProtocol(object): · line 79

Quoted 8 lines
python/qemu/qmp.py +1 -1
@@ -73,7 +73,7 @@ class QEMUMonitorProtocol(object):
              raise QMPConnectError
          # Greeting seems ok, negotiate capabilities
          resp = self.cmd('qmp_capabilities')
-        if "return" in resp:
+        if resp and "return" in resp:
              return greeting
          raise QMPCapabilitiesError
 
Reviewed-by on v1 1/1
#2 lore raw
In reply to Lukáš Doktor
Quoted 8 lines · Lukáš Doktor

In case qemu process dies the "monitor.cmd" returns None which gets passed to the "__negotiate_capabilities" and leads to unhandled exception. Let's only check the resp in case it has a value.

---
  python/qemu/qmp.py | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 14 lines
python/qemu/qmp.py +1 -1
index 5c8cf6a056..a3e5de718a 100644
@@ -73,7 +73,7 @@ class QEMUMonitorProtocol(object):
              raise QMPConnectError
          # Greeting seems ok, negotiate capabilities
          resp = self.cmd('qmp_capabilities')
-        if "return" in resp:
+        if resp and "return" in resp:
              return greeting
          raise QMPCapabilitiesError
 
#3 lore raw
In reply to Lukáš Doktor
Quoted 15 lines · Lukáš Doktor

In case qemu process dies the "monitor.cmd" returns None which gets passed to the "__negotiate_capabilities" and leads to unhandled exception. Let's only check the resp in case it has a value.

---
  python/qemu/qmp.py | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
python/qemu/qmp.py +0 -0
index 5c8cf6a056..a3e5de718a 100644

python/qemu/qmp.py class QEMUMonitorProtocol(object): · line 79

Quoted 8 lines
python/qemu/qmp.py +1 -1
@@ -73,7 +73,7 @@ class QEMUMonitorProtocol(object):
              raise QMPConnectError
          # Greeting seems ok, negotiate capabilities
          resp = self.cmd('qmp_capabilities')
-        if "return" in resp:
+        if resp and "return" in resp:
              return greeting
          raise QMPCapabilitiesError
 

Thanks, applied to my python-next tree:
https://gitlab.com/philmd/qemu/commits/python-next