Skip to contentSkip to conversation

qemurunner: Improves checking for Server and Target IPs on qemus parameters

PATCH Superseded Alejandro Hernandez 2 participants 2 messages Aug 5, 2015 – Aug 6, 2015 1 message not in the archive

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#1 lore raw

PATCH 1/1 qemurunner: Improves checking for Server and Target IPs on qemus parameters

In reply to a message not in the archive

Fixes server hanging infinitely waiting for qemus process to let go of bitbake.lock

---
 meta/lib/oeqa/utils/qemurunner.py | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
meta/lib/oeqa/utils/qemurunner.py +8 -5
index 1cf8f76..ff53af3 100644
@@ -120,14 +120,17 @@ class QemuRunner:
             cmdline = ''
             with open('/proc/%s/cmdline' % self.qemupid) as p:
                 cmdline = p.read()
-            ips = re.findall("((?:[0-9]{1,3}\.){3}[0-9]{1,3})", cmdline.split("ip=")[1])
-            if not ips or len(ips) != 3:
+	    try:
+                ips = re.findall("((?:[0-9]{1,3}\.){3}[0-9]{1,3})", cmdline.split("ip=")[1])
+                if not ips or len(ips) != 3:
+	            raise Exception
+                else:
+                    self.ip = ips[0]
+                    self.server_ip = ips[1]
+	    except Exception:
                 logger.info("Couldn't get ip from qemu process arguments! Here is the qemu command line used: %s" % cmdline)
                 self.stop()
                 return False
-            else:
-                self.ip = ips[0]
-                self.server_ip = ips[1]
             logger.info("Target IP: %s" % self.ip)
             logger.info("Server IP: %s" % self.server_ip)
             logger.info("Waiting at most %d seconds for login banner" % self.boottime)
Signature · 1 line
1.8.4.5
#2 lore raw
Quoted 24 lines · Alejandro Hernandez

Fixes server hanging infinitely waiting for qemus process to let go of bitbake.lock

---
 meta/lib/oeqa/utils/qemurunner.py | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
meta/lib/oeqa/utils/qemurunner.py +7 -2
index 1cf8f76..ff53af3 100644
@@ -120,14 +120,17 @@ class QemuRunner:
             cmdline = ''
             with open('/proc/%s/cmdline' % self.qemupid) as p:
                 cmdline = p.read()
-            ips = re.findall("((?:[0-9]{1,3}\.){3}[0-9]{1,3})", cmdline.split("ip=")[1])
-            if not ips or len(ips) != 3:
+	    try:
+                ips = re.findall("((?:[0-9]{1,3}\.){3}[0-9]{1,3})", cmdline.split("ip=")[1])
+                if not ips or len(ips) != 3:
+	            raise Exception
+                else:
+                    self.ip = ips[0]
+                    self.server_ip = ips[1]

meta/lib/oeqa/utils/qemurunner.py class QemuRunner: · line 136

Quoted 10 lines
meta/lib/oeqa/utils/qemurunner.py +1 -3
+	    except Exception:
                 logger.info("Couldn't get ip from qemu process arguments! Here is the qemu command line used: %s" % cmdline)
                 self.stop()
                 return False
-            else:
-                self.ip = ips[0]
-                self.server_ip = ips[1]
             logger.info("Target IP: %s" % self.ip)
             logger.info("Server IP: %s" % self.server_ip)
             logger.info("Waiting at most %d seconds for login banner" % self.boottime)

This is ok, however its not as pythonic as perhaps it could/should be. Usually with python you should always trap specific exceptions, so in this case you'd do:

try:

    y = x[1]
    if len(ips) != 3:
        raise ValueError

except IndexError, ValueError:
<handle error>

You do this so that if something unexpected happens, the code doesn't "swallow" the error but shows a complete traceback and failure.

The whitespace on this patch also looks a little bit odd although I didn't try applying the patch.

Cheers,

Richard