X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=tests%2Ftransportpce_tests%2F1.2.1%2Ftest_gnpy.py;h=e7f3a4849a9abf8cc06902e95e6ecbaf10f21806;hb=c8bd98e0844257ae2e40e01d54546a40596df26d;hp=64a88194a9a9dc471a66f302e38ca1e8fe0db7d3;hpb=31bc01d3dab733bbb6ad48cc43586de43cb6c5c9;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 64a88194a..e7f3a4849 100644 --- a/tests/transportpce_tests/1.2.1/test_gnpy.py +++ b/tests/transportpce_tests/1.2.1/test_gnpy.py @@ -16,33 +16,27 @@ import requests import signal import time import unittest -import test_utils +from common import test_utils class TransportGNPYtesting(unittest.TestCase): - gnpy_process = None - odl_process = None - restconf_baseurl = "http://localhost:8181/restconf" - @classmethod def __init_logfile(cls): if os.path.isfile("./transportpce_tests/gnpy.log"): os.remove("transportpce_tests/gnpy.log") + processes = None + @classmethod def setUpClass(cls): - cls.odl_process = test_utils.start_tpce() - time.sleep(30) - print("opendaylight started") + cls.processes = test_utils.start_tpce() @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 process in cls.processes: + test_utils.shutdown_process(process) + print("all processes killed") def setUp(self): time.sleep(2) @@ -50,50 +44,47 @@ class TransportGNPYtesting(unittest.TestCase): # Mount the different topologies def test_01_connect_clliNetwork(self): url = ("{}/config/ietf-network:networks/network/clli-network" - .format(self.restconf_baseurl)) + .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() - headers = {'content-type': 'application/json'} response = requests.request( - "PUT", url, data=body, headers=headers, - auth=('admin', 'admin')) + "PUT", url, data=body, headers=test_utils.TYPE_APPLICATION_JSON, + auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD)) 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(self.restconf_baseurl)) + .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() - headers = {'content-type': 'application/json'} response = requests.request( - "PUT", url, data=body, headers=headers, - auth=('admin', 'admin')) + "PUT", url, data=body, headers=test_utils.TYPE_APPLICATION_JSON, + auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD)) 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(self.restconf_baseurl)) + .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() - headers = {'content-type': 'application/json'} response = requests.request( - "PUT", url, data=body, headers=headers, - auth=('admin', 'admin')) + "PUT", url, data=body, headers=test_utils.TYPE_APPLICATION_JSON, + auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD)) 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(self.restconf_baseurl)) + .format(test_utils.RESTCONF_BASE_URL)) body = { "input": { "service-name": "service-1", @@ -116,11 +107,9 @@ class TransportGNPYtesting(unittest.TestCase): } } } - headers = {'content-type': 'application/json', - "Accept": "application/json"} response = requests.request( - "POST", url, data=json.dumps(body), headers=headers, - auth=('admin', 'admin')) + "POST", url, data=json.dumps(body), headers=test_utils.TYPE_APPLICATION_JSON, + auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD)) self.assertEqual(response.status_code, requests.codes.ok) res = response.json() self.assertEqual(res['output']['configuration-response-common'][ @@ -140,7 +129,7 @@ class TransportGNPYtesting(unittest.TestCase): # another one (low SNR) def test_05_path_computation_FoundByPCE_NotFeasibleByGnpy(self): url = ("{}/operations/transportpce-pce:path-computation-request" - .format(self.restconf_baseurl)) + .format(test_utils.RESTCONF_BASE_URL)) body = { "input": { "service-name": "service-2", @@ -187,11 +176,9 @@ class TransportGNPYtesting(unittest.TestCase): } } } - headers = {'content-type': 'application/json', - "Accept": "application/json"} response = requests.request( - "POST", url, data=json.dumps(body), headers=headers, - auth=('admin', 'admin')) + "POST", url, data=json.dumps(body), headers=test_utils.TYPE_APPLICATION_JSON, + auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD)) self.assertEqual(response.status_code, requests.codes.ok) res = response.json() self.assertEqual(res['output']['configuration-response-common'][ @@ -212,7 +199,7 @@ 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(self.restconf_baseurl)) + .format(test_utils.RESTCONF_BASE_URL)) body = { "input": { "service-name": "service-3", @@ -253,11 +240,9 @@ class TransportGNPYtesting(unittest.TestCase): } } } - headers = {'content-type': 'application/json', - "Accept": "application/json"} response = requests.request( - "POST", url, data=json.dumps(body), headers=headers, - auth=('admin', 'admin')) + "POST", url, data=json.dumps(body), headers=test_utils.TYPE_APPLICATION_JSON, + auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD)) self.assertEqual(response.status_code, requests.codes.ok) res = response.json() self.assertEqual(res['output']['configuration-response-common'][ @@ -276,7 +261,7 @@ 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(self.restconf_baseurl)) + .format(test_utils.RESTCONF_BASE_URL)) body = { "input": { "service-name": "service-4", @@ -329,11 +314,9 @@ class TransportGNPYtesting(unittest.TestCase): } } } - headers = {'content-type': 'application/json', - "Accept": "application/json"} response = requests.request( - "POST", url, data=json.dumps(body), headers=headers, - auth=('admin', 'admin')) + "POST", url, data=json.dumps(body), headers=test_utils.TYPE_APPLICATION_JSON, + auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD)) self.assertEqual(response.status_code, requests.codes.ok) res = response.json() self.assertEqual(res['output']['configuration-response-common'][ @@ -346,34 +329,31 @@ class TransportGNPYtesting(unittest.TestCase): # Disconnect the different topologies def test_08_disconnect_openroadmTopology(self): url = ("{}/config/ietf-network:networks/network/openroadm-topology" - .format(self.restconf_baseurl)) + .format(test_utils.RESTCONF_BASE_URL)) data = {} - headers = {'content-type': 'application/json'} response = requests.request( - "DELETE", url, data=json.dumps(data), headers=headers, - auth=('admin', 'admin')) + "DELETE", url, data=json.dumps(data), headers=test_utils.TYPE_APPLICATION_JSON, + auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD)) 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(self.restconf_baseurl)) + .format(test_utils.RESTCONF_BASE_URL)) data = {} - headers = {'content-type': 'application/json'} response = requests.request( - "DELETE", url, data=json.dumps(data), headers=headers, - auth=('admin', 'admin')) + "DELETE", url, data=json.dumps(data), headers=test_utils.TYPE_APPLICATION_JSON, + auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD)) 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(self.restconf_baseurl)) + .format(test_utils.RESTCONF_BASE_URL)) data = {} - headers = {'content-type': 'application/json'} response = requests.request( - "DELETE", url, data=json.dumps(data), headers=headers, - auth=('admin', 'admin')) + "DELETE", url, data=json.dumps(data), headers=test_utils.TYPE_APPLICATION_JSON, + auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD)) self.assertEqual(response.status_code, requests.codes.ok) time.sleep(3)