X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=tests%2Ftransportpce_tests%2F2.2.1%2Ftest_utils.py;h=79d8fdbaffe383828a7cbe777305215cf1221de9;hb=f14d37954ffcf069743b1c1b8f52811606667ed8;hp=0275d05d42368e723c98e2b5c2e5edf887052984;hpb=71016c482ba9143af363caac46367256e698046c;p=transportpce.git diff --git a/tests/transportpce_tests/2.2.1/test_utils.py b/tests/transportpce_tests/2.2.1/test_utils.py index 0275d05d4..79d8fdbaf 100644 --- a/tests/transportpce_tests/2.2.1/test_utils.py +++ b/tests/transportpce_tests/2.2.1/test_utils.py @@ -16,7 +16,19 @@ import subprocess import psutil import requests +sims = { + 'xpdra': {'port': '17840', 'configfile': 'oper-XPDRA.xml', 'logfile': 'oper-XPDRA.log'}, + 'roadma': {'port': '17841', 'configfile': 'oper-ROADMA.xml', 'logfile': 'oper-ROADMA.log'}, + 'roadmb': {'port': '17842', 'configfile': 'oper-ROADMB.xml', 'logfile': 'oper-ROADMB.log'}, + 'roadmc': {'port': '17843', 'configfile': 'oper-ROADMC.xml', 'logfile': 'oper-ROADMC.log'}, + 'xpdrc': {'port': '17844', 'configfile': 'oper-XPDRC.xml', 'logfile': 'oper-XPDRC.log'}, + 'spdrav2': {'port': '17845', 'configfile': 'oper-SPDRAv2.xml', 'logfile': 'oper-SPDRAv2.log'}, + 'spdrav1': {'port': '17846', 'configfile': 'oper-SPDRAv1.xml', 'logfile': 'oper-SPDRAv1.log'} +} + 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'} @@ -29,69 +41,57 @@ samples_directory = os.path.join( log_directory = os.path.dirname(os.path.realpath(__file__)) - -def start_xpdra_honeynode(): - log_file = os.path.join(log_directory, "oper-XPDRA.log") - process = start_node(log_file, "17840", "oper-XPDRA.xml") - wait_until_log_contains(log_file, HONEYNODE_OK_START_MSG, 5000) - return process - - -def start_roadma_honeynode(): - log_file = os.path.join(log_directory, "oper-ROADMA.log") - process = start_node(log_file, "17841", "oper-ROADMA.xml") - wait_until_log_contains(log_file, HONEYNODE_OK_START_MSG, 5000) - return process - - -def start_roadmb_honeynode(): - log_file = os.path.join(log_directory, "oper-ROADMB.log") - process = start_node(log_file, "17842", "oper-ROADMB.xml") - wait_until_log_contains(log_file, HONEYNODE_OK_START_MSG, 5000) - return process +karaf_log = os.path.join( + os.path.dirname(os.path.realpath(__file__)), + "..", "..", "..", "karaf", "target", "assembly", "data", "log", "karaf.log") -def start_roadmc_honeynode(): - log_file = os.path.join(log_directory, "oper-ROADMC.log") - process = start_node(log_file, "17843", "oper-ROADMC.xml") - wait_until_log_contains(log_file, HONEYNODE_OK_START_MSG, 5000) +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_xpdrc_honeynode(): - log_file = os.path.join(log_directory, "oper-XPDRC.log") - process = start_node(log_file, "17844", "oper-XPDRC.xml") - wait_until_log_contains(log_file, HONEYNODE_OK_START_MSG, 5000) +def start_tpce(): + print("starting opendaylight...") + if "USE_LIGHTY" in os.environ and os.environ['USE_LIGHTY'] == 'True': + process = start_lighty() + # TODO: add some sort of health check similar to Karaf below + else: + 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_spdra_honeynode(): - log_file = os.path.join(log_directory, "oper-SPDRAv2.log") - process = start_node(log_file, "17845", "oper-SPDRAv2.xml") - wait_until_log_contains(log_file, HONEYNODE_OK_START_MSG, 5000) - 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_tpce(): - 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=open(os.devnull)) - 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=open(os.devnull)) +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): @@ -159,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(