From f14d37954ffcf069743b1c1b8f52811606667ed8 Mon Sep 17 00:00:00 2001 From: "guillaume.lambert" Date: Wed, 17 Jun 2020 11:32:12 +0200 Subject: [PATCH] review sims/tpce start-up sequence in 2.2.1 tests and make tests fail immediately when tpce does not start correctly Signed-off-by: guillaume.lambert Change-Id: I472a132873e0180a1900642c412d8bfef71ab72e --- .../transportpce_tests/2.2.1/test_end2end.py | 9 +-- tests/transportpce_tests/2.2.1/test_olm.py | 10 +--- .../2.2.1/test_otn_renderer.py | 5 +- .../2.2.1/test_otn_topology.py | 5 +- .../2.2.1/test_portmapping.py | 7 +-- .../test_renderer_service_path_nominal.py | 9 +-- tests/transportpce_tests/2.2.1/test_tapi.py | 48 +++++++--------- .../2.2.1/test_topoPortMapping.py | 7 +-- .../transportpce_tests/2.2.1/test_topology.py | 10 +--- tests/transportpce_tests/2.2.1/test_utils.py | 56 +++++++++++++------ 10 files changed, 67 insertions(+), 99 deletions(-) diff --git a/tests/transportpce_tests/2.2.1/test_end2end.py b/tests/transportpce_tests/2.2.1/test_end2end.py index 1b1aab3db..44636a11b 100644 --- a/tests/transportpce_tests/2.2.1/test_end2end.py +++ b/tests/transportpce_tests/2.2.1/test_end2end.py @@ -35,18 +35,11 @@ class TransportPCEFulltesting(unittest.TestCase): @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') - print("all sims started") - - cls.odl_process = test_utils.start_tpce() - time.sleep(80) - print("opendaylight started") @classmethod def tearDownClass(cls): diff --git a/tests/transportpce_tests/2.2.1/test_olm.py b/tests/transportpce_tests/2.2.1/test_olm.py index edca444ca..ab4100dc4 100644 --- a/tests/transportpce_tests/2.2.1/test_olm.py +++ b/tests/transportpce_tests/2.2.1/test_olm.py @@ -35,20 +35,12 @@ class TransportOlmTesting(unittest.TestCase): @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') - print("all sims started") - - cls.odl_process = test_utils.start_tpce() - time.sleep(60) - print("opendaylight started") - @classmethod def tearDownClass(cls): for child in psutil.Process(cls.odl_process.pid).children(): diff --git a/tests/transportpce_tests/2.2.1/test_otn_renderer.py b/tests/transportpce_tests/2.2.1/test_otn_renderer.py index 97a6983da..69eee8579 100644 --- a/tests/transportpce_tests/2.2.1/test_otn_renderer.py +++ b/tests/transportpce_tests/2.2.1/test_otn_renderer.py @@ -34,11 +34,8 @@ class TransportPCEtesting(unittest.TestCase): @classmethod def setUpClass(cls): - cls.sim_process1 = test_utils.start_sim('spdrav2') - cls.odl_process = test_utils.start_tpce() - time.sleep(60) - print("opendaylight started") + cls.sim_process1 = test_utils.start_sim('spdrav2') @classmethod def tearDownClass(cls): diff --git a/tests/transportpce_tests/2.2.1/test_otn_topology.py b/tests/transportpce_tests/2.2.1/test_otn_topology.py index 062c0d9c4..7505306cc 100644 --- a/tests/transportpce_tests/2.2.1/test_otn_topology.py +++ b/tests/transportpce_tests/2.2.1/test_otn_topology.py @@ -30,11 +30,8 @@ class TransportPCEtesting(unittest.TestCase): @classmethod def setUpClass(cls): - cls.sim_process1 = test_utils.start_sim('spdrav2') - cls.odl_process = test_utils.start_tpce() - time.sleep(60) - print("opendaylight started") + cls.sim_process1 = test_utils.start_sim('spdrav2') @classmethod def tearDownClass(cls): diff --git a/tests/transportpce_tests/2.2.1/test_portmapping.py b/tests/transportpce_tests/2.2.1/test_portmapping.py index 5bed24b53..f28beb45f 100644 --- a/tests/transportpce_tests/2.2.1/test_portmapping.py +++ b/tests/transportpce_tests/2.2.1/test_portmapping.py @@ -30,14 +30,9 @@ class TransportPCEPortMappingTesting(unittest.TestCase): @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') - print("all sims started") - - cls.odl_process = test_utils.start_tpce() - time.sleep(60) - print("opendaylight started") @classmethod def tearDownClass(cls): diff --git a/tests/transportpce_tests/2.2.1/test_renderer_service_path_nominal.py b/tests/transportpce_tests/2.2.1/test_renderer_service_path_nominal.py index df0cc32de..da93789ef 100644 --- a/tests/transportpce_tests/2.2.1/test_renderer_service_path_nominal.py +++ b/tests/transportpce_tests/2.2.1/test_renderer_service_path_nominal.py @@ -33,15 +33,10 @@ class TransportPCERendererTesting(unittest.TestCase): @classmethod def setUpClass(cls): - cls.sim_process1 = test_utils.start_sim('xpdra') + cls.odl_process = test_utils.start_tpce() + cls.sim_process1 = test_utils.start_sim('xpdra') cls.sim_process2 = test_utils.start_sim('roadma') - print("all sims started") - - print("starting opendaylight...") - cls.odl_process = test_utils.start_tpce() - time.sleep(60) - print("opendaylight started") @classmethod def tearDownClass(cls): diff --git a/tests/transportpce_tests/2.2.1/test_tapi.py b/tests/transportpce_tests/2.2.1/test_tapi.py index 4594085e8..3814042a9 100644 --- a/tests/transportpce_tests/2.2.1/test_tapi.py +++ b/tests/transportpce_tests/2.2.1/test_tapi.py @@ -40,36 +40,26 @@ class TransportTapitesting(unittest.TestCase): cls.init_failed = False cls.odl_process = 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': - karaf_log = os.path.join( - os.path.dirname(os.path.realpath(__file__)), - "..", "..", "..", "karaf", "target", "assembly", "data", "log", "karaf.log") - searched_expr = re.escape("Blueprint container for bundle " - "org.opendaylight.netconf.restconf") + ".* was successfully created" - found = test_utils.wait_until_log_contains(karaf_log, searched_expr, time_to_wait=60) - cls.init_failed = not found - if not cls.init_failed: - print("opendaylight started") - print("installing tapi feature...") - result = test_utils.install_karaf_feature("odl-transportpce-tapi") - 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() - found = test_utils.wait_until_log_contains(karaf_log, searched_expr, time_to_wait=60) - cls.init_failed = not found - if not cls.init_failed: - 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') - print("all sims started") + print("installing tapi feature...") + result = test_utils.install_karaf_feature("odl-transportpce-tapi") + 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() + 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) + 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') @classmethod def tearDownClass(cls): diff --git a/tests/transportpce_tests/2.2.1/test_topoPortMapping.py b/tests/transportpce_tests/2.2.1/test_topoPortMapping.py index 7f23aee79..70a17e3f3 100644 --- a/tests/transportpce_tests/2.2.1/test_topoPortMapping.py +++ b/tests/transportpce_tests/2.2.1/test_topoPortMapping.py @@ -33,14 +33,9 @@ class TransportPCEtesting(unittest.TestCase): @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') - print("all sims started") - - cls.odl_process = test_utils.start_tpce() - time.sleep(60) - print("opendaylight started") @classmethod def tearDownClass(cls): diff --git a/tests/transportpce_tests/2.2.1/test_topology.py b/tests/transportpce_tests/2.2.1/test_topology.py index a00733479..eed85b278 100644 --- a/tests/transportpce_tests/2.2.1/test_topology.py +++ b/tests/transportpce_tests/2.2.1/test_topology.py @@ -35,19 +35,11 @@ class TransportPCEtesting(unittest.TestCase): @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') - print("all sims started") - - print("starting opendaylight...") - cls.odl_process = test_utils.start_tpce() - time.sleep(60) - print("opendaylight started") @classmethod def tearDownClass(cls): diff --git a/tests/transportpce_tests/2.2.1/test_utils.py b/tests/transportpce_tests/2.2.1/test_utils.py index e6b6f9209..79d8fdbaf 100644 --- a/tests/transportpce_tests/2.2.1/test_utils.py +++ b/tests/transportpce_tests/2.2.1/test_utils.py @@ -27,6 +27,8 @@ sims = { } HONEYNODE_OK_START_MSG = re.escape("Netconf SSH endpoint started successfully at 0.0.0.0") +KARAF_OK_START_MSG = re.escape("Blueprint container for bundle " + "org.opendaylight.netconf.restconf") + ".* was successfully created" TYPE_APPLICATION_JSON = {'content-type': 'application/json'} @@ -39,11 +41,15 @@ samples_directory = os.path.join( log_directory = os.path.dirname(os.path.realpath(__file__)) +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_node(log_file, sims[sim]['port'], sims[sim]['configfile']) + 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: @@ -54,22 +60,38 @@ def start_sim(sim): def start_tpce(): print("starting opendaylight...") if "USE_LIGHTY" in os.environ and os.environ['USE_LIGHTY'] == 'True': - print("starting LIGHTY.IO TransportPCE build...") - executable = os.path.join( - os.path.dirname(os.path.realpath(__file__)), - "..", "..", "..", "lighty", "target", "tpce", - "clean-start-controller.sh") - with open('odl.log', 'w') as outfile: - return subprocess.Popen( - ["sh", executable], stdout=outfile, stderr=outfile, stdin=None) + process = start_lighty() + # TODO: add some sort of health check similar to Karaf below else: - print("starting KARAF TransportPCE build...") - executable = os.path.join( - os.path.dirname(os.path.realpath(__file__)), - "..", "..", "..", "karaf", "target", "assembly", "bin", "karaf") - with open('odl.log', 'w') as outfile: - return subprocess.Popen( - ["sh", executable, "server"], stdout=outfile, stderr=outfile, stdin=None) + process = start_karaf() + if wait_until_log_contains(karaf_log, KARAF_OK_START_MSG, time_to_wait=60): + print("opendaylight started") + else: + print("opendaylight failed to start") + shutdown_process(process) + exit(1) + return process + + +def start_karaf(): + print("starting KARAF TransportPCE build...") + executable = os.path.join( + os.path.dirname(os.path.realpath(__file__)), + "..", "..", "..", "karaf", "target", "assembly", "bin", "karaf") + with open('odl.log', 'w') as outfile: + return subprocess.Popen( + ["sh", executable, "server"], stdout=outfile, stderr=outfile, stdin=None) + + +def start_lighty(): + print("starting LIGHTY.IO TransportPCE build...") + executable = os.path.join( + os.path.dirname(os.path.realpath(__file__)), + "..", "..", "..", "lighty", "target", "tpce", + "clean-start-controller.sh") + with open('odl.log', 'w') as outfile: + return subprocess.Popen( + ["sh", executable], stdout=outfile, stderr=outfile, stdin=None) def install_karaf_feature(feature_name: str): @@ -137,7 +159,7 @@ def shutdown_process(process): process.send_signal(signal.SIGINT) -def start_node(log_file: str, node_port: str, node_config_file_name: str): +def start_honeynode(log_file: str, node_port: str, node_config_file_name: str): if os.path.isfile(honeynode_executable): with open(log_file, 'w') as outfile: return subprocess.Popen( -- 2.36.6