def __init__(self, *args, **kwargs): super(self.__class__, self).__init__(*args, **kwargs) self.folder = './test/policy-local-files' self.valid_policies_file = self.folder + '/' + 'meta-valid-policies.txt' self.invalid_policies_file = self.folder + '/' + 'meta-invalid-policies.txt' self.valid_policies = local_policies.get_policy_names_from_file(self.valid_policies_file) self.invalid_policies = local_policies.get_policy_names_from_file(self.invalid_policies_file)
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 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 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 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 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_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()