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