review sims/tpce process management in 2.2.1 tests 71/90471/3
authorguillaume.lambert <guillaume.lambert@orange.com>
Wed, 17 Jun 2020 22:07:51 +0000 (00:07 +0200)
committerguillaume.lambert <guillaume.lambert@orange.com>
Mon, 22 Jun 2020 08:09:31 +0000 (10:09 +0200)
Change-Id: I441312ada9b10f498d86fcb1fd6fda0aa0be4d3f
Signed-off-by: guillaume.lambert <guillaume.lambert@orange.com>
tests/transportpce_tests/2.2.1/test_end2end.py
tests/transportpce_tests/2.2.1/test_olm.py
tests/transportpce_tests/2.2.1/test_otn_renderer.py
tests/transportpce_tests/2.2.1/test_otn_topology.py
tests/transportpce_tests/2.2.1/test_portmapping.py
tests/transportpce_tests/2.2.1/test_renderer_service_path_nominal.py
tests/transportpce_tests/2.2.1/test_tapi.py
tests/transportpce_tests/2.2.1/test_topoPortMapping.py
tests/transportpce_tests/2.2.1/test_topology.py
tests/transportpce_tests/2.2.1/test_utils.py

index 44636a11b7caba7f104e0fba1e473364e608381c..8e33de6aac192c59d80178feeefaf31cea286ef2 100644 (file)
@@ -23,58 +23,24 @@ import test_utils
 
 class TransportPCEFulltesting(unittest.TestCase):
 
-    odl_process = None
-    sim_process1 = None
-    sim_process2 = None
-    sim_process3 = None
-    sim_process4 = None
+    processes = None
     restconf_baseurl = "http://localhost:8181/restconf"
     WAITING = 20  # nominal value is 300
 
-# START_IGNORE_XTESTING
-
     @classmethod
     def setUpClass(cls):
-        cls.odl_process = test_utils.start_tpce()
-        cls.sim_process1 = test_utils.start_sim('xpdra')
-        cls.sim_process2 = test_utils.start_sim('roadma')
-        cls.sim_process3 = test_utils.start_sim('roadmc')
-        cls.sim_process4 = test_utils.start_sim('xpdrc')
+        cls.processes = test_utils.start_tpce()
+        cls.processes = test_utils.start_sims(['xpdra', 'roadma', 'roadmc', 'xpdrc'])
 
     @classmethod
     def tearDownClass(cls):
-        for child in psutil.Process(cls.odl_process.pid).children():
-            child.send_signal(signal.SIGINT)
-            child.wait()
-        cls.odl_process.send_signal(signal.SIGINT)
-        cls.odl_process.wait()
-        for child in psutil.Process(cls.sim_process1.pid).children():
-            child.send_signal(signal.SIGINT)
-            child.wait()
-        cls.sim_process1.send_signal(signal.SIGINT)
-        cls.sim_process1.wait()
-        for child in psutil.Process(cls.sim_process2.pid).children():
-            child.send_signal(signal.SIGINT)
-            child.wait()
-        cls.sim_process2.send_signal(signal.SIGINT)
-        cls.sim_process2.wait()
-        for child in psutil.Process(cls.sim_process3.pid).children():
-            child.send_signal(signal.SIGINT)
-            child.wait()
-        cls.sim_process3.send_signal(signal.SIGINT)
-        cls.sim_process3.wait()
-        for child in psutil.Process(cls.sim_process4.pid).children():
-            child.send_signal(signal.SIGINT)
-            child.wait()
-        cls.sim_process4.send_signal(signal.SIGINT)
-        cls.sim_process4.wait()
+        for process in cls.processes:
+            test_utils.shutdown_process(process)
         print("all processes killed")
 
     def setUp(self):  # instruction executed before each test method
         print("execution of {}".format(self.id().split(".")[-1]))
 
-# END_IGNORE_XTESTING
-
 #  connect netconf devices
     def test_01_connect_xpdrA(self):
         url = ("{}/config/network-topology:"
index ab4100dc4718f098f44178bc19aed17aa41cdef3..d96b302aa42288f1f4c77044cf5cb7a31f29abc8 100644 (file)
@@ -24,57 +24,24 @@ import test_utils
 
 class TransportOlmTesting(unittest.TestCase):
 
-    sim_process1 = None
-    sim_process2 = None
-    sim_process3 = None
-    sim_process4 = None
-    odl_process = None
+    processes = None
     restconf_baseurl = "http://localhost:8181/restconf"
 
-# START_IGNORE_XTESTING
-
     @classmethod
     def setUpClass(cls):
-        cls.odl_process = test_utils.start_tpce()
-        cls.sim_process1 = test_utils.start_sim('xpdra')
-        cls.sim_process2 = test_utils.start_sim('roadma')
-        cls.sim_process3 = test_utils.start_sim('roadmc')
-        cls.sim_process4 = test_utils.start_sim('xpdrc')
+        cls.processes = test_utils.start_tpce()
+        cls.processes = test_utils.start_sims(['xpdra', 'roadma', 'roadmc', 'xpdrc'])
 
     @classmethod
     def tearDownClass(cls):
-        for child in psutil.Process(cls.odl_process.pid).children():
-            child.send_signal(signal.SIGINT)
-            child.wait()
-        cls.odl_process.send_signal(signal.SIGINT)
-        cls.odl_process.wait()
-        for child in psutil.Process(cls.sim_process1.pid).children():
-            child.send_signal(signal.SIGINT)
-            child.wait()
-        cls.sim_process1.send_signal(signal.SIGINT)
-        cls.sim_process1.wait()
-        for child in psutil.Process(cls.sim_process2.pid).children():
-            child.send_signal(signal.SIGINT)
-            child.wait()
-        cls.sim_process2.send_signal(signal.SIGINT)
-        cls.sim_process2.wait()
-        for child in psutil.Process(cls.sim_process3.pid).children():
-            child.send_signal(signal.SIGINT)
-            child.wait()
-        cls.sim_process3.send_signal(signal.SIGINT)
-        cls.sim_process3.wait()
-        for child in psutil.Process(cls.sim_process4.pid).children():
-            child.send_signal(signal.SIGINT)
-            child.wait()
-        cls.sim_process4.send_signal(signal.SIGINT)
-        cls.sim_process4.wait()
+        for process in cls.processes:
+            test_utils.shutdown_process(process)
+        print("all processes killed")
 
     def setUp(self):
         print("execution of {}".format(self.id().split(".")[-1]))
         time.sleep(1)
 
-# END_IGNORE_XTESTING
-
     def test_01_xpdrA_device_connected(self):
         url = ("{}/config/network-topology:"
                "network-topology/topology/topology-netconf/node/XPDR-A1"
index 69eee8579fc0cafca609152608df71ec4e7fc0c9..f1a617365ec1ef0d53c9606216481a64a48d77bb 100644 (file)
@@ -28,27 +28,19 @@ def extract_a_from_b(a, b):
 
 class TransportPCEtesting(unittest.TestCase):
 
-    sim_process1 = None
-    odl_process = None
+    processes = None
     restconf_baseurl = "http://localhost:8181/restconf"
 
     @classmethod
     def setUpClass(cls):
-        cls.odl_process = test_utils.start_tpce()
-        cls.sim_process1 = test_utils.start_sim('spdrav2')
+        cls.processes = test_utils.start_tpce()
+        cls.processes = test_utils.start_sims(['spdrav2'])
 
     @classmethod
     def tearDownClass(cls):
-        for child in psutil.Process(cls.odl_process.pid).children():
-            child.send_signal(signal.SIGINT)
-            child.wait()
-        cls.odl_process.send_signal(signal.SIGINT)
-        cls.odl_process.wait()
-        for child in psutil.Process(cls.sim_process1.pid).children():
-            child.send_signal(signal.SIGINT)
-            child.wait()
-        cls.sim_process1.send_signal(signal.SIGINT)
-        cls.sim_process1.wait()
+        for process in cls.processes:
+            test_utils.shutdown_process(process)
+        print("all processes killed")
 
     def setUp(self):
         time.sleep(5)
index 7505306cc77dd58a9f4e3f0470c577364ca44cd2..8fa8b8b8745789139ef24fb1d10d58a6c81bd9ac 100644 (file)
@@ -24,27 +24,19 @@ import test_utils
 
 class TransportPCEtesting(unittest.TestCase):
 
-    sim_process1 = None
-    odl_process = None
+    processes = None
     restconf_baseurl = "http://localhost:8181/restconf"
 
     @classmethod
     def setUpClass(cls):
-        cls.odl_process = test_utils.start_tpce()
-        cls.sim_process1 = test_utils.start_sim('spdrav2')
+        cls.processes = test_utils.start_tpce()
+        cls.processes = test_utils.start_sims(['spdrav2'])
 
     @classmethod
     def tearDownClass(cls):
-        for child in psutil.Process(cls.odl_process.pid).children():
-            child.send_signal(signal.SIGINT)
-            child.wait()
-        cls.odl_process.send_signal(signal.SIGINT)
-        cls.odl_process.wait()
-        for child in psutil.Process(cls.sim_process1.pid).children():
-            child.send_signal(signal.SIGINT)
-            child.wait()
-        cls.sim_process1.send_signal(signal.SIGINT)
-        cls.sim_process1.wait()
+        for process in cls.processes:
+            test_utils.shutdown_process(process)
+        print("all processes killed")
 
     def setUp(self):
         time.sleep(5)
index f28beb45f43e4ba31f0b797e3dfb578a6928bb7a..f532c4e231f10e64b20a93a2400554a1070a4195 100644 (file)
@@ -23,34 +23,19 @@ import test_utils
 
 class TransportPCEPortMappingTesting(unittest.TestCase):
 
-    sim_process1 = None
-    sim_process2 = None
-    odl_process = None
+    processes = None
     restconf_baseurl = "http://localhost:8181/restconf"
 
     @classmethod
     def setUpClass(cls):
-        cls.odl_process = test_utils.start_tpce()
-        cls.sim_process1 = test_utils.start_sim('xpdra')
-        cls.sim_process2 = test_utils.start_sim('roadma')
+        cls.processes = test_utils.start_tpce()
+        cls.processes = test_utils.start_sims(['xpdra', 'roadma'])
 
     @classmethod
     def tearDownClass(cls):
-        for child in psutil.Process(cls.odl_process.pid).children():
-            child.send_signal(signal.SIGINT)
-            child.wait()
-        cls.odl_process.send_signal(signal.SIGINT)
-        cls.odl_process.wait()
-        for child in psutil.Process(cls.sim_process1.pid).children():
-            child.send_signal(signal.SIGINT)
-            child.wait()
-        cls.sim_process1.send_signal(signal.SIGINT)
-        cls.sim_process1.wait()
-        for child in psutil.Process(cls.sim_process2.pid).children():
-            child.send_signal(signal.SIGINT)
-            child.wait()
-        cls.sim_process2.send_signal(signal.SIGINT)
-        cls.sim_process2.wait()
+        for process in cls.processes:
+            test_utils.shutdown_process(process)
+        print("all processes killed")
 
     def setUp(self):
         print("execution of {}".format(self.id().split(".")[-1]))
index da93789ef90b13781fabb1e2b9f4309d75ed6142..213530692198248339403e92d6122ca5c800b5d6 100644 (file)
@@ -24,43 +24,19 @@ import test_utils
 
 class TransportPCERendererTesting(unittest.TestCase):
 
-    sim_process1 = None
-    sim_process2 = None
-    odl_process = None
+    processes = None
     restconf_baseurl = "http://localhost:8181/restconf"
 
-# START_IGNORE_XTESTING
-
     @classmethod
     def setUpClass(cls):
-        cls.odl_process = test_utils.start_tpce()
-
-        cls.sim_process1 = test_utils.start_sim('xpdra')
-        cls.sim_process2 = test_utils.start_sim('roadma')
+        cls.processes = test_utils.start_tpce()
+        cls.processes = test_utils.start_sims(['xpdra', 'roadma'])
 
     @classmethod
     def tearDownClass(cls):
-        for child in psutil.Process(cls.odl_process.pid).children():
-            child.send_signal(signal.SIGINT)
-            child.wait()
-        cls.odl_process.send_signal(signal.SIGINT)
-        cls.odl_process.wait()
-        for child in psutil.Process(cls.sim_process1.pid).children():
-            child.send_signal(signal.SIGINT)
-            child.wait()
-        cls.sim_process1.send_signal(signal.SIGINT)
-        cls.sim_process1.wait()
-        for child in psutil.Process(cls.sim_process2.pid).children():
-            child.send_signal(signal.SIGINT)
-            child.wait()
-        cls.sim_process2.send_signal(signal.SIGINT)
-        cls.sim_process2.wait()
-
-    def setUp(self):
-        print("execution of {}".format(self.id().split(".")[-1]))
-        time.sleep(10)
-
-# END_IGNORE_XTESTING
+        for process in cls.processes:
+            test_utils.shutdown_process(process)
+        print("all processes killed")
 
     def test_01_rdm_device_connected(self):
         url = ("{}/config/network-topology:"
index 3814042a943503387fddf5015d6a0204d005d8c7..6f7eb37a6c7ccc0eec4bfe3a6f7111af39121486 100644 (file)
@@ -26,20 +26,14 @@ CREATED_SUCCESSFULLY = 'Result message should contain Xponder Roadm Link created
 
 
 class TransportTapitesting(unittest.TestCase):
-    odl_process = None
-    sim_process1 = None
-    sim_process2 = None
-    sim_process3 = None
-    sim_process4 = None
-    sim_process5 = None
 
-    # START_IGNORE_XTESTING
+    processes = None
 
     @classmethod
     def setUpClass(cls):
         cls.init_failed = False
 
-        cls.odl_process = test_utils.start_tpce()
+        cls.processes = test_utils.start_tpce()
         # TAPI feature is not installed by default in Karaf
         if "USE_LIGHTY" not in os.environ or os.environ['USE_LIGHTY'] != 'True':
             print("installing tapi feature...")
@@ -47,28 +41,20 @@ class TransportTapitesting(unittest.TestCase):
             if result.returncode != 0:
                 cls.init_failed = True
             print("Restarting opendaylight...")
-            test_utils.shutdown_process(cls.odl_process)
-            cls.odl_process = test_utils.start_tpce()
+            test_utils.shutdown_process(cls.processes[0])
+            cls.processes = test_utils.start_tpce()
             cls.init_failed = not test_utils.wait_until_log_contains(
                 test_utils.karaf_log, test_utils.KARAF_OK_START_MSG, time_to_wait=60)
         if cls.init_failed:
             print("tapi installaiton feature failed...")
-            test_utils.shutdown_process(cls.odl_process)
+            test_utils.shutdown_process(cls.odl_processes[0])
             exit(2)
-        cls.sim_process1 = test_utils.start_sim('xpdra')
-        cls.sim_process2 = test_utils.start_sim('roadma')
-        cls.sim_process3 = test_utils.start_sim('roadmc')
-        cls.sim_process4 = test_utils.start_sim('xpdrc')
-        cls.sim_process5 = test_utils.start_sim('spdrav2')
+        cls.processes = test_utils.start_sims(['xpdra', 'roadma', 'roadmc', 'xpdrc', 'spdrav2'])
 
     @classmethod
     def tearDownClass(cls):
-        test_utils.shutdown_process(cls.odl_process)
-        test_utils.shutdown_process(cls.sim_process1)
-        test_utils.shutdown_process(cls.sim_process2)
-        test_utils.shutdown_process(cls.sim_process3)
-        test_utils.shutdown_process(cls.sim_process4)
-        test_utils.shutdown_process(cls.sim_process5)
+        for process in cls.processes:
+            test_utils.shutdown_process(process)
         print("all processes killed")
 
     def setUp(self):  # instruction executed before each test method
@@ -76,9 +62,8 @@ class TransportTapitesting(unittest.TestCase):
             self.fail('Feature installation failed')
         print("execution of {}".format(self.id().split(".")[-1]))
 
-    # END_IGNORE_XTESTING
-
     #  connect netconf devices
+
     def test_00_connect_spdr_sa1(self):
         url = ("{}/config/network-topology:"
                "network-topology/topology/topology-netconf/node/SPDR-SA1"
index 70a17e3f3259fa92e3fc5211d00f8c1a648c8c43..b88f199916b248f83efda0bd7c3af4bb1001bf40 100644 (file)
@@ -24,42 +24,23 @@ import test_utils
 
 class TransportPCEtesting(unittest.TestCase):
 
-    sim_process1 = None
-    sim_process2 = None
-    odl_process = None
+    processes = None
     restconf_baseurl = "http://localhost:8181/restconf"
 
-# START_IGNORE_XTESTING
-
     @classmethod
     def setUpClass(cls):
-        cls.odl_process = test_utils.start_tpce()
-        cls.sim_process1 = test_utils.start_sim('xpdra')
-        cls.sim_process2 = test_utils.start_sim('roadma')
+        cls.processes = test_utils.start_tpce()
+        cls.processes = test_utils.start_sims(['xpdra', 'roadma'])
 
     @classmethod
     def tearDownClass(cls):
-        for child in psutil.Process(cls.odl_process.pid).children():
-            child.send_signal(signal.SIGINT)
-            child.wait()
-        cls.odl_process.send_signal(signal.SIGINT)
-        cls.odl_process.wait()
-        for child in psutil.Process(cls.sim_process1.pid).children():
-            child.send_signal(signal.SIGINT)
-            child.wait()
-        cls.sim_process1.send_signal(signal.SIGINT)
-        cls.sim_process1.wait()
-        for child in psutil.Process(cls.sim_process2.pid).children():
-            child.send_signal(signal.SIGINT)
-            child.wait()
-        cls.sim_process2.send_signal(signal.SIGINT)
-        cls.sim_process2.wait()
+        for process in cls.processes:
+            test_utils.shutdown_process(process)
+        print("all processes killed")
 
     def setUp(self):
         time.sleep(10)
 
-# END_IGNORE_XTESTING
-
     # Connect the ROADMA
     def test_01_connect_rdm(self):
         # Config ROADMA
index eed85b278c10c663dafd149e84bcdfdb404ec8ef..54c172e87e5248988df5db091c2c1b4591c56466 100644 (file)
@@ -24,56 +24,23 @@ import test_utils
 
 class TransportPCEtesting(unittest.TestCase):
 
-    sim_process1 = None
-    sim_process2 = None
-    sim_process3 = None
-    sim_process4 = None
-    odl_process = None
+    processes = None
     restconf_baseurl = "http://localhost:8181/restconf"
 
-# START_IGNORE_XTESTING
-
     @classmethod
     def setUpClass(cls):
-        cls.odl_process = test_utils.start_tpce()
-        cls.sim_process1 = test_utils.start_sim('xpdra')
-        cls.sim_process2 = test_utils.start_sim('roadma')
-        cls.sim_process3 = test_utils.start_sim('roadmb')
-        cls.sim_process4 = test_utils.start_sim('roadmc')
+        cls.processes = test_utils.start_tpce()
+        cls.processes = test_utils.start_sims(['xpdra', 'roadma', 'roadmb', 'roadmc'])
 
     @classmethod
     def tearDownClass(cls):
-        for child in psutil.Process(cls.odl_process.pid).children():
-            child.send_signal(signal.SIGINT)
-            child.wait()
-        cls.odl_process.send_signal(signal.SIGINT)
-        cls.odl_process.wait()
-        for child in psutil.Process(cls.sim_process1.pid).children():
-            child.send_signal(signal.SIGINT)
-            child.wait()
-        cls.sim_process1.send_signal(signal.SIGINT)
-        cls.sim_process1.wait()
-        for child in psutil.Process(cls.sim_process2.pid).children():
-            child.send_signal(signal.SIGINT)
-            child.wait()
-        cls.sim_process2.send_signal(signal.SIGINT)
-        cls.sim_process2.wait()
-        for child in psutil.Process(cls.sim_process3.pid).children():
-            child.send_signal(signal.SIGINT)
-            child.wait()
-        cls.sim_process3.send_signal(signal.SIGINT)
-        cls.sim_process3.wait()
-        for child in psutil.Process(cls.sim_process4.pid).children():
-            child.send_signal(signal.SIGINT)
-            child.wait()
-        cls.sim_process4.send_signal(signal.SIGINT)
-        cls.sim_process4.wait()
+        for process in cls.processes:
+            test_utils.shutdown_process(process)
+        print("all processes killed")
 
     def setUp(self):
         time.sleep(5)
 
-# END_IGNORE_XTESTING
-
     def test_01_connect_ROADM_A1(self):
         # Config ROADMA
         url = ("{}/config/network-topology:"
index 9e2ef6b9f3e79819e27bf1d52371a133405334ba..5402eae5b4610b236cb8de6a77e90a8932e1cc6c 100644 (file)
@@ -46,16 +46,23 @@ karaf_log = os.path.join(
     os.path.dirname(os.path.realpath(__file__)),
     "..", "..", "..", "karaf", "target", "assembly", "data", "log", "karaf.log")
 
-
-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, 100):
-        print("simulator for " + sim + " started")
-    else:
-        print("simulator for " + sim + "failed to start")
-    return process
+process_list = []
+
+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():
@@ -70,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():