review sims/tpce process management in 2.2.1 tests
[transportpce.git] / tests / transportpce_tests / 2.2.1 / test_utils.py
index 79d8fdbaffe383828a7cbe777305215cf1221de9..5402eae5b4610b236cb8de6a77e90a8932e1cc6c 100644 (file)
@@ -35,6 +35,7 @@ TYPE_APPLICATION_JSON = {'content-type': 'application/json'}
 honeynode_executable = os.path.join(
     os.path.dirname(os.path.realpath(__file__)),
     "..", "..", "honeynode", "2.2.1", "honeynode-simulator", "honeycomb-tpce")
+
 samples_directory = os.path.join(
     os.path.dirname(os.path.realpath(__file__)),
     "..", "..", "sample_configs", "openroadm", "2.2.1")
@@ -45,16 +46,23 @@ karaf_log = os.path.join(
     os.path.dirname(os.path.realpath(__file__)),
     "..", "..", "..", "karaf", "target", "assembly", "data", "log", "karaf.log")
 
+process_list = []
 
-def start_sim(sim):
-    print("starting simulator for " + sim + "...")
-    log_file = os.path.join(log_directory, sims[sim]['logfile'])
-    process = start_honeynode(log_file, sims[sim]['port'], sims[sim]['configfile'])
-    if wait_until_log_contains(log_file, HONEYNODE_OK_START_MSG, 5000):
-        print("simulator for " + sim + " started")
-    else:
-        print("simulator for " + sim + "failed to start")
-    return process
+def start_sims(sims_list):
+    for sim in sims_list:
+        print("starting simulator for " + sim + "...")
+        log_file = os.path.join(log_directory, sims[sim]['logfile'])
+        process = start_honeynode(log_file, sims[sim]['port'], sims[sim]['configfile'])
+        if wait_until_log_contains(log_file, HONEYNODE_OK_START_MSG, 100):
+            print("simulator for " + sim + " started")
+        else:
+            print("simulator for " + sim + " failed to start")
+            shutdown_process(process)
+            for pid in process_list:
+                shutdown_process(pid)
+            exit(3)
+        process_list.append(process)
+    return process_list
 
 
 def start_tpce():
@@ -69,8 +77,11 @@ def start_tpce():
         else:
             print("opendaylight failed to start")
             shutdown_process(process)
+            for pid in process_list:
+                shutdown_process(pid)
             exit(1)
-    return process
+    process_list.append(process)
+    return process_list
 
 
 def start_karaf():