Add process group so can kill possible hanging subprocesses. 75/52075/2
authorTomi Juvonen <tomi.juvonen@nokia.com>
Tue, 13 Feb 2018 06:32:43 +0000 (08:32 +0200)
committerTomi Juvonen <tomi.juvonen@nokia.com>
Wed, 14 Feb 2018 06:50:56 +0000 (08:50 +0200)
This should be workaround before actual fix is done.

JIRA: DOCTOR-123

Change-Id: I70fd4ed9d2aa2cc3a6c46e2515062b7acd31ca0a
Signed-off-by: Tomi Juvonen <tomi.juvonen@nokia.com>
doctor_tests/main.py

index 5bd3c59..efbd8c6 100644 (file)
@@ -9,6 +9,7 @@
 import os
 from os.path import isfile, join
 import random
+import signal
 import sys
 import time
 
@@ -180,13 +181,11 @@ class DoctorTest(object):
         num = random.randint(0, self.conf.instance_count - 1)
         vm_name = "%s%d" % (self.conf.instance_basename, num)
 
-        servers = \
-            {getattr(server, 'name'): server
-             for server in self.nova.servers.list()}
+        servers = {getattr(server, 'name'): server
+                   for server in self.nova.servers.list()}
         server = servers.get(vm_name)
         if not server:
-            raise \
-                Exception('Can not find instance: vm_name(%s)' % vm_name)
+            raise Exception('Can not find instance: vm_name(%s)' % vm_name)
         host_name = server.__dict__.get('OS-EXT-SRV-ATTR:hypervisor_hostname')
         host_ip = self.installer.get_host_ip_from_hostname(host_name)
 
@@ -231,16 +230,16 @@ class DoctorTest(object):
         # TODO(yujunz) check the actual delay to verify time sync status
         # expected ~1s delay from $trigger to $linkdown
         relative_start = linkdown
-        os.environ['DOCTOR_PROFILER_T00'] = \
-            str(int((linkdown - relative_start) * 1000))
-        os.environ['DOCTOR_PROFILER_T01'] = \
-            str(int((detected - relative_start) * 1000))
-        os.environ['DOCTOR_PROFILER_T03'] = \
-            str(int((vmdown - relative_start) * 1000))
-        os.environ['DOCTOR_PROFILER_T04'] = \
-            str(int((hostdown - relative_start) * 1000))
-        os.environ['DOCTOR_PROFILER_T09'] = \
-            str(int((notified - relative_start) * 1000))
+        os.environ['DOCTOR_PROFILER_T00'] = (
+            str(int((linkdown - relative_start) * 1000)))
+        os.environ['DOCTOR_PROFILER_T01'] = (
+            str(int((detected - relative_start) * 1000)))
+        os.environ['DOCTOR_PROFILER_T03'] = (
+            str(int((vmdown - relative_start) * 1000)))
+        os.environ['DOCTOR_PROFILER_T04'] = (
+            str(int((hostdown - relative_start) * 1000)))
+        os.environ['DOCTOR_PROFILER_T09'] = (
+            str(int((notified - relative_start) * 1000)))
 
         profiler_main(log=LOG)
 
@@ -258,10 +257,16 @@ class DoctorTest(object):
         self.installer.cleanup()
         self.image.delete()
         self.user.delete()
+        # Kill possible hanging subprocess
+        os.killpg(0, signal.SIGKILL)
 
 
 def main():
     """doctor main"""
+    # TODO (tojuvone): JIRA DOCTOR-123: Test cases have some issue to always
+    # kill all subprocesses. To ensure they are killed this group is done so
+    # all processes can be killed without knowing what they are.
+    os.setpgrp()
     test_dir = os.path.split(os.path.realpath(__file__))[0]
     doctor_root_dir = os.path.dirname(test_dir)