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 # pylint: disable=too-few-public-methods
30 # pylint: disable=invalid-name
37 # pylint: disable=too-few-public-methods
38 class UuidSubscriptions:
40 # pylint: disable=invalid-name
47 class TransportNbiNotificationstesting(unittest.TestCase):
48 cr_serv_sample_data = {
52 "layer-protocol-name": "DSR",
53 "service-interface-point": {
54 "service-interface-point-uuid": "b1f4bd3b-7fa9-367b-a8ab-6e80293238df"
56 "administrative-state": "UNLOCKED",
57 "operational-state": "ENABLED",
58 "direction": "BIDIRECTIONAL",
60 "protection-role": "WORK",
61 "local-id": "XPDR-C1-XPDR1",
64 "value-name": "OpenROADM node id",
65 "value": "XPDR-C1-XPDR1"
70 "layer-protocol-name": "DSR",
71 "service-interface-point": {
72 "service-interface-point-uuid": "b5964ce9-274c-3f68-b4d1-83c0b61bc74e"
74 "administrative-state": "UNLOCKED",
75 "operational-state": "ENABLED",
76 "direction": "BIDIRECTIONAL",
78 "protection-role": "WORK",
79 "local-id": "XPDR-A1-XPDR1",
82 "value-name": "OpenROADM node id",
83 "value": "XPDR-A1-XPDR1"
88 "connectivity-constraint": {
89 "service-layer": "ETH",
90 "service-type": "POINT_TO_POINT_CONNECTIVITY",
91 "service-level": "Some service-level",
92 "requested-capacity": {
103 cr_notif_subs_sample_data = {
105 "subscription-filter": {
106 "requested-notification-types": [
109 "requested-object-types": [
110 "CONNECTIVITY_SERVICE"
112 "requested-layer-protocols": [
115 "requested-object-identifier": [
116 "76d8f07b-ead5-4132-8eb8-cf3fdef7e079"
118 "include-content": True,
119 "local-id": "localId",
122 "value-name": "Subscription name",
123 "value": "test subscription"
127 "subscription-state": "ACTIVE"
131 cr_get_notif_list_sample_data = {
133 "subscription-id-or-name": "c07e7fd1-0377-4fbf-8928-36c17b0d0d68",
134 "time-period": "time-period"
139 uuid_services = UuidServices()
140 uuid_subscriptions = UuidSubscriptions()
141 WAITING = 25 # nominal value is 300
142 NODE_VERSION_221 = '2.2.1'
146 # pylint: disable=unsubscriptable-object
147 # TODO: for lighty manage the activation of NBI notification feature
148 cls.init_failed_nbi = False
149 cls.init_failed_tapi = False
150 os.environ['JAVA_MIN_MEM'] = '1024M'
151 os.environ['JAVA_MAX_MEM'] = '4096M'
152 cls.processes = test_utils.start_tpce()
153 # NBI notification feature is not installed by default in Karaf
154 if "USE_LIGHTY" not in os.environ or os.environ['USE_LIGHTY'] != 'True':
155 print("installing NBI notification feature...")
156 result = test_utils.install_karaf_feature("odl-transportpce-nbinotifications")
157 if result.returncode != 0:
158 cls.init_failed_nbi = True
159 print("installing tapi feature...")
160 result = test_utils.install_karaf_feature("odl-transportpce-tapi")
161 if result.returncode != 0:
162 cls.init_failed_tapi = True
163 print("Restarting OpenDaylight...")
164 test_utils.shutdown_process(cls.processes[0])
165 cls.processes[0] = test_utils.start_karaf()
166 test_utils.process_list[0] = cls.processes[0]
167 cls.init_failed = not test_utils.wait_until_log_contains(
168 test_utils.KARAF_LOG, test_utils.KARAF_OK_START_MSG, time_to_wait=60)
169 if cls.init_failed_nbi:
170 print("NBI notification installation feature failed...")
171 test_utils.shutdown_process(cls.processes[0])
173 if cls.init_failed_tapi:
174 print("tapi installation feature failed...")
175 test_utils.shutdown_process(cls.processes[0])
177 cls.processes = test_utils.start_sims([('xpdra', cls.NODE_VERSION_221),
178 ('roadma', cls.NODE_VERSION_221),
179 ('roadmc', cls.NODE_VERSION_221),
180 ('xpdrc', cls.NODE_VERSION_221)])
183 def tearDownClass(cls):
184 # pylint: disable=not-an-iterable
185 for process in cls.processes:
186 test_utils.shutdown_process(process)
187 print("all processes killed")
189 def setUp(self): # instruction executed before each test method
190 # pylint: disable=consider-using-f-string
191 print("execution of {}".format(self.id().split(".")[-1]))
193 def test_01_connect_xpdrA(self):
194 response = test_utils.mount_device("XPDR-A1", ('xpdra', self.NODE_VERSION_221))
195 self.assertEqual(response.status_code, requests.codes.created, test_utils.CODE_SHOULD_BE_201)
197 def test_02_connect_xpdrC(self):
198 response = test_utils.mount_device("XPDR-C1", ('xpdrc', self.NODE_VERSION_221))
199 self.assertEqual(response.status_code, requests.codes.created, test_utils.CODE_SHOULD_BE_201)
201 def test_03_connect_rdmA(self):
202 response = test_utils.mount_device("ROADM-A1", ('roadma', self.NODE_VERSION_221))
203 self.assertEqual(response.status_code, requests.codes.created, test_utils.CODE_SHOULD_BE_201)
205 def test_04_connect_rdmC(self):
206 response = test_utils.mount_device("ROADM-C1", ('roadmc', self.NODE_VERSION_221))
207 self.assertEqual(response.status_code, requests.codes.created, test_utils.CODE_SHOULD_BE_201)
209 def test_05_connect_xprdA_N1_to_roadmA_PP1(self):
210 response = test_utils.connect_xpdr_to_rdm_request("XPDR-A1", "1", "1",
211 "ROADM-A1", "1", "SRG1-PP1-TXRX")
212 self.assertEqual(response.status_code, requests.codes.ok)
213 res = response.json()
214 self.assertIn('Xponder Roadm Link created successfully', res["output"]["result"])
217 def test_06_connect_roadmA_PP1_to_xpdrA_N1(self):
218 response = test_utils.connect_rdm_to_xpdr_request("XPDR-A1", "1", "1",
219 "ROADM-A1", "1", "SRG1-PP1-TXRX")
220 self.assertEqual(response.status_code, requests.codes.ok)
221 res = response.json()
222 self.assertIn('Roadm Xponder links created successfully', res["output"]["result"])
225 def test_07_connect_xprdC_N1_to_roadmC_PP1(self):
226 response = test_utils.connect_xpdr_to_rdm_request("XPDR-C1", "1", "1",
227 "ROADM-C1", "1", "SRG1-PP1-TXRX")
228 self.assertEqual(response.status_code, requests.codes.ok)
229 res = response.json()
230 self.assertIn('Xponder Roadm Link created successfully', res["output"]["result"])
233 def test_08_connect_roadmC_PP1_to_xpdrC_N1(self):
234 response = test_utils.connect_rdm_to_xpdr_request("XPDR-C1", "1", "1",
235 "ROADM-C1", "1", "SRG1-PP1-TXRX")
236 self.assertEqual(response.status_code, requests.codes.ok)
237 res = response.json()
238 self.assertIn('Roadm Xponder links created successfully', res["output"]["result"])
241 def test_09_add_omsAttributes_ROADMA_ROADMC(self):
242 # Config ROADMA-ROADMC oms-attributes
244 "auto-spanloss": "true",
245 "spanloss-base": 11.4,
246 "spanloss-current": 12,
247 "engineered-spanloss": 12.2,
248 "link-concatenation": [{
251 "SRLG-length": 100000,
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)
256 def test_10_add_omsAttributes_ROADMC_ROADMA(self):
257 # Config ROADMC-ROADMA oms-attributes
259 "auto-spanloss": "true",
260 "spanloss-base": 11.4,
261 "spanloss-current": 12,
262 "engineered-spanloss": 12.2,
263 "link-concatenation": [{
266 "SRLG-length": 100000,
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)
271 # test service-create for Eth service from xpdr to xpdr
272 def test_11_create_connectivity_service_Ethernet(self):
273 response = test_utils.tapi_create_connectivity_request(self.cr_serv_sample_data)
274 time.sleep(self.WAITING)
275 self.assertEqual(response.status_code, requests.codes.ok)
276 res = response.json()
277 self.uuid_services.eth = res['output']['service']['uuid']
278 # pylint: disable=consider-using-f-string
280 input_dict_1 = {'administrative-state': 'LOCKED',
281 'lifecycle-state': 'PLANNED',
282 'operational-state': 'DISABLED',
283 'service-type': 'POINT_TO_POINT_CONNECTIVITY',
284 'service-layer': 'ETH',
285 'connectivity-direction': 'BIDIRECTIONAL'
287 input_dict_2 = {'value-name': 'OpenROADM node id',
288 'value': 'XPDR-C1-XPDR1'}
289 input_dict_3 = {'value-name': 'OpenROADM node id',
290 'value': 'XPDR-A1-XPDR1'}
292 self.assertDictEqual(dict(input_dict_1, **res['output']['service']),
293 res['output']['service'])
294 self.assertDictEqual(dict(input_dict_2, **res['output']['service']['end-point'][0]['name'][0]),
295 res['output']['service']['end-point'][0]['name'][0])
296 self.assertDictEqual(dict(input_dict_3, **res['output']['service']['end-point'][1]['name'][0]),
297 res['output']['service']['end-point'][1]['name'][0])
298 # If the gate fails is because of the waiting time not being enough
299 time.sleep(self.WAITING)
301 def test_12_get_service_Ethernet(self):
302 response = test_utils.get_service_list_request("services/" + str(self.uuid_services.eth))
303 self.assertEqual(response.status_code, requests.codes.ok)
304 res = response.json()
306 res['services'][0]['administrative-state'], 'inService')
308 res['services'][0]['service-name'], self.uuid_services.eth)
310 res['services'][0]['connection-type'], 'service')
312 res['services'][0]['lifecycle-state'], 'planned')
315 def test_13_get_connectivity_service_Ethernet(self):
316 response = test_utils.tapi_get_connectivity_request(str(self.uuid_services.eth))
317 self.assertEqual(response.status_code, requests.codes.ok)
318 res = response.json()
320 res['output']['service']['operational-state'], 'ENABLED')
322 res['output']['service']['name'][0]['value'], self.uuid_services.eth)
324 res['output']['service']['administrative-state'], 'UNLOCKED')
326 res['output']['service']['lifecycle-state'], 'INSTALLED')
329 def test_14_create_notifications_subscription_service(self):
330 self.cr_notif_subs_sample_data["input"]["subscription-filter"]["requested-object-identifier"][0] = str(
331 self.uuid_services.eth)
332 response = test_utils.tapi_create_notification_subscription_service_request(self.cr_notif_subs_sample_data)
333 self.assertEqual(response.status_code, requests.codes.ok)
334 res = response.json()
335 self.uuid_subscriptions.eth = res['output']['subscription-service']['uuid']
336 self.assertEqual(res['output']['subscription-service']['subscription-filter']
337 ['requested-object-types'][0], 'CONNECTIVITY_SERVICE')
338 self.assertEqual(res['output']['subscription-service']['subscription-filter']
339 ['requested-notification-types'][0], 'ALARM_EVENT')
340 self.assertEqual(res['output']['subscription-service']['subscription-filter']
341 ['requested-object-identifier'][0], str(self.uuid_services.eth))
344 def test_15_change_status_port_roadma_srg(self):
345 url = "{}/config/org-openroadm-device:org-openroadm-device/circuit-packs/3%2F0/ports/C1"
348 "logical-connection-point": "SRG1-PP1",
349 "port-type": "client",
350 "circuit-id": "SRG1",
351 "administrative-state": "outOfService",
352 "port-qual": "roadm-external"}]}
353 response = requests.request("PUT", url.format("http://127.0.0.1:8141/restconf"),
354 data=json.dumps(body), headers=test_utils.TYPE_APPLICATION_JSON,
355 auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD),
356 timeout=test_utils.REQUEST_TIMEOUT)
357 self.assertEqual(response.status_code, requests.codes.ok)
358 # If the gate fails is because of the waiting time not being enough
361 def test_16_get_tapi_notifications_connectivity_service_Ethernet(self):
362 self.cr_get_notif_list_sample_data["input"]["subscription-id-or-name"] = str(self.uuid_subscriptions.eth)
363 response = test_utils.tapi_get_notifications_list_request(self.cr_get_notif_list_sample_data)
364 self.assertEqual(response.status_code, requests.codes.ok)
365 res = response.json()
366 self.assertEqual(res['output']['notification'][0]['target-object-identifier'], str(self.uuid_services.eth))
367 self.assertEqual(res['output']['notification'][0]['target-object-type'], 'CONNECTIVITY_SERVICE')
368 self.assertEqual(res['output']['notification'][0]['changed-attributes'][0]['new-value'], 'LOCKED')
369 self.assertEqual(res['output']['notification'][0]['changed-attributes'][1]['new-value'], 'DISABLED')
372 def test_17_restore_status_port_roadma_srg(self):
373 url = "{}/config/org-openroadm-device:org-openroadm-device/circuit-packs/3%2F0/ports/C1"
376 "logical-connection-point": "SRG1-PP1",
377 "port-type": "client",
378 "circuit-id": "SRG1",
379 "administrative-state": "inService",
380 "port-qual": "roadm-external"}]}
381 response = requests.request("PUT", url.format("http://127.0.0.1:8141/restconf"),
382 data=json.dumps(body), headers=test_utils.TYPE_APPLICATION_JSON,
383 auth=(test_utils.ODL_LOGIN, test_utils.ODL_PWD),
384 timeout=test_utils.REQUEST_TIMEOUT)
385 self.assertEqual(response.status_code, requests.codes.ok)
386 # If the gate fails is because of the waiting time not being enough
389 def test_18_get_tapi_notifications_connectivity_service_Ethernet(self):
390 self.cr_get_notif_list_sample_data["input"]["subscription-id-or-name"] = str(self.uuid_subscriptions.eth)
391 response = test_utils.tapi_get_notifications_list_request(self.cr_get_notif_list_sample_data)
392 self.assertEqual(response.status_code, requests.codes.ok)
393 res = response.json()
394 self.assertEqual(res['output']['notification'][1]['target-object-identifier'], str(self.uuid_services.eth))
395 self.assertEqual(res['output']['notification'][1]['target-object-type'], 'CONNECTIVITY_SERVICE')
396 self.assertEqual(res['output']['notification'][1]['changed-attributes'][0]['new-value'], 'UNLOCKED')
397 self.assertEqual(res['output']['notification'][1]['changed-attributes'][1]['new-value'], 'ENABLED')
400 def test_19_delete_connectivity_service_Ethernet(self):
401 response = test_utils.tapi_delete_connectivity_request(str(self.uuid_services.eth))
402 self.assertEqual(response.status_code, requests.codes.no_content)
403 time.sleep(self.WAITING)
405 def test_20_disconnect_XPDRA(self):
406 response = test_utils.unmount_device("XPDR-A1")
407 self.assertEqual(response.status_code, requests.codes.ok, test_utils.CODE_SHOULD_BE_200)
409 def test_21_disconnect_XPDRC(self):
410 response = test_utils.unmount_device("XPDR-C1")
411 self.assertEqual(response.status_code, requests.codes.ok, test_utils.CODE_SHOULD_BE_200)
413 def test_22_disconnect_ROADMA(self):
414 response = test_utils.unmount_device("ROADM-A1")
415 self.assertEqual(response.status_code, requests.codes.ok, test_utils.CODE_SHOULD_BE_200)
417 def test_23_disconnect_ROADMC(self):
418 response = test_utils.unmount_device("ROADM-C1")
419 self.assertEqual(response.status_code, requests.codes.ok, test_utils.CODE_SHOULD_BE_200)
422 if __name__ == "__main__":
423 unittest.main(verbosity=2)