Openembedded Core Discussions
 help / color / mirror / Atom feed
* [PATCH 1/1] qemurunner: Improves checking for Server and Target IPs on qemus parameters
       [not found] <cover.1438816804.git.alejandro.hernandez@linux.intel.com>
@ 2015-08-05 23:21 ` Alejandro Hernandez
  2015-08-06 14:21   ` Richard Purdie
  0 siblings, 1 reply; 2+ messages in thread
From: Alejandro Hernandez @ 2015-08-05 23:21 UTC (permalink / raw)
  To: openembedded-core

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

Signed-off-by: Alejandro Hernandez <alejandro.hernandez@linux.intel.com>
---
 meta/lib/oeqa/utils/qemurunner.py | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/meta/lib/oeqa/utils/qemurunner.py b/meta/lib/oeqa/utils/qemurunner.py
index 1cf8f76..ff53af3 100644
--- a/meta/lib/oeqa/utils/qemurunner.py
+++ b/meta/lib/oeqa/utils/qemurunner.py
@@ -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)
-- 
1.8.4.5



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH 1/1] qemurunner: Improves checking for Server and Target IPs on qemus parameters
  2015-08-05 23:21 ` [PATCH 1/1] qemurunner: Improves checking for Server and Target IPs on qemus parameters Alejandro Hernandez
@ 2015-08-06 14:21   ` Richard Purdie
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Purdie @ 2015-08-06 14:21 UTC (permalink / raw)
  To: Alejandro Hernandez; +Cc: openembedded-core

On Wed, 2015-08-05 at 23:21 +0000, Alejandro Hernandez wrote:
> Fixes server hanging infinitely waiting for qemus process to let go of bitbake.lock
> 
> Signed-off-by: Alejandro Hernandez <alejandro.hernandez@linux.intel.com>
> ---
>  meta/lib/oeqa/utils/qemurunner.py | 13 ++++++++-----
>  1 file changed, 8 insertions(+), 5 deletions(-)
> 
> diff --git a/meta/lib/oeqa/utils/qemurunner.py b/meta/lib/oeqa/utils/qemurunner.py
> index 1cf8f76..ff53af3 100644
> --- a/meta/lib/oeqa/utils/qemurunner.py
> +++ b/meta/lib/oeqa/utils/qemurunner.py
> @@ -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)

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



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-08-06 14:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <cover.1438816804.git.alejandro.hernandez@linux.intel.com>
2015-08-05 23:21 ` [PATCH 1/1] qemurunner: Improves checking for Server and Target IPs on qemus parameters Alejandro Hernandez
2015-08-06 14:21   ` Richard Purdie

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox