Fix flow_config_blaster hanging on network errors 36/23236/4
authorGary Wu <Gary.Wu1@huawei.com>
Wed, 24 Jun 2015 17:36:35 +0000 (10:36 -0700)
committerGerrit Code Review <gerrit@opendaylight.org>
Mon, 29 Jun 2015 22:25:10 +0000 (22:25 +0000)
flow_config_blaster was hanging on network errors
(e.g. bad hostname) and not exiting properly.
This fixes the issue by using thread.join instead
of waiting for a manually tracked thread count.

Also added a default timeout for connections.

Change-Id: I8b858d12393b4f1d70379233f0a6b35e63d95beb
Signed-off-by: Gary Wu <Gary.Wu1@huawei.com>
test/tools/odl-mdsal-clustering-tests/clustering-performance-test/flow_config_blaster.py

index a384085b5121ef2d7ff67a875413e81fd8543693..6bb4715096d8209cc4fe2338613c4e1e5dc6f7e4 100755 (executable)
@@ -54,6 +54,7 @@ class FlowConfigBlaster(object):
     FLWURL = "restconf/config/opendaylight-inventory:nodes/node/openflow:%d/table/0/flow/%d"
     TBLURL = "restconf/config/opendaylight-inventory:nodes/node/openflow:%d/table/0"
     INVURL = 'restconf/operational/opendaylight-inventory:nodes'
+    TIMEOUT = 10
 
     flows = {}
 
@@ -208,9 +209,10 @@ class FlowConfigBlaster(object):
         nodes = self.nnodes
 
         if not self.auth:
-            r = session.get(inventory_url, headers=self.getheaders, stream=False)
+            r = session.get(inventory_url, headers=self.getheaders, stream=False, timeout=self.TIMEOUT)
         else:
-            r = session.get(inventory_url, headers=self.getheaders, stream=False, auth=('admin', 'admin'))
+            r = session.get(inventory_url, headers=self.getheaders, stream=False, auth=('admin', 'admin'),
+                            timeout=self.TIMEOUT)
 
         if r.status_code == 200:
             try:
@@ -262,9 +264,10 @@ class FlowConfigBlaster(object):
         # print flow_url
 
         if not self.auth:
-            r = session.post(flow_url, data=flow_data, headers=self.putheaders, stream=False)
+            r = session.post(flow_url, data=flow_data, headers=self.putheaders, stream=False, timeout=self.TIMEOUT)
         else:
-            r = session.post(flow_url, data=flow_data, headers=self.putheaders, stream=False, auth=('admin', 'admin'))
+            r = session.post(flow_url, data=flow_data, headers=self.putheaders, stream=False, auth=('admin', 'admin'),
+                             timeout=self.TIMEOUT)
 
         return r.status_code
 
@@ -343,9 +346,9 @@ class FlowConfigBlaster(object):
         # print flow_url
 
         if not self.auth:
-            r = session.delete(flow_url, headers=self.getheaders)
+            r = session.delete(flow_url, headers=self.getheaders, timeout=self.TIMEOUT)
         else:
-            r = session.delete(flow_url, headers=self.getheaders, auth=('admin', 'admin'))
+            r = session.delete(flow_url, headers=self.getheaders, auth=('admin', 'admin'), timeout=self.TIMEOUT)
 
         return r.status_code
 
@@ -419,9 +422,8 @@ class FlowConfigBlaster(object):
 
             # Wait for all threads to finish and measure the execution time
             with Timer() as t:
-                while self.threads_done < self.nthreads:
-                    with self.cond:
-                        self.cond.wait()
+                for thread in threads:
+                    thread.join()
 
             with self.print_lock:
                 print '\n*** Test summary:'