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