From 6d13e57b71d9779444b784c9a56d6d3908c9240f Mon Sep 17 00:00:00 2001 From: "guillaume.lambert" Date: Mon, 29 Jun 2020 10:48:08 +0200 Subject: [PATCH] do not start tests if sample files cannot be read Signed-off-by: guillaume.lambert Change-Id: I4f28b20004ff34f951afcde0d14b845301cc2dce --- tests/transportpce_tests/1.2.1/test_gnpy.py | 59 ++++++++++++++------- tests/transportpce_tests/1.2.1/test_pce.py | 48 ++++++++++------- 2 files changed, 71 insertions(+), 36 deletions(-) diff --git a/tests/transportpce_tests/1.2.1/test_gnpy.py b/tests/transportpce_tests/1.2.1/test_gnpy.py index 111d8d892..a3d2ae0fe 100644 --- a/tests/transportpce_tests/1.2.1/test_gnpy.py +++ b/tests/transportpce_tests/1.2.1/test_gnpy.py @@ -12,6 +12,7 @@ import unittest import json import os +import sys import time import requests from common import test_utils @@ -21,13 +22,48 @@ class TransportGNPYtesting(unittest.TestCase): @classmethod def __init_logfile(cls): - if os.path.isfile("./transportpce_tests/gnpy.log"): - os.remove("transportpce_tests/gnpy.log") + GNPY_LOGFILE = os.path.join(os.path.dirname(os.path.realpath(__file__)), + "..", "..", "transportpce_tests", "gnpy.log") + if os.path.isfile(GNPY_LOFGILE): + os.remove(GNPY_LOFGILE) + topo_cllinet_data = None + topo_ordnet_data = None + topo_ordtopo_data = None processes = None @classmethod def setUpClass(cls): + try: + sample_files_parsed = False + TOPO_CLLINET_FILE = os.path.join(os.path.dirname(os.path.realpath(__file__)), + "..", "..", "sample_configs", "gnpy", "clliNetwork.json") + with open(TOPO_CLLINET_FILE, 'r') as topo_cllinet: + cls.topo_cllinet_data = topo_cllinet.read() + + TOPO_ORDNET_FILE = os.path.join(os.path.dirname(os.path.realpath(__file__)), + "..", "..", "sample_configs", "gnpy", "openroadmNetwork.json") + with open(TOPO_ORDNET_FILE, 'r') as topo_ordnet: + cls.topo_ordnet_data = topo_ordnet.read() + + TOPO_ORDTOPO_FILE = os.path.join(os.path.dirname(os.path.realpath(__file__)), + "..", "..", "sample_configs", "gnpy", "openroadmTopology.json") + with open(TOPO_ORDTOPO_FILE, 'r') as topo_ordtopo: + cls.topo_ordtopo_data = topo_ordtopo.read() + sample_files_parsed = True + except PermissionError as err: + print("Permission Error when trying to read sample files\n", err) + sys.exit(2) + except FileNotFoundError as err: + print("File Not found Error when trying to read sample files\n", err) + sys.exit(2) + except: + print("Unexpected error when trying to read sample files\n", sys.exc_info()[0]) + sys.exit(2) + finally: + if sample_files_parsed: + print("sample files content loaded") + cls.processes = test_utils.start_tpce() @classmethod @@ -42,32 +78,19 @@ class TransportGNPYtesting(unittest.TestCase): # Mount the different topologies def test_01_connect_clliNetwork(self): url = "{}/config/ietf-network:networks/network/clli-network" - topo_cllinet_file = "sample_configs/gnpy/clliNetwork.json" - if os.path.isfile(topo_cllinet_file): - with open(topo_cllinet_file, 'r') as clli_net: - data = clli_net.read() - #TODO : review this os specific path and treat error with an else-statement - response = test_utils.rawput_request(url, data) + response = test_utils.rawput_request(url, self.topo_cllinet_data) self.assertEqual(response.status_code, requests.codes.ok) time.sleep(3) def test_02_connect_openroadmNetwork(self): url = "{}/config/ietf-network:networks/network/openroadm-network" - topo_ordnet_file = "sample_configs/gnpy/openroadmNetwork.json" - if os.path.isfile(topo_ordnet_file): - with open(topo_ordnet_file, 'r') as ord_net: - data = ord_net.read() - response = test_utils.rawput_request(url, data) + response = test_utils.rawput_request(url, self.topo_ordnet_data) self.assertEqual(response.status_code, requests.codes.ok) time.sleep(3) def test_03_connect_openroadmTopology(self): url = "{}/config/ietf-network:networks/network/openroadm-topology" - topo_ordtopo_file = "sample_configs/gnpy/openroadmTopology.json" - if os.path.isfile(topo_ordtopo_file): - with open(topo_ordtopo_file, 'r') as ord_topo: - data = ord_topo.read() - response = test_utils.rawput_request(url, data) + response = test_utils.rawput_request(url, self.topo_ordtopo_data) self.assertEqual(response.status_code, requests.codes.ok) time.sleep(3) diff --git a/tests/transportpce_tests/1.2.1/test_pce.py b/tests/transportpce_tests/1.2.1/test_pce.py index a1b35323b..7ff098f62 100644 --- a/tests/transportpce_tests/1.2.1/test_pce.py +++ b/tests/transportpce_tests/1.2.1/test_pce.py @@ -11,6 +11,7 @@ import unittest import json import os +import sys import time import requests from common import test_utils @@ -21,30 +22,41 @@ class TransportPCEtesting(unittest.TestCase): simple_topo_bi_dir_data = None simple_topo_uni_dir_data = None complex_topo_uni_dir_data = None + processes = None @classmethod - def _get_file(cls): - topo_bi_dir_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), - "..", "..", "sample_configs", "honeynode-topo.xml") - if os.path.isfile(topo_bi_dir_file): - with open(topo_bi_dir_file, 'r') as topo_bi_dir: + def setUpClass(cls): + try: + sample_files_parsed = False + TOPO_BI_DIR_FILE = os.path.join(os.path.dirname(os.path.realpath(__file__)), + "..", "..", "sample_configs", "honeynode-topo.xml") + with open(TOPO_BI_DIR_FILE, 'r') as topo_bi_dir: cls.simple_topo_bi_dir_data = topo_bi_dir.read() - topo_uni_dir_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), - "..", "..", "sample_configs", "NW-simple-topology.xml") - if os.path.isfile(topo_uni_dir_file): - with open(topo_uni_dir_file, 'r') as topo_uni_dir: + + TOPO_UNI_DIR_FILE = os.path.join(os.path.dirname(os.path.realpath(__file__)), + "..", "..", "sample_configs", "NW-simple-topology.xml") + + with open(TOPO_UNI_DIR_FILE, 'r') as topo_uni_dir: cls.simple_topo_uni_dir_data = topo_uni_dir.read() - topo_uni_dir_complex_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), - "..", "..", "sample_configs", "NW-for-test-5-4.xml") - if os.path.isfile(topo_uni_dir_complex_file): - with open(topo_uni_dir_complex_file, 'r') as topo_uni_dir_complex: - cls.complex_topo_uni_dir_data = topo_uni_dir_complex.read() - processes = None + TOPO_UNI_DIR_COMPLEX_FILE = os.path.join(os.path.dirname(os.path.realpath(__file__)), + "..", "..", "sample_configs", "NW-for-test-5-4.xml") + with open(TOPO_UNI_DIR_COMPLEX_FILE, 'r') as topo_uni_dir_complex: + cls.complex_topo_uni_dir_data = topo_uni_dir_complex.read() + sample_files_parsed = True + except PermissionError as err: + print("Permission Error when trying to read sample files\n", err) + sys.exit(2) + except FileNotFoundError as err: + print("File Not found Error when trying to read sample files\n", err) + sys.exit(2) + except: + print("Unexpected error when trying to read sample files\n", sys.exc_info()[0]) + sys.exit(2) + finally: + if sample_files_parsed: + print("sample files content loaded") - @classmethod - def setUpClass(cls): - cls._get_file() cls.processes = test_utils.start_tpce() @classmethod -- 2.36.6