diff options
author | krishnaa96 <krishna.moorthy6@wipro.com> | 2020-03-10 10:55:13 +0530 |
---|---|---|
committer | krishnaa96 <krishna.moorthy6@wipro.com> | 2020-03-20 20:39:59 +0530 |
commit | f30da9513ae0501f453ee93729b381270fad0a2b (patch) | |
tree | a3ab005e2f16bfe8709bdcfbab6d28b5c6760a19 /test | |
parent | 420f4b3a4ca25d5de5c9318b2ca89e1ef126b278 (diff) |
Add generic conductor interface
Issue-ID: OPTFRA-715
Signed-off-by: krishnaa96 <krishna.moorthy6@wipro.com>
Change-Id: I84218ab65e645a90d2ff1c365bdde1e06ab27d2e
Diffstat (limited to 'test')
-rw-r--r-- | test/conductor/test_conductor_calls.py | 15 | ||||
-rw-r--r-- | test/conductor/test_conductor_translation.py | 8 | ||||
-rw-r--r-- | test/test_ConductorApiBuilder.py | 19 | ||||
-rw-r--r-- | test/test_PolicyCalls.py | 8 | ||||
-rw-r--r-- | test/test_get_opt_query_data.py | 7 | ||||
-rw-r--r-- | test/test_process_placement_opt.py | 7 | ||||
-rw-r--r-- | test/test_so_response_gen.py | 5 |
7 files changed, 49 insertions, 20 deletions
diff --git a/test/conductor/test_conductor_calls.py b/test/conductor/test_conductor_calls.py index 52e0367..0042ecb 100644 --- a/test/conductor/test_conductor_calls.py +++ b/test/conductor/test_conductor_calls.py @@ -1,5 +1,6 @@ # ------------------------------------------------------------------------- # Copyright (c) 2018 AT&T Intellectual Property +# Copyright (C) 2020 Wipro Limited. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -17,7 +18,7 @@ # import unittest -from apps.placement.optimizers.conductor import conductor +from osdf.adapters.conductor import conductor import osdf.config.loader as config_loader from osdf.utils.interfaces import json_from_file from osdf.utils.programming_utils import DotDict @@ -41,12 +42,20 @@ class TestConductorCalls(unittest.TestCase): def test_request(self): req_json = json_from_file("./test/placement-tests/request.json") policies = pol.get_local_policies("test/policy-local-files/", self.lp) - conductor.request(req_json, self.osdf_config, policies) + req_info = req_json['requestInfo'] + demands = req_json['placementInfo']['placementDemands'] + request_parameters = req_json['placementInfo']['requestParameters'] + service_info = req_json['serviceInfo'] + conductor.request(req_info, demands, request_parameters, service_info, self.osdf_config, policies) def test_request_vfmod(self): req_json = json_from_file("./test/placement-tests/request_vfmod.json") policies = pol.get_local_policies("test/policy-local-files/", self.lp) - conductor.request(req_json, self.osdf_config, policies) + req_info = req_json['requestInfo'] + demands = req_json['placementInfo']['placementDemands'] + request_parameters = req_json['placementInfo']['requestParameters'] + service_info = req_json['serviceInfo'] + conductor.request(req_info, demands, request_parameters, service_info, self.osdf_config, policies) if __name__ == "__main__": diff --git a/test/conductor/test_conductor_translation.py b/test/conductor/test_conductor_translation.py index 3481b88..8b6c0a1 100644 --- a/test/conductor/test_conductor_translation.py +++ b/test/conductor/test_conductor_translation.py @@ -1,5 +1,6 @@ # ------------------------------------------------------------------------- # Copyright (c) 2017-2018 AT&T Intellectual Property +# Copyright (C) 2020 Wipro Limited. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,7 +19,7 @@ import unittest from osdf.adapters.local_data import local_policies -from apps.placement.optimizers.conductor import translation as tr +from osdf.adapters.conductor import translation as tr from osdf.utils.interfaces import json_from_file @@ -46,14 +47,15 @@ class TestConductorTranslation(unittest.TestCase): # need to run this only on vnf policies vnf_policies = [x for x in self.policies if x[list(x.keys())[0]]["type"] == "onap.policies.optimization.VnfPolicy"] - res = tr.gen_demands(self.request_json, vnf_policies) + res = tr.gen_demands(self.request_json['placementInfo']['placementDemands'], vnf_policies) + assert res is not None def test_gen_vfmod_demands(self): # need to run this only on vnf policies vnf_policies = [x for x in self.policies if x[list(x.keys())[0]]["type"] == "onap.policies.optimization.VnfPolicy"] - res = tr.gen_demands(self.request_vfmod_json, vnf_policies) + res = tr.gen_demands(self.request_vfmod_json['placementInfo']['placementDemands'], vnf_policies) assert res is not None diff --git a/test/test_ConductorApiBuilder.py b/test/test_ConductorApiBuilder.py index 07cb3bb..44c14d8 100644 --- a/test/test_ConductorApiBuilder.py +++ b/test/test_ConductorApiBuilder.py @@ -1,5 +1,6 @@ # ------------------------------------------------------------------------- # Copyright (c) 2017-2018 AT&T Intellectual Property +# Copyright (C) 2020 Wipro Limited. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -19,7 +20,7 @@ import unittest import json import yaml -from apps.placement.optimizers.conductor.api_builder import conductor_api_builder +from osdf.adapters.conductor.api_builder import conductor_api_builder from osdf.adapters.local_data import local_policies from osdf.utils.interfaces import json_from_file @@ -28,7 +29,7 @@ class TestConductorApiBuilder(unittest.TestCase): def setUp(self): self.main_dir = "" - self.conductor_api_template = self.main_dir + "apps/placement/templates/conductor_interface.json" + self.conductor_api_template = self.main_dir + "osdf/adapters/conductor/templates/conductor_interface.json" self.local_config_file = self.main_dir + "config/common_config.yaml" policy_data_path = self.main_dir + "test/policy-local-files" # "test/policy-local-files" @@ -48,7 +49,12 @@ class TestConductorApiBuilder(unittest.TestCase): request_json = self.request_json policies = self.policies local_config = yaml.safe_load(open(self.local_config_file)) - templ_string = conductor_api_builder(request_json, policies, local_config, self.conductor_api_template) + req_info = request_json['requestInfo'] + demands = request_json['placementInfo']['placementDemands'] + request_parameters = request_json['placementInfo']['requestParameters'] + service_info = request_json['serviceInfo'] + templ_string = conductor_api_builder(req_info, demands, request_parameters, service_info, policies, + local_config, self.conductor_api_template) templ_json = json.loads(templ_string) self.assertEqual(templ_json["name"], "yyy-yyy-yyyy") @@ -56,7 +62,12 @@ class TestConductorApiBuilder(unittest.TestCase): request_json = self.request_vfmod_json policies = self.policies local_config = yaml.safe_load(open(self.local_config_file)) - templ_string = conductor_api_builder(request_json, policies, local_config, self.conductor_api_template) + req_info = request_json['requestInfo'] + demands = request_json['placementInfo']['placementDemands'] + request_parameters = request_json['placementInfo']['requestParameters'] + service_info = request_json['serviceInfo'] + templ_string = conductor_api_builder(req_info, demands, request_parameters, service_info, policies, + local_config, self.conductor_api_template) templ_json = json.loads(templ_string) self.assertEqual(templ_json, self.request_placement_vfmod_json) diff --git a/test/test_PolicyCalls.py b/test/test_PolicyCalls.py index 0b17081..c41c487 100644 --- a/test/test_PolicyCalls.py +++ b/test/test_PolicyCalls.py @@ -1,5 +1,6 @@ # ------------------------------------------------------------------------- # Copyright (c) 2017-2018 AT&T Intellectual Property +# Copyright (C) 2020 Wipro Limited. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -24,7 +25,7 @@ from osdf.adapters.policy import interface from osdf.utils.interfaces import RestClient, json_from_file import yaml from mock import patch -from apps.placement.optimizers.conductor import translation +from osdf.adapters.conductor import translation from osdf.operation.exceptions import BusinessException @@ -101,13 +102,14 @@ class TestPolicyCalls(unittest.TestCase): # need to run this only on vnf policies vnf_policies = [x for x in self.policies if x[list(x.keys())[0]]["type"] == "onap.policies.optimization.VnfPolicy"] - gen_demands = translation.gen_demands(req_json, vnf_policies) + gen_demands = translation.gen_demands(req_json['placementInfo']['placementDemands'], vnf_policies) + for action in req_json['placementInfo']['placementDemands']: actions_list.append(action['resourceModuleName']) for key2,value in gen_demands.items(): gen_demands_list.append(key2) self.assertListEqual(gen_demands_list, actions_list, 'generated demands are not equal to the passed input' - '[placementDemand][resourceModuleName] list') + '[placementDemand][resourceModuleName] list') def test_local_policy_location(self): req_json = json_from_file("./test/placement-tests/request.json") diff --git a/test/test_get_opt_query_data.py b/test/test_get_opt_query_data.py index a7a4d88..8e6c324 100644 --- a/test/test_get_opt_query_data.py +++ b/test/test_get_opt_query_data.py @@ -1,5 +1,6 @@ # ------------------------------------------------------------------------- # Copyright (c) 2017-2018 AT&T Intellectual Property +# Copyright (C) 2020 Wipro Limited. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -17,7 +18,7 @@ # import unittest import json -from apps.placement.optimizers.conductor.translation import get_opt_query_data +from osdf.adapters.conductor.translation import get_opt_query_data class TestGetOptQueryData(unittest.TestCase): @@ -30,7 +31,7 @@ class TestGetOptQueryData(unittest.TestCase): query_policy_data_file = ["QueryPolicy_vCPE.json"] request_json = json.loads(open(parameter_data_file).read()) policies = [json.loads(open(policy_data_path + file).read()) for file in query_policy_data_file] - req_param_dict = get_opt_query_data(request_json, policies) + req_param_dict = get_opt_query_data(request_json['placementInfo']['requestParameters'], policies) self.assertTrue(req_param_dict is not None) @@ -42,7 +43,7 @@ class TestGetOptQueryData(unittest.TestCase): query_policy_data_file = ["QueryPolicy_vFW_TD.json"] request_json = json.loads(open(parameter_data_file).read()) policies = [json.loads(open(policy_data_path + file).read()) for file in query_policy_data_file] - req_param_dict = get_opt_query_data(request_json, policies) + req_param_dict = get_opt_query_data(request_json['placementInfo']['requestParameters'], policies) self.assertTrue(req_param_dict is not None) diff --git a/test/test_process_placement_opt.py b/test/test_process_placement_opt.py index 64b69a8..8a29100 100644 --- a/test/test_process_placement_opt.py +++ b/test/test_process_placement_opt.py @@ -1,5 +1,6 @@ # ------------------------------------------------------------------------- # Copyright (c) 2017-2018 AT&T Intellectual Property +# Copyright (C) 2020 Wipro Limited. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -30,8 +31,10 @@ class TestProcessPlacementOpt(unittest.TestCase): def setUp(self): mock_req_accept_message = Response("Accepted Request", content_type='application/json; charset=utf-8') - self.patcher_req = patch('apps.placement.optimizers.conductor.conductor.request', - return_value={"solutionInfo": {"placementInfo": "dummy"}}) + conductor_response_file = 'test/placement-tests/conductor_response.json' + conductor_response = json_from_file(conductor_response_file) + self.patcher_req = patch('osdf.adapters.conductor.conductor.request', + return_value=conductor_response) self.patcher_req_accept = patch('osdf.operation.responses.osdf_response_for_request_accept', return_value=mock_req_accept_message) self.patcher_callback = patch( diff --git a/test/test_so_response_gen.py b/test/test_so_response_gen.py index 6705cc8..1e6079b 100644 --- a/test/test_so_response_gen.py +++ b/test/test_so_response_gen.py @@ -1,5 +1,6 @@ # ------------------------------------------------------------------------- # Copyright (c) 2017-2018 AT&T Intellectual Property +# Copyright (C) 2020 Wipro Limited. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -17,7 +18,7 @@ # import unittest -from apps.placement.optimizers.conductor.conductor import conductor_response_processor +from apps.placement.optimizers.conductor.remote_opt_processor import conductor_response_processor from osdf.utils.interfaces import json_from_file from osdf.utils.interfaces import RestClient @@ -35,4 +36,4 @@ class TestSoResponseGen(unittest.TestCase): if __name__ == "__main__": - unittest.main()
\ No newline at end of file + unittest.main() |