Fix some pylint warnings
[transportpce.git] / tests / transportpce_tests / with_docker / test01_gnpy.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 os
17 # pylint: disable=wrong-import-order
18 import sys
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 TransportGNPYtesting(unittest.TestCase):
28
29     topo_cllinet_data = None
30     topo_ordnet_data = None
31     topo_ordtopo_data = None
32     port_mapping_data = None
33     processes = None
34
35     @classmethod
36     def setUpClass(cls):
37         # pylint: disable=bare-except
38         try:
39             sample_files_parsed = False
40             TOPO_CLLINET_FILE = os.path.join(os.path.dirname(os.path.realpath(__file__)),
41                                              "..", "..", "sample_configs", "gnpy", "clliNetwork.json")
42             with open(TOPO_CLLINET_FILE, 'r') as topo_cllinet:
43                 cls.topo_cllinet_data = topo_cllinet.read()
44
45             TOPO_ORDNET_FILE = os.path.join(os.path.dirname(os.path.realpath(__file__)),
46                                             "..", "..", "sample_configs", "gnpy", "openroadmNetwork.json")
47             with open(TOPO_ORDNET_FILE, 'r') as topo_ordnet:
48                 cls.topo_ordnet_data = topo_ordnet.read()
49
50             TOPO_ORDTOPO_FILE = os.path.join(os.path.dirname(os.path.realpath(__file__)),
51                                              "..", "..", "sample_configs", "gnpy", "openroadmTopology.json")
52             with open(TOPO_ORDTOPO_FILE, 'r') as topo_ordtopo:
53                 cls.topo_ordtopo_data = topo_ordtopo.read()
54             PORT_MAPPING_FILE = os.path.join(os.path.dirname(os.path.realpath(__file__)),
55                                              "..", "..", "sample_configs", "gnpy", "gnpy_portmapping_121.json")
56             with open(PORT_MAPPING_FILE, 'r') as port_mapping:
57                 cls.port_mapping_data = port_mapping.read()
58             sample_files_parsed = True
59         except PermissionError as err:
60             print("Permission Error when trying to read sample files\n", err)
61             sys.exit(2)
62         except FileNotFoundError as err:
63             print("File Not found Error when trying to read sample files\n", err)
64             sys.exit(2)
65         except:
66             print("Unexpected error when trying to read sample files\n", sys.exc_info()[0])
67             sys.exit(2)
68         finally:
69             if sample_files_parsed:
70                 print("sample files content loaded")
71
72         cls.processes = test_utils.start_tpce()
73
74     @classmethod
75     def tearDownClass(cls):
76         # pylint: disable=not-an-iterable
77         for process in cls.processes:
78             test_utils.shutdown_process(process)
79         print("all processes killed")
80
81     def setUp(self):
82         time.sleep(2)
83
84      # Load port mapping
85     def test_00_load_port_mapping(self):
86         response = test_utils.rawpost_request(test_utils.URL_FULL_PORTMAPPING, self.port_mapping_data)
87         self.assertEqual(response.status_code, requests.codes.no_content)
88         time.sleep(2)
89
90     # Mount the different topologies
91     def test_01_connect_clliNetwork(self):
92         response = test_utils.rawput_request(test_utils.URL_CONFIG_CLLI_NET, self.topo_cllinet_data)
93         self.assertEqual(response.status_code, requests.codes.ok)
94         time.sleep(3)
95
96     def test_02_connect_openroadmNetwork(self):
97         response = test_utils.rawput_request(test_utils.URL_CONFIG_ORDM_NET, self.topo_ordnet_data)
98         self.assertEqual(response.status_code, requests.codes.ok)
99         time.sleep(3)
100
101     def test_03_connect_openroadmTopology(self):
102         response = test_utils.rawput_request(test_utils.URL_CONFIG_ORDM_TOPO, self.topo_ordtopo_data)
103         self.assertEqual(response.status_code, requests.codes.ok)
104         time.sleep(3)
105
106     # Path computed by PCE is feasible according to Gnpy
107     def test_04_path_computation_FeasibleWithPCE(self):
108         response = test_utils.path_computation_request("request-1", "service-1",
109                                                        {"node-id": "XPONDER-1", "service-rate": "100",
110                                                            "service-format": "Ethernet", "clli": "Node1"},
111                                                        {"node-id": "XPONDER-5", "service-rate": "100",
112                                                            "service-format": "Ethernet", "clli": "Node5"})
113         self.assertEqual(response.status_code, requests.codes.ok)
114         res = response.json()
115         self.assertEqual(res['output']['configuration-response-common'][
116             'response-code'], '200')
117         self.assertEqual(res['output']['configuration-response-common'][
118             'response-message'],
119             'Path is calculated by PCE')
120         self.assertIn('A-to-Z',
121                       [res['output']['gnpy-response'][0]['path-dir'],
122                        res['output']['gnpy-response'][1]['path-dir']])
123         self.assertIn('Z-to-A',
124                       [res['output']['gnpy-response'][0]['path-dir'],
125                        res['output']['gnpy-response'][1]['path-dir']])
126         self.assertEqual(res['output']['gnpy-response'][0]['feasibility'], True)
127         self.assertEqual(res['output']['gnpy-response'][1]['feasibility'], True)
128         time.sleep(5)
129
130     # Path computed by PCE is not feasible by GNPy and GNPy cannot find
131     # another one (low SNR)
132     def test_05_path_computation_FoundByPCE_NotFeasibleByGnpy(self):
133         response = test_utils.path_computation_request("request-2", "service-2",
134                                                        {"node-id": "XPONDER-1", "service-rate": "100",
135                                                            "service-format": "Ethernet", "clli": "Node1"},
136                                                        {"node-id": "XPONDER-5", "service-rate": "100",
137                                                            "service-format": "Ethernet", "clli": "Node5"},
138                                                        {"include_": {"ordered-hops": [
139                                                            {"hop-number": "0", "hop-type": {"node-id": "OpenROADM-2"}},
140                                                            {"hop-number": "1", "hop-type": {"node-id": "OpenROADM-3"}},
141                                                            {"hop-number": "2", "hop-type": {"node-id": "OpenROADM-4"}}]}
142                                                         })
143         self.assertEqual(response.status_code, requests.codes.ok)
144         res = response.json()
145         self.assertEqual(res['output']['configuration-response-common'][
146             'response-code'], '500')
147         self.assertEqual(res['output']['configuration-response-common'][
148             'response-message'],
149             'No path available by PCE and GNPy ')
150         self.assertIn('A-to-Z',
151                       [res['output']['gnpy-response'][0]['path-dir'],
152                        res['output']['gnpy-response'][1]['path-dir']])
153         self.assertIn('Z-to-A',
154                       [res['output']['gnpy-response'][0]['path-dir'],
155                        res['output']['gnpy-response'][1]['path-dir']])
156         self.assertEqual(res['output']['gnpy-response'][0]['feasibility'],
157                          False)
158         self.assertEqual(res['output']['gnpy-response'][1]['feasibility'],
159                          False)
160         time.sleep(5)
161
162     # #PCE cannot find a path while GNPy finds a feasible one
163     def test_06_path_computation_NotFoundByPCE_FoundByGNPy(self):
164         response = test_utils.path_computation_request("request-3", "service-3",
165                                                        {"node-id": "XPONDER-1", "service-rate": "100",
166                                                            "service-format": "Ethernet", "clli": "Node1"},
167                                                        {"node-id": "XPONDER-4", "service-rate": "100",
168                                                            "service-format": "Ethernet", "clli": "Node5"},
169                                                        {"include_": {"ordered-hops": [
170                                                            {"hop-number": "0", "hop-type": {"node-id": "OpenROADM-2"}},
171                                                            {"hop-number": "1", "hop-type": {"node-id": "OpenROADM-3"}}]}
172                                                         })
173         self.assertEqual(response.status_code, requests.codes.ok)
174         res = response.json()
175         self.assertEqual(res['output']['configuration-response-common'][
176             'response-code'], '200')
177         self.assertEqual(res['output']['configuration-response-common'][
178             'response-message'],
179             'Path is calculated by GNPy')
180         self.assertIn('A-to-Z',
181                       [res['output']['gnpy-response'][0]['path-dir'],
182                        res['output']['gnpy-response'][1]['path-dir']])
183         self.assertIn('Z-to-A',
184                       [res['output']['gnpy-response'][0]['path-dir'],
185                        res['output']['gnpy-response'][1]['path-dir']])
186         self.assertEqual(res['output']['gnpy-response'][1]['feasibility'], True)
187         self.assertEqual(res['output']['gnpy-response'][0]['feasibility'], True)
188         time.sleep(5)
189
190     # Not found path by PCE and GNPy cannot find another one
191     def test_07_path_computation_FoundByPCE_NotFeasibleByGnpy(self):
192         response = test_utils.path_computation_request("request-4", "service-4",
193                                                        {"node-id": "XPONDER-1", "service-rate": "100",
194                                                            "service-format": "Ethernet", "clli": "Node1"},
195                                                        {"node-id": "XPONDER-4", "service-rate": "100",
196                                                            "service-format": "Ethernet", "clli": "Node5"},
197                                                        {"include_": {"ordered-hops": [
198                                                            {"hop-number": "0", "hop-type": {"node-id": "OpenROADM-2"}},
199                                                            {"hop-number": "1", "hop-type": {"node-id": "OpenROADM-3"}},
200                                                            {"hop-number": "2", "hop-type": {"node-id": "OpenROADM-4"}},
201                                                            {"hop-number": "3", "hop-type": {"node-id": "OpenROADM-3"}}]}
202                                                         })
203         self.assertEqual(response.status_code, requests.codes.ok)
204         res = response.json()
205         self.assertEqual(res['output']['configuration-response-common'][
206             'response-code'], '500')
207         self.assertEqual(res['output']['configuration-response-common'][
208             'response-message'],
209             'No path available by PCE and GNPy ')
210         time.sleep(5)
211
212     # Disconnect the different topologies
213     def test_08_disconnect_openroadmTopology(self):
214         response = test_utils.delete_request(test_utils.URL_CONFIG_ORDM_TOPO)
215         self.assertEqual(response.status_code, requests.codes.ok)
216         time.sleep(3)
217
218     def test_09_disconnect_openroadmNetwork(self):
219         response = test_utils.delete_request(test_utils.URL_CONFIG_ORDM_NET)
220         self.assertEqual(response.status_code, requests.codes.ok)
221         time.sleep(3)
222
223     def test_10_disconnect_clliNetwork(self):
224         response = test_utils.delete_request(test_utils.URL_CONFIG_CLLI_NET)
225         self.assertEqual(response.status_code, requests.codes.ok)
226         time.sleep(3)
227
228     # Delete portmapping
229     def test_11_delete_port_mapping(self):
230         response = test_utils.delete_request(test_utils.URL_FULL_PORTMAPPING)
231         self.assertEqual(response.status_code, requests.codes.ok)
232         time.sleep(2)
233
234
235 if __name__ == "__main__":
236     # logging.basicConfig(filename='./transportpce_tests/log/response.log',filemode='w',level=logging.DEBUG)
237     unittest.main(verbosity=2)