1 # -------------------------------------------------------------------------
2 # Copyright (c) 2020 Fujitsu Limited Intellectual Property
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
16 # -------------------------------------------------------------------------
19 from unittest.mock import patch
20 from apps.route.optimizers.inter_domain_route_opt import InterDomainRouteOpt
21 import osdf.config.loader as config_loader
22 from osdf.utils.interfaces import json_from_file
23 from osdf.utils.programming_utils import DotDict
27 def mocked_requests_get(*args, **kwargs):
29 def __init__(self, json_data, status_code):
30 self.json_data = json_data
31 self.status_code = status_code
37 response_data_file = main_dir + "test/inter_domain_route_opt/get_links.json"
38 bandwidth_attributes = main_dir + "test/inter_domain_route_opt/bandwidth_attributes.json"
39 bandwidth_attribute_values = json_from_file(bandwidth_attributes)
41 controllers_list = main_dir + "test/inter_domain_route_opt/controllers_list.json"
43 if args[0] == 'https://api.url:30233/aai/v19/network/logical-links?link-type=inter-domain&operational-status=up':
44 return MockResponse(json_from_file(response_data_file), 200)
45 elif args[0] == 'https://api.url:30233/aai/v19/network/pnfs/pnf/pnf1/p-interfaces/p-interface/int1?depth=all':
46 return MockResponse(bandwidth_attribute_values["int-1-bw"], 200)
47 elif args[0] == 'https://api.url:30233/aai/v19/network/pnfs/pnf/pnf2/p-interfaces/p-interface/int3?depth=all':
48 return MockResponse(bandwidth_attribute_values["int-3-bw"], 200)
49 elif args[0] == 'https://api.url:30233/aai/v19/network/pnfs/pnf/pnf2/p-interfaces/p-interface/int4?depth=all':
50 return MockResponse(bandwidth_attribute_values["int-4-bw"], 200)
51 elif args[0] == 'https://api.url:30233/aai/v19/network/pnfs/pnf/pnf3/p-interfaces/p-interface/int5?depth=all':
52 return MockResponse(bandwidth_attribute_values["int-5-bw"], 200)
53 elif args[0] == 'https://api.url:30233/aai/v19/network/pnfs/pnf/pnf3/p-interfaces/p-interface/int6?depth=all':
54 return MockResponse(bandwidth_attribute_values["int-6-bw"], 200)
55 elif args[0] == 'https://api.url:30233/aai/v19/network/pnfs/pnf/pnf4/p-interfaces/p-interface/int7?depth=all':
56 return MockResponse(bandwidth_attribute_values["int-7-bw"], 200)
57 elif args[0] == 'https://api.url:30233/aai/v19/external-system/esr-thirdparty-sdnc-list':
58 return MockResponse(json_from_file(controllers_list), 200)
59 return MockResponse(None, 404)
62 def mocked_requests_put(*args, **kwargs):
64 def __init__(self, json_data, status_code):
65 self.json_data = json_data
66 self.status_code = status_code
71 controllers_for_interfaces = main_dir + "test/inter_domain_route_opt/controllers_for_interfaces.json"
72 controllers_for_interfaces_values = json_from_file(controllers_for_interfaces)
78 return MockResponse(controllers_for_interfaces_values["int-1-cont"], 200)
81 return MockResponse(controllers_for_interfaces_values["int-3-cont"], 200)
84 return MockResponse(controllers_for_interfaces_values["int-4-cont"], 200)
87 return MockResponse(controllers_for_interfaces_values["int-5-cont"], 200)
90 return MockResponse(controllers_for_interfaces_values["int-6-cont"], 200)
93 return MockResponse(controllers_for_interfaces_values["int-7-cont"], 200)
95 return MockResponse(None, 404)
99 class TestInterDomainRouteOpt(unittest.TestCase):
100 @patch('apps.route.optimizers.inter_domain_route_opt.requests.get', side_effect=mocked_requests_get)
101 @patch('apps.route.optimizers.inter_domain_route_opt.requests.put', side_effect=mocked_requests_put)
102 @patch('apps.route.optimizers.simple_route_opt.pymzn.minizinc')
103 def test_process_get_route(self, mock_solve , mock_put, mock_get):
105 mock_solve.return_value = [{'x': [1, 1, 0, 0, 0, 0]}]
107 "deployment": "test/functest/simulators/simulated-config/osdf_config.yaml",
108 "core": "test/functest/simulators/simulated-config/common_config.yaml"
110 self.osdf_config = DotDict(config_loader.all_configs(**self.config_spec))
111 parameter_data_file = main_dir + "test/inter_domain_route_opt/request.json"
112 request_json = json_from_file(parameter_data_file)
113 routopt = InterDomainRouteOpt()
114 actual_response = routopt.get_route(request_json,self.osdf_config)
116 "requestId":"789456",
117 "transactionId":"123456",
118 "statusMessage":"SUCCESS",
119 "requestStatus":"accepted",
124 "srcInterfaceId":"int19",
125 "dstInterfaceId":"int1",
126 "controllerId":"Controller1"
129 "srcInterfaceId":"int3",
130 "dstInterfaceId":"int4",
131 "controllerId":"Controller2"
134 "srcInterfaceId":"int5",
135 "dstInterfaceId":"int20",
136 "controllerId":"Controller3"
146 self.assertEqual(mock_response, actual_response)
149 if __name__ == '__main__':