X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=tests%2Ftransportpce_tests%2F1.2.1%2Ftest_topoPortMapping.py;h=712dfe1790af7b464aea2f5e8b3739c1b8c97c80;hb=78881abcc31dc039c374bcc15266030e8dabcf87;hp=b9b4bccd7bce25e6cd070f9c1b69574eefbe4e09;hpb=de9c823434160ba713e598018cd1cfc09d8cbb08;p=transportpce.git diff --git a/tests/transportpce_tests/1.2.1/test_topoPortMapping.py b/tests/transportpce_tests/1.2.1/test_topoPortMapping.py index b9b4bccd7..712dfe179 100644 --- a/tests/transportpce_tests/1.2.1/test_topoPortMapping.py +++ b/tests/transportpce_tests/1.2.1/test_topoPortMapping.py @@ -9,89 +9,41 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## -import json -import signal import time import unittest import requests -import psutil -import test_utils +from common import test_utils class TransportPCEtesting(unittest.TestCase): - honeynode_process1 = None - honeynode_process2 = None - odl_process = None - restconf_baseurl = "http://localhost:8181/restconf" - -# START_IGNORE_XTESTING + processes = None @classmethod def setUpClass(cls): - print("starting honeynode1...") - cls.honeynode_process1 = test_utils.start_xpdra_honeynode() - time.sleep(20) - - print("starting honeynode2...") - cls.honeynode_process2 = test_utils.start_roadma_honeynode() - time.sleep(20) - - print("starting opendaylight...") - cls.odl_process = test_utils.start_tpce() - time.sleep(60) - print("opendaylight started") + cls.processes = test_utils.start_tpce() + cls.processes = test_utils.start_sims(['xpdra', 'roadma']) @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 child in psutil.Process(cls.honeynode_process1.pid).children(): - child.send_signal(signal.SIGINT) - child.wait() - cls.honeynode_process1.send_signal(signal.SIGINT) - cls.honeynode_process1.wait() - for child in psutil.Process(cls.honeynode_process2.pid).children(): - child.send_signal(signal.SIGINT) - child.wait() - cls.honeynode_process2.send_signal(signal.SIGINT) - cls.honeynode_process2.wait() + for process in cls.processes: + test_utils.shutdown_process(process) + print("all processes killed") def setUp(self): time.sleep(10) -# END_IGNORE_XTESTING - # Connect the ROADMA def test_01_connect_rdm(self): - # Config ROADMA - url = ("{}/config/network-topology:" - "network-topology/topology/topology-netconf/node/ROADMA01" - .format(self.restconf_baseurl)) - data = {"node": [{ - "node-id": "ROADMA01", - "netconf-node-topology:username": "admin", - "netconf-node-topology:password": "admin", - "netconf-node-topology:host": "127.0.0.1", - "netconf-node-topology:port": "17831", - "netconf-node-topology:tcp-only": "false", - "netconf-node-topology:pass-through": {}}]} - headers = {'content-type': 'application/json'} - response = requests.request( - "PUT", url, data=json.dumps(data), headers=headers, - auth=('admin', 'admin')) - self.assertEqual(response.status_code, requests.codes.created) - time.sleep(20) + response = test_utils.mount_device("ROADMA01", 'roadma') + self.assertEqual(response.status_code, requests.codes.created, test_utils.CODE_SHOULD_BE_201) # Verify the termination points of the ROADMA def test_02_compareOpenroadmTopologyPortMapping_rdm(self): urlTopo = ("{}/config/ietf-network:networks/network/openroadm-topology" - .format(self.restconf_baseurl)) - headers = {'content-type': 'application/json'} - responseTopo = requests.request("GET", urlTopo, headers=headers, auth=('admin', 'admin')) + .format(test_utils.RESTCONF_BASE_URL)) + responseTopo = requests.request("GET", urlTopo, headers=test_utils.TYPE_APPLICATION_JSON, + auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD)) resTopo = responseTopo.json() nbNode = len(resTopo['network'][0]['node']) nbMapCumul = 0 @@ -100,8 +52,9 @@ class TransportPCEtesting(unittest.TestCase): nodeId = resTopo['network'][0]['node'][i]['node-id'] nodeMapId = nodeId.split("-")[0] urlMapList = "{}/config/transportpce-portmapping:network/nodes/" + nodeMapId - urlMapListFull = urlMapList.format(self.restconf_baseurl) - responseMapList = requests.request("GET", urlMapListFull, headers=headers, auth=('admin', 'admin')) + urlMapListFull = urlMapList.format(test_utils.RESTCONF_BASE_URL) + responseMapList = requests.request("GET", urlMapListFull, headers=test_utils.TYPE_APPLICATION_JSON, + auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD)) resMapList = responseMapList.json() nbMappings = len(resMapList['nodes'][0]['mapping']) - nbMapCumul @@ -111,8 +64,9 @@ class TransportPCEtesting(unittest.TestCase): tpId = resTopo['network'][0]['node'][i]['ietf-network-topology:termination-point'][j]['tp-id'] if((not "CP" in tpId) and (not "CTP" in tpId)): urlMap = "{}/config/transportpce-portmapping:network/nodes/" + nodeMapId + "/mapping/" + tpId - urlMapFull = urlMap.format(self.restconf_baseurl) - responseMap = requests.request("GET", urlMapFull, headers=headers, auth=('admin', 'admin')) + urlMapFull = urlMap.format(test_utils.RESTCONF_BASE_URL) + responseMap = requests.request("GET", urlMapFull, headers=test_utils.TYPE_APPLICATION_JSON, + auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD)) self.assertEqual(responseMap.status_code, requests.codes.ok) if responseMap.status_code == requests.codes.ok: nbMapCurrent += 1 @@ -122,36 +76,13 @@ class TransportPCEtesting(unittest.TestCase): # Disconnect the ROADMA def test_03_disconnect_rdm(self): - url = ("{}/config/network-topology:" - "network-topology/topology/topology-netconf/node/ROADMA01" - .format(self.restconf_baseurl)) - data = {} - headers = {'content-type': 'application/json'} - response = requests.request( - "DELETE", url, data=json.dumps(data), headers=headers, - auth=('admin', 'admin')) - self.assertEqual(response.status_code, requests.codes.ok) + response = test_utils.unmount_device("ROADMA01") + self.assertEqual(response.status_code, requests.codes.ok, test_utils.CODE_SHOULD_BE_200) # #Connect the XPDRA def test_04_connect_xpdr(self): - # Config XPDRA - url = ("{}/config/network-topology:" - "network-topology/topology/topology-netconf/node/XPDRA01" - .format(self.restconf_baseurl)) - data = {"node": [{ - "node-id": "XPDRA01", - "netconf-node-topology:username": "admin", - "netconf-node-topology:password": "admin", - "netconf-node-topology:host": "127.0.0.1", - "netconf-node-topology:port": "17830", - "netconf-node-topology:tcp-only": "false", - "netconf-node-topology:pass-through": {}}]} - headers = {'content-type': 'application/json'} - response = requests.request( - "PUT", url, data=json.dumps(data), headers=headers, - auth=('admin', 'admin')) - self.assertEqual(response.status_code, requests.codes.created) - time.sleep(20) + response = test_utils.mount_device("XPDRA01", 'xpdra') + self.assertEqual(response.status_code, requests.codes.created, test_utils.CODE_SHOULD_BE_201) # #Verify the termination points related to XPDR def test_05_compareOpenroadmTopologyPortMapping_xpdr(self): @@ -159,15 +90,8 @@ class TransportPCEtesting(unittest.TestCase): # Disconnect the XPDRA def test_06_disconnect_device(self): - url = ("{}/config/network-topology:" - "network-topology/topology/topology-netconf/node/XPDRA01" - .format(self.restconf_baseurl)) - data = {} - headers = {'content-type': 'application/json'} - response = requests.request( - "DELETE", url, data=json.dumps(data), headers=headers, - auth=('admin', 'admin')) - self.assertEqual(response.status_code, requests.codes.ok) + response = test_utils.unmount_device("XPDRA01") + self.assertEqual(response.status_code, requests.codes.ok, test_utils.CODE_SHOULD_BE_200) if __name__ == "__main__":