diff options
Diffstat (limited to 'test')
15 files changed, 542 insertions, 4 deletions
diff --git a/test/apps/slice_selection/conductor_error_response.json b/test/apps/slice_selection/conductor_error_response.json new file mode 100644 index 0000000..95a9750 --- /dev/null +++ b/test/apps/slice_selection/conductor_error_response.json @@ -0,0 +1,18 @@ +{ + "plans": [ + { + "status": "error", + "message": "Some error message", + "name": "Plan Name 1", + "links": [ + [ + { + "href": "http://conductor:8091/v1/plans/plan_id", + "rel": "self" + } + ] + ], + "id": "plan_id" + } + ] +} diff --git a/test/apps/slice_selection/new_solution_conductor_response.json b/test/apps/slice_selection/new_solution_conductor_response.json new file mode 100644 index 0000000..39fef7b --- /dev/null +++ b/test/apps/slice_selection/new_solution_conductor_response.json @@ -0,0 +1,87 @@ +{ + "plans":[ + { + "status":"done", + "id":"plan_id", + "name":"Plan Name 1", + "links":[ + [ + { + "href":"http://conductor:8091/v1/plans/plan_id", + "rel":"self" + } + ] + ], + "recommendations":[ + { + "URLLC_Core_1":{ + "inventory_provider":"aai", + "candidate":{ + "exp_data_rate":0, + "conn_density":0, + "coverage_area_ta_list":"[{\"province\":\"??\",\"city\":\"???\",\"county\":\"???\",\"street\":\"?????\"}]", + "activity_factor":0, + "cs_availability":null, + "candidate_id":"1a636c4d-5e76-427e-bfd6-241a947224b0", + "area_traffic_cap_dl":null, + "latency":20, + "service_area_dimension":null, + "domain":"cn", + "e2e_latency":0, + "area_traffic_cap_ul":null, + "inventory_provider":"aai", + "exp_data_rate_ul":100, + "max_number_of_ues":0, + "ue_mobility_level":"stationary", + "candidate_type":"nssi", + "traffic_density":0, + "payload_size":0, + "exp_data_rate_dl":100, + "jitter":0, + "survival_time":0, + "resource_sharing_level":"0", + "inventory_type":"nssi", + "reliability":null, + "cost":1.0, + "nsi_name":"nsi_test_0211", + "instance_name":"nssi_test_0211" + } + }, + "URLLC_Ran_1":{ + "inventory_provider":"aai", + "candidate":{ + "exp_data_rate":0, + "conn_density":0, + "coverage_area_ta_list":"[{\"province\":\"??\",\"city\":\"???\",\"county\":\"???\",\"street\":\"?????\"}]", + "activity_factor":0, + "cs_availability":null, + "candidate_id":"490c68b0-639c-11ea-bc55-0242ac130003", + "area_traffic_cap_dl":null, + "latency":15, + "service_area_dimension":null, + "domain":"cn", + "e2e_latency":0, + "area_traffic_cap_ul":null, + "inventory_provider":"aai", + "exp_data_rate_ul":100, + "max_number_of_ues":0, + "ue_mobility_level":"stationary", + "candidate_type":"nssi", + "traffic_density":0, + "payload_size":0, + "exp_data_rate_dl":100, + "jitter":0, + "survival_time":0, + "resource_sharing_level":"0", + "inventory_type":"nssi", + "reliability":null, + "cost":1.0, + "nsi_name":"nsi_test_0212", + "instance_name":"nssi_test_ran_0211" + } + } + } + ] + } + ] +}
\ No newline at end of file diff --git a/test/apps/slice_selection/new_solution_nsi_response.json b/test/apps/slice_selection/new_solution_nsi_response.json new file mode 100644 index 0000000..de248c6 --- /dev/null +++ b/test/apps/slice_selection/new_solution_nsi_response.json @@ -0,0 +1,53 @@ +{ + "requestId":"d290f1ee-6c54-4b01-90e6-d701748f0851", + "transactionId":"d290f1ee-6c54-4b01-90e6-d701748f0851", + "requestStatus":"completed", + "statusMessage":"", + "solutions":{ + "sharedNSISolutions":[ + + ], + "newNSISolutions":[ + { + "matchLevel":"", + "NSTInfo":null, + "NSSISolutions":[ + { + "sliceProfile":{ + "latency":20, + "coverage_area_ta_list":"[{\"province\":\"??\",\"city\":\"???\",\"county\":\"???\",\"street\":\"?????\"}]", + "ue_mobility_level":"stationary", + "resource_sharing_level":"0", + "exp_data_rate_ul":100, + "exp_data_rate_dl":100 + }, + "NSSTInfo":{ + "NSSTName":"URLLC_Core_1" + }, + "NSSISolution":{ + "NSSIName":"nssi_test_0211", + "NSSIId":"1a636c4d-5e76-427e-bfd6-241a947224b0" + } + }, + { + "sliceProfile":{ + "latency":15, + "coverage_area_ta_list":"[{\"province\":\"??\",\"city\":\"???\",\"county\":\"???\",\"street\":\"?????\"}]", + "ue_mobility_level":"stationary", + "resource_sharing_level":"0", + "exp_data_rate_ul":100, + "exp_data_rate_dl":100 + }, + "NSSTInfo":{ + "NSSTName":"URLLC_Ran_1" + }, + "NSSISolution":{ + "NSSIName":"nssi_test_ran_0211", + "NSSIId":"490c68b0-639c-11ea-bc55-0242ac130003" + } + } + ] + } + ] + } +}
\ No newline at end of file diff --git a/test/apps/slice_selection/nsi_error_response.json b/test/apps/slice_selection/nsi_error_response.json new file mode 100644 index 0000000..c09bda8 --- /dev/null +++ b/test/apps/slice_selection/nsi_error_response.json @@ -0,0 +1,6 @@ +{ + "requestId":"d290f1ee-6c54-4b01-90e6-d701748f0851", + "transactionId":"d290f1ee-6c54-4b01-90e6-d701748f0851", + "requestStatus":"error", + "statusMessage":"Some error message" +}
\ No newline at end of file diff --git a/test/apps/slice_selection/nsi_request.json b/test/apps/slice_selection/nsi_request.json new file mode 100644 index 0000000..69d6e80 --- /dev/null +++ b/test/apps/slice_selection/nsi_request.json @@ -0,0 +1,30 @@ +{ + "serviceProfile": { + "latency": 2, + "security": "High", + "reliability": 99.9999, + "trafficDensity": 1, + "connDensity": 100000, + "expDataRate": 50, + "jitter": 1, + "survivalTime": 0 + }, + "serviceInfo":{ + "serviceInstanceId": "209fb01e-60ca-4325-b074-c5ad4e0499f8", + "serviceName": "" + }, + "requestInfo": { + "transactionId": "d290f1ee-6c54-4b01-90e6-d701748f0851", + "requestId": "d290f1ee-6c54-4b01-90e6-d701748f0851", + "callbackUrl": "http://0.0.0.0:9000/osdfCallback/", + "sourceId": "SO", + "timeout": 5 + }, + "NSTInfoList": [ + { + "modelInvariantId": "fda3c1e8-7653-4acd-80ef-f5755c1d3859", + "modelVersionId": "a6906768-1cae-4e78-acd1-d753ac61f3e8", + "modelName": "URLLC_1" + } + ] +}
\ No newline at end of file diff --git a/test/apps/slice_selection/shared_solution_conductor_response.json b/test/apps/slice_selection/shared_solution_conductor_response.json new file mode 100644 index 0000000..5bccd44 --- /dev/null +++ b/test/apps/slice_selection/shared_solution_conductor_response.json @@ -0,0 +1,87 @@ +{ + "plans":[ + { + "status":"done", + "id":"plan_id", + "name":"Plan Name 1", + "links":[ + [ + { + "href":"http://conductor:8091/v1/plans/plan_id", + "rel":"self" + } + ] + ], + "recommendations":[ + { + "URLLC_Core_1":{ + "inventory_provider":"aai", + "candidate":{ + "exp_data_rate":0, + "conn_density":0, + "coverage_area_ta_list":"[{\"province\":\"??\",\"city\":\"???\",\"county\":\"???\",\"street\":\"?????\"}]", + "activity_factor":0, + "cs_availability":null, + "candidate_id":"1a636c4d-5e76-427e-bfd6-241a947224b0", + "area_traffic_cap_dl":null, + "latency":20, + "service_area_dimension":null, + "domain":"cn", + "e2e_latency":0, + "area_traffic_cap_ul":null, + "inventory_provider":"aai", + "exp_data_rate_ul":100, + "max_number_of_ues":0, + "ue_mobility_level":"stationary", + "candidate_type":"nssi", + "traffic_density":0, + "payload_size":0, + "exp_data_rate_dl":100, + "jitter":0, + "survival_time":0, + "resource_sharing_level":"0", + "inventory_type":"nssi", + "reliability":null, + "cost":1.0, + "nsi_name":"nsi_test_0212", + "instance_name":"nssi_test_0211" + } + }, + "URLLC_Ran_1":{ + "inventory_provider":"aai", + "candidate":{ + "exp_data_rate":0, + "conn_density":0, + "coverage_area_ta_list":"[{\"province\":\"??\",\"city\":\"???\",\"county\":\"???\",\"street\":\"?????\"}]", + "activity_factor":0, + "cs_availability":null, + "candidate_id":"490c68b0-639c-11ea-bc55-0242ac130003", + "area_traffic_cap_dl":null, + "latency":15, + "service_area_dimension":null, + "domain":"cn", + "e2e_latency":0, + "area_traffic_cap_ul":null, + "inventory_provider":"aai", + "exp_data_rate_ul":100, + "max_number_of_ues":0, + "ue_mobility_level":"stationary", + "candidate_type":"nssi", + "traffic_density":0, + "payload_size":0, + "exp_data_rate_dl":100, + "jitter":0, + "survival_time":0, + "resource_sharing_level":"0", + "inventory_type":"nssi", + "reliability":null, + "cost":1.0, + "nsi_name":"nsi_test_0212", + "instance_name":"nssi_test_ran_0211" + } + } + } + ] + } + ] +}
\ No newline at end of file diff --git a/test/apps/slice_selection/shared_solution_nsi_response.json b/test/apps/slice_selection/shared_solution_nsi_response.json new file mode 100644 index 0000000..b0c0e2a --- /dev/null +++ b/test/apps/slice_selection/shared_solution_nsi_response.json @@ -0,0 +1,16 @@ +{ + "requestId":"d290f1ee-6c54-4b01-90e6-d701748f0851", + "transactionId":"d290f1ee-6c54-4b01-90e6-d701748f0851", + "requestStatus":"completed", + "statusMessage":"", + "solutions":{ + "sharedNSISolutions":[ + { + "NSIName":"nsi_test_0212" + } + ], + "newNSISolutions":[ + + ] + } +}
\ No newline at end of file diff --git a/test/apps/slice_selection/slice_policies.txt b/test/apps/slice_selection/slice_policies.txt new file mode 100644 index 0000000..e4ccb65 --- /dev/null +++ b/test/apps/slice_selection/slice_policies.txt @@ -0,0 +1,4 @@ +subscriber_policy_URLLC_1.json +thresholdPolicy_URLLC_Core_1_latency.json +thresholdPolicy_URLLC_Core_1_reliability.json +vnfPolicy_URLLC_Core_1.json
\ No newline at end of file diff --git a/test/apps/slice_selection/test_remote_opt_processor.py b/test/apps/slice_selection/test_remote_opt_processor.py new file mode 100644 index 0000000..d9b4f24 --- /dev/null +++ b/test/apps/slice_selection/test_remote_opt_processor.py @@ -0,0 +1,102 @@ +# ------------------------------------------------------------------------- +# 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. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ------------------------------------------------------------------------- +# + +import json +import unittest +from requests import RequestException + +from apps.slice_selection.optimizers.conductor.remote_opt_processor import process_nsi_selection_opt +from osdf.adapters.local_data import local_policies +from osdf.utils.interfaces import json_from_file, yaml_from_file +from osdf.utils.programming_utils import DotDict +import osdf.config.loader as config_loader +from mock import patch, MagicMock +import json +from osdf.logging.osdf_logging import error_log, debug_log +from osdf.adapters.policy.interface import get_policies + + +class TestRemoteOptProcessor(unittest.TestCase): + def setUp(self): + self.config_spec = { + "deployment": "config/osdf_config.yaml", + "core": "config/common_config.yaml" + } + self.osdf_config = DotDict(config_loader.all_configs(**self.config_spec)) + + def tearDown(self): + patch.stopall() + + def test_process_nsi_selection_opt(self): + main_dir = "" + request_file = main_dir + 'test/apps/slice_selection/nsi_request.json' + 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' + 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) + error_response_json = json_from_file(error_response_file) + + policies_path = main_dir + 'test/policy-local-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_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() + self.assertEquals(new_solution_response_json, process_nsi_selection_opt(request_json, self.osdf_config)) + self.patcher_req.stop() + + 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() + self.assertEquals(shared_solution_response_json, + process_nsi_selection_opt(request_json, self.osdf_config)) + self.patcher_req.stop() + + conductor_error_response_file = 'test/apps/slice_selection/conductor_error_response.json' + conductor_error_response = json_from_file(conductor_error_response_file) + + self.patcher_req = patch('osdf.adapters.conductor.conductor.request', + side_effect=RequestException(response=json.dumps(conductor_error_response))) + self.Mock_req = self.patcher_req.start() + self.assertEquals(error_response_json, process_nsi_selection_opt(request_json, self.osdf_config)) + self.patcher_req.stop() + + self.patcher_req = patch('osdf.adapters.conductor.conductor.request', + side_effect=Exception("test_exception")) + self.Mock_req = self.patcher_req.start() + self.assertEquals('test_exception', + process_nsi_selection_opt(request_json, self.osdf_config).get('statusMessage')) + self.patcher_req.stop() + + +if __name__ == "__main__": + unittest.main() + diff --git a/test/conductor/test_conductor_calls.py b/test/conductor/test_conductor_calls.py index 0042ecb..d342fa5 100644 --- a/test/conductor/test_conductor_calls.py +++ b/test/conductor/test_conductor_calls.py @@ -46,7 +46,7 @@ class TestConductorCalls(unittest.TestCase): 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) + conductor.request(req_info, demands, request_parameters, service_info, True, self.osdf_config, policies) def test_request_vfmod(self): req_json = json_from_file("./test/placement-tests/request_vfmod.json") @@ -55,7 +55,7 @@ class TestConductorCalls(unittest.TestCase): 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) + conductor.request(req_info, demands, request_parameters, service_info, True, self.osdf_config, policies) if __name__ == "__main__": diff --git a/test/policy-local-files/subscriber_policy_URLLC_1.json b/test/policy-local-files/subscriber_policy_URLLC_1.json new file mode 100644 index 0000000..ffa4d79 --- /dev/null +++ b/test/policy-local-files/subscriber_policy_URLLC_1.json @@ -0,0 +1,34 @@ +{ + "OSDF_FRANKFURT.SubscriberPolicy_URLLC_1": { + "type": "onap.policies.optimization.SubscriberPolicy", + "version": "1.0.0", + "type_version": "1.0.0", + "metadata": { + "policy-id": "OSDF_FRANKFURT.SubscriberPolicy_URLLC_1", + "policy-version": 1 + }, + "properties": { + "scope": [ + "OSDF_FRANKFURT", + "URLLC_1" + ], + "services": [ + "URLLC_1" + ], + "identity": "subscriber_URLLC_1", + "properties": { + "subscriberName": [ + "URLLC_Core_1" + ], + "subscriberRole": [ + { + "URLLC_Core_1": { + "modelInvariantId": "21d57d4b-52ad-4d3c-a798-248b5bb9124a", + "modelVersionId": "bfba363e-e39c-4bd9-a9d5-1371c28f4d22" + } + } + ] + } + } + } +} diff --git a/test/policy-local-files/thresholdPolicy_URLLC_Core_1_latency.json b/test/policy-local-files/thresholdPolicy_URLLC_Core_1_latency.json new file mode 100644 index 0000000..35106f6 --- /dev/null +++ b/test/policy-local-files/thresholdPolicy_URLLC_Core_1_latency.json @@ -0,0 +1,32 @@ +{ + "OSDF_FRANKFURT.Threshold_URLLC_Core_1": { + "type": "onap.policies.optimization.ThresholdPolicy", + "version": "1.0.0", + "type_version": "1.0.0", + "metadata": { + "policy-id": "OSDF_FRANKFURT.Threshold_URLLC_Core_1_latency", + "policy-version": 1 + }, + "properties": { + "scope": [ + "OSDF_FRANKFURT", + "URLLC_1", + "URLLC_Core_1" + ], + "resources": [ + "URLLC_Core_1" + ], + "services": [ + "URLLC_1" + ], + "identity": "Threshold_URLLC_Core_1_latency", + "applicableResources": "any", + "thresholdProperty": { + "attribute": "latency", + "operator": "lte", + "threshold": 5, + "unit": "ms" + } + } + } +}
\ No newline at end of file diff --git a/test/policy-local-files/thresholdPolicy_URLLC_Core_1_reliability.json b/test/policy-local-files/thresholdPolicy_URLLC_Core_1_reliability.json new file mode 100644 index 0000000..56089f0 --- /dev/null +++ b/test/policy-local-files/thresholdPolicy_URLLC_Core_1_reliability.json @@ -0,0 +1,32 @@ +{ + "OSDF_FRANKFURT.Threshold_URLLC_Core_1": { + "type": "onap.policies.optimization.ThresholdPolicy", + "version": "1.0.0", + "type_version": "1.0.0", + "metadata": { + "policy-id": "OSDF_FRANKFURT.Threshold_URLLC_Core_1_reliability", + "policy-version": 1 + }, + "properties": { + "scope": [ + "OSDF_FRANKFURT", + "URLLC_1", + "URLLC_Core_1" + ], + "resources": [ + "URLLC_Core_1" + ], + "services": [ + "URLLC_1" + ], + "identity": "Threshold_URLLC_Core_1_reliability", + "applicableResources": "any", + "thresholdProperty": { + "attribute":"reliability", + "operator":"gte", + "threshold":99.999, + "unit":"" + } + } + } +}
\ No newline at end of file diff --git a/test/policy-local-files/vnfPolicy_URLLC_Core_1.json b/test/policy-local-files/vnfPolicy_URLLC_Core_1.json new file mode 100644 index 0000000..6582c17 --- /dev/null +++ b/test/policy-local-files/vnfPolicy_URLLC_Core_1.json @@ -0,0 +1,37 @@ +{ + "OSDF_FRANKFURT.vnfPolicy_URLLC_Core_1": { + "type": "onap.policies.optimization.VnfPolicy", + "version": "1.0.0", + "type_version": "1.0.0", + "metadata": { + "policy-id": "OSDF_FRANKFURT.vnfPolicy_URLLC_Core_1", + "policy-version": 1 + }, + "properties": { + "scope": [ + "OSDF_FRANKFURT", + "URLLC_1", + "URLLC_Core_1" + ], + "resources": [ + "URLLC_Core_1" + ], + "services": [ + "URLLC_1" + ], + "identity": "vnf_URLLC_Core_1", + "applicableResources": "any", + "vnfProperties": [ + { + "inventoryProvider": "aai", + "inventoryType": "nssi", + "region": "RegionOne", + "attributes": { + "orchestrationStatus": "active", + "service-role": "nssi" + } + } + ] + } + } +} diff --git a/test/test_ConductorApiBuilder.py b/test/test_ConductorApiBuilder.py index 44c14d8..b3dd97c 100644 --- a/test/test_ConductorApiBuilder.py +++ b/test/test_ConductorApiBuilder.py @@ -53,7 +53,7 @@ class TestConductorApiBuilder(unittest.TestCase): 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, + templ_string = conductor_api_builder(req_info, demands, request_parameters, service_info, True, policies, local_config, self.conductor_api_template) templ_json = json.loads(templ_string) self.assertEqual(templ_json["name"], "yyy-yyy-yyyy") @@ -66,7 +66,7 @@ class TestConductorApiBuilder(unittest.TestCase): 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, + templ_string = conductor_api_builder(req_info, demands, request_parameters, service_info, True, policies, local_config, self.conductor_api_template) templ_json = json.loads(templ_string) self.assertEqual(templ_json, self.request_placement_vfmod_json) |