From: leonardo.sandoval.gonzalez@linux.intel.com
To: openembedded-core@lists.openembedded.org
Subject: [PATCH] masterimage: ignore return status in case of ssh shutdown command
Date: Tue, 13 Dec 2016 15:27:20 -0600 [thread overview]
Message-ID: <1481664440-6184-1-git-send-email-leonardo.sandoval.gonzalez@linux.intel.com> (raw)
From: Leonardo Sandoval <leonardo.sandoval.gonzalez@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@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
+@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
reply other threads:[~2016-12-13 21:21 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1481664440-6184-1-git-send-email-leonardo.sandoval.gonzalez@linux.intel.com \
--to=leonardo.sandoval.gonzalez@linux.intel.com \
--cc=openembedded-core@lists.openembedded.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox