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 ##############################################################################
25 class TransportPCEtesting(unittest.TestCase):
27 honeynode_process1 = None
28 honeynode_process2 = None
30 restconf_baseurl = "http://localhost:8181/restconf"
32 # START_IGNORE_XTESTING
36 print("starting honeynode1...")
37 cls.honeynode_process1 = test_utils.start_xpdra_honeynode()
40 print("starting honeynode2...")
41 cls.honeynode_process2 = test_utils.start_roadma_honeynode()
43 print("all honeynodes started")
45 print("starting opendaylight...")
46 cls.odl_process = test_utils.start_tpce()
48 print("opendaylight started")
51 def tearDownClass(cls):
52 for child in psutil.Process(cls.odl_process.pid).children():
53 child.send_signal(signal.SIGINT)
55 cls.odl_process.send_signal(signal.SIGINT)
56 cls.odl_process.wait()
57 for child in psutil.Process(cls.honeynode_process1.pid).children():
58 child.send_signal(signal.SIGINT)
60 cls.honeynode_process1.send_signal(signal.SIGINT)
61 cls.honeynode_process1.wait()
62 for child in psutil.Process(cls.honeynode_process2.pid).children():
63 child.send_signal(signal.SIGINT)
65 cls.honeynode_process2.send_signal(signal.SIGINT)
66 cls.honeynode_process2.wait()
74 def test_01_connect_rdm(self):
76 url = ("{}/config/network-topology:"
77 "network-topology/topology/topology-netconf/node/ROADM-A1"
78 .format(self.restconf_baseurl))
80 "node-id": "ROADM-A1",
81 "netconf-node-topology:username": "admin",
82 "netconf-node-topology:password": "admin",
83 "netconf-node-topology:host": "127.0.0.1",
84 "netconf-node-topology:port": "17841",
85 "netconf-node-topology:tcp-only": "false",
86 "netconf-node-topology:pass-through": {}}]}
87 headers = {'content-type': 'application/json'}
88 response = requests.request(
89 "PUT", url, data=json.dumps(data), headers=headers,
90 auth=('admin', 'admin'))
91 self.assertEqual(response.status_code, requests.codes.created)
94 # Verify the termination points of the ROADMA
95 def test_02_compareOpenroadmTopologyPortMapping_rdm(self):
96 urlTopo = ("{}/config/ietf-network:networks/network/openroadm-topology"
97 .format(self.restconf_baseurl))
98 headers = {'content-type': 'application/json'}
99 responseTopo = requests.request(
100 "GET", urlTopo, headers=headers, auth=('admin', 'admin'))
101 resTopo = responseTopo.json()
102 nbNode = len(resTopo['network'][0]['node'])
105 for i in range(0, nbNode):
106 nodeId = resTopo['network'][0]['node'][i]['node-id']
107 print("nodeId={}".format(nodeId))
108 nodeMapId = nodeId.split("-")[0] + "-" + nodeId.split("-")[1]
109 print("nodeMapId={}".format(nodeMapId))
110 urlMapList = "{}/config/transportpce-portmapping:network/nodes/" + nodeMapId
111 urlMapListFull = urlMapList.format(self.restconf_baseurl)
112 responseMapList = requests.request(
113 "GET", urlMapListFull, headers=headers, auth=('admin', 'admin'))
114 resMapList = responseMapList.json()
116 nbMappings = len(resMapList['nodes'][0]['mapping']) - nbMapCumul
117 nbTp = len(resTopo['network'][0]['node'][i]['ietf-network-topology:termination-point'])
119 for j in range(0, nbTp):
120 tpId = resTopo['network'][0]['node'][i]['ietf-network-topology:termination-point'][j]['tp-id']
121 if((not "CP" in tpId) and (not "CTP" in tpId)):
122 urlMap = "{}/config/transportpce-portmapping:network/nodes/" + nodeMapId + "/mapping/" + tpId
123 urlMapFull = urlMap.format(self.restconf_baseurl)
124 responseMap = requests.request(
125 "GET", urlMapFull, headers=headers, auth=('admin', 'admin'))
126 self.assertEqual(responseMap.status_code, requests.codes.ok)
127 if(responseMap.status_code == requests.codes.ok):
129 nbMapCumul += nbMapCurrent
130 nbMappings -= nbMapCurrent
131 self.assertEqual(nbMappings, 0)
133 # Disconnect the ROADMA
134 def test_03_disconnect_rdm(self):
135 url = ("{}/config/network-topology:"
136 "network-topology/topology/topology-netconf/node/ROADM-A1"
137 .format(self.restconf_baseurl))
139 headers = {'content-type': 'application/json'}
140 response = requests.request(
141 "DELETE", url, data=json.dumps(data), headers=headers,
142 auth=('admin', 'admin'))
143 self.assertEqual(response.status_code, requests.codes.ok)
146 def test_04_connect_xpdr(self):
148 url = ("{}/config/network-topology:"
149 "network-topology/topology/topology-netconf/node/XPDR-A1"
150 .format(self.restconf_baseurl))
152 "node-id": "XPDR-A1",
153 "netconf-node-topology:username": "admin",
154 "netconf-node-topology:password": "admin",
155 "netconf-node-topology:host": "127.0.0.1",
156 "netconf-node-topology:port": "17840",
157 "netconf-node-topology:tcp-only": "false",
158 "netconf-node-topology:pass-through": {}}]}
159 headers = {'content-type': 'application/json'}
160 response = requests.request(
161 "PUT", url, data=json.dumps(data), headers=headers,
162 auth=('admin', 'admin'))
163 self.assertEqual(response.status_code, requests.codes.created)
166 # #Verify the termination points related to XPDR
167 def test_05_compareOpenroadmTopologyPortMapping_xpdr(self):
168 self.test_02_compareOpenroadmTopologyPortMapping_rdm()
170 # Disconnect the XPDRA
171 def test_06_disconnect_device(self):
172 url = ("{}/config/network-topology:"
173 "network-topology/topology/topology-netconf/node/XPDR-A1"
174 .format(self.restconf_baseurl))
176 headers = {'content-type': 'application/json'}
177 response = requests.request(
178 "DELETE", url, data=json.dumps(data), headers=headers,
179 auth=('admin', 'admin'))
180 self.assertEqual(response.status_code, requests.codes.ok)
183 if __name__ == "__main__":
184 # logging.basicConfig(filename='./transportpce_tests/log/response.log',filemode='w',level=logging.DEBUG)
185 #logging.debug('I am there')
186 unittest.main(verbosity=2)