3 ##############################################################################
4 #Copyright (c) 2017 Orange, Inc. and others. All rights reserved.
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Apache License, Version 2.0
8 # which accompanies this distribution, and is available at
9 # http://www.apache.org/licenses/LICENSE-2.0
10 ##############################################################################
24 class TransportPCEtesting(unittest.TestCase):
26 honeynode_process1 = None
27 honeynode_process2 = None
29 restconf_baseurl = "http://localhost:8181/restconf"
31 #START_IGNORE_XTESTING
35 print ("starting honeynode1...")
36 cls.honeynode_process1 = test_utils.start_xpdra_honeynode()
39 print ("starting honeynode2...")
40 cls.honeynode_process2 = test_utils.start_roadma_honeynode()
42 print ("all honeynodes started")
44 print ("starting opendaylight...")
45 cls.odl_process = test_utils.start_tpce()
47 print ("opendaylight started")
50 def tearDownClass(cls):
51 for child in psutil.Process(cls.odl_process.pid).children():
52 child.send_signal(signal.SIGINT)
54 cls.odl_process.send_signal(signal.SIGINT)
55 cls.odl_process.wait()
56 for child in psutil.Process(cls.honeynode_process1.pid).children():
57 child.send_signal(signal.SIGINT)
59 cls.honeynode_process1.send_signal(signal.SIGINT)
60 cls.honeynode_process1.wait()
61 for child in psutil.Process(cls.honeynode_process2.pid).children():
62 child.send_signal(signal.SIGINT)
64 cls.honeynode_process2.send_signal(signal.SIGINT)
65 cls.honeynode_process2.wait()
73 def test_01_connect_rdm(self):
75 url = ("{}/config/network-topology:"
76 "network-topology/topology/topology-netconf/node/ROADM-A1"
77 .format(self.restconf_baseurl))
79 "node-id": "ROADM-A1",
80 "netconf-node-topology:username": "admin",
81 "netconf-node-topology:password": "admin",
82 "netconf-node-topology:host": "127.0.0.1",
83 "netconf-node-topology:port": "17841",
84 "netconf-node-topology:tcp-only": "false",
85 "netconf-node-topology:pass-through": {}}]}
86 headers = {'content-type': 'application/json'}
87 response = requests.request(
88 "PUT", url, data=json.dumps(data), headers=headers,
89 auth=('admin', 'admin'))
90 self.assertEqual(response.status_code, requests.codes.created)
93 #Verify the termination points of the ROADMA
94 def test_02_compareOpenroadmTopologyPortMapping_rdm(self):
95 urlTopo = ("{}/config/ietf-network:networks/network/openroadm-topology"
96 .format(self.restconf_baseurl))
97 headers = {'content-type': 'application/json'}
98 responseTopo = requests.request(
99 "GET", urlTopo, headers=headers, auth=('admin', 'admin'))
100 resTopo = responseTopo.json()
101 nbNode = len(resTopo['network'][0]['node'])
104 for i in range(0, nbNode):
105 nodeId = resTopo['network'][0]['node'][i]['node-id']
106 print("nodeId={}".format(nodeId))
107 nodeMapId = nodeId.split("-")[0] + "-" + nodeId.split("-")[1]
108 print("nodeMapId={}".format(nodeMapId))
109 urlMapList = "{}/config/transportpce-portmapping:network/nodes/" + nodeMapId
110 urlMapListFull = urlMapList.format(self.restconf_baseurl)
111 responseMapList = requests.request(
112 "GET", urlMapListFull, headers=headers, auth=('admin', 'admin'))
113 resMapList = responseMapList.json()
115 nbMappings = len(resMapList['nodes'][0]['mapping']) - nbMapCumul
116 nbTp = len(resTopo['network'][0]['node'][i]['ietf-network-topology:termination-point'])
118 for j in range(0, nbTp):
119 tpId = resTopo['network'][0]['node'][i]['ietf-network-topology:termination-point'][j]['tp-id']
120 if((not "CP" in tpId) and (not "CTP" in tpId)):
121 urlMap = "{}/config/transportpce-portmapping:network/nodes/" + nodeMapId + "/mapping/" + tpId
122 urlMapFull = urlMap.format(self.restconf_baseurl)
123 responseMap = requests.request(
124 "GET", urlMapFull, headers=headers, auth=('admin', 'admin'))
125 self.assertEqual(responseMap.status_code, requests.codes.ok)
126 if(responseMap.status_code == requests.codes.ok):
128 nbMapCumul += nbMapCurrent
129 nbMappings -= nbMapCurrent
130 self.assertEqual(nbMappings, 0)
132 #Disconnect the ROADMA
133 def test_03_disconnect_rdm(self):
134 url = ("{}/config/network-topology:"
135 "network-topology/topology/topology-netconf/node/ROADM-A1"
136 .format(self.restconf_baseurl))
138 headers = {'content-type': 'application/json'}
139 response = requests.request(
140 "DELETE", url, data=json.dumps(data), headers=headers,
141 auth=('admin', 'admin'))
142 self.assertEqual(response.status_code, requests.codes.ok)
145 def test_04_connect_xpdr(self):
147 url = ("{}/config/network-topology:"
148 "network-topology/topology/topology-netconf/node/XPDR-A1"
149 .format(self.restconf_baseurl))
151 "node-id": "XPDR-A1",
152 "netconf-node-topology:username": "admin",
153 "netconf-node-topology:password": "admin",
154 "netconf-node-topology:host": "127.0.0.1",
155 "netconf-node-topology:port": "17840",
156 "netconf-node-topology:tcp-only": "false",
157 "netconf-node-topology:pass-through": {}}]}
158 headers = {'content-type': 'application/json'}
159 response = requests.request(
160 "PUT", url, data=json.dumps(data), headers=headers,
161 auth=('admin', 'admin'))
162 self.assertEqual(response.status_code, requests.codes.created)
165 # #Verify the termination points related to XPDR
166 def test_05_compareOpenroadmTopologyPortMapping_xpdr(self):
167 self.test_02_compareOpenroadmTopologyPortMapping_rdm()
169 #Disconnect the XPDRA
170 def test_06_disconnect_device(self):
171 url = ("{}/config/network-topology:"
172 "network-topology/topology/topology-netconf/node/XPDR-A1"
173 .format(self.restconf_baseurl))
175 headers = {'content-type': 'application/json'}
176 response = requests.request(
177 "DELETE", url, data=json.dumps(data), headers=headers,
178 auth=('admin', 'admin'))
179 self.assertEqual(response.status_code, requests.codes.ok)
181 if __name__ == "__main__":
182 #logging.basicConfig(filename='./transportpce_tests/log/response.log',filemode='w',level=logging.DEBUG)
183 #logging.debug('I am there')
184 unittest.main(verbosity=2)