Improve some func. tests variables naming
[transportpce.git] / tests / transportpce_tests / 2.2.1 / test02_topo_portmapping.py
1 #!/usr/bin/env python
2
3 ##############################################################################
4 # Copyright (c) 2017 Orange, Inc. and others.  All rights reserved.
5 #
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Apache License, Version 2.0
8 # which accompanies this distribution, and is available at
9 # http://www.apache.org/licenses/LICENSE-2.0
10 ##############################################################################
11
12 # pylint: disable=no-member
13 # pylint: disable=too-many-public-methods
14
15 import unittest
16 import time
17 import requests
18 # pylint: disable=wrong-import-order
19 import sys
20 sys.path.append('transportpce_tests/common/')
21 # pylint: disable=wrong-import-position
22 # pylint: disable=import-error
23 import test_utils_rfc8040  # nopep8
24
25
26 class TransportPCEtesting(unittest.TestCase):
27
28     processes = None
29     NODE_VERSION = '2.2.1'
30
31     @classmethod
32     def setUpClass(cls):
33         cls.processes = test_utils_rfc8040.start_tpce()
34         cls.processes = test_utils_rfc8040.start_sims([('xpdra', cls.NODE_VERSION), ('roadma', cls.NODE_VERSION)])
35
36     @classmethod
37     def tearDownClass(cls):
38         # pylint: disable=not-an-iterable
39         for process in cls.processes:
40             test_utils_rfc8040.shutdown_process(process)
41         print("all processes killed")
42
43     def setUp(self):
44         time.sleep(10)
45
46     # Connect the ROADMA
47     def test_01_connect_rdm(self):
48         response = test_utils_rfc8040.mount_device("ROADM-A1", ('roadma', self.NODE_VERSION))
49         self.assertEqual(response.status_code, requests.codes.created, test_utils_rfc8040.CODE_SHOULD_BE_201)
50
51     # Verify the termination points of the ROADMA
52     def test_02_compareOpenroadmTopologyPortMapping_rdm(self):
53         resTopo = test_utils_rfc8040.get_ietf_network_request('openroadm-topology', 'config')
54         self.assertEqual(resTopo['status_code'], requests.codes.ok)
55         nbMapCumul = 0
56         nbMappings = 0
57         for node in resTopo['network'][0]['node']:
58             nodeId = node['node-id']
59             # pylint: disable=consider-using-f-string
60             print("nodeId={}".format(nodeId))
61             nodeMapId = nodeId.split("-")[0] + "-" + nodeId.split("-")[1]
62             print("nodeMapId={}".format(nodeMapId))
63             response = test_utils_rfc8040.get_portmapping_node_info(nodeMapId)
64             self.assertEqual(response['status_code'], requests.codes.ok)
65             responseMapList = test_utils_rfc8040.get_portmapping(nodeMapId)
66             nbMappings = len(responseMapList['nodes'][0]['mapping']) - nbMapCumul
67             nbMapCurrent = 0
68             for tp in node['ietf-network-topology:termination-point']:
69                 tpId = tp['tp-id']
70                 if (not "CP" in tpId) and (not "CTP" in tpId):
71                     responseMap = test_utils_rfc8040.portmapping_request(nodeMapId, tpId)
72                     self.assertEqual(responseMap['status_code'], requests.codes.ok)
73                     if responseMap['status_code'] == requests.codes.ok:
74                         nbMapCurrent += 1
75             nbMapCumul += nbMapCurrent
76         nbMappings -= nbMapCurrent
77         self.assertEqual(nbMappings, 0)
78
79     # Disconnect the ROADMA
80     def test_03_disconnect_rdm(self):
81         response = test_utils_rfc8040.unmount_device("ROADM-A1")
82         self.assertIn(response.status_code, (requests.codes.ok, requests.codes.no_content))
83
84 #     #Connect the XPDRA
85     def test_04_connect_xpdr(self):
86         response = test_utils_rfc8040.mount_device("XPDR-A1", ('xpdra', self.NODE_VERSION))
87         self.assertEqual(response.status_code, requests.codes.created, test_utils_rfc8040.CODE_SHOULD_BE_201)
88
89 #     #Verify the termination points related to XPDR
90     def test_05_compareOpenroadmTopologyPortMapping_xpdr(self):
91         self.test_02_compareOpenroadmTopologyPortMapping_rdm()
92
93     # Disconnect the XPDRA
94     def test_06_disconnect_device(self):
95         response = test_utils_rfc8040.unmount_device("XPDR-A1")
96         self.assertIn(response.status_code, (requests.codes.ok, requests.codes.no_content))
97
98
99 if __name__ == "__main__":
100     # logging.basicConfig(filename='./transportpce_tests/log/response.log',filemode='w',level=logging.DEBUG)
101     #logging.debug('I am there')
102     unittest.main(verbosity=2)