2 ##############################################################################
3 # Copyright (c) 2020 Orange, Inc. and others. All rights reserved.
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 ##############################################################################
11 # pylint: disable=no-member
12 # pylint: disable=too-many-public-methods
16 # pylint: disable=wrong-import-order
21 sys.path.append('transportpce_tests/common/')
22 # pylint: disable=wrong-import-position
23 # pylint: disable=import-error
24 import test_utils # nopep8
27 class TransportNbiNotificationstesting(unittest.TestCase):
29 cr_serv_input_data = {
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"
36 "service-name": "service1",
37 "common-id": "ASATT1234567",
38 "connection-type": "service",
40 "service-rate": "100",
42 "service-format": "Ethernet",
43 "clli": "SNJSCAMCJP8",
44 "tx-direction": [{"index": 0}],
45 "rx-direction": [{"index": 0}],
49 "service-rate": "100",
51 "service-format": "Ethernet",
52 "clli": "SNJSCAMCJT4",
53 "tx-direction": [{"index": 0}],
54 "rx-direction": [{"index": 0}],
57 "due-date": "2016-11-28T00:00:01Z",
58 "operator-contact": "pw1234"
61 del_serv_input_data = {
62 "sdnc-request-header": {
63 "request-id": "e3028bae-a90f-4ddd-a83f-cf224eba0e58",
64 "rpc-action": "service-delete",
65 "request-system-id": "appname",
66 "notification-url": "http://localhost:8585/NotificationServer/notify"},
67 "service-delete-req-info": {
68 "service-name": "TBD",
69 "tail-retention": "no"}
72 nbi_notif_input_data = {
73 "connection-type": "service",
74 "id-consumer": "consumer",
75 "group-id": "transportpceTest"
78 WAITING = 20 # nominal value is 300
79 NODE_VERSION = '2.2.1'
83 # pylint: disable=unsubscriptable-object
84 # TODO: for lighty manage the activation of NBI notification feature
85 cls.init_failed = False
86 cls.processes = test_utils.start_tpce()
87 # NBI notification feature is not installed by default in Karaf
88 if "USE_LIGHTY" not in os.environ or os.environ['USE_LIGHTY'] != 'True':
89 print("installing NBI notification feature...")
90 result = test_utils.install_karaf_feature("odl-transportpce-nbinotifications")
91 if result.returncode != 0:
92 cls.init_failed = True
93 print("Restarting OpenDaylight...")
94 test_utils.shutdown_process(cls.processes[0])
95 cls.processes[0] = test_utils.start_karaf()
96 test_utils.process_list[0] = cls.processes[0]
97 cls.init_failed = not test_utils.wait_until_log_contains(
98 test_utils.KARAF_LOG, test_utils.KARAF_OK_START_MSG, time_to_wait=60)
100 print("NBI notification installation feature failed...")
101 test_utils.shutdown_process(cls.processes[0])
103 cls.processes = test_utils.start_sims([('xpdra', cls.NODE_VERSION),
104 ('roadma', cls.NODE_VERSION),
105 ('roadmc', cls.NODE_VERSION),
106 ('xpdrc', cls.NODE_VERSION)])
109 def tearDownClass(cls):
110 # pylint: disable=not-an-iterable
111 for process in cls.processes:
112 test_utils.shutdown_process(process)
113 print("all processes killed")
115 def setUp(self): # instruction executed before each test method
116 # pylint: disable=consider-using-f-string
117 print("execution of {}".format(self.id().split(".")[-1]))
119 def test_01_connect_xpdrA(self):
120 response = test_utils.mount_device("XPDR-A1", ('xpdra', self.NODE_VERSION))
121 self.assertEqual(response.status_code,
122 requests.codes.created, test_utils.CODE_SHOULD_BE_201)
124 def test_02_connect_xpdrC(self):
125 response = test_utils.mount_device("XPDR-C1", ('xpdrc', self.NODE_VERSION))
126 self.assertEqual(response.status_code,
127 requests.codes.created, test_utils.CODE_SHOULD_BE_201)
129 def test_03_connect_rdmA(self):
130 response = test_utils.mount_device("ROADM-A1", ('roadma', self.NODE_VERSION))
131 self.assertEqual(response.status_code,
132 requests.codes.created, test_utils.CODE_SHOULD_BE_201)
134 def test_04_connect_rdmC(self):
135 response = test_utils.mount_device("ROADM-C1", ('roadmc', self.NODE_VERSION))
136 self.assertEqual(response.status_code,
137 requests.codes.created, test_utils.CODE_SHOULD_BE_201)
139 def test_05_connect_xprdA_N1_to_roadmA_PP1(self):
140 response = test_utils.transportpce_api_rpc_request(
141 'transportpce-networkutils', 'init-xpdr-rdm-links',
142 {'links-input': {'xpdr-node': 'XPDR-A1', 'xpdr-num': '1', 'network-num': '1',
143 'rdm-node': 'ROADM-A1', 'srg-num': '1', 'termination-point-num': 'SRG1-PP1-TXRX'}})
144 self.assertEqual(response['status_code'], requests.codes.ok)
145 self.assertIn('Xponder Roadm Link created successfully', response["output"]["result"])
148 def test_06_connect_roadmA_PP1_to_xpdrA_N1(self):
149 response = test_utils.transportpce_api_rpc_request(
150 'transportpce-networkutils', 'init-rdm-xpdr-links',
151 {'links-input': {'xpdr-node': 'XPDR-A1', 'xpdr-num': '1', 'network-num': '1',
152 'rdm-node': 'ROADM-A1', 'srg-num': '1', 'termination-point-num': 'SRG1-PP1-TXRX'}})
153 self.assertEqual(response['status_code'], requests.codes.ok)
154 self.assertIn('Roadm Xponder links created successfully', response["output"]["result"])
157 def test_07_connect_xprdC_N1_to_roadmC_PP1(self):
158 response = test_utils.transportpce_api_rpc_request(
159 'transportpce-networkutils', 'init-xpdr-rdm-links',
160 {'links-input': {'xpdr-node': 'XPDR-C1', 'xpdr-num': '1', 'network-num': '1',
161 'rdm-node': 'ROADM-C1', 'srg-num': '1', 'termination-point-num': 'SRG1-PP1-TXRX'}})
162 self.assertEqual(response['status_code'], requests.codes.ok)
163 self.assertIn('Xponder Roadm Link created successfully', response["output"]["result"])
166 def test_08_connect_roadmC_PP1_to_xpdrC_N1(self):
167 response = test_utils.transportpce_api_rpc_request(
168 'transportpce-networkutils', 'init-rdm-xpdr-links',
169 {'links-input': {'xpdr-node': 'XPDR-C1', 'xpdr-num': '1', 'network-num': '1',
170 'rdm-node': 'ROADM-C1', 'srg-num': '1', 'termination-point-num': 'SRG1-PP1-TXRX'}})
171 self.assertEqual(response['status_code'], requests.codes.ok)
172 self.assertIn('Roadm Xponder links created successfully', response["output"]["result"])
175 def test_09_get_notifications_service1(self):
176 response = test_utils.transportpce_api_rpc_request(
177 'nbi-notifications', 'get-notifications-process-service', self.nbi_notif_input_data)
178 self.assertEqual(response['status_code'], requests.codes.no_content)
181 def test_10_create_eth_service1(self):
182 self.cr_serv_input_data["service-name"] = "service1"
183 response = test_utils.transportpce_api_rpc_request(
184 'org-openroadm-service', 'service-create', self.cr_serv_input_data)
185 self.assertEqual(response['status_code'], requests.codes.ok)
186 self.assertIn('PCE calculation in progress',
187 response['output']['configuration-response-common']['response-message'])
188 time.sleep(self.WAITING)
190 def test_11_get_notifications_service1(self):
191 response = test_utils.transportpce_api_rpc_request(
192 'nbi-notifications', 'get-notifications-process-service', self.nbi_notif_input_data)
193 self.assertEqual(response['status_code'], requests.codes.ok)
194 self.assertEqual(response['output']['notifications-process-service'][-1]['service-name'], 'service1')
195 self.assertEqual(response['output']['notifications-process-service'][-1]['connection-type'], 'service')
196 self.assertEqual(response['output']['notifications-process-service'][-1]['message'],
197 'ServiceCreate request failed ...')
198 self.assertEqual(response['output']['notifications-process-service'][-1]['response-failed'],
199 'PCE path computation failed !')
202 def test_12_add_omsAttributes_ROADMA_ROADMC(self):
203 # Config ROADMA-ROADMC oms-attributes
205 "auto-spanloss": "true",
206 "spanloss-base": 11.4,
207 "spanloss-current": 12,
208 "engineered-spanloss": 12.2,
209 "link-concatenation": [{
212 "SRLG-length": 100000,
214 response = test_utils.add_oms_attr_request(
215 "ROADM-A1-DEG2-DEG2-TTP-TXRXtoROADM-C1-DEG1-DEG1-TTP-TXRX", data)
216 self.assertEqual(response.status_code, requests.codes.created)
218 def test_13_add_omsAttributes_ROADMC_ROADMA(self):
219 # Config ROADMC-ROADMA oms-attributes
221 "auto-spanloss": "true",
222 "spanloss-base": 11.4,
223 "spanloss-current": 12,
224 "engineered-spanloss": 12.2,
225 "link-concatenation": [{
228 "SRLG-length": 100000,
230 response = test_utils.add_oms_attr_request(
231 "ROADM-C1-DEG1-DEG1-TTP-TXRXtoROADM-A1-DEG2-DEG2-TTP-TXRX", data)
232 self.assertEqual(response.status_code, requests.codes.created)
234 # test service-create for Eth service from xpdr to xpdr
235 def test_14_create_eth_service1(self):
236 self.cr_serv_input_data["service-name"] = "service1"
237 response = test_utils.transportpce_api_rpc_request(
238 'org-openroadm-service', 'service-create', self.cr_serv_input_data)
239 self.assertEqual(response['status_code'], requests.codes.ok)
240 self.assertIn('PCE calculation in progress',
241 response['output']['configuration-response-common']['response-message'])
242 time.sleep(self.WAITING)
244 def test_15_get_eth_service1(self):
245 response = test_utils.get_ordm_serv_list_attr_request("services", "service1")
246 self.assertEqual(response['status_code'], requests.codes.ok)
247 self.assertEqual(response['services'][0]['administrative-state'], 'inService')
248 self.assertEqual(response['services'][0]['service-name'], 'service1')
249 self.assertEqual(response['services'][0]['connection-type'], 'service')
250 self.assertEqual(response['services'][0]['lifecycle-state'], 'planned')
252 def test_16_get_notifications_service1(self):
253 response = test_utils.transportpce_api_rpc_request(
254 'nbi-notifications', 'get-notifications-process-service', self.nbi_notif_input_data)
255 self.assertEqual(response['status_code'], requests.codes.ok)
256 self.assertEqual(response['output']['notifications-process-service'][-1]['service-name'], 'service1')
257 self.assertEqual(response['output']['notifications-process-service'][-1]['connection-type'], 'service')
258 self.assertEqual(response['output']['notifications-process-service'][-1]['message'], 'Service implemented !')
260 def test_17_get_notifications_alarm_service1(self):
261 response = test_utils.transportpce_api_rpc_request(
262 'nbi-notifications', 'get-notifications-alarm-service', self.nbi_notif_input_data)
263 self.assertEqual(response['status_code'], requests.codes.ok)
264 self.assertEqual(response['output']['notifications-alarm-service'][-1]['service-name'], 'service1')
265 self.assertEqual(response['output']['notifications-alarm-service'][-1]['connection-type'], 'service')
266 self.assertEqual(response['output']['notifications-alarm-service'][-1]['operational-state'], 'inService')
267 self.assertEqual(response['output']['notifications-alarm-service'][-1]['message'],
268 'The service is now inService')
270 def test_18_change_status_port_roadma_srg(self):
271 url = "{}/config/org-openroadm-device:org-openroadm-device/circuit-packs/3%2F0/ports/C1"
274 "logical-connection-point": "SRG1-PP1",
275 "port-type": "client",
276 "circuit-id": "SRG1",
277 "administrative-state": "outOfService",
278 "port-qual": "roadm-external"}]}
279 response = requests.request("PUT", url.format("http://127.0.0.1:8141/restconf"),
280 data=json.dumps(body), headers=test_utils.TYPE_APPLICATION_JSON,
281 auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD),
282 timeout=test_utils.REQUEST_TIMEOUT)
283 self.assertEqual(response.status_code, requests.codes.ok)
286 def test_19_get_notifications_alarm_service1(self):
287 response = test_utils.transportpce_api_rpc_request(
288 'nbi-notifications', 'get-notifications-alarm-service', self.nbi_notif_input_data)
289 self.assertEqual(response['status_code'], requests.codes.ok)
290 self.assertEqual(response['output']['notifications-alarm-service'][-1]['service-name'], 'service1')
291 self.assertEqual(response['output']['notifications-alarm-service'][-1]['connection-type'], 'service')
292 self.assertEqual(response['output']['notifications-alarm-service'][-1]['operational-state'], 'outOfService')
293 self.assertEqual(response['output']['notifications-alarm-service'][-1]['message'],
294 'The service is now outOfService')
296 def test_20_restore_status_port_roadma_srg(self):
297 url = "{}/config/org-openroadm-device:org-openroadm-device/circuit-packs/3%2F0/ports/C1"
300 "logical-connection-point": "SRG1-PP1",
301 "port-type": "client",
302 "circuit-id": "SRG1",
303 "administrative-state": "inService",
304 "port-qual": "roadm-external"}]}
305 response = requests.request("PUT", url.format("http://127.0.0.1:8141/restconf"),
306 data=json.dumps(body), headers=test_utils.TYPE_APPLICATION_JSON,
307 auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD),
308 timeout=test_utils.REQUEST_TIMEOUT)
309 self.assertEqual(response.status_code, requests.codes.ok)
312 def test_21_get_notifications_alarm_service1(self):
313 self.test_17_get_notifications_alarm_service1()
315 def test_22_delete_eth_service1(self):
316 self.del_serv_input_data["service-delete-req-info"]["service-name"] = "service1"
317 response = test_utils.transportpce_api_rpc_request(
318 'org-openroadm-service', 'service-delete', self.del_serv_input_data)
319 self.assertEqual(response['status_code'], requests.codes.ok)
320 self.assertIn('Renderer service delete in progress',
321 response['output']['configuration-response-common']['response-message'])
324 def test_23_get_notifications_service1(self):
325 response = test_utils.transportpce_api_rpc_request(
326 'nbi-notifications', 'get-notifications-process-service', self.nbi_notif_input_data)
327 self.assertEqual(response['status_code'], requests.codes.ok)
328 self.assertEqual(response['output']['notifications-process-service'][-1]['service-name'], 'service1')
329 self.assertEqual(response['output']['notifications-process-service'][-1]['connection-type'], 'service')
330 self.assertEqual(response['output']['notifications-process-service'][-1]['message'], 'Service deleted !')
333 def test_24_disconnect_XPDRA(self):
334 response = test_utils.unmount_device("XPDR-A1")
335 self.assertIn(response.status_code, (requests.codes.ok, requests.codes.no_content))
337 def test_25_disconnect_XPDRC(self):
338 response = test_utils.unmount_device("XPDR-C1")
339 self.assertIn(response.status_code, (requests.codes.ok, requests.codes.no_content))
341 def test_26_disconnect_ROADMA(self):
342 response = test_utils.unmount_device("ROADM-A1")
343 self.assertIn(response.status_code, (requests.codes.ok, requests.codes.no_content))
345 def test_27_disconnect_ROADMC(self):
346 response = test_utils.unmount_device("ROADM-C1")
347 self.assertIn(response.status_code, (requests.codes.ok, requests.codes.no_content))
350 if __name__ == "__main__":
351 unittest.main(verbosity=2)