def test_process_pci_anr_opt_solutions(self): main_dir = "" parameter_data_file = main_dir + "test/pci-optimization-tests/pci_anr_request.json" policy_data_path = main_dir + "test/policy-local-files/" self.config_spec = { "deployment": "test/functest/simulators/simulated-config/osdf_config.yaml", "core": "test/functest/simulators/simulated-config/common_config.yaml" } self.osdf_config = DotDict( config_loader.all_configs(**self.config_spec)) valid_policies_list_file = policy_data_path + '/' + 'meta-valid-policies.txt' valid_policies_files = local_policies.get_policy_names_from_file( valid_policies_list_file) request_json = json_from_file(parameter_data_file) policies = [ json_from_file(policy_data_path + '/' + name) for name in valid_policies_files ] templ_string = process_pci_optimation(request_json, self.osdf_config, policies)
def mocked_requests_get(*args, **kwargs): class MockResponse: def __init__(self, json_data, status_code): self.json_data = json_data self.status_code = status_code def json(self): return self.json_data main_dir = "" response_data_file = main_dir + "test/inter_domain_route_opt/get_links.json" bandwidth_attributes = main_dir + "test/inter_domain_route_opt/bandwidth_attributes.json" bandwidth_attribute_values = json_from_file(bandwidth_attributes) controllers_list = main_dir + "test/inter_domain_route_opt/controllers_list.json" if args[0] == 'https://api.url:30233/aai/v19/network/logical-links?link-type=inter-domain&operational-status=up': return MockResponse(json_from_file(response_data_file), 200) elif args[0] == 'https://api.url:30233/aai/v19/network/pnfs/pnf/pnf1/p-interfaces/p-interface/int1?depth=all': return MockResponse(bandwidth_attribute_values["int-1-bw"], 200) elif args[0] == 'https://api.url:30233/aai/v19/network/pnfs/pnf/pnf2/p-interfaces/p-interface/int3?depth=all': return MockResponse(bandwidth_attribute_values["int-3-bw"], 200) elif args[0] == 'https://api.url:30233/aai/v19/network/pnfs/pnf/pnf2/p-interfaces/p-interface/int4?depth=all': return MockResponse(bandwidth_attribute_values["int-4-bw"], 200) elif args[0] == 'https://api.url:30233/aai/v19/network/pnfs/pnf/pnf3/p-interfaces/p-interface/int5?depth=all': return MockResponse(bandwidth_attribute_values["int-5-bw"], 200) elif args[0] == 'https://api.url:30233/aai/v19/network/pnfs/pnf/pnf3/p-interfaces/p-interface/int6?depth=all': return MockResponse(bandwidth_attribute_values["int-6-bw"], 200) elif args[0] == 'https://api.url:30233/aai/v19/network/pnfs/pnf/pnf4/p-interfaces/p-interface/int7?depth=all': return MockResponse(bandwidth_attribute_values["int-7-bw"], 200) elif args[0] == 'https://api.url:30233/aai/v19/external-system/esr-thirdparty-sdnc-list': return MockResponse(json_from_file(controllers_list), 200) return MockResponse(None, 404)
def setUp(self): self.config_spec = { "deployment": os.environ.get("OSDF_MANAGER_CONFIG_FILE", "config/osdf_config.yaml"), "core": "config/common_config.yaml" } self.osdf_config = DotDict( config_loader.all_configs(**self.config_spec)) main_dir = "" conductor_api_template = main_dir + "osdf/templates/conductor_interface.json" parameter_data_file = main_dir + "test/placement-tests/request.json" policy_data_path = main_dir + "test/policy-local-files/" local_config_file = main_dir + "config/common_config.yaml" valid_policies_list_file = policy_data_path + '/' + 'meta-valid-policies.txt' self.valid_policies_files = local_policies.get_policy_names_from_file( valid_policies_list_file) self.request_json = json_from_file(parameter_data_file) self.policies = [ json_from_file(policy_data_path + '/' + name) for name in self.valid_policies_files ]
def test_get_aai_data(self): main_dir = "" response_file = main_dir + 'test/apps/nxi_termination/aai_response.json' exception_response_file = main_dir + 'test/apps/nxi_termination/aai_exception_response.json' request_file = main_dir + 'test/apps/nxi_termination/nxi_termination.json' response_json = json_from_file(response_file) request_json = json_from_file(request_file) exception_json = json_from_file(exception_response_file) response = mock.MagicMock() response.status_code = 200 response.ok = True response.json.return_value = response_json self.patcher_req = patch('requests.get', return_value=response) self.Mock_req = self.patcher_req.start() self.assertEquals(response_json, get_aai_data(request_json, osdf_config)) self.patcher_req.stop() responsenew = mock.MagicMock() responsenew.status_code = 404 responsenew.json.return_value = exception_json self.patcher_req = patch('requests.get', return_value=responsenew) self.Mock_req = self.patcher_req.start() self.assertRaises(AAIException, get_aai_data, request_json, osdf_config) self.patcher_req.stop()
def setUp(self): main_dir = "" parameter_data_file = main_dir + "test/placement-tests/request.json" policy_data_path = main_dir + "test/policy-local-files/" local_config_file = main_dir + "config/common_config.yaml" valid_policies_list_file = policy_data_path + '/' + 'meta-valid-policies.txt' valid_policies_files = local_policies.get_policy_names_from_file( valid_policies_list_file) self.request_json = json_from_file(parameter_data_file) self.policies = [ json_from_file(policy_data_path + '/' + name) for name in valid_policies_files ]
def mocked_requests_put(*args, **kwargs): class MockResponse: def __init__(self, json_data, status_code): self.json_data = json_data self.status_code = status_code def json(self): return self.json_data main_dir = "" controllers_for_interfaces = main_dir + "test/inter_domain_route_opt/controllers_for_interfaces.json" controllers_for_interfaces_values = json_from_file(controllers_for_interfaces) global count if count == 1: count += 1 return MockResponse(controllers_for_interfaces_values["int-1-cont"], 200) elif count == 2: count += 1 return MockResponse(controllers_for_interfaces_values["int-3-cont"], 200) elif count == 3: count += 1 return MockResponse(controllers_for_interfaces_values["int-4-cont"], 200) elif count == 4: count += 1 return MockResponse(controllers_for_interfaces_values["int-5-cont"], 200) elif count == 5: count += 1 return MockResponse(controllers_for_interfaces_values["int-6-cont"], 200) elif count == 6: count += 1 return MockResponse(controllers_for_interfaces_values["int-7-cont"], 200) return MockResponse(None, 404)
def test_extract_data(self): response_file = 'test/adapters/dcae/des_response.json' response_json = json_from_file(response_file) des_config = self.osdf_config.core['PCI']['DES'] service_id = des_config['service_id'] data = des_config['filter'] expected = response_json['result'] response = mock.MagicMock() response.status_code = 200 response.ok = True response.json.return_value = response_json self.patcher_req = patch('requests.request', return_value=response) self.Mock_req = self.patcher_req.start() self.assertEqual(expected, des.extract_data(service_id, data)) self.patcher_req.stop() response = mock.MagicMock() response.status_code = 404 response.raise_for_status.side_effect = HTTPError("404") self.patcher_req = patch('requests.request', return_value=response) self.Mock_req = self.patcher_req.start() self.assertRaises(DESException, des.extract_data, service_id, data) self.patcher_req.stop() self.patcher_req = patch('requests.request', side_effect=RequestException("error")) self.Mock_req = self.patcher_req.start() self.assertRaises(DESException, des.extract_data, service_id, data) self.patcher_req.stop()
def test_process_nssi_selection_opt(self): main_dir = "" request_file = main_dir + 'test/apps/slice_selection/nssi_selection_request.json' # response files shared_solution_response_file = main_dir + 'test/apps/slice_selection/shared_solution_nssi_response.json' error_response_file = main_dir + 'test/apps/slice_selection/nssi_error_response.json' request_json = json_from_file(request_file) shared_solution_response_json = json_from_file( shared_solution_response_file) error_response_json = json_from_file(error_response_file) policies_path = main_dir + 'test/policy-local-files/slice-selection-files' slice_policies_file = main_dir + 'test/apps/slice_selection/subnet_policies.txt' valid_policies_files = local_policies.get_policy_names_from_file( slice_policies_file) policies = [ json_from_file(policies_path + '/' + name) for name in valid_policies_files ] self.patcher_get_policies = patch( 'osdf.adapters.policy.interface.remote_api', return_value=policies) self.Mock_get_policies = self.patcher_get_policies.start() shared_solution_conductor_response_file = 'test/apps/slice_selection/nssi_conductor_response.json' shared_solution_conductor_response = json_from_file( shared_solution_conductor_response_file) self.patcher_req = patch( 'osdf.adapters.conductor.conductor.request', return_value=shared_solution_conductor_response) self.Mock_req = self.patcher_req.start() slice_select_opt = SliceSelectionOptimizer(self.osdf_config, self.slice_config, request_json, 'NSSI') slice_select_opt.process_slice_selection_opt() self.mock_rc.assert_called_with(json=shared_solution_response_json, noresponse=True) self.patcher_req.stop() request_json['sliceProfile']['resourceSharingLevel'] = "not-shared" slice_select_opt = SliceSelectionOptimizer(self.osdf_config, self.slice_config, request_json, 'NSSI') slice_select_opt.process_slice_selection_opt() self.mock_rc.assert_called_with(json=error_response_json, noresponse=True)
def test_process_placement_opt_placementDemand_vfmodule(self): main_dir = "" parameter_data_file = main_dir + "test/placement-tests/request_vfmod.json" policy_data_path = main_dir + "test/policy-local-files/" local_config_file = main_dir + "config/common_config.yaml" valid_policies_list_file = policy_data_path + '/' + 'meta-valid-policies.txt' valid_policies_files = local_policies.get_policy_names_from_file( valid_policies_list_file) request_json = json_from_file(parameter_data_file) policies = [ json_from_file(policy_data_path + '/' + name) for name in valid_policies_files ] local_config = yaml_from_file(local_config_file) templ_string = process_placement_opt(request_json, policies, local_config)
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) 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.template_fields, self.osdf_config, policies)
def get_payload_for_simulated_component(component, mainpath): """ Get the payload for the given path for the given component :param component: Component we are using (e.g. HAS-API, Policy, SO-callback, etc.) :param mainpath: path within the URL (e.g. /main/X1/y1/) :return: Content if file exists, or else 503 error """ file_name = "{}/response-payloads/{}".format(component, mainpath) data = json_from_file(file_name) if not data: return {"Error": "Unable to read File {}".format(file_name)}, 503 return data, None
def test_process_nst_selection_solutions( self, mock_solve, mock_get): main_dir = "" response_data_file = main_dir + "test/simple_route_opt/AAI.json" mock_get.return_value.json.return_value = json_from_file(response_data_file) mock_get.return_value.status_code = 200 mock_solve.return_value = [{'x': [1, 1, 1]}] self.config_spec = { "deployment": "test/functest/simulators/simulated-config/osdf_config.yaml", "core": "test/functest/simulators/simulated-config/common_config.yaml" } self.osdf_config = DotDict(config_loader.all_configs(**self.config_spec)) parameter_data_file = main_dir + "test/simple_route_opt/routeOpt.json" request_json = json_from_file(parameter_data_file) mock_response = { "requestId": "yyy-yyy-yyyy", "requestStatus": "accepted", "solutions": [ { "end_node": "10.10.10.10", "link": "link-id-1", "start_node": "20.20.20.20" }, { "end_node": "11.11.11.11", "link": "link-id-2", "start_node": "22.22.22.22" }, { "end_node": "20.20.20.20", "link": "link-id-3", "start_node": "11.11.11.11" } ], "statusMessage": " ", "transactionId": "xxx-xxx-xxxx" } routopt = RouteOpt() actual_response = routopt.get_route(request_json,self.osdf_config) self.assertEqual(mock_response, actual_response)
def setUp(self): self.main_dir = "" self.conductor_api_template = self.main_dir + "osdf/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" valid_policies_list_file = policy_data_path + '/' + 'meta-valid-policies.txt' valid_policies_files = local_policies.get_policy_names_from_file( valid_policies_list_file) parameter_data_file = self.main_dir + "test/placement-tests/request.json" self.request_json = json_from_file(parameter_data_file) parameter_data_file = self.main_dir + "test/placement-tests/request_vfmod.json" self.request_vfmod_json = json_from_file(parameter_data_file) self.policies = [ json_from_file(policy_data_path + '/' + name) for name in valid_policies_files ] self.optimization_policies = [ json_from_file(policy_data_path + '/' + "slice-selection-files/opt_policy_nsi_reuse.json") ]
def setUp(self): self.main_dir = "" 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" valid_policies_list_file = policy_data_path + '/' + 'meta-valid-policies.txt' valid_policies_files = local_policies.get_policy_names_from_file( valid_policies_list_file) parameter_data_file = self.main_dir + "test/placement-tests/request.json" # "test/placement-tests/request.json" self.request_json = json_from_file(parameter_data_file) parameter_data_file = self.main_dir + "test/placement-tests/request_vfmod.json" self.request_vfmod_json = json_from_file(parameter_data_file) parameter_data_file = self.main_dir + "test/placement-tests/request_placement_vfmod.json" self.request_placement_vfmod_json = json_from_file(parameter_data_file) self.policies = [ json_from_file(policy_data_path + '/' + name) for name in valid_policies_files ] self.template_fields = { 'location_enabled': True, 'version': '2017-10-10' }
def test_ml_model(self): des_result_file = 'test/apps/pci_optimization/des_result.json' results = json_from_file(des_result_file) dzn_data = { 'NUM_NODES': 4, 'NUM_PCIS': 4, 'NUM_NEIGHBORS': 4, 'NEIGHBORS': [], 'NUM_SECOND_LEVEL_NEIGHBORS': 1, 'SECOND_LEVEL_NEIGHBORS': [], 'PCI_UNCHANGEABLE_CELLS': {}, 'ORIGINAL_PCIS': [] } network_cell_info = { 'cell_list': [{ 'cell_id': 'Chn0001', 'id': 1, 'nbr_list': [] }, { 'cell_id': 'Chn0002', 'id': 2, 'nbr_list': [] }] } self.patcher_req = patch('osdf.adapters.dcae.des.extract_data', side_effect=results) self.Mock_req = self.patcher_req.start() mlmodel = MlModel() mlmodel.get_additional_inputs(dzn_data, network_cell_info) self.assertEqual({1}, dzn_data['PCI_UNCHANGEABLE_CELLS']) self.patcher_req.stop() dzn_data['PCI_UNCHANGEABLE_CELLS'] = [] self.patcher_req = patch('osdf.adapters.dcae.des.extract_data', side_effect=DESException('error')) self.Mock_req = self.patcher_req.start() mlmodel.get_additional_inputs(dzn_data, network_cell_info) self.assertEqual(set(), dzn_data['PCI_UNCHANGEABLE_CELLS']) self.patcher_req.stop() self.patcher_req = patch('osdf.adapters.dcae.des.extract_data', return_value=[]) self.Mock_req = self.patcher_req.start() mlmodel.get_additional_inputs(dzn_data, network_cell_info) self.assertEqual(set(), dzn_data['PCI_UNCHANGEABLE_CELLS']) self.patcher_req.stop()
def test_process_get_route(self, mock_solve , mock_put, mock_get): main_dir = "" mock_solve.return_value = [{'x': [1, 1, 0, 0, 0, 0]}] self.config_spec = { "deployment": "test/functest/simulators/simulated-config/osdf_config.yaml", "core": "test/functest/simulators/simulated-config/common_config.yaml" } self.osdf_config = DotDict(config_loader.all_configs(**self.config_spec)) parameter_data_file = main_dir + "test/inter_domain_route_opt/request.json" request_json = json_from_file(parameter_data_file) routopt = InterDomainRouteOpt() actual_response = routopt.get_route(request_json,self.osdf_config) mock_response = { "requestId":"789456", "transactionId":"123456", "statusMessage":"SUCCESS", "requestStatus":"accepted", "solutions":{ "routeInfo":{ "serviceRoute":[ { "srcInterfaceId":"int19", "dstInterfaceId":"int1", "controllerId":"Controller1" }, { "srcInterfaceId":"int3", "dstInterfaceId":"int4", "controllerId":"Controller2" }, { "srcInterfaceId":"int5", "dstInterfaceId":"int20", "controllerId":"Controller3" } ], "linkList":[ "link1", "link2" ] } } } self.assertEqual(mock_response, actual_response)
def setUp(self): mock_req_accept_message = Response( "Accepted Request", content_type='application/json; charset=utf-8') 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( 'apps.placement.optimizers.conductor.remote_opt_processor.process_placement_opt', return_value=mock_req_accept_message) self.patcher_RestClient = patch('osdf.utils.interfaces.RestClient', return_value=mock.MagicMock()) self.Mock_req = self.patcher_req.start() self.Mock_req_accept = self.patcher_req_accept.start() self.Mock_callback = self.patcher_callback.start() self.Mock_RestClient = self.patcher_RestClient.start()
def get_policies(sub_component): """ Get all policies for this folder :param sub_component: The folder we are interested in (e.g. "pdp-has-vcpe-good", "pdp-has-vcpe-bad") :return: A list of policies as a json object (each element is one policy) """ main_dir = "policy/response-payloads/" + sub_component files = glob.glob("{}/*.json".format(main_dir)) list_json = [] for x in files: list_json.append({ "policyConfigMessage": "Config Retrieved! ", "policyConfigStatus": "CONFIG_RETRIEVED", "type": "JSON", "config": json.dumps(json_from_file(x)), "policyName": os.path.basename(x), "policyType": "MicroService", "policyVersion": "1" }) return jsonify(list_json)
def get_req_resp(self, req_file, resp_file): """Get request/response from files""" req_json = json_from_file(req_file) resp_json = json_from_file(resp_file) return req_json, resp_json
def test_process_nxi_termination_opt(self): main_dir = "" request_file = main_dir + 'test/apps/nxi_termination/nxi_termination.json' nssi_request_file = main_dir + 'test/apps/nxi_termination/nssi_termination.json' service_file = main_dir + 'test/apps/nxi_termination/service_profiles.json' failure_service_file = main_dir + 'test/apps/nxi_termination/failure_service_profiles.json' failure_service_file2 = main_dir + 'test/apps/nxi_termination/failure_service_profiles2.json' nsi_success = main_dir + 'test/apps/nxi_termination/nsi_success_output.json' nxi_failure1 = main_dir + 'test/apps/nxi_termination/nxi_failure_output1.json' nxi_failure2 = main_dir + 'test/apps/nxi_termination/nxi_failure_output2.json' nssi_failure = main_dir + 'test/apps/nxi_termination/nssi_failure_output.json' success_rel_file = main_dir + 'test/apps/nxi_termination/success_relationship_list.json' failure_rel_file1 = main_dir + 'test/apps/nxi_termination/failure_relationship_list.json' failure_rel_file2 = main_dir + 'test/apps/nxi_termination/failure_relationship_list2.json' exception_response_file1 = main_dir + 'test/apps/nxi_termination/exception_response1.json' request_json = json_from_file(request_file) nssi_request_json = json_from_file(nssi_request_file) service_profile_json = json_from_file(service_file) failure_service_profile_json = json_from_file(failure_service_file) failure_service_profile_json2 = json_from_file(failure_service_file2) success_rel_json = json_from_file(success_rel_file) failure_rel_json = json_from_file(failure_rel_file1) failure_rel_json2 = json_from_file(failure_rel_file2) success_output_json = json_from_file(nsi_success) nxi_failure_output_json1 = json_from_file(nxi_failure1) nxi_failure_output_json2 = json_from_file(nxi_failure2) nssi_failure_output_json = json_from_file(nssi_failure) exception_response_json1 = json_from_file(exception_response_file1) #nsi success scenario self.patcher_req = patch( 'apps.nxi_termination.optimizers.remote_opt_processor.get_allotted_resources', return_value=success_rel_json) self.Mock_req = self.patcher_req.start() self.assertEquals( success_output_json, process_nxi_termination_opt(request_json, osdf_config)) self.patcher_req.stop() #nsi failure scenario self.patcher_req = patch( 'apps.nxi_termination.optimizers.remote_opt_processor.get_allotted_resources', return_value=failure_rel_json) self.Mock_req = self.patcher_req.start() self.assertEquals( nxi_failure_output_json1, process_nxi_termination_opt(request_json, osdf_config)) self.patcher_req.stop() request_json["requestInfo"]["addtnlArgs"] = {} #nsi success scenario self.patcher_req = patch( 'apps.nxi_termination.optimizers.remote_opt_processor.get_allotted_resources', return_value=[]) self.Mock_req = self.patcher_req.start() self.assertEquals( success_output_json, process_nxi_termination_opt(request_json, osdf_config)) self.patcher_req.stop() # # # nssi success scenario self.patcher_req = patch( 'apps.nxi_termination.optimizers.remote_opt_processor.get_resource_count', return_value=1) self.Mock_req = self.patcher_req.start() self.assertEquals( success_output_json, process_nxi_termination_opt(nssi_request_json, osdf_config)) self.patcher_req.stop() # nssi failure scenario self.patcher_req = patch( 'apps.nxi_termination.optimizers.remote_opt_processor.get_resource_count', return_value=2) self.Mock_req = self.patcher_req.start() self.assertEquals( nssi_failure_output_json, process_nxi_termination_opt(nssi_request_json, osdf_config)) self.patcher_req.stop() nssi_request_json["requestInfo"]["addtnlArgs"] = {} # nssi success scenario self.patcher_req = patch( 'apps.nxi_termination.optimizers.remote_opt_processor.get_resource_count', return_value=0) self.Mock_req = self.patcher_req.start() self.assertEquals( success_output_json, process_nxi_termination_opt(nssi_request_json, osdf_config)) self.patcher_req.stop() # nssi failure scenario self.patcher_req = patch( 'apps.nxi_termination.optimizers.remote_opt_processor.get_resource_count', return_value=1) self.Mock_req = self.patcher_req.start() self.assertEquals( nxi_failure_output_json2, process_nxi_termination_opt(nssi_request_json, osdf_config)) self.patcher_req.stop() self.patcher_req = patch( 'apps.nxi_termination.optimizers.remote_opt_processor.get_resource_count', side_effect=AAIException( "Error response recieved from AAI for the request")) self.Mock_req = self.patcher_req.start() self.assertEquals( "failure", process_nxi_termination_opt(nssi_request_json, osdf_config).get('requestStatus')) self.patcher_req.stop() self.patcher_req = patch( 'apps.nxi_termination.optimizers.remote_opt_processor.get_resource_count', side_effect=AAIException("Request exception was encountered")) self.Mock_req = self.patcher_req.start() self.assertEquals( "failure", process_nxi_termination_opt(nssi_request_json, osdf_config).get('requestStatus')) self.patcher_req.stop()
def get_pdx_policies(): """ get the pdpx policy """ return jsonify(json_from_file("policy/response-payloads/policy_response.json"))
def setUp(self): main_dir = "" conductor_response_file = main_dir + "test/placement-tests/conductor_response.json" self.conductor_res = json_from_file(conductor_response_file) self.rc = RestClient()
def test_process_nsi_selection_opt(self): main_dir = "" request_file = main_dir + 'test/apps/slice_selection/nsi_selection_request.json' not_shared_request_file = main_dir + 'test/apps/slice_selection/not_shared_nsi_request.json' #response files new_solution_response_file = main_dir + 'test/apps/slice_selection/new_solution_nsi_response.json' shared_solution_response_file = main_dir + 'test/apps/slice_selection/shared_solution_nsi_response.json' no_solution_response_file = main_dir + 'test/apps/slice_selection/no_recomm_nsi_response.json' error_response_file = main_dir + 'test/apps/slice_selection/nsi_error_response.json' request_json = json_from_file(request_file) new_solution_response_json = json_from_file(new_solution_response_file) shared_solution_response_json = json_from_file( shared_solution_response_file) no_solution_response_json = json_from_file(no_solution_response_file) error_response_json = json_from_file(error_response_file) policies_path = main_dir + 'test/policy-local-files/slice-selection-files' slice_policies_file = main_dir + 'test/apps/slice_selection/slice_policies.txt' valid_policies_files = local_policies.get_policy_names_from_file( slice_policies_file) policies = [ json_from_file(policies_path + '/' + name) for name in valid_policies_files ] self.patcher_get_policies = patch( 'osdf.adapters.policy.interface.remote_api', return_value=policies) self.Mock_get_policies = self.patcher_get_policies.start() # new solution new_solution_conductor_response_file = 'test/apps/slice_selection/new_solution_conductor_response.json' new_solution_conductor_response = json_from_file( new_solution_conductor_response_file) self.patcher_req = patch('osdf.adapters.conductor.conductor.request', return_value=new_solution_conductor_response) self.Mock_req = self.patcher_req.start() slice_select_opt = SliceSelectionOptimizer(self.osdf_config, self.slice_config, request_json, 'NSI') slice_select_opt.process_slice_selection_opt() self.mock_rc.assert_called_with(json=new_solution_response_json, noresponse=True) self.patcher_req.stop() # shared solution request_json['preferReuse'] = True shared_solution_conductor_response_file = 'test/apps/slice_selection/shared_solution_conductor_response.json' shared_solution_conductor_response = json_from_file( shared_solution_conductor_response_file) self.patcher_req = patch( 'osdf.adapters.conductor.conductor.request', return_value=shared_solution_conductor_response) self.Mock_req = self.patcher_req.start() slice_select_opt = SliceSelectionOptimizer(self.osdf_config, self.slice_config, request_json, 'NSI') slice_select_opt.process_slice_selection_opt() self.mock_rc.assert_called_with(json=shared_solution_response_json, noresponse=True) self.patcher_req.stop() # no recommendation no_solution_conductor_response_file = 'test/apps/slice_selection/no_rec.json' no_solution_conductor_response = json_from_file( no_solution_conductor_response_file) self.patcher_req = patch('osdf.adapters.conductor.conductor.request', return_value=no_solution_conductor_response) self.Mock_req = self.patcher_req.start() slice_select_opt.process_slice_selection_opt() self.mock_rc.assert_called_with(json=no_solution_response_json, noresponse=True) self.patcher_req.stop() # Exception conductor_error_response_file = 'test/apps/slice_selection/conductor_error_response.json' conductor_error_response = json_from_file( conductor_error_response_file) response = Response() response._content = json.dumps(conductor_error_response).encode() self.patcher_req = patch( 'osdf.adapters.conductor.conductor.request', side_effect=RequestException(response=response)) self.Mock_req = self.patcher_req.start() slice_select_opt.process_slice_selection_opt() self.mock_rc.assert_called_with(json=error_response_json, noresponse=True) self.patcher_req.stop() self.patcher_req = patch('osdf.adapters.conductor.conductor.request', side_effect=Exception("Some error message")) self.Mock_req = self.patcher_req.start() slice_select_opt.process_slice_selection_opt() self.mock_rc.assert_called_with(json=error_response_json, noresponse=True) self.patcher_req.stop()
def test_request(self): self.setUp() req_json = json_from_file("./test/pci-optimization-tests/request.json") policies = pol.get_local_policies("test/policy-local-files/", self.lp) cell_list = request(req_json, self.osdf_config, policies)
def setUp(self): main_dir = "" parameter_data_file = main_dir + "test/placement-tests/request.json" # "test/placement-tests/request.json" self.request_json = json_from_file(parameter_data_file)
def test_local_policy_location(self): req_json = json_from_file("./test/placement-tests/request.json") return interface.local_policies_location(req_json, osdf_config, service_type="placement")