summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--apps/slice_selection/optimizers/conductor/remote_opt_processor.py21
-rw-r--r--test/apps/slice_selection/nsi_error_response.json37
-rw-r--r--test/apps/slice_selection/test_remote_opt_processor.py6
3 files changed, 47 insertions, 17 deletions
diff --git a/apps/slice_selection/optimizers/conductor/remote_opt_processor.py b/apps/slice_selection/optimizers/conductor/remote_opt_processor.py
index b34c8b1..40638fc 100644
--- a/apps/slice_selection/optimizers/conductor/remote_opt_processor.py
+++ b/apps/slice_selection/optimizers/conductor/remote_opt_processor.py
@@ -66,10 +66,13 @@ def process_nsi_selection_opt(request_json, osdf_config):
request_parameters = request_json.get('serviceProfile',{})
service_info = {}
req_info['numSolutions'] = 'all'
- resp = conductor.request(req_info, demands, request_parameters, service_info, False,
- osdf_config, policies)
- if resp["plans"][0].get("status") == "not found":
- resp["recommendations"] = list()
+ try:
+ resp = conductor.request(req_info, demands, request_parameters, service_info, False,
+ osdf_config, policies)
+ except RequestException as e:
+ resp = e.response.json()
+ error = resp['plans'][0]['message']
+ error_log.error('Error from conductor {}'.format(error))
debug_log.debug("Response from conductor {}".format(str(resp)))
overall_recommendations[nst_name] = resp["plans"][0].get("recommendations")
@@ -78,18 +81,12 @@ def process_nsi_selection_opt(request_json, osdf_config):
solutions['newNSISolutions'] = new_nsi_solutions
solutions['sharedNSISolutions'] = []
return get_nsi_selection_response(req_info, solutions)
- else:
+ else:
return conductor_response_processor(overall_recommendations, nst_info_map, req_info, request_json["serviceProfile"])
except Exception as ex:
error_log.error("Error for {} {}".format(req_info.get('requestId'),
traceback.format_exc()))
- if isinstance(ex, RequestException):
- try:
- error_message = json.loads(ex.response)['plans'][0]['message']
- except Exception:
- error_message = "Problem connecting to conductor"
- else:
- error_message = str(ex)
+ error_message = str(ex)
return conductor_error_response_processor(req_info, error_message)
diff --git a/test/apps/slice_selection/nsi_error_response.json b/test/apps/slice_selection/nsi_error_response.json
index c09bda8..f022779 100644
--- a/test/apps/slice_selection/nsi_error_response.json
+++ b/test/apps/slice_selection/nsi_error_response.json
@@ -1,6 +1,37 @@
{
"requestId":"d290f1ee-6c54-4b01-90e6-d701748f0851",
"transactionId":"d290f1ee-6c54-4b01-90e6-d701748f0851",
- "requestStatus":"error",
- "statusMessage":"Some error message"
-} \ No newline at end of file
+ "requestStatus":"completed",
+ "statusMessage":"",
+ "solutions":{
+ "sharedNSISolutions":[
+
+ ],
+ "newNSISolutions":[
+ {
+ "matchLevel":"",
+ "NSTInfo":{"invariantUUID": "fda3c1e8-7653-4acd-80ef-f5755c1d3859",
+ "UUID": "a6906768-1cae-4e78-acd1-d753ac61f3e8",
+ "NSTName": "URLLC_1"
+ },
+
+ "NSSISolutions":[
+ {
+ "sliceProfile": {
+ "latency": 2,
+ "security": "High",
+ "reliability": 99.9999,
+ "trafficDensity": 1,
+ "connDensity": 100000,
+ "expDataRate": 50,
+ "jitter": 1,
+ "survivalTime": 0,
+ "domainType":"cn",
+ "resourceSharingLevel":"shared"
+ }
+ }
+ ]
+ }
+ ]
+ }
+}
diff --git a/test/apps/slice_selection/test_remote_opt_processor.py b/test/apps/slice_selection/test_remote_opt_processor.py
index 136bb71..5321880 100644
--- a/test/apps/slice_selection/test_remote_opt_processor.py
+++ b/test/apps/slice_selection/test_remote_opt_processor.py
@@ -18,7 +18,7 @@
import json
import unittest
-from requests import RequestException
+from requests import RequestException, Response
from apps.slice_selection.optimizers.conductor.remote_opt_processor import process_nsi_selection_opt
from osdf.adapters.local_data import local_policies
@@ -102,8 +102,10 @@ class TestRemoteOptProcessor(unittest.TestCase):
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=json.dumps(conductor_error_response)))
+ side_effect=RequestException(response=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()