Merge changes I27d64e31,I9d7bba90
[transportpce.git] / tests / transportpce_tests / with_docker / test02_nbinotifications.py
1 #!/usr/bin/env python
2 ##############################################################################
3 # Copyright (c) 2020 Orange, Inc. and others.  All rights reserved.
4 #
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
10
11 # pylint: disable=no-member
12 # pylint: disable=too-many-public-methods
13
14 import os
15 import json
16 import sys
17 import unittest
18 import time
19 import requests
20 sys.path.append('transportpce_tests/common/')
21 import test_utils
22
23 class TransportNbiNotificationstesting(unittest.TestCase):
24     processes = None
25     cr_serv_sample_data = {"input": {
26         "sdnc-request-header": {
27             "request-id": "e3028bae-a90f-4ddd-a83f-cf224eba0e58",
28             "rpc-action": "service-create",
29             "request-system-id": "appname",
30             "notification-url": "http://localhost:8585/NotificationServer/notify"
31         },
32         "service-name": "service1",
33         "common-id": "ASATT1234567",
34         "connection-type": "service",
35         "service-a-end": {
36             "service-rate": "100",
37             "node-id": "XPDR-A1",
38             "service-format": "Ethernet",
39             "clli": "SNJSCAMCJP8",
40             "tx-direction": {
41                 "port": {
42                     "port-device-name": "ROUTER_SNJSCAMCJP8_000000.00_00",
43                     "port-type": "router",
44                     "port-name": "Gigabit Ethernet_Tx.ge-5/0/0.0",
45                     "port-rack": "000000.00",
46                     "port-shelf": "00"
47                 },
48                 "lgx": {
49                     "lgx-device-name": "LGX Panel_SNJSCAMCJP8_000000.00_00",
50                     "lgx-port-name": "LGX Back.3",
51                     "lgx-port-rack": "000000.00",
52                     "lgx-port-shelf": "00"
53                 }
54             },
55             "rx-direction": {
56                 "port": {
57                     "port-device-name": "ROUTER_SNJSCAMCJP8_000000.00_00",
58                     "port-type": "router",
59                     "port-name": "Gigabit Ethernet_Rx.ge-5/0/0.0",
60                     "port-rack": "000000.00",
61                     "port-shelf": "00"
62                 },
63                 "lgx": {
64                     "lgx-device-name": "LGX Panel_SNJSCAMCJP8_000000.00_00",
65                     "lgx-port-name": "LGX Back.4",
66                     "lgx-port-rack": "000000.00",
67                     "lgx-port-shelf": "00"
68                 }
69             },
70             "optic-type": "gray"
71         },
72         "service-z-end": {
73             "service-rate": "100",
74             "node-id": "XPDR-C1",
75             "service-format": "Ethernet",
76             "clli": "SNJSCAMCJT4",
77             "tx-direction": {
78                 "port": {
79                     "port-device-name": "ROUTER_SNJSCAMCJT4_000000.00_00",
80                     "port-type": "router",
81                     "port-name": "Gigabit Ethernet_Tx.ge-1/0/0.0",
82                     "port-rack": "000000.00",
83                     "port-shelf": "00"
84                 },
85                 "lgx": {
86                     "lgx-device-name": "LGX Panel_SNJSCAMCJT4_000000.00_00",
87                     "lgx-port-name": "LGX Back.29",
88                     "lgx-port-rack": "000000.00",
89                     "lgx-port-shelf": "00"
90                 }
91             },
92             "rx-direction": {
93                 "port": {
94                     "port-device-name": "ROUTER_SNJSCAMCJT4_000000.00_00",
95                     "port-type": "router",
96                     "port-name": "Gigabit Ethernet_Rx.ge-1/0/0.0",
97                     "port-rack": "000000.00",
98                     "port-shelf": "00"
99                 },
100                 "lgx": {
101                     "lgx-device-name": "LGX Panel_SNJSCAMCJT4_000000.00_00",
102                     "lgx-port-name": "LGX Back.30",
103                     "lgx-port-rack": "000000.00",
104                     "lgx-port-shelf": "00"
105                 }
106             },
107             "optic-type": "gray"
108         },
109         "due-date": "2016-11-28T00:00:01Z",
110         "operator-contact": "pw1234"
111     }
112     }
113
114     WAITING = 20  # nominal value is 300
115     NODE_VERSION = '2.2.1'
116
117     @classmethod
118     def setUpClass(cls):
119         # TODO: for lighty manage the activation of NBI notification feature
120         cls.init_failed = False
121         cls.processes = test_utils.start_tpce()
122         # NBI notification feature is not installed by default in Karaf
123         if "USE_LIGHTY" not in os.environ or os.environ['USE_LIGHTY'] != 'True':
124             print("installing NBI notification feature...")
125             result = test_utils.install_karaf_feature("odl-transportpce-nbinotifications")
126             if result.returncode != 0:
127                 cls.init_failed = True
128             print("Restarting OpenDaylight...")
129             test_utils.shutdown_process(cls.processes[0])
130             cls.processes[0] = test_utils.start_karaf()
131             test_utils.process_list[0] = cls.processes[0]
132             cls.init_failed = not test_utils.wait_until_log_contains(
133                 test_utils.KARAF_LOG, test_utils.KARAF_OK_START_MSG, time_to_wait=60)
134         if cls.init_failed:
135             print("NBI notification installation feature failed...")
136             test_utils.shutdown_process(cls.processes[0])
137             sys.exit(2)
138         cls.processes = test_utils.start_sims([('xpdra', cls.NODE_VERSION),
139                                                ('roadma', cls.NODE_VERSION),
140                                                ('roadmc', cls.NODE_VERSION),
141                                                ('xpdrc', cls.NODE_VERSION)])
142
143     @classmethod
144     def tearDownClass(cls):
145         # pylint: disable=not-an-iterable
146         for process in cls.processes:
147             test_utils.shutdown_process(process)
148         print("all processes killed")
149
150     def setUp(self):  # instruction executed before each test method
151         print("execution of {}".format(self.id().split(".")[-1]))
152
153     def test_01_connect_xpdrA(self):
154         response = test_utils.mount_device("XPDR-A1", ('xpdra', self.NODE_VERSION))
155         self.assertEqual(response.status_code, requests.codes.created, test_utils.CODE_SHOULD_BE_201)
156
157     def test_02_connect_xpdrC(self):
158         response = test_utils.mount_device("XPDR-C1", ('xpdrc', self.NODE_VERSION))
159         self.assertEqual(response.status_code, requests.codes.created, test_utils.CODE_SHOULD_BE_201)
160
161     def test_03_connect_rdmA(self):
162         response = test_utils.mount_device("ROADM-A1", ('roadma', self.NODE_VERSION))
163         self.assertEqual(response.status_code, requests.codes.created, test_utils.CODE_SHOULD_BE_201)
164
165     def test_04_connect_rdmC(self):
166         response = test_utils.mount_device("ROADM-C1", ('roadmc', self.NODE_VERSION))
167         self.assertEqual(response.status_code, requests.codes.created, test_utils.CODE_SHOULD_BE_201)
168
169     def test_05_connect_xprdA_N1_to_roadmA_PP1(self):
170         response = test_utils.connect_xpdr_to_rdm_request("XPDR-A1", "1", "1",
171                                                           "ROADM-A1", "1", "SRG1-PP1-TXRX")
172         self.assertEqual(response.status_code, requests.codes.ok)
173         res = response.json()
174         self.assertIn('Xponder Roadm Link created successfully', res["output"]["result"])
175         time.sleep(2)
176
177     def test_06_connect_roadmA_PP1_to_xpdrA_N1(self):
178         response = test_utils.connect_rdm_to_xpdr_request("XPDR-A1", "1", "1",
179                                                           "ROADM-A1", "1", "SRG1-PP1-TXRX")
180         self.assertEqual(response.status_code, requests.codes.ok)
181         res = response.json()
182         self.assertIn('Roadm Xponder links created successfully', res["output"]["result"])
183         time.sleep(2)
184
185     def test_07_connect_xprdC_N1_to_roadmC_PP1(self):
186         response = test_utils.connect_xpdr_to_rdm_request("XPDR-C1", "1", "1",
187                                                           "ROADM-C1", "1", "SRG1-PP1-TXRX")
188         self.assertEqual(response.status_code, requests.codes.ok)
189         res = response.json()
190         self.assertIn('Xponder Roadm Link created successfully', res["output"]["result"])
191         time.sleep(2)
192
193     def test_08_connect_roadmC_PP1_to_xpdrC_N1(self):
194         response = test_utils.connect_rdm_to_xpdr_request("XPDR-C1", "1", "1",
195                                                           "ROADM-C1", "1", "SRG1-PP1-TXRX")
196         self.assertEqual(response.status_code, requests.codes.ok)
197         res = response.json()
198         self.assertIn('Roadm Xponder links created successfully', res["output"]["result"])
199         time.sleep(2)
200
201     def test_09_get_notifications_service1(self):
202         data = {
203             "input": {
204                 "connection-type": "service",
205                 "id-consumer": "consumer",
206                 "group-id": "transportpceTest"
207             }
208         }
209         response = test_utils.get_notifications_process_service_request(data)
210         self.assertEqual(response.status_code, requests.codes.no_content)
211         time.sleep(2)
212
213     def test_10_create_eth_service1(self):
214         self.cr_serv_sample_data["input"]["service-name"] = "service1"
215         response = test_utils.service_create_request(self.cr_serv_sample_data)
216         self.assertEqual(response.status_code, requests.codes.ok)
217         res = response.json()
218         self.assertIn('PCE calculation in progress',
219                       res['output']['configuration-response-common']['response-message'])
220         time.sleep(self.WAITING)
221
222     def test_11_get_notifications_service1(self):
223         data = {
224             "input": {
225                 "connection-type": "service",
226                 "id-consumer": "consumer",
227                 "group-id": "transportpceTest"
228             }
229         }
230         response = test_utils.get_notifications_process_service_request(data)
231         self.assertEqual(response.status_code, requests.codes.ok)
232         res = response.json()
233         self.assertEqual(res['output']['notifications-process-service'][-1]['service-name'], 'service1')
234         self.assertEqual(res['output']['notifications-process-service'][-1]['connection-type'], 'service')
235         self.assertEqual(res['output']['notifications-process-service'][-1]['message'],
236                          'ServiceCreate request failed ...')
237         self.assertEqual(res['output']['notifications-process-service'][-1]['response-failed'],
238                          'PCE path computation failed !')
239         time.sleep(2)
240
241     def test_12_add_omsAttributes_ROADMA_ROADMC(self):
242         # Config ROADMA-ROADMC oms-attributes
243         data = {"span": {
244             "auto-spanloss": "true",
245             "spanloss-base": 11.4,
246             "spanloss-current": 12,
247             "engineered-spanloss": 12.2,
248             "link-concatenation": [{
249                 "SRLG-Id": 0,
250                 "fiber-type": "smf",
251                 "SRLG-length": 100000,
252                 "pmd": 0.5}]}}
253         response = test_utils.add_oms_attr_request("ROADM-A1-DEG2-DEG2-TTP-TXRXtoROADM-C1-DEG1-DEG1-TTP-TXRX", data)
254         self.assertEqual(response.status_code, requests.codes.created)
255
256     def test_13_add_omsAttributes_ROADMC_ROADMA(self):
257         # Config ROADMC-ROADMA oms-attributes
258         data = {"span": {
259             "auto-spanloss": "true",
260             "spanloss-base": 11.4,
261             "spanloss-current": 12,
262             "engineered-spanloss": 12.2,
263             "link-concatenation": [{
264                 "SRLG-Id": 0,
265                 "fiber-type": "smf",
266                 "SRLG-length": 100000,
267                 "pmd": 0.5}]}}
268         response = test_utils.add_oms_attr_request("ROADM-C1-DEG1-DEG1-TTP-TXRXtoROADM-A1-DEG2-DEG2-TTP-TXRX", data)
269         self.assertEqual(response.status_code, requests.codes.created)
270
271     # test service-create for Eth service from xpdr to xpdr
272     def test_14_create_eth_service1(self):
273         self.cr_serv_sample_data["input"]["service-name"] = "service1"
274         response = test_utils.service_create_request(self.cr_serv_sample_data)
275         self.assertEqual(response.status_code, requests.codes.ok)
276         res = response.json()
277         self.assertIn('PCE calculation in progress',
278                       res['output']['configuration-response-common']['response-message'])
279         time.sleep(self.WAITING)
280
281     def test_15_get_eth_service1(self):
282         response = test_utils.get_service_list_request("services/service1")
283         self.assertEqual(response.status_code, requests.codes.ok)
284         res = response.json()
285         self.assertEqual(
286             res['services'][0]['administrative-state'], 'inService')
287         self.assertEqual(
288             res['services'][0]['service-name'], 'service1')
289         self.assertEqual(
290             res['services'][0]['connection-type'], 'service')
291         self.assertEqual(
292             res['services'][0]['lifecycle-state'], 'planned')
293         time.sleep(2)
294
295     def test_16_get_notifications_service1(self):
296         data = {
297             "input": {
298                 "connection-type": "service",
299                 "id-consumer": "consumer",
300                 "group-id": "transportpceTest"
301             }
302         }
303         response = test_utils.get_notifications_process_service_request(data)
304         self.assertEqual(response.status_code, requests.codes.ok)
305         res = response.json()
306         self.assertEqual(res['output']['notifications-process-service'][-1]['service-name'], 'service1')
307         self.assertEqual(res['output']['notifications-process-service'][-1]['connection-type'], 'service')
308         self.assertEqual(res['output']['notifications-process-service'][-1]['message'], 'Service implemented !')
309         time.sleep(2)
310
311     def test_17_get_notifications_alarm_service1(self):
312         data = {
313             "input": {
314                 "connection-type": "service",
315                 "id-consumer": "consumer",
316                 "group-id": "transportpceTest"
317             }
318         }
319         response = test_utils.get_notifications_alarm_service_request(data)
320         self.assertEqual(response.status_code, requests.codes.ok)
321         res = response.json()
322         self.assertEqual(res['output']['notifications-alarm-service'][-1]['service-name'], 'service1')
323         self.assertEqual(res['output']['notifications-alarm-service'][-1]['connection-type'], 'service')
324         self.assertEqual(res['output']['notifications-alarm-service'][-1]['operational-state'], 'inService')
325         self.assertEqual(res['output']['notifications-alarm-service'][-1]['message'], 'The service is now inService')
326         time.sleep(2)
327
328     def test_18_change_status_port_roadma_srg(self):
329         url = "{}/config/org-openroadm-device:org-openroadm-device/circuit-packs/3%2F0/ports/C1"
330         body = {"ports": [{
331             "port-name": "C1",
332             "logical-connection-point": "SRG1-PP1",
333             "port-type": "client",
334             "circuit-id": "SRG1",
335             "administrative-state": "outOfService",
336             "port-qual": "roadm-external"}]}
337         response = requests.request("PUT", url.format("http://127.0.0.1:8141/restconf"),
338                                     data=json.dumps(body), headers=test_utils.TYPE_APPLICATION_JSON,
339                                     auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD))
340         self.assertEqual(response.status_code, requests.codes.ok)
341         time.sleep(2)
342
343     def test_19_get_notifications_alarm_service1(self):
344         data = {
345             "input": {
346                 "connection-type": "service",
347                 "id-consumer": "consumer",
348                 "group-id": "transportpceTest"
349             }
350         }
351         response = test_utils.get_notifications_alarm_service_request(data)
352         self.assertEqual(response.status_code, requests.codes.ok)
353         res = response.json()
354         self.assertEqual(res['output']['notifications-alarm-service'][-1]['service-name'], 'service1')
355         self.assertEqual(res['output']['notifications-alarm-service'][-1]['connection-type'], 'service')
356         self.assertEqual(res['output']['notifications-alarm-service'][-1]['operational-state'], 'outOfService')
357         self.assertEqual(res['output']['notifications-alarm-service'][-1]['message'], 'The service is now outOfService')
358         time.sleep(2)
359
360     def test_20_restore_status_port_roadma_srg(self):
361         url = "{}/config/org-openroadm-device:org-openroadm-device/circuit-packs/3%2F0/ports/C1"
362         body = {"ports": [{
363             "port-name": "C1",
364             "logical-connection-point": "SRG1-PP1",
365             "port-type": "client",
366             "circuit-id": "SRG1",
367             "administrative-state": "inService",
368             "port-qual": "roadm-external"}]}
369         response = requests.request("PUT", url.format("http://127.0.0.1:8141/restconf"),
370                                     data=json.dumps(body), headers=test_utils.TYPE_APPLICATION_JSON,
371                                     auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD))
372         self.assertEqual(response.status_code, requests.codes.ok)
373         time.sleep(2)
374
375     def test_21_get_notifications_alarm_service1(self):
376         self.test_17_get_notifications_alarm_service1()
377
378     def test_22_delete_eth_service1(self):
379         response = test_utils.service_delete_request("service1")
380         self.assertEqual(response.status_code, requests.codes.ok)
381         res = response.json()
382         self.assertIn('Renderer service delete in progress',
383                       res['output']['configuration-response-common']['response-message'])
384         time.sleep(20)
385
386     def test_23_get_notifications_service1(self):
387         data = {
388             "input": {
389                 "connection-type": "service",
390                 "id-consumer": "consumer",
391                 "group-id": "transportpceTest"
392             }
393         }
394         response = test_utils.get_notifications_process_service_request(data)
395         self.assertEqual(response.status_code, requests.codes.ok)
396         res = response.json()
397         self.assertEqual(res['output']['notifications-process-service'][-1]['service-name'], 'service1')
398         self.assertEqual(res['output']['notifications-process-service'][-1]['connection-type'], 'service')
399         self.assertEqual(res['output']['notifications-process-service'][-1]['message'], 'Service deleted !')
400         time.sleep(2)
401
402     def test_24_disconnect_XPDRA(self):
403         response = test_utils.unmount_device("XPDR-A1")
404         self.assertEqual(response.status_code, requests.codes.ok, test_utils.CODE_SHOULD_BE_200)
405
406     def test_25_disconnect_XPDRC(self):
407         response = test_utils.unmount_device("XPDR-C1")
408         self.assertEqual(response.status_code, requests.codes.ok, test_utils.CODE_SHOULD_BE_200)
409
410     def test_26_disconnect_ROADMA(self):
411         response = test_utils.unmount_device("ROADM-A1")
412         self.assertEqual(response.status_code, requests.codes.ok, test_utils.CODE_SHOULD_BE_200)
413
414     def test_27_disconnect_ROADMC(self):
415         response = test_utils.unmount_device("ROADM-C1")
416         self.assertEqual(response.status_code, requests.codes.ok, test_utils.CODE_SHOULD_BE_200)
417
418
419 if __name__ == "__main__":
420     unittest.main(verbosity=2)