make test: handle exceptions from VppPapiProvider.__init__
[vpp.git] / test / framework.py
index 227428e..5a9aba2 100644 (file)
@@ -177,6 +177,7 @@ class VppTestCase(unittest.TestCase):
         cls.pg_streams = []
         cls.packet_infos = {}
         cls.verbose = 0
+        cls.vpp_dead = False
         print(double_line_delim)
         print(colorize(getdoc(cls).splitlines()[0], YELLOW))
         print(double_line_delim)
@@ -184,13 +185,22 @@ class VppTestCase(unittest.TestCase):
         # doesn't get called and we might end with a zombie vpp
         try:
             cls.run_vpp()
-            cls.vpp_dead = False
+            cls.vpp_stdout_queue = Queue()
+            cls.vpp_stdout_reader_thread = Thread(target=pump_output, args=(
+                cls.vpp.stdout, cls.vpp_stdout_queue))
+            cls.vpp_stdout_reader_thread.start()
+            cls.vpp_stderr_queue = Queue()
+            cls.vpp_stderr_reader_thread = Thread(target=pump_output, args=(
+                cls.vpp.stderr, cls.vpp_stderr_queue))
+            cls.vpp_stderr_reader_thread.start()
             cls.vapi = VppPapiProvider(cls.shm_prefix, cls.shm_prefix)
             if cls.step:
-                cls.vapi.register_hook(StepHook(cls))
+                hook = StepHook(cls)
             else:
-                cls.vapi.register_hook(PollHook(cls))
+                hook = PollHook(cls)
+            cls.vapi.register_hook(hook)
             time.sleep(0.1)
+            hook.poll_vpp()
             try:
                 cls.vapi.connect()
             except:
@@ -199,19 +209,13 @@ class VppTestCase(unittest.TestCase):
                                    "VPP-API connection failed, did you forget "
                                    "to 'continue' VPP from within gdb?", RED))
                 raise
-            cls.vpp_stdout_queue = Queue()
-            cls.vpp_stdout_reader_thread = Thread(
-                target=pump_output, args=(cls.vpp.stdout, cls.vpp_stdout_queue))
-            cls.vpp_stdout_reader_thread.start()
-            cls.vpp_stderr_queue = Queue()
-            cls.vpp_stderr_reader_thread = Thread(
-                target=pump_output, args=(cls.vpp.stderr, cls.vpp_stderr_queue))
-            cls.vpp_stderr_reader_thread.start()
         except:
-            if hasattr(cls, 'vpp'):
-                cls.vpp.terminate()
-                del cls.vpp
-            raise
+            t, v, tb = sys.exc_info()
+            try:
+                cls.quit()
+            except:
+                pass
+            raise t, v, tb
 
     @classmethod
     def quit(cls):
@@ -228,7 +232,8 @@ class VppTestCase(unittest.TestCase):
                           " and finish running the testcase...")
 
         if hasattr(cls, 'vpp'):
-            cls.vapi.disconnect()
+            if hasattr(cls, 'vapi'):
+                cls.vapi.disconnect()
             cls.vpp.poll()
             if cls.vpp.returncode is None:
                 cls.vpp.terminate()
@@ -265,8 +270,8 @@ class VppTestCase(unittest.TestCase):
     def tearDown(self):
         """ Show various debug prints after each test """
         if not self.vpp_dead:
-            self.logger.info(self.vapi.ppcli("show int"))
             self.logger.debug(self.vapi.cli("show trace"))
+            self.logger.info(self.vapi.ppcli("show int"))
             self.logger.info(self.vapi.ppcli("show hardware"))
             self.logger.info(self.vapi.ppcli("show error"))
             self.logger.info(self.vapi.ppcli("show run"))