[yocto] [[PATCH][qa-tools] 08/16] toaster/helper.py: Add force mode to stop method.

Aníbal Limón anibal.limon at linux.intel.com
Tue Feb 9 14:43:17 PST 2016


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 at 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




More information about the yocto mailing list