X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=tests%2Ftransportpce_tests%2F1.2.1%2Ftest_gnpy.py;h=80a92bf0dc1146f0c0ded39da425880431e7d828;hb=6fe500a1bf557eb44d22584ac6bf7c924f12c47f;hp=26ab184b9f7d4850cbf9c6b972ef02df5f2dfd68;hpb=78881abcc31dc039c374bcc15266030e8dabcf87;p=transportpce.git diff --git a/tests/transportpce_tests/1.2.1/test_gnpy.py b/tests/transportpce_tests/1.2.1/test_gnpy.py index 26ab184b9..80a92bf0d 100644 --- a/tests/transportpce_tests/1.2.1/test_gnpy.py +++ b/tests/transportpce_tests/1.2.1/test_gnpy.py @@ -9,9 +9,12 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## +# pylint: disable=no-member +# pylint: disable=too-many-public-methods + import unittest -import json import os +import sys import time import requests from common import test_utils @@ -19,19 +22,49 @@ from common import test_utils class TransportGNPYtesting(unittest.TestCase): - @classmethod - def __init_logfile(cls): - if os.path.isfile("./transportpce_tests/gnpy.log"): - os.remove("transportpce_tests/gnpy.log") - + topo_cllinet_data = None + topo_ordnet_data = None + topo_ordtopo_data = None processes = None @classmethod def setUpClass(cls): + # pylint: disable=bare-except + 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 def tearDownClass(cls): + # pylint: disable=not-an-iterable for process in cls.processes: test_utils.shutdown_process(process) print("all processes killed") @@ -41,73 +74,27 @@ class TransportGNPYtesting(unittest.TestCase): # Mount the different topologies def test_01_connect_clliNetwork(self): - url = ("{}/config/ietf-network:networks/network/clli-network" - .format(test_utils.RESTCONF_BASE_URL)) - topo_cllinet_file = "sample_configs/gnpy/clliNetwork.json" - if os.path.isfile(topo_cllinet_file): - with open(topo_cllinet_file, 'r') as clli_net: - body = clli_net.read() - response = requests.request( - "PUT", url, data=body, headers=test_utils.TYPE_APPLICATION_JSON, - auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD)) + response = test_utils.rawput_request(test_utils.URL_CONFIG_CLLI_NET, 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" - .format(test_utils.RESTCONF_BASE_URL)) - topo_ordnet_file = "sample_configs/gnpy/openroadmNetwork.json" - if os.path.isfile(topo_ordnet_file): - with open(topo_ordnet_file, 'r') as ord_net: - body = ord_net.read() - response = requests.request( - "PUT", url, data=body, headers=test_utils.TYPE_APPLICATION_JSON, - auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD)) + response = test_utils.rawput_request(test_utils.URL_CONFIG_ORDM_NET, 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" - .format(test_utils.RESTCONF_BASE_URL)) - topo_ordtopo_file = "sample_configs/gnpy/openroadmTopology.json" - if os.path.isfile(topo_ordtopo_file): - with open(topo_ordtopo_file, 'r') as ord_topo: - body = ord_topo.read() - response = requests.request( - "PUT", url, data=body, headers=test_utils.TYPE_APPLICATION_JSON, - auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD)) + response = test_utils.rawput_request(test_utils.URL_CONFIG_ORDM_TOPO, self.topo_ordtopo_data) self.assertEqual(response.status_code, requests.codes.ok) time.sleep(3) # Path computed by PCE is feasible according to Gnpy def test_04_path_computation_FeasibleWithPCE(self): - url = ("{}/operations/transportpce-pce:path-computation-request" - .format(test_utils.RESTCONF_BASE_URL)) - body = { - "input": { - "service-name": "service-1", - "resource-reserve": "true", - "pce-metric": "hop-count", - "service-handler-header": { - "request-id": "request-1" - }, - "service-a-end": { - "node-id": "XPONDER-1", - "service-rate": "100", - "service-format": "Ethernet", - "clli": "Node1" - }, - "service-z-end": { - "node-id": "XPONDER-5", - "service-rate": "100", - "service-format": "Ethernet", - "clli": "Node5" - } - } - } - response = requests.request( - "POST", url, data=json.dumps(body), headers=test_utils.TYPE_APPLICATION_JSON, - auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD)) + response = test_utils.path_computation_request("request-1", "service-1", + {"node-id": "XPONDER-1", "service-rate": "100", + "service-format": "Ethernet", "clli": "Node1"}, + {"node-id": "XPONDER-5", "service-rate": "100", + "service-format": "Ethernet", "clli": "Node5"}) self.assertEqual(response.status_code, requests.codes.ok) res = response.json() self.assertEqual(res['output']['configuration-response-common'][ @@ -126,57 +113,16 @@ class TransportGNPYtesting(unittest.TestCase): # Path computed by PCE is not feasible by GNPy and GNPy cannot find # another one (low SNR) def test_05_path_computation_FoundByPCE_NotFeasibleByGnpy(self): - url = ("{}/operations/transportpce-pce:path-computation-request" - .format(test_utils.RESTCONF_BASE_URL)) - body = { - "input": { - "service-name": "service-2", - "resource-reserve": "true", - "pce-metric": "hop-count", - "service-handler-header": { - "request-id": "request-2" - }, - "service-a-end": { - "node-id": "XPONDER-1", - "service-rate": "100", - "service-format": "Ethernet", - "clli": "Node1" - }, - "service-z-end": { - "node-id": "XPONDER-5", - "service-rate": "100", - "service-format": "Ethernet", - "clli": "Node5" - }, - "hard-constraints": { - "include_": { - "ordered-hops": [ - { - "hop-number": "0", - "hop-type": { - "node-id": "OpenROADM-2" - } - }, - { - "hop-number": "1", - "hop-type": { - "node-id": "OpenROADM-3" - } - }, - { - "hop-number": "2", - "hop-type": { - "node-id": "OpenROADM-4" - } - } - ] - } - } - } - } - response = requests.request( - "POST", url, data=json.dumps(body), headers=test_utils.TYPE_APPLICATION_JSON, - auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD)) + response = test_utils.path_computation_request("request-2", "service-2", + {"node-id": "XPONDER-1", "service-rate": "100", + "service-format": "Ethernet", "clli": "Node1"}, + {"node-id": "XPONDER-5", "service-rate": "100", + "service-format": "Ethernet", "clli": "Node5"}, + {"include_": {"ordered-hops": [ + {"hop-number": "0", "hop-type": {"node-id": "OpenROADM-2"}}, + {"hop-number": "1", "hop-type": {"node-id": "OpenROADM-3"}}, + {"hop-number": "2", "hop-type": {"node-id": "OpenROADM-4"}}]} + }) self.assertEqual(response.status_code, requests.codes.ok) res = response.json() self.assertEqual(res['output']['configuration-response-common'][ @@ -196,51 +142,15 @@ class TransportGNPYtesting(unittest.TestCase): # #PCE cannot find a path while GNPy finds a feasible one def test_06_path_computation_NotFoundByPCE_FoundByGNPy(self): - url = ("{}/operations/transportpce-pce:path-computation-request" - .format(test_utils.RESTCONF_BASE_URL)) - body = { - "input": { - "service-name": "service-3", - "resource-reserve": "true", - "pce-metric": "hop-count", - "service-handler-header": { - "request-id": "request-3" - }, - "service-a-end": { - "node-id": "XPONDER-1", - "service-rate": "100", - "service-format": "Ethernet", - "clli": "Node1" - }, - "service-z-end": { - "node-id": "XPONDER-4", - "service-rate": "100", - "service-format": "Ethernet", - "clli": "Node5" - }, - "hard-constraints": { - "include_": { - "ordered-hops": [ - { - "hop-number": "0", - "hop-type": { - "node-id": "OpenROADM-2" - } - }, - { - "hop-number": "1", - "hop-type": { - "node-id": "OpenROADM-3" - } - } - ] - } - } - } - } - response = requests.request( - "POST", url, data=json.dumps(body), headers=test_utils.TYPE_APPLICATION_JSON, - auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD)) + response = test_utils.path_computation_request("request-3", "service-3", + {"node-id": "XPONDER-1", "service-rate": "100", + "service-format": "Ethernet", "clli": "Node1"}, + {"node-id": "XPONDER-4", "service-rate": "100", + "service-format": "Ethernet", "clli": "Node5"}, + {"include_": {"ordered-hops": [ + {"hop-number": "0", "hop-type": {"node-id": "OpenROADM-2"}}, + {"hop-number": "1", "hop-type": {"node-id": "OpenROADM-3"}}]} + }) self.assertEqual(response.status_code, requests.codes.ok) res = response.json() self.assertEqual(res['output']['configuration-response-common'][ @@ -258,63 +168,17 @@ class TransportGNPYtesting(unittest.TestCase): # Not found path by PCE and GNPy cannot find another one def test_07_path_computation_FoundByPCE_NotFeasibleByGnpy(self): - url = ("{}/operations/transportpce-pce:path-computation-request" - .format(test_utils.RESTCONF_BASE_URL)) - body = { - "input": { - "service-name": "service-4", - "resource-reserve": "true", - "pce-metric": "hop-count", - "service-handler-header": { - "request-id": "request-4" - }, - "service-a-end": { - "node-id": "XPONDER-1", - "service-rate": "100", - "service-format": "Ethernet", - "clli": "Node1" - }, - "service-z-end": { - "node-id": "XPONDER-4", - "service-rate": "100", - "service-format": "Ethernet", - "clli": "Node5" - }, - "hard-constraints": { - "include_": { - "ordered-hops": [ - { - "hop-number": "0", - "hop-type": { - "node-id": "OpenROADM-2" - } - }, - { - "hop-number": "1", - "hop-type": { - "node-id": "OpenROADM-3" - } - }, - { - "hop-number": "2", - "hop-type": { - "node-id": "OpenROADM-4" - } - }, - { - "hop-number": "3", - "hop-type": { - "node-id": "OpenROADM-3" - } - } - ] - } - } - } - } - response = requests.request( - "POST", url, data=json.dumps(body), headers=test_utils.TYPE_APPLICATION_JSON, - auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD)) + response = test_utils.path_computation_request("request-4", "service-4", + {"node-id": "XPONDER-1", "service-rate": "100", + "service-format": "Ethernet", "clli": "Node1"}, + {"node-id": "XPONDER-4", "service-rate": "100", + "service-format": "Ethernet", "clli": "Node5"}, + {"include_": {"ordered-hops": [ + {"hop-number": "0", "hop-type": {"node-id": "OpenROADM-2"}}, + {"hop-number": "1", "hop-type": {"node-id": "OpenROADM-3"}}, + {"hop-number": "2", "hop-type": {"node-id": "OpenROADM-4"}}, + {"hop-number": "3", "hop-type": {"node-id": "OpenROADM-3"}}]} + }) self.assertEqual(response.status_code, requests.codes.ok) res = response.json() self.assertEqual(res['output']['configuration-response-common'][ @@ -326,32 +190,17 @@ class TransportGNPYtesting(unittest.TestCase): # Disconnect the different topologies def test_08_disconnect_openroadmTopology(self): - url = ("{}/config/ietf-network:networks/network/openroadm-topology" - .format(test_utils.RESTCONF_BASE_URL)) - data = {} - response = requests.request( - "DELETE", url, data=json.dumps(data), headers=test_utils.TYPE_APPLICATION_JSON, - auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD)) + response = test_utils.delete_request(test_utils.URL_CONFIG_ORDM_TOPO) self.assertEqual(response.status_code, requests.codes.ok) time.sleep(3) def test_09_disconnect_openroadmNetwork(self): - url = ("{}/config/ietf-network:networks/network/openroadm-network" - .format(test_utils.RESTCONF_BASE_URL)) - data = {} - response = requests.request( - "DELETE", url, data=json.dumps(data), headers=test_utils.TYPE_APPLICATION_JSON, - auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD)) + response = test_utils.delete_request(test_utils.URL_CONFIG_ORDM_NET) self.assertEqual(response.status_code, requests.codes.ok) time.sleep(3) def test_10_disconnect_clliNetwork(self): - url = ("{}/config/ietf-network:networks/network/clli-network" - .format(test_utils.RESTCONF_BASE_URL)) - data = {} - response = requests.request( - "DELETE", url, data=json.dumps(data), headers=test_utils.TYPE_APPLICATION_JSON, - auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD)) + response = test_utils.delete_request(test_utils.URL_CONFIG_CLLI_NET) self.assertEqual(response.status_code, requests.codes.ok) time.sleep(3)