034da46781ad91701a62164efb2b480c265538cd
[transportpce.git] / tests / transportpce_tests / 2.2.1 / test_portmapping.py
1 #!/usr/bin/env python
2
3 ##############################################################################
4 # Copyright (c) 2019 Orange, Inc. and others.  All rights reserved.
5 #
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 ##############################################################################
11
12 import json
13 import os
14 import psutil
15 import requests
16 import signal
17 import shutil
18 import subprocess
19 import time
20 import unittest
21 import test_utils
22
23
24 class TransportPCEPortMappingTesting(unittest.TestCase):
25
26     honeynode_process1 = None
27     honeynode_process2 = None
28     odl_process = None
29     restconf_baseurl = "http://localhost:8181/restconf"
30
31     @classmethod
32     def setUpClass(cls):
33         print("starting honeynode1...")
34         cls.honeynode_process1 = test_utils.start_xpdra_honeynode()
35         time.sleep(20)
36
37         print("starting honeynode2...")
38         cls.honeynode_process2 = test_utils.start_roadma_honeynode()
39         time.sleep(20)
40         print("all honeynodes started")
41
42         print("starting opendaylight...")
43         cls.odl_process = test_utils.start_tpce()
44         time.sleep(60)
45         print("opendaylight started")
46
47     @classmethod
48     def tearDownClass(cls):
49         for child in psutil.Process(cls.odl_process.pid).children():
50             child.send_signal(signal.SIGINT)
51             child.wait()
52         cls.odl_process.send_signal(signal.SIGINT)
53         cls.odl_process.wait()
54         for child in psutil.Process(cls.honeynode_process1.pid).children():
55             child.send_signal(signal.SIGINT)
56             child.wait()
57         cls.honeynode_process1.send_signal(signal.SIGINT)
58         cls.honeynode_process1.wait()
59         for child in psutil.Process(cls.honeynode_process2.pid).children():
60             child.send_signal(signal.SIGINT)
61             child.wait()
62         cls.honeynode_process2.send_signal(signal.SIGINT)
63         cls.honeynode_process2.wait()
64
65     def setUp(self):
66         print("execution of {}".format(self.id().split(".")[-1]))
67         time.sleep(10)
68
69     def test_01_rdm_device_connected(self):
70         url = ("{}/config/network-topology:"
71                "network-topology/topology/topology-netconf/node/ROADM-A1"
72                .format(self.restconf_baseurl))
73         data = {"node": [{
74             "node-id": "ROADM-A1",
75             "netconf-node-topology:username": "admin",
76             "netconf-node-topology:password": "admin",
77             "netconf-node-topology:host": "127.0.0.1",
78             "netconf-node-topology:port": "17841",
79             "netconf-node-topology:tcp-only": "false",
80             "netconf-node-topology:pass-through": {}}]}
81         headers = {'content-type': 'application/json'}
82         response = requests.request(
83             "PUT", url, data=json.dumps(data), headers=headers,
84             auth=('admin', 'admin'))
85         self.assertEqual(response.status_code, requests.codes.created)
86         time.sleep(20)
87
88     def test_02_rdm_device_connected(self):
89         url = ("{}/operational/network-topology:"
90                "network-topology/topology/topology-netconf/node/ROADM-A1"
91                .format(self.restconf_baseurl))
92         headers = {'content-type': 'application/json'}
93         response = requests.request(
94             "GET", url, headers=headers, auth=('admin', 'admin'))
95         self.assertEqual(response.status_code, requests.codes.ok)
96         res = response.json()
97         self.assertEqual(
98             res['node'][0]['netconf-node-topology:connection-status'],
99             'connected')
100         time.sleep(10)
101
102     def test_03_rdm_portmapping_info(self):
103         url = ("{}/config/transportpce-portmapping:network/"
104                "nodes/ROADM-A1/node-info"
105                .format(self.restconf_baseurl))
106         headers = {'content-type': 'application/json'}
107         response = requests.request(
108             "GET", url, headers=headers, auth=('admin', 'admin'))
109         self.assertEqual(response.status_code, requests.codes.ok)
110         res = response.json()
111         self.assertEqual(
112             {u'node-info': {u'node-type': u'rdm',
113                             u'node-ip-address': u'127.0.0.11',
114                             u'node-clli': u'NodeA',
115                             u'openroadm-version': u'2.2.1', u'node-vendor': u'vendorA',
116                             u'node-model': u'model2'}},
117             res)
118         time.sleep(3)
119
120     def test_04_rdm_portmapping_DEG1_TTP_TXRX(self):
121         url = ("{}/config/transportpce-portmapping:network/"
122                "nodes/ROADM-A1/mapping/DEG1-TTP-TXRX"
123                .format(self.restconf_baseurl))
124         headers = {'content-type': 'application/json'}
125         response = requests.request(
126             "GET", url, headers=headers, auth=('admin', 'admin'))
127         self.assertEqual(response.status_code, requests.codes.ok)
128         res = response.json()
129         self.assertIn(
130             {'supporting-port': 'L1', 'supporting-circuit-pack-name': '1/0',
131              'logical-connection-point': 'DEG1-TTP-TXRX', 'port-direction': 'bidirectional'},
132             res['mapping'])
133
134     def test_05_rdm_portmapping_DEG2_TTP_TXRX_with_ots_oms(self):
135         url = ("{}/config/transportpce-portmapping:network/"
136                "nodes/ROADM-A1/mapping/DEG2-TTP-TXRX"
137                .format(self.restconf_baseurl))
138         headers = {'content-type': 'application/json'}
139         response = requests.request(
140             "GET", url, headers=headers, auth=('admin', 'admin'))
141         self.assertEqual(response.status_code, requests.codes.ok)
142         res = response.json()
143         self.assertIn(
144             {'supporting-port': 'L1', 'supporting-circuit-pack-name': '2/0',
145              'logical-connection-point': 'DEG2-TTP-TXRX',
146              'supporting-oms': 'OMS-DEG2-TTP-TXRX', 'supporting-ots': 'OTS-DEG2-TTP-TXRX',
147              'port-direction': 'bidirectional'},
148             res['mapping'])
149
150     def test_06_rdm_portmapping_SRG1_PP3_TXRX(self):
151         url = ("{}/config/transportpce-portmapping:network/"
152                "nodes/ROADM-A1/mapping/SRG1-PP3-TXRX"
153                .format(self.restconf_baseurl))
154         headers = {'content-type': 'application/json'}
155         response = requests.request(
156             "GET", url, headers=headers, auth=('admin', 'admin'))
157         self.assertEqual(response.status_code, requests.codes.ok)
158         res = response.json()
159         self.assertIn(
160             {'supporting-port': 'C3', 'supporting-circuit-pack-name': '3/0',
161              'logical-connection-point': 'SRG1-PP3-TXRX', 'port-direction': 'bidirectional'},
162             res['mapping'])
163
164     def test_07_rdm_portmapping_SRG3_PP1_TXRX(self):
165         url = ("{}/config/transportpce-portmapping:network/"
166                "nodes/ROADM-A1/mapping/SRG3-PP1-TXRX"
167                .format(self.restconf_baseurl))
168         headers = {'content-type': 'application/json'}
169         response = requests.request(
170             "GET", url, headers=headers, auth=('admin', 'admin'))
171         self.assertEqual(response.status_code, requests.codes.ok)
172         res = response.json()
173         self.assertIn(
174             {'supporting-port': 'C1', 'supporting-circuit-pack-name': '5/0',
175              'logical-connection-point': 'SRG3-PP1-TXRX', 'port-direction': 'bidirectional'},
176             res['mapping'])
177
178     def test_08_xpdr_device_connected(self):
179         url = ("{}/config/network-topology:"
180                "network-topology/topology/topology-netconf/node/XPDR-A1"
181                .format(self.restconf_baseurl))
182         data = {"node": [{
183             "node-id": "XPDR-A1",
184             "netconf-node-topology:username": "admin",
185             "netconf-node-topology:password": "admin",
186             "netconf-node-topology:host": "127.0.0.1",
187             "netconf-node-topology:port": "17840",
188             "netconf-node-topology:tcp-only": "false",
189             "netconf-node-topology:pass-through": {}}]}
190         headers = {'content-type': 'application/json'}
191         response = requests.request(
192             "PUT", url, data=json.dumps(data), headers=headers,
193             auth=('admin', 'admin'))
194         self.assertEqual(response.status_code, requests.codes.created)
195         time.sleep(20)
196
197     def test_09_xpdr_device_connected(self):
198         url = ("{}/operational/network-topology:"
199                "network-topology/topology/topology-netconf/node/XPDR-A1"
200                .format(self.restconf_baseurl))
201         headers = {'content-type': 'application/json'}
202         response = requests.request(
203             "GET", url, headers=headers, auth=('admin', 'admin'))
204         self.assertEqual(response.status_code, requests.codes.ok)
205         res = response.json()
206         self.assertEqual(
207             res['node'][0]['netconf-node-topology:connection-status'],
208             'connected')
209         time.sleep(10)
210
211     def test_10_xpdr_portmapping_info(self):
212         url = ("{}/config/transportpce-portmapping:network/"
213                "nodes/XPDR-A1/node-info"
214                .format(self.restconf_baseurl))
215         headers = {'content-type': 'application/json'}
216         response = requests.request(
217             "GET", url, headers=headers, auth=('admin', 'admin'))
218         self.assertEqual(response.status_code, requests.codes.ok)
219         res = response.json()
220         self.assertEqual(
221             {u'node-info': {u'node-type': u'xpdr',
222                             u'node-ip-address': u'1.2.3.4',
223                             u'node-clli': u'NodeA',
224                             u'openroadm-version': u'2.2.1', u'node-vendor': u'vendorA',
225                             u'node-model': u'model2'}},
226             res)
227         time.sleep(3)
228
229     def test_11_xpdr_portmapping_NETWORK1(self):
230         url = ("{}/config/transportpce-portmapping:network/"
231                "nodes/XPDR-A1/mapping/XPDR1-NETWORK1"
232                .format(self.restconf_baseurl))
233         headers = {'content-type': 'application/json'}
234         response = requests.request(
235             "GET", url, headers=headers, auth=('admin', 'admin'))
236         self.assertEqual(response.status_code, requests.codes.ok)
237         res = response.json()
238         self.assertIn(
239             {'supported-interface-capability': ['org-openroadm-port-types:if-OCH'],
240              'supporting-port': '1', 'supporting-circuit-pack-name': '1/0/1-PLUG-NET',
241              'logical-connection-point': 'XPDR1-NETWORK1', 'port-qual': 'xpdr-network',
242              'port-direction': 'bidirectional', 'connection-map-lcp': 'XPDR1-CLIENT1'},
243             res['mapping'])
244
245     def test_12_xpdr_portmapping_NETWORK2(self):
246         url = ("{}/config/transportpce-portmapping:network/"
247                "nodes/XPDR-A1/mapping/XPDR1-NETWORK2"
248                .format(self.restconf_baseurl))
249         headers = {'content-type': 'application/json'}
250         response = requests.request(
251             "GET", url, headers=headers, auth=('admin', 'admin'))
252         self.assertEqual(response.status_code, requests.codes.ok)
253         res = response.json()
254         self.assertIn(
255             {'supported-interface-capability': ['org-openroadm-port-types:if-OCH'],
256              'supporting-port': '1', 'supporting-circuit-pack-name': '1/0/2-PLUG-NET',
257              'logical-connection-point': 'XPDR1-NETWORK2', 'port-direction': 'bidirectional',
258              'connection-map-lcp': 'XPDR1-CLIENT2', 'port-qual': 'xpdr-network'},
259             res['mapping'])
260
261     def test_13_xpdr_portmapping_CLIENT1(self):
262         url = ("{}/config/transportpce-portmapping:network/"
263                "nodes/XPDR-A1/mapping/XPDR1-CLIENT1"
264                .format(self.restconf_baseurl))
265         headers = {'content-type': 'application/json'}
266         response = requests.request(
267             "GET", url, headers=headers, auth=('admin', 'admin'))
268         self.assertEqual(response.status_code, requests.codes.ok)
269         res = response.json()
270         self.assertIn(
271             {'supported-interface-capability': ['org-openroadm-port-types:if-100GE'],
272              'supporting-port': 'C1',
273              'supporting-circuit-pack-name': '1/0/1-PLUG-CLIENT',
274              'logical-connection-point': 'XPDR1-CLIENT1', 'port-direction': 'bidirectional',
275              'connection-map-lcp': 'XPDR1-NETWORK1', 'port-qual': 'xpdr-client'},
276             res['mapping'])
277
278     def test_14_xpdr_portmapping_CLIENT2(self):
279         url = ("{}/config/transportpce-portmapping:network/"
280                "nodes/XPDR-A1/mapping/XPDR1-CLIENT2"
281                .format(self.restconf_baseurl))
282         headers = {'content-type': 'application/json'}
283         response = requests.request(
284             "GET", url, headers=headers, auth=('admin', 'admin'))
285         self.assertEqual(response.status_code, requests.codes.ok)
286         res = response.json()
287         self.assertIn(
288             {'supported-interface-capability': ['org-openroadm-port-types:if-100GE'],
289              'supporting-port': 'C1',
290              'supporting-circuit-pack-name': '1/0/2-PLUG-CLIENT',
291              'logical-connection-point': 'XPDR1-CLIENT2', 'port-direction': 'bidirectional',
292              'connection-map-lcp': 'XPDR1-NETWORK2', 'port-qual': 'xpdr-client'},
293             res['mapping'])
294
295     def test_15_xpdr_device_disconnected(self):
296         url = ("{}/config/network-topology:"
297                "network-topology/topology/topology-netconf/node/XPDR-A1"
298                .format(self.restconf_baseurl))
299         headers = {'content-type': 'application/json'}
300         response = requests.request(
301             "DELETE", url, headers=headers,
302             auth=('admin', 'admin'))
303         self.assertEqual(response.status_code, requests.codes.ok)
304         time.sleep(20)
305
306     def test_16_xpdr_device_disconnected(self):
307         url = ("{}/operational/network-topology:network-topology/topology/"
308                "topology-netconf/node/XPDR-A1".format(self.restconf_baseurl))
309         headers = {'content-type': 'application/json'}
310         response = requests.request(
311             "GET", url, headers=headers, auth=('admin', 'admin'))
312         self.assertEqual(response.status_code, requests.codes.not_found)
313         res = response.json()
314         self.assertIn(
315             {"error-type": "application", "error-tag": "data-missing",
316              "error-message": "Request could not be completed because the relevant data model content does not exist"},
317             res['errors']['error'])
318
319     def test_17_xpdr_device_disconnected(self):
320         url = ("{}/config/transportpce-portmapping:network/nodes/XPDR-A1".format(self.restconf_baseurl))
321         headers = {'content-type': 'application/json'}
322         response = requests.request(
323             "GET", url, headers=headers, auth=('admin', 'admin'))
324         self.assertEqual(response.status_code, requests.codes.not_found)
325         res = response.json()
326         self.assertIn(
327             {"error-type": "application", "error-tag": "data-missing",
328              "error-message": "Request could not be completed because the relevant data model content does not exist"},
329             res['errors']['error'])
330
331     def test_18_rdm_device_disconnected(self):
332         url = ("{}/config/network-topology:network-topology/topology/topology-netconf/node/ROADM-A1"
333                .format(self.restconf_baseurl))
334         headers = {'content-type': 'application/json'}
335         response = requests.request(
336             "DELETE", url, headers=headers,
337             auth=('admin', 'admin'))
338         self.assertEqual(response.status_code, requests.codes.ok)
339         time.sleep(20)
340
341     def test_19_rdm_device_disconnected(self):
342         url = ("{}/operational/network-topology:network-topology/topology/topology-netconf/node/ROADM-A1"
343                .format(self.restconf_baseurl))
344         headers = {'content-type': 'application/json'}
345         response = requests.request(
346             "GET", url, headers=headers, auth=('admin', 'admin'))
347         self.assertEqual(response.status_code, requests.codes.not_found)
348         res = response.json()
349         self.assertIn(
350             {"error-type": "application", "error-tag": "data-missing",
351              "error-message": "Request could not be completed because the relevant data model content does not exist"},
352             res['errors']['error'])
353
354     def test_20_rdm_device_disconnected(self):
355         url = ("{}/config/transportpce-portmapping:network/nodes/ROADM-A1".format(self.restconf_baseurl))
356         headers = {'content-type': 'application/json'}
357         response = requests.request(
358             "GET", url, headers=headers, auth=('admin', 'admin'))
359         self.assertEqual(response.status_code, requests.codes.not_found)
360         res = response.json()
361         self.assertIn(
362             {"error-type": "application", "error-tag": "data-missing",
363              "error-message": "Request could not be completed because the relevant data model content does not exist"},
364             res['errors']['error'])
365
366
367 if __name__ == "__main__":
368     unittest.main(verbosity=2)