All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Aníbal Limón" <anibal.limon@linux.intel.com>
To: yocto@yoctoproject.org
Cc: richard.purdie@intel.com, benjamin.esquivel@intel.com
Subject: [[PATCH][qa-tools] 08/16] toaster/helper.py: Add force mode to stop method.
Date: Tue,  9 Feb 2016 16:43:17 -0600	[thread overview]
Message-ID: <1455057798-3213-9-git-send-email-anibal.limon@linux.intel.com> (raw)
In-Reply-To: <1455057798-3213-1-git-send-email-anibal.limon@linux.intel.com>

The stop method have force mode because toaster without production
setup have known issues when is on load, the server response 503
service unavailable.

This mode iterates over process to found PID's of toaster instance
then sends SIGKILL to it.

Signed-off-by: Aníbal Limón <anibal.limon@linux.intel.com>
---
 requeriments.txt         |  1 +
 tests/toaster/helpers.py | 38 ++++++++++++++++++++++++++++++++++----
 2 files changed, 35 insertions(+), 4 deletions(-)

diff --git a/requeriments.txt b/requeriments.txt
index 9ee5047..89a735d 100644
--- a/requeriments.txt
+++ b/requeriments.txt
@@ -2,3 +2,4 @@ python-bugzilla==1.2.2
 
 # toaster requirements
 selenium
+proc
diff --git a/tests/toaster/helpers.py b/tests/toaster/helpers.py
index 98b65e0..753bbf0 100644
--- a/tests/toaster/helpers.py
+++ b/tests/toaster/helpers.py
@@ -4,6 +4,8 @@ import shutil
 import signal
 import tempfile
 
+from proc.core import find_processes
+
 TOASTER_TEST_BRANCH = 'toaster_tests'
 VENV_NAME = 'venv'
 SHELL_CMD = os.environ['SHELL'] if 'SHELL' in os.environ else "/bin/bash"
@@ -73,7 +75,35 @@ class ToasterHelper(object):
             "source %s/oe-init-build-env; source %s/bitbake/bin/toaster start" % \
             (self.directory, self.directory))
 
-    def stop(self):
-        return self._execute_command_venv(VENV_NAME,
-            "source %s/oe-init-build-env; source %s/bitbake/bin/toaster stop" % \
-            (self.directory, self.directory))
+    def _stop_force(self):
+        """
+            The _stop_force method iterates over the /proc and search for toaster path
+            in the process cmdline then send SIGKILL for every matched process.
+        """
+        pids = []
+        for p in find_processes():
+            if len(p.cmdline) > 1 and \
+                os.path.basename(p.cmdline[0]) == 'python' and \
+                p.cmdline[1].startswith(self.directory):
+                    pids.append(p.pid)
+
+        for pid in pids:
+            try:
+                os.kill(pid, signal.SIGKILL)
+            except:
+                pass
+
+        return ''
+
+    def stop(self, force=False):
+        """
+            The stop method have force mode because toaster without production 
+            setup have known issues when is on load, the server response 503
+            service unavailable.
+        """
+        if force:
+            return self._stop_force()
+        else:
+            return self._execute_command_venv(VENV_NAME,
+                "source %s/oe-init-build-env; source %s/bitbake/bin/toaster stop" % \
+                (self.directory, self.directory))
-- 
2.1.4



  parent reply	other threads:[~2016-02-09 22:41 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-09 22:43 [[PATCH][qa-tools] 00/16] Add Toaster test suite support Aníbal Limón
2016-02-09 22:43 ` [[PATCH][qa-tools] 01/16] README.md: Update instructions on how install host deps on debian Aníbal Limón
2016-02-09 22:43 ` [[PATCH][qa-tools] 02/16] utils/run/toaster.sh: Get rid of toaster shell script Aníbal Limón
2016-02-09 22:43 ` [[PATCH][qa-tools] 03/16] toaster: Add helpers for clone, setup, start and stop Aníbal Limón
2016-02-09 22:43 ` [[PATCH][qa-tools] 04/16] tests/toaster/__init__.py: Add support for clone/setup/start/stop Aníbal Limón
2016-02-09 22:43 ` [[PATCH][qa-tools] 05/16] tests/toaster/helpers.py: When execute bash remove interactive mode Aníbal Limón
2016-02-09 22:43 ` [[PATCH][qa-tools] 06/16] tests/toaster/helpers.py: Fix toaster_start deadlocks Aníbal Limón
2016-02-09 22:43 ` [[PATCH][qa-tools] 07/16] ts/toaster/helpers.py: Add new class ToasterHelper instead functions Aníbal Limón
2016-02-09 22:43 ` Aníbal Limón [this message]
2016-02-09 22:43 ` [[PATCH][qa-tools] 09/16] toaster/__init__.py: Update toaster test to match new ToasterHelper Aníbal Limón

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=1455057798-3213-9-git-send-email-anibal.limon@linux.intel.com \
    --to=anibal.limon@linux.intel.com \
    --cc=benjamin.esquivel@intel.com \
    --cc=richard.purdie@intel.com \
    --cc=yocto@yoctoproject.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.