osdf rearchitecture into apps and libs
[optf/osdf.git] / test / conductor / test_conductor_translation.py
1 # -------------------------------------------------------------------------
2 #   Copyright (c) 2017-2018 AT&T Intellectual Property
3 #
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
7 #
8 #       http://www.apache.org/licenses/LICENSE-2.0
9 #
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.
15 #
16 # -------------------------------------------------------------------------
17 #
18 import unittest
19
20 from osdf.adapters.local_data import local_policies
21 from apps.placement.optimizers.conductor import translation as tr
22 from osdf.utils.interfaces import json_from_file
23
24
25 class TestConductorTranslation(unittest.TestCase):
26
27     def setUp(self):
28         self.main_dir = ""
29         self.conductor_api_template = self.main_dir + "osdf/templates/conductor_interface.json"
30         self.local_config_file = self.main_dir + "config/common_config.yaml"
31         policy_data_path = self.main_dir + "test/policy-local-files"
32
33         valid_policies_list_file = policy_data_path + '/' + 'meta-valid-policies.txt'
34         valid_policies_files = local_policies.get_policy_names_from_file(valid_policies_list_file)
35
36         parameter_data_file = self.main_dir + "test/placement-tests/request.json"
37         self.request_json = json_from_file(parameter_data_file)
38         parameter_data_file = self.main_dir + "test/placement-tests/request_vfmod.json"
39         self.request_vfmod_json = json_from_file(parameter_data_file)
40         self.policies = [json_from_file(policy_data_path + '/' + name) for name in valid_policies_files]
41
42     def tearDown(self):
43         pass
44
45     def test_gen_demands(self):
46         # need to run this only on vnf policies
47         vnf_policies = [x for x in self.policies if x["content"]["policyType"] == "vnfPolicy"]
48         res = tr.gen_demands(self.request_json, vnf_policies)
49         assert res is not None
50
51     def test_gen_vfmod_demands(self):
52         # need to run this only on vnf policies
53         vnf_policies = [x for x in self.policies if x["content"]["policyType"] == "vnfPolicy"]
54         res = tr.gen_demands(self.request_vfmod_json, vnf_policies)
55         assert res is not None
56
57
58 if __name__ == "__main__":
59     unittest.main()
60