[OE-core] [PATCH] masterimage: ignore return status in case of ssh shutdown command

leonardo.sandoval.gonzalez at linux.intel.com leonardo.sandoval.gonzalez at linux.intel.com
Tue Dec 13 21:27:20 UTC 2016


From: Leonardo Sandoval <leonardo.sandoval.gonzalez at linux.intel.com>

There are reported cases (see bugzilla entry below) where ssh process
is killed by the shutdown command it runs, thus the ssh's return
status is non-zero. To ignore the ssh return status, a context manager decorador
is use together with the 'with' statement, ignoring the status of any command
run inside the later body.

[YOCTO #10101]

Signed-off-by: Leonardo Sandoval <leonardo.sandoval.gonzalez at linux.intel.com>
---
 meta/lib/oeqa/controllers/masterimage.py | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/meta/lib/oeqa/controllers/masterimage.py b/meta/lib/oeqa/controllers/masterimage.py
index 9ce3bf8..1054fb4 100644
--- a/meta/lib/oeqa/controllers/masterimage.py
+++ b/meta/lib/oeqa/controllers/masterimage.py
@@ -16,6 +16,7 @@ import bb
 import traceback
 import time
 import subprocess
+from contextlib import contextmanager
 
 import oeqa.targetcontrol
 import oeqa.utils.sshcontrol as sshcontrol
@@ -24,6 +25,15 @@ from oeqa.utils import CommandError
 
 from abc import ABCMeta, abstractmethod
 
+ at contextmanager
+def ignorestatus(conn):
+    previous = conn.ignore_status
+    conn.ignore_status = True
+    try:
+        yield conn
+    finally:
+        conn.ignore_status = previous
+
 class MasterImageHardwareTarget(oeqa.targetcontrol.BaseTarget, metaclass=ABCMeta):
 
     supported_image_fstypes = ['tar.gz', 'tar.bz2']
@@ -103,8 +113,11 @@ class MasterImageHardwareTarget(oeqa.targetcontrol.BaseTarget, metaclass=ABCMeta
 
     def power_cycle(self, conn):
         if self.powercontrol_cmd:
-            # be nice, don't just cut power
-            conn.run("shutdown -h now")
+            # be nice, don't just cut power and ignore status just for shutdown cmd
+            # status is ignore because the ssh connection may be killed by the
+            # shutdown process, thus yielding a non-zero exit status
+            with c = ignorestatus(conn):
+                c.run("shutdown -h now")
             time.sleep(10)
             self.power_ctl("cycle")
         else:
-- 
2.1.4




More information about the Openembedded-core mailing list