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_rfc8040 # 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_input_data = {
51 "layer-protocol-name": "DSR",
52 "service-interface-point": {
53 "service-interface-point-uuid": "b1f4bd3b-7fa9-367b-a8ab-6e80293238df"
55 "administrative-state": "UNLOCKED",
56 "operational-state": "ENABLED",
57 "direction": "BIDIRECTIONAL",
59 "protection-role": "WORK",
60 "local-id": "XPDR-C1-XPDR1",
63 "value-name": "OpenROADM node id",
64 "value": "XPDR-C1-XPDR1"
69 "layer-protocol-name": "DSR",
70 "service-interface-point": {
71 "service-interface-point-uuid": "b5964ce9-274c-3f68-b4d1-83c0b61bc74e"
73 "administrative-state": "UNLOCKED",
74 "operational-state": "ENABLED",
75 "direction": "BIDIRECTIONAL",
77 "protection-role": "WORK",
78 "local-id": "XPDR-A1-XPDR1",
81 "value-name": "OpenROADM node id",
82 "value": "XPDR-A1-XPDR1"
87 "connectivity-constraint": {
88 "service-layer": "ETH",
89 "service-type": "POINT_TO_POINT_CONNECTIVITY",
90 "service-level": "Some service-level",
91 "requested-capacity": {
101 tapi_serv_details = {"service-id-or-name": "TBD"}
103 cr_notif_subs_input_data = {
104 "subscription-filter": {
105 "requested-notification-types": [
108 "requested-object-types": [
109 "CONNECTIVITY_SERVICE"
111 "requested-layer-protocols": [
114 "requested-object-identifier": [
115 "76d8f07b-ead5-4132-8eb8-cf3fdef7e079"
117 "include-content": True,
118 "local-id": "localId",
121 "value-name": "Subscription name",
122 "value": "test subscription"
126 "subscription-state": "ACTIVE"
129 cr_get_notif_list_input_data = {
130 "subscription-id-or-name": "c07e7fd1-0377-4fbf-8928-36c17b0d0d68",
131 "time-period": "time-period"
135 uuid_services = UuidServices()
136 uuid_subscriptions = UuidSubscriptions()
137 WAITING = 25 # nominal value is 300
138 NODE_VERSION_221 = '2.2.1'
142 # pylint: disable=unsubscriptable-object
143 # TODO: for lighty manage the activation of NBI notification feature
144 cls.init_failed_nbi = False
145 cls.init_failed_tapi = False
146 os.environ['JAVA_MIN_MEM'] = '1024M'
147 os.environ['JAVA_MAX_MEM'] = '4096M'
148 cls.processes = test_utils_rfc8040.start_tpce()
149 # NBI notification feature is not installed by default in Karaf
150 if "USE_LIGHTY" not in os.environ or os.environ['USE_LIGHTY'] != 'True':
151 print("installing NBI notification feature...")
152 result = test_utils_rfc8040.install_karaf_feature("odl-transportpce-nbinotifications")
153 if result.returncode != 0:
154 cls.init_failed_nbi = True
155 print("installing tapi feature...")
156 result = test_utils_rfc8040.install_karaf_feature("odl-transportpce-tapi")
157 if result.returncode != 0:
158 cls.init_failed_tapi = True
159 print("Restarting OpenDaylight...")
160 test_utils_rfc8040.shutdown_process(cls.processes[0])
161 cls.processes[0] = test_utils_rfc8040.start_karaf()
162 test_utils_rfc8040.process_list[0] = cls.processes[0]
163 cls.init_failed = not test_utils_rfc8040.wait_until_log_contains(
164 test_utils_rfc8040.KARAF_LOG, test_utils_rfc8040.KARAF_OK_START_MSG, time_to_wait=60)
165 if cls.init_failed_nbi:
166 print("NBI notification installation feature failed...")
167 test_utils_rfc8040.shutdown_process(cls.processes[0])
169 if cls.init_failed_tapi:
170 print("tapi installation feature failed...")
171 test_utils_rfc8040.shutdown_process(cls.processes[0])
173 cls.processes = test_utils_rfc8040.start_sims([('xpdra', cls.NODE_VERSION_221),
174 ('roadma', cls.NODE_VERSION_221),
175 ('roadmc', cls.NODE_VERSION_221),
176 ('xpdrc', cls.NODE_VERSION_221)])
179 def tearDownClass(cls):
180 # pylint: disable=not-an-iterable
181 for process in cls.processes:
182 test_utils_rfc8040.shutdown_process(process)
183 print("all processes killed")
185 def setUp(self): # instruction executed before each test method
186 # pylint: disable=consider-using-f-string
187 print("execution of {}".format(self.id().split(".")[-1]))
189 def test_01_connect_xpdrA(self):
190 response = test_utils_rfc8040.mount_device("XPDR-A1", ('xpdra', self.NODE_VERSION_221))
191 self.assertEqual(response.status_code,
192 requests.codes.created, test_utils_rfc8040.CODE_SHOULD_BE_201)
194 def test_02_connect_xpdrC(self):
195 response = test_utils_rfc8040.mount_device("XPDR-C1", ('xpdrc', self.NODE_VERSION_221))
196 self.assertEqual(response.status_code,
197 requests.codes.created, test_utils_rfc8040.CODE_SHOULD_BE_201)
199 def test_03_connect_rdmA(self):
200 response = test_utils_rfc8040.mount_device("ROADM-A1", ('roadma', self.NODE_VERSION_221))
201 self.assertEqual(response.status_code,
202 requests.codes.created, test_utils_rfc8040.CODE_SHOULD_BE_201)
204 def test_04_connect_rdmC(self):
205 response = test_utils_rfc8040.mount_device("ROADM-C1", ('roadmc', self.NODE_VERSION_221))
206 self.assertEqual(response.status_code,
207 requests.codes.created, test_utils_rfc8040.CODE_SHOULD_BE_201)
209 def test_05_connect_xprdA_N1_to_roadmA_PP1(self):
210 response = test_utils_rfc8040.transportpce_api_rpc_request(
211 'transportpce-networkutils', 'init-xpdr-rdm-links',
212 {'links-input': {'xpdr-node': 'XPDR-A1', 'xpdr-num': '1', 'network-num': '1',
213 'rdm-node': 'ROADM-A1', 'srg-num': '1', 'termination-point-num': 'SRG1-PP1-TXRX'}})
214 self.assertEqual(response['status_code'], requests.codes.ok)
215 self.assertIn('Xponder Roadm Link created successfully', response["output"]["result"])
218 def test_06_connect_roadmA_PP1_to_xpdrA_N1(self):
219 response = test_utils_rfc8040.transportpce_api_rpc_request(
220 'transportpce-networkutils', 'init-rdm-xpdr-links',
221 {'links-input': {'xpdr-node': 'XPDR-A1', 'xpdr-num': '1', 'network-num': '1',
222 'rdm-node': 'ROADM-A1', 'srg-num': '1', 'termination-point-num': 'SRG1-PP1-TXRX'}})
223 self.assertEqual(response['status_code'], requests.codes.ok)
224 self.assertIn('Roadm Xponder links created successfully', response["output"]["result"])
227 def test_07_connect_xprdC_N1_to_roadmC_PP1(self):
228 response = test_utils_rfc8040.transportpce_api_rpc_request(
229 'transportpce-networkutils', 'init-xpdr-rdm-links',
230 {'links-input': {'xpdr-node': 'XPDR-C1', 'xpdr-num': '1', 'network-num': '1',
231 'rdm-node': 'ROADM-C1', 'srg-num': '1', 'termination-point-num': 'SRG1-PP1-TXRX'}})
232 self.assertEqual(response['status_code'], requests.codes.ok)
233 self.assertIn('Xponder Roadm Link created successfully', response["output"]["result"])
236 def test_08_connect_roadmC_PP1_to_xpdrC_N1(self):
237 response = test_utils_rfc8040.transportpce_api_rpc_request(
238 'transportpce-networkutils', 'init-rdm-xpdr-links',
239 {'links-input': {'xpdr-node': 'XPDR-C1', 'xpdr-num': '1', 'network-num': '1',
240 'rdm-node': 'ROADM-C1', 'srg-num': '1', 'termination-point-num': 'SRG1-PP1-TXRX'}})
241 self.assertEqual(response['status_code'], requests.codes.ok)
242 self.assertIn('Roadm Xponder links created successfully', response["output"]["result"])
245 def test_09_add_omsAttributes_ROADMA_ROADMC(self):
246 # Config ROADMA-ROADMC oms-attributes
248 "auto-spanloss": "true",
249 "spanloss-base": 11.4,
250 "spanloss-current": 12,
251 "engineered-spanloss": 12.2,
252 "link-concatenation": [{
255 "SRLG-length": 100000,
257 response = test_utils_rfc8040.add_oms_attr_request(
258 "ROADM-A1-DEG2-DEG2-TTP-TXRXtoROADM-C1-DEG1-DEG1-TTP-TXRX", data)
259 self.assertEqual(response.status_code, requests.codes.created)
261 def test_10_add_omsAttributes_ROADMC_ROADMA(self):
262 # Config ROADMC-ROADMA oms-attributes
264 "auto-spanloss": "true",
265 "spanloss-base": 11.4,
266 "spanloss-current": 12,
267 "engineered-spanloss": 12.2,
268 "link-concatenation": [{
271 "SRLG-length": 100000,
273 response = test_utils_rfc8040.add_oms_attr_request(
274 "ROADM-C1-DEG1-DEG1-TTP-TXRXtoROADM-A1-DEG2-DEG2-TTP-TXRX", data)
275 self.assertEqual(response.status_code, requests.codes.created)
277 # test service-create for Eth service from xpdr to xpdr
278 def test_11_create_connectivity_service_Ethernet(self):
279 response = test_utils_rfc8040.transportpce_api_rpc_request(
280 'tapi-connectivity', 'create-connectivity-service', self.cr_serv_input_data)
281 time.sleep(self.WAITING)
282 self.assertEqual(response['status_code'], requests.codes.ok)
283 self.uuid_services.eth = response['output']['service']['uuid']
284 # pylint: disable=consider-using-f-string
286 input_dict_1 = {'administrative-state': 'LOCKED',
287 'lifecycle-state': 'PLANNED',
288 'operational-state': 'DISABLED',
289 'service-type': 'POINT_TO_POINT_CONNECTIVITY',
290 'service-layer': 'ETH',
291 'connectivity-direction': 'BIDIRECTIONAL'
293 input_dict_2 = {'value-name': 'OpenROADM node id',
294 'value': 'XPDR-C1-XPDR1'}
295 input_dict_3 = {'value-name': 'OpenROADM node id',
296 'value': 'XPDR-A1-XPDR1'}
298 self.assertDictEqual(dict(input_dict_1, **response['output']['service']),
299 response['output']['service'])
300 self.assertDictEqual(dict(input_dict_2, **response['output']['service']['end-point'][0]['name'][0]),
301 response['output']['service']['end-point'][0]['name'][0])
302 self.assertDictEqual(dict(input_dict_3, **response['output']['service']['end-point'][1]['name'][0]),
303 response['output']['service']['end-point'][1]['name'][0])
304 # If the gate fails is because of the waiting time not being enough
305 time.sleep(self.WAITING)
307 def test_12_get_service_Ethernet(self):
308 response = test_utils_rfc8040.get_ordm_serv_list_attr_request("services", str(self.uuid_services.eth))
309 self.assertEqual(response['status_code'], requests.codes.ok)
310 self.assertEqual(response['services'][0]['administrative-state'], 'inService')
311 self.assertEqual(response['services'][0]['service-name'], str(self.uuid_services.eth))
312 self.assertEqual(response['services'][0]['connection-type'], 'service')
313 self.assertEqual(response['services'][0]['lifecycle-state'], 'planned')
316 def test_13_get_connectivity_service_Ethernet(self):
317 self.tapi_serv_details["service-id-or-name"] = str(self.uuid_services.eth)
318 response = test_utils_rfc8040.transportpce_api_rpc_request(
319 'tapi-connectivity', 'get-connectivity-service-details', self.tapi_serv_details)
320 self.assertEqual(response['status_code'], requests.codes.ok)
321 self.assertEqual(response['output']['service']['operational-state'], 'ENABLED')
322 self.assertEqual(response['output']['service']['name'][0]['value'], self.uuid_services.eth)
323 self.assertEqual(response['output']['service']['administrative-state'], 'UNLOCKED')
324 self.assertEqual(response['output']['service']['lifecycle-state'], 'INSTALLED')
326 def test_14_create_notifications_subscription_service(self):
327 self.cr_notif_subs_input_data["subscription-filter"]["requested-object-identifier"][0] =\
328 str(self.uuid_services.eth)
329 response = test_utils_rfc8040.transportpce_api_rpc_request(
330 'tapi-notification', 'create-notification-subscription-service', self.cr_notif_subs_input_data)
331 self.assertEqual(response['status_code'], requests.codes.ok)
332 self.uuid_subscriptions.eth = response['output']['subscription-service']['uuid']
333 self.assertEqual(response['output']['subscription-service']['subscription-filter']
334 ['requested-object-types'][0], 'CONNECTIVITY_SERVICE')
335 self.assertEqual(response['output']['subscription-service']['subscription-filter']
336 ['requested-notification-types'][0], 'ALARM_EVENT')
337 self.assertEqual(response['output']['subscription-service']['subscription-filter']
338 ['requested-object-identifier'][0], str(self.uuid_services.eth))
341 def test_15_change_status_port_roadma_srg(self):
342 url = "{}/config/org-openroadm-device:org-openroadm-device/circuit-packs/3%2F0/ports/C1"
345 "logical-connection-point": "SRG1-PP1",
346 "port-type": "client",
347 "circuit-id": "SRG1",
348 "administrative-state": "outOfService",
349 "port-qual": "roadm-external"}]}
350 response = requests.request("PUT", url.format("http://127.0.0.1:8141/restconf"),
351 data=json.dumps(body), headers=test_utils_rfc8040.TYPE_APPLICATION_JSON,
352 auth=(test_utils_rfc8040.ODL_LOGIN, test_utils_rfc8040.ODL_PWD),
353 timeout=test_utils_rfc8040.REQUEST_TIMEOUT)
354 self.assertEqual(response.status_code, requests.codes.ok)
355 # If the gate fails is because of the waiting time not being enough
358 def test_16_get_tapi_notifications_connectivity_service_Ethernet(self):
359 self.cr_get_notif_list_input_data["subscription-id-or-name"] = str(self.uuid_subscriptions.eth)
360 response = test_utils_rfc8040.transportpce_api_rpc_request(
361 'tapi-notification', 'get-notification-list', self.cr_get_notif_list_input_data)
362 self.assertEqual(response['status_code'], requests.codes.ok)
363 self.assertEqual(response['output']['notification'][0]['target-object-identifier'], str(self.uuid_services.eth))
364 self.assertEqual(response['output']['notification'][0]['target-object-type'], 'CONNECTIVITY_SERVICE')
365 self.assertEqual(response['output']['notification'][0]['changed-attributes'][0]['new-value'], 'LOCKED')
366 self.assertEqual(response['output']['notification'][0]['changed-attributes'][1]['new-value'], 'DISABLED')
369 def test_17_restore_status_port_roadma_srg(self):
370 url = "{}/config/org-openroadm-device:org-openroadm-device/circuit-packs/3%2F0/ports/C1"
373 "logical-connection-point": "SRG1-PP1",
374 "port-type": "client",
375 "circuit-id": "SRG1",
376 "administrative-state": "inService",
377 "port-qual": "roadm-external"}]}
378 response = requests.request("PUT", url.format("http://127.0.0.1:8141/restconf"),
379 data=json.dumps(body), headers=test_utils_rfc8040.TYPE_APPLICATION_JSON,
380 auth=(test_utils_rfc8040.ODL_LOGIN, test_utils_rfc8040.ODL_PWD),
381 timeout=test_utils_rfc8040.REQUEST_TIMEOUT)
382 self.assertEqual(response.status_code, requests.codes.ok)
383 # If the gate fails is because of the waiting time not being enough
386 def test_18_get_tapi_notifications_connectivity_service_Ethernet(self):
387 self.cr_get_notif_list_input_data["subscription-id-or-name"] = str(self.uuid_subscriptions.eth)
388 response = test_utils_rfc8040.transportpce_api_rpc_request(
389 'tapi-notification', 'get-notification-list', self.cr_get_notif_list_input_data)
390 self.assertEqual(response['status_code'], requests.codes.ok)
391 self.assertEqual(response['output']['notification'][1]['target-object-identifier'], str(self.uuid_services.eth))
392 self.assertEqual(response['output']['notification'][1]['target-object-type'], 'CONNECTIVITY_SERVICE')
393 self.assertEqual(response['output']['notification'][1]['changed-attributes'][0]['new-value'], 'UNLOCKED')
394 self.assertEqual(response['output']['notification'][1]['changed-attributes'][1]['new-value'], 'ENABLED')
397 def test_19_delete_connectivity_service_Ethernet(self):
398 self.tapi_serv_details["service-id-or-name"] = str(self.uuid_services.eth)
399 response = test_utils_rfc8040.transportpce_api_rpc_request(
400 'tapi-connectivity', 'delete-connectivity-service', self.tapi_serv_details)
401 self.assertIn(response['status_code'], (requests.codes.ok, requests.codes.no_content))
402 time.sleep(self.WAITING)
404 def test_20_disconnect_XPDRA(self):
405 response = test_utils_rfc8040.unmount_device("XPDR-A1")
406 self.assertIn(response.status_code, (requests.codes.ok, requests.codes.no_content))
408 def test_21_disconnect_XPDRC(self):
409 response = test_utils_rfc8040.unmount_device("XPDR-C1")
410 self.assertIn(response.status_code, (requests.codes.ok, requests.codes.no_content))
412 def test_22_disconnect_ROADMA(self):
413 response = test_utils_rfc8040.unmount_device("ROADM-A1")
414 self.assertIn(response.status_code, (requests.codes.ok, requests.codes.no_content))
416 def test_23_disconnect_ROADMC(self):
417 response = test_utils_rfc8040.unmount_device("ROADM-C1")
418 self.assertIn(response.status_code, (requests.codes.ok, requests.codes.no_content))
421 if __name__ == "__main__":
422 unittest.main(verbosity=2)