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