1 # -------------------------------------------------------------------------
2 # Copyright (c) 2017-2018 AT&T 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 # -------------------------------------------------------------------------
22 from osdf.adapters.local_data import local_policies
23 from osdf.optimizers.placementopt.conductor.api_builder import conductor_api_builder
24 from osdf.utils.interfaces import json_from_file
27 class TestConductorApiBuilder(unittest.TestCase):
31 self.conductor_api_template = self.main_dir + "osdf/templates/conductor_interface.json"
32 self.local_config_file = self.main_dir + "config/common_config.yaml"
33 policy_data_path = self.main_dir + "test/policy-local-files" # "test/policy-local-files"
35 valid_policies_list_file = policy_data_path + '/' + 'meta-valid-policies.txt'
36 valid_policies_files = local_policies.get_policy_names_from_file(valid_policies_list_file)
38 parameter_data_file = self.main_dir + "test/placement-tests/request.json" # "test/placement-tests/request.json"
39 self.request_json = json_from_file(parameter_data_file)
40 parameter_data_file = self.main_dir + "test/placement-tests/request_vfmod.json"
41 self.request_vfmod_json = json_from_file(parameter_data_file)
42 parameter_data_file = self.main_dir + "test/placement-tests/request_placement_vfmod.json"
43 self.request_placement_vfmod_json = json_from_file(parameter_data_file)
44 self.policies = [json_from_file(policy_data_path + '/' + name) for name in valid_policies_files]
46 def test_conductor_api_call_builder(self):
47 main_dir = self.main_dir
48 request_json = self.request_json
49 policies = self.policies
50 local_config = yaml.load(open(self.local_config_file))
51 templ_string = conductor_api_builder(request_json, policies, local_config, self.conductor_api_template)
52 templ_json = json.loads(templ_string)
53 self.assertEqual(templ_json["name"], "yyy-yyy-yyyy")
55 def test_conductor_api_call_builder_vfmod(self):
56 request_json = self.request_vfmod_json
57 policies = self.policies
58 local_config = yaml.load(open(self.local_config_file))
59 templ_string = conductor_api_builder(request_json, policies, local_config, self.conductor_api_template)
60 templ_json = json.loads(templ_string)
61 self.assertEqual(templ_json, self.request_placement_vfmod_json)
64 if __name__ == "__main__":