summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--apps/nxi_termination/optimizers/remote_opt_processor.py115
-rw-r--r--apps/nxi_termination/optimizers/response_processor.py15
-rw-r--r--config/common_config.yaml7
-rwxr-xr-xconfig/osdf_config.yaml1
-rwxr-xr-xcsit/scripts/osdf-properties/osdf_config.yaml11
-rwxr-xr-xcsit/scripts/osdf_script.sh4
-rw-r--r--csit/tests/osdf/data/termination_request.json14
-rw-r--r--csit/tests/osdf/optf_osdf_nxi_termination.robot69
-rw-r--r--csit/tests/osdf/optf_osdf_setup.robot2
-rw-r--r--csit/tests/osdf/optf_osdf_test.robot6
-rw-r--r--csit/tests/osdf/resources/common-keywords.robot1
-rw-r--r--osdf/adapters/aai/fetch_aai_data.py46
-rw-r--r--test/apps/nxi_termination/nssi_failure_output.json2
-rw-r--r--test/apps/nxi_termination/nxi_failure_output1.json2
-rw-r--r--test/apps/nxi_termination/nxi_failure_output2.json2
-rw-r--r--test/apps/nxi_termination/test_remote_opt_processor_termination.py49
-rw-r--r--test/functest/simulators/oof_dependencies_simulators.py42
17 files changed, 254 insertions, 134 deletions
diff --git a/apps/nxi_termination/optimizers/remote_opt_processor.py b/apps/nxi_termination/optimizers/remote_opt_processor.py
index 8867c97..7878f5d 100644
--- a/apps/nxi_termination/optimizers/remote_opt_processor.py
+++ b/apps/nxi_termination/optimizers/remote_opt_processor.py
@@ -15,109 +15,72 @@
#
# -------------------------------------------------------------------------
#
-from apps.nxi_termination.optimizers.response_processor import get_nxi_termination_failure_response
+
+from jinja2 import Template
+
from apps.nxi_termination.optimizers.response_processor import get_nxi_termination_response
from osdf.adapters.aai.fetch_aai_data import AAIException
-from osdf.adapters.aai.fetch_aai_data import get_aai_data
+from osdf.adapters.aai.fetch_aai_data import execute_dsl_query
+from osdf.logging.osdf_logging import debug_log
def process_nxi_termination_opt(request_json, osdf_config):
-
"""Process the nxi Termination request from API layer
- :param request_json: api request
- :param osdf_config: configuration specific to OSDF app
- :return: response as a success,failure
+ :param request_json: api request
+ :param osdf_config: configuration specific to OSDF app
+ :return: response as a success,failure
"""
- type = request_json["type"]
+ request_type = request_json["type"]
request_info = request_json.get("requestInfo", {})
addtnl_args = request_info.get("addtnlArgs", {})
- if type == "NSI":
- arg_val = addtnl_args.get("serviceProfileId", "")
- return check_nxi_termination(request_json, osdf_config, addtnl_args, arg_val,
- get_service_profiles, get_service_profile_id)
+ query_templates = osdf_config.core["nxi_termination"]["query_templates"]
- else:
- arg_val = addtnl_args.get("serviceInstanceId", "")
- return check_nxi_termination(request_json, osdf_config, addtnl_args, arg_val, get_relationshiplist, get_nsi_id)
-
-
-def check_nxi_termination(request_json, osdf_config, addtnl_args, arg_val, get_response_object, get_response_id):
- request_info = request_json.get("requestInfo", {})
+ inputs = {
+ "instance_id": request_json["NxIId"]
+ }
try:
- response_object = get_response_object(request_json, osdf_config)
- if addtnl_args and arg_val and len(response_object) == 1:
- response_id = get_response_id(response_object)
- if arg_val == response_id:
- reason = ''
- return set_success_response(reason, request_info, terminate_response=True)
-
- else:
- reason = "{} is not available in AAI".format(arg_val)
- return set_success_response(reason, request_info, terminate_response=False)
+ if request_type == "NSI":
+ query_type = "nsi"
+ if addtnl_args and "serviceProfileId" in addtnl_args:
+ inputs["profile_id"] = addtnl_args["serviceProfileId"]
+ query_type = "nsi_with_profile"
+ else:
+ query_type = "nssi"
+ if addtnl_args and "serviceInstanceId" in addtnl_args:
+ inputs["nsi_id"] = addtnl_args["serviceInstanceId"]
+ query_type = "nssi_with_nsi"
- elif len(response_object) == 0:
- reason = ''
- return set_success_response(reason, request_info, terminate_response=True)
+ debug_log.debug("query type: {}".format(query_type))
- else:
- reason = "Associated to more than one"
- return set_success_response(reason, request_info, terminate_response=False)
+ resource_count = get_resource_count(query_templates[query_type], inputs, osdf_config)
+ if query_type not in ["nsi", "nssi"]:
+ # if additional args is provided, it must have exactly one resource in its relationships
+ resource_count = resource_count - 1
+ return set_response("success", "", request_info, resource_count <= 0)
except AAIException as e:
reason = str(e)
- return set_failure_response(reason, request_info)
+ return set_response("failure", reason, request_info)
except Exception as e:
reason = "{} Exception Occurred while processing".format(str(e))
- return set_failure_response(reason, request_info)
+ return set_response("failure", reason, request_info)
-def get_service_profiles(request_json, osdf_config):
- try:
- json_response = get_aai_data(request_json, osdf_config)
- service_profiles = json_response.get("service-profiles", {})
- service_profile = service_profiles.get("service-profile", [])
- return service_profile
- except AAIException as e:
- raise AAIException(e)
-
-
-def get_relationshiplist(request_json, osdf_config):
- try:
- json_response = get_aai_data(request_json, osdf_config)
- rel_list = json_response.get("relationship-list", {})
- relationship = rel_list.get("relationship", [])
- return relationship
- except AAIException as e:
- raise AAIException(e)
-
-
-def get_service_profile_id(service_profile):
- profile_obj = service_profile[0]
- return profile_obj.get("profile-id", "")
-
-
-def get_nsi_id(relationship):
- rel_obj = relationship[0]
- rel_data = rel_obj.get("relationship-data", [])
- for data in rel_data:
- if data["relationship-key"] == "service-instance.service-instance-id":
- return data["relationship-value"]
-
-
-def set_success_response(reason, request_info, terminate_response):
+def set_response(status, reason, request_info, terminate_response=None):
res = dict()
- res["requestStatus"] = "success"
+ res["requestStatus"] = status
res["terminateResponse"] = terminate_response
res["reason"] = reason
return get_nxi_termination_response(request_info, res)
-def set_failure_response(reason, request_info,):
- res = dict()
- res["requestStatus"] = "failure"
- res["reason"] = reason
- return get_nxi_termination_failure_response(request_info, res)
+def get_resource_count(query_template, inputs, osdf_config):
+ query = Template(query_template).render(inputs)
+ dsl_response = execute_dsl_query(query, "count", osdf_config)
+ debug_log.debug("dsl_response {}".format(dsl_response))
+ # the dsl query with format "count" includes the original service-instance, hence reducing one from the result
+ return dsl_response["results"][0]["service-instance"] - 1
diff --git a/apps/nxi_termination/optimizers/response_processor.py b/apps/nxi_termination/optimizers/response_processor.py
index e7f1041..3ea35c0 100644
--- a/apps/nxi_termination/optimizers/response_processor.py
+++ b/apps/nxi_termination/optimizers/response_processor.py
@@ -16,6 +16,7 @@
# -------------------------------------------------------------------------
#
+
def get_nxi_termination_response(request_info, response):
"""Get NXI termination response from final solution
@@ -29,17 +30,3 @@ def get_nxi_termination_response(request_info, response):
'requestStatus': response["requestStatus"],
'terminateResponse': response["terminateResponse"],
'reason': response['reason']}
-
-
-def get_nxi_termination_failure_response(request_info, response):
-
- """Get NXI termination response from final solution
-
- :param request_info: request info
- :param response: response to be send
- :return: NxI Termination response to send back as dictionary
- """
- return {'requestId': request_info['requestId'],
- 'transactionId': request_info['transactionId'],
- 'requestStatus': response["requestStatus"],
- 'reason': response['reason']}
diff --git a/config/common_config.yaml b/config/common_config.yaml
index d4d205e..b9578f2 100644
--- a/config/common_config.yaml
+++ b/config/common_config.yaml
@@ -150,3 +150,10 @@ PCI:
filter:
interval: 10
ml_enabled: false
+
+nxi_termination:
+ query_templates:
+ nsi: "service-instance*('service-instance-id','{{instance_id}}') > service-instance*('service-role','e2eserviceprofile-service')"
+ nsi_with_profile: "service-instance*('service-instance-id','{{instance_id}}') > service-instance*('service-role','e2eserviceprofile-service')('service-instance-id','{{profile_id}}')"
+ nssi: "service-instance*('service-instance-id','{{instance_id}}') > service-instance*('service-role','nsi')"
+ nssi_with_nsi: "service-instance*('service-instance-id','{{instance_id}}') > service-instance*('service-role','nsi')('service-instance-id','{{nsi_id}}')" \ No newline at end of file
diff --git a/config/osdf_config.yaml b/config/osdf_config.yaml
index 9f98101..ee32221 100755
--- a/config/osdf_config.yaml
+++ b/config/osdf_config.yaml
@@ -57,6 +57,7 @@ aaiServiceInstanceUrl : "/aai/v20/nodes/service-instances/service-instance/"
aaiGetControllersUrl: /aai/v19/external-system/esr-thirdparty-sdnc-list
controllerQueryUrl: /aai/v19/query?format=resource
aaiGetInterDomainLinksUrl: /aai/v19/network/logical-links?link-type=inter-domain&operational-status=up
+dslQueryPath: /aai/v23/dsl?format=
#DES api
desUrl: http://des.url:9000
diff --git a/csit/scripts/osdf-properties/osdf_config.yaml b/csit/scripts/osdf-properties/osdf_config.yaml
index 95856df..3ca4cd1 100755
--- a/csit/scripts/osdf-properties/osdf_config.yaml
+++ b/csit/scripts/osdf-properties/osdf_config.yaml
@@ -41,12 +41,21 @@ aaf_user_roles:
aaf_sms_url: http://aaf-sms.onap:10443
aaf_sms_timeout: 30
secret_domain: osdf
-aaf_ca_certs: ssl_certs/aaf_root_ca.cer
+aaf_ca_certs: /opt/aaf_root_ca.cer
# config db api
configDbUrl: http://127.0.0.1:5000/simulated/configdb
configDbGetCellListUrl: 'getCellList'
configDbGetNbrListUrl: 'getNbrList'
+#aai api
+aaiUrl: "http://127.0.0.1:5000"
+aaiGetLinksUrl: "/aai/v16/network/logical-links"
+aaiServiceInstanceUrl : "/aai/v20/nodes/service-instances/service-instance/"
+aaiGetControllersUrl: /aai/v19/external-system/esr-thirdparty-sdnc-list
+controllerQueryUrl: /aai/v19/query?format=resource
+aaiGetInterDomainLinksUrl: /aai/v19/network/logical-links?link-type=inter-domain&operational-status=up
+dslQueryPath: /simulated/aai/v23/dsl?format=
+
#key
appkey:
diff --git a/csit/scripts/osdf_script.sh b/csit/scripts/osdf_script.sh
index fe0b743..0d86a63 100755
--- a/csit/scripts/osdf_script.sh
+++ b/csit/scripts/osdf_script.sh
@@ -33,6 +33,7 @@ cd ${DIR}
# create directory for volume and copy configuration file
# run docker containers
OSDF_CONF=/tmp/osdf/properties/osdf_config.yaml
+AAF_CER=/tmp/osdf/properties/aaf_root_ca.cer
IMAGE_NAME=nexus3.onap.org:10003/onap/optf-osdf
IMAGE_VER=latest
@@ -40,6 +41,7 @@ mkdir -p /tmp/osdf/properties
mkdir -p /tmp/sms/properties
cp ${WORKSPACE}/scripts/osdf-properties/*.yaml /tmp/osdf/properties/.
+cp ${WORKSPACE}/scripts/osdf-properties/aaf_root_ca.cer /tmp/osdf/properties/.
cp ${WORKSPACE}/scripts/osdf-properties/osdf.json /tmp/sms/properties/.
#change conductor/configdb simulator urls
@@ -57,7 +59,7 @@ docker cp /tmp/sms/properties/osdf.json sms:/preload/config/osdf.json
docker exec --user root -i sms /bin/sh -c "/sms/bin/preload -cacert /sms/certs/aaf_root_ca.cer -jsondir /preload/config -serviceport 10443 -serviceurl http://localhost"
docker logs vault
-docker run -d --name optf-osdf -v ${OSDF_CONF}:/opt/osdf/config/osdf_config.yaml -p "8698:8699" ${IMAGE_NAME}:${IMAGE_VER}
+docker run -d --name optf-osdf -v ${AAF_CER}:/opt/aaf_root_ca.cer -v ${OSDF_CONF}:/opt/osdf/config/osdf_config.yaml -p "8698:8699" ${IMAGE_NAME}:${IMAGE_VER}
sleep 20
diff --git a/csit/tests/osdf/data/termination_request.json b/csit/tests/osdf/data/termination_request.json
new file mode 100644
index 0000000..b219645
--- /dev/null
+++ b/csit/tests/osdf/data/termination_request.json
@@ -0,0 +1,14 @@
+{
+ "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,
+ "addtnlArgs": {}
+ },
+ "type":"NSI",
+ "NxIId":"9629e36c-a3d9-4aed-8368-f72b8be1cd34",
+ "UUID":"9629e36c-a3d9-4aed-8368-f72b8be1cd34",
+ "invariantUUID":"9629e36c-a3d9-4aed-8368-f72b8be1cd34"
+} \ No newline at end of file
diff --git a/csit/tests/osdf/optf_osdf_nxi_termination.robot b/csit/tests/osdf/optf_osdf_nxi_termination.robot
new file mode 100644
index 0000000..da6836e
--- /dev/null
+++ b/csit/tests/osdf/optf_osdf_nxi_termination.robot
@@ -0,0 +1,69 @@
+*** Settings ***
+Library copy
+Library json
+Library Collections
+Library OperatingSystem
+Resource ./resources/common-keywords.robot
+
+Suite Teardown Delete All Sessions
+
+*** Variables ***
+&{placement_auth} = username=test password=testpwd
+
+*** Keywords ***
+
+NxiTerminationRequest
+ [Documentation] Sends request to NxiTermination API
+ [Arguments] ${data}
+ ${data_str}= json.dumps ${data}
+ ${resp}= Http Post host=${osdf_host} restUrl=/api/oof/terminate/nxi/v1 data=${data_str} auth=${placement_auth}
+ ${response_json} json.loads ${resp.content}
+ Should Be Equal As Integers ${resp.status_code} 200
+ [Return] ${response_json}
+
+*** Test Cases ***
+
+TerminationRequestGeneration
+ [Documentation] This test case will generate request json for different scenarios
+ ${data}= Get Binary File ${CURDIR}${/}data${/}termination_request.json
+ ${nsi_termination_request}= json.loads ${data}
+ Set Global Variable ${nsi_termination_request}
+ ${nssi_termination_request}= copy.deepcopy ${nsi_termination_request}
+ Set To Dictionary ${nssi_termination_request} type=NSSI
+ Set Global Variable ${nssi_termination_request}
+ ${nsi_termination_request_args}= copy.deepcopy ${nsi_termination_request}
+ ${request_info}= Set Variable ${nsi_termination_request_args["requestInfo"]}
+ ${addtnl_args}= Create Dictionary serviceProfileId=660ca85c-1a0f-4521-a559-65f23e794699
+ Set To Dictionary ${request_info} addtnlArgs=${addtnl_args}
+ Set To Dictionary ${nsi_termination_request_args} requestInfo=${request_info}
+ Set Global Variable ${nsi_termination_request_args}
+ ${nssi_termination_request_args}= copy.deepcopy ${nssi_termination_request}
+ ${request_info}= Set Variable ${nssi_termination_request_args["requestInfo"]}
+ ${addtnl_args}= Create Dictionary serviceInstanceId=660ca85c-1a0f-4521-a559-65f23e794699
+ Set To Dictionary ${request_info} addtnlArgs=${addtnl_args}
+ Set To Dictionary ${nssi_termination_request_args} requestInfo=${request_info}
+ Set Global Variable ${nssi_termination_request_args}
+
+NSITermination
+ [Documentation] It sends a NSI termination request with no additional arguments
+ ${response_json}= NxiTerminationRequest ${nsi_termination_request}
+ Should Be Equal success ${response_json['requestStatus']}
+ Should Be True ${response_json['terminateResponse']}
+
+NSSITermination
+ [Documentation] It sends a NSSI termination request with no additional arguments
+ ${response_json}= NxiTerminationRequest ${nssi_termination_request}
+ Should Be Equal success ${response_json['requestStatus']}
+ Should Be True ${response_json['terminateResponse']}
+
+NSITerminationWithAddtnlArgs
+ [Documentation] It sends a NSSI termination request with additional arguments
+ ${response_json}= NxiTerminationRequest ${nsi_termination_request_args}
+ Should Be Equal success ${response_json['requestStatus']}
+ Should Be True ${response_json['terminateResponse']}
+
+NSSITerminationWithAddtnlArgs
+ [Documentation] It sends a NSSI termination request with additional arguments
+ ${response_json}= NxiTerminationRequest ${nssi_termination_request_args}
+ Should Be Equal success ${response_json['requestStatus']}
+ Should Be True ${response_json['terminateResponse']}
diff --git a/csit/tests/osdf/optf_osdf_setup.robot b/csit/tests/osdf/optf_osdf_setup.robot
index fdf7f3e..ae3c271 100644
--- a/csit/tests/osdf/optf_osdf_setup.robot
+++ b/csit/tests/osdf/optf_osdf_setup.robot
@@ -9,4 +9,4 @@ Check OSDF_SIM Docker Container
Check OSDF Docker Container
[Documentation] It checks optf-osdf docker container is running
- Verify Docker RC Status optf-osdf \ No newline at end of file
+ Verify Docker RC Status optf-osdf
diff --git a/csit/tests/osdf/optf_osdf_test.robot b/csit/tests/osdf/optf_osdf_test.robot
index 79a5750..292df64 100644
--- a/csit/tests/osdf/optf_osdf_test.robot
+++ b/csit/tests/osdf/optf_osdf_test.robot
@@ -6,7 +6,6 @@ Resource ./resources/common-keywords.robot
Suite Teardown Delete All Sessions
*** Variables ***
-${osdf_host} ${OSDF_HOSTNAME}:${OSDF_PORT}
&{placement_auth} = username=test password=testpwd
&{wrong_authorization} = username=test password=test
&{pci_auth}= username=pci_test password=pci_testpwd
@@ -41,8 +40,3 @@ SendPCIOptimizationWithAuth
${response_json} json.loads ${resp.content}
Should Be Equal As Integers ${resp.status_code} 202
Should Be Equal accepted ${response_json['requestStatus']}
-
-
-
-
-
diff --git a/csit/tests/osdf/resources/common-keywords.robot b/csit/tests/osdf/resources/common-keywords.robot
index 74232c5..114c8a0 100644
--- a/csit/tests/osdf/resources/common-keywords.robot
+++ b/csit/tests/osdf/resources/common-keywords.robot
@@ -6,6 +6,7 @@ Library json
Library RequestsLibrary
*** Variables ***
&{headers}= Content-Type=application/json Accept=application/json
+${osdf_host} ${OSDF_HOSTNAME}:${OSDF_PORT}
*** Keywords ***
Verify Docker RC Status
[Documentation] Method to verify whether docker instance is up and running
diff --git a/osdf/adapters/aai/fetch_aai_data.py b/osdf/adapters/aai/fetch_aai_data.py
index d869882..fad2512 100644
--- a/osdf/adapters/aai/fetch_aai_data.py
+++ b/osdf/adapters/aai/fetch_aai_data.py
@@ -16,10 +16,22 @@
# -------------------------------------------------------------------------
#
+import json
import requests
from requests.auth import HTTPBasicAuth
from requests import RequestException
+from osdf.logging.osdf_logging import debug_log
+
+AAI_HEADERS = {
+ "X-TransactionId": "9999",
+ "X-FromAppId": "OOF",
+ "Accept": "application/json",
+ "Content-Type": "application/json",
+}
+
+AUTH = HTTPBasicAuth("AAI", "AAI")
+
class AAIException(Exception):
pass
@@ -33,19 +45,14 @@ def get_aai_data(request_json, osdf_config):
:param osdf_config: configuration specific to OSDF app
:return:response body from AAI
"""
- aai_headers = {
- "X-TransactionId": "9999",
- "X-FromAppId": "OOF",
- "Accept": "application/json",
- "Content-Type": "application/json",
- }
+
nxi_id = request_json["NxIId"]
config = osdf_config.deployment
aai_url = config["aaiUrl"]
aai_req_url = aai_url + config["aaiServiceInstanceUrl"] + nxi_id + "?depth=2"
try:
- response = requests.get(aai_req_url, headers=aai_headers, auth=HTTPBasicAuth("AAI", "AAI"), verify=False)
+ response = requests.get(aai_req_url, headers=AAI_HEADERS, auth=AUTH, verify=False)
except RequestException as e:
raise AAIException("Request exception was encountered {}".format(e))
@@ -53,3 +60,28 @@ def get_aai_data(request_json, osdf_config):
return response.json()
else:
raise AAIException("Error response recieved from AAI for the request {}".format(aai_req_url))
+
+
+def execute_dsl_query(query, format, osdf_config):
+ """Get the response from AAI
+
+ :param query: dsl query to be executed
+ :param format format of the output
+ :param osdf_config: configuration specific to OSDF app
+ :return:response body from AAI
+ """
+ config = osdf_config.deployment
+ dsl_url = config["aaiUrl"] + config["dslQueryPath"] + format
+
+ data = json.dumps({'dsl': query})
+ debug_log.debug("aai dsl request: {}".format(data))
+ try:
+ response = requests.put(dsl_url, data=data, headers=AAI_HEADERS, auth=AUTH, verify=False)
+ except RequestException as ex:
+ raise AAIException("Request exception was encountered {}".format(ex))
+
+ if response.status_code == 200:
+ return response.json()
+ else:
+ raise AAIException("Response code other than 200 from AAI: {} {}".format(response.status_code,
+ response.content))
diff --git a/test/apps/nxi_termination/nssi_failure_output.json b/test/apps/nxi_termination/nssi_failure_output.json
index 5ada892..f300c53 100644
--- a/test/apps/nxi_termination/nssi_failure_output.json
+++ b/test/apps/nxi_termination/nssi_failure_output.json
@@ -3,6 +3,6 @@
"transactionId": "d290f1ee-6c54-4b01-90e6-d701748f0851",
"requestStatus": "success",
"terminateResponse": false,
- "reason": "4115d3c8-dd59-45d6-b09d-e756dee9b518 is not available in AAI"
+ "reason": ""
} \ No newline at end of file
diff --git a/test/apps/nxi_termination/nxi_failure_output1.json b/test/apps/nxi_termination/nxi_failure_output1.json
index b363e86..4cce5eb 100644
--- a/test/apps/nxi_termination/nxi_failure_output1.json
+++ b/test/apps/nxi_termination/nxi_failure_output1.json
@@ -3,7 +3,7 @@
"transactionId": "d290f1ee-6c54-4b01-90e6-d701748f0851",
"requestStatus": "success",
"terminateResponse": false,
- "reason": "cdad9f49-4201-4e3a-aac1-b0f27902c299 is not available in AAI"
+ "reason": ""
}
diff --git a/test/apps/nxi_termination/nxi_failure_output2.json b/test/apps/nxi_termination/nxi_failure_output2.json
index 5d430bc..f18b73c 100644
--- a/test/apps/nxi_termination/nxi_failure_output2.json
+++ b/test/apps/nxi_termination/nxi_failure_output2.json
@@ -3,5 +3,5 @@
"transactionId": "d290f1ee-6c54-4b01-90e6-d701748f0851",
"requestStatus": "success",
"terminateResponse": false,
- "reason": "Associated to more than one"
+ "reason": ""
} \ No newline at end of file
diff --git a/test/apps/nxi_termination/test_remote_opt_processor_termination.py b/test/apps/nxi_termination/test_remote_opt_processor_termination.py
index 4fa8170..9fbc27b 100644
--- a/test/apps/nxi_termination/test_remote_opt_processor_termination.py
+++ b/test/apps/nxi_termination/test_remote_opt_processor_termination.py
@@ -69,73 +69,74 @@ class TestRemoteOptProcessor(unittest.TestCase):
exception_response_json1 = json_from_file(exception_response_file1)
#nsi success scenario
- self.patcher_req=patch('apps.nxi_termination.optimizers.remote_opt_processor.get_service_profiles',return_value=service_profile_json)
+ 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(request_json,osdf_config))
+ 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_service_profiles', return_value=failure_service_profile_json)
+ self.patcher_req = patch('apps.nxi_termination.optimizers.remote_opt_processor.get_resource_count', return_value=3)
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_service_profiles',
- return_value=[])
+ 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(request_json, osdf_config))
self.patcher_req.stop()
# nsi failure scenario
- self.patcher_req = patch('apps.nxi_termination.optimizers.remote_opt_processor.get_service_profiles',
- return_value=failure_service_profile_json2)
+ 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(request_json, osdf_config))
self.patcher_req.stop()
# #
# nssi success scenario
- self.patcher_req = patch('apps.nxi_termination.optimizers.remote_opt_processor.get_relationshiplist', return_value=success_rel_json)
+ 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 success scenario
- self.patcher_req = patch('apps.nxi_termination.optimizers.remote_opt_processor.get_relationshiplist',
- return_value=[])
+ # 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(success_output_json, process_nxi_termination_opt(nssi_request_json, osdf_config))
+ self.assertEquals(nssi_failure_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_relationshiplist',
- return_value=failure_rel_json)
+ 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(nssi_failure_output_json, process_nxi_termination_opt(nssi_request_json, osdf_config))
+ 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_relationshiplist',
- return_value=failure_rel_json2)
+ 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_relationshiplist',
+ 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(exception_response_json1, process_nxi_termination_opt(nssi_request_json, osdf_config))
+ 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_relationshiplist',
+ 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()
-
-
if __name__ == "__main__":
unittest.main() \ No newline at end of file
diff --git a/test/functest/simulators/oof_dependencies_simulators.py b/test/functest/simulators/oof_dependencies_simulators.py
index b0b7b32..53cc74e 100644
--- a/test/functest/simulators/oof_dependencies_simulators.py
+++ b/test/functest/simulators/oof_dependencies_simulators.py
@@ -23,7 +23,7 @@ import glob
import json
import os
-from flask import Flask, jsonify
+from flask import Flask, jsonify, request
from osdf.utils.interfaces import json_from_file
@@ -119,5 +119,45 @@ def get_nbr_list(cell_id, ts):
return jsonify(data), 503
+@app.route("/simulated/aai/v23/dsl", methods=["PUT"])
+def dsl_query():
+
+ nsi_query = {"dsl": "service-instance*('service-instance-id','9629e36c-a3d9-4aed-8368-f72b8be1cd34') > "
+ "service-instance*('service-role','e2eserviceprofile-service')"}
+
+ nssi_query = {"dsl": "service-instance*('service-instance-id','9629e36c-a3d9-4aed-8368-f72b8be1cd34') > "
+ "service-instance*('service-role','nsi')"}
+
+ nsi_with_sp_query = {"dsl": "service-instance*('service-instance-id','9629e36c-a3d9-4aed-8368-f72b8be1cd34') > "
+ "service-instance*('service-role','e2eserviceprofile-service')("
+ "'service-instance-id',"
+ "'660ca85c-1a0f-4521-a559-65f23e794699660ca85c-1a0f-4521-a559-65f23e794699')"}
+
+ nssi_with_nsi_query = {"dsl": "service-instance*('service-instance-id','9629e36c-a3d9-4aed-8368-f72b8be1cd34') > "
+ "service-instance*('service-role','nsi')('service-instance-id',"
+ "'660ca85c-1a0f-4521-a559-65f23e794699')"}
+
+ queries = {
+ "nsi": nsi_query,
+ "nssi_query": nssi_query,
+ "nsi_with_sp": nsi_with_sp_query,
+ "nssi_with_nsi": nssi_with_nsi_query
+ }
+
+ count = {
+ "nsi": 1,
+ "nssi_query": 1,
+ "nsi_with_sp": 2,
+ "nssi_with_nsi": 2
+ }
+
+ request_body = request.get_json()
+ service_count = 0
+ for query_type, query in queries.items():
+ if request_body == query:
+ service_count = count[query_type]
+ return {'results': [{'service-instance': service_count}]}
+
+
if __name__ == "__main__":
app.run(debug=True, host='0.0.0.0')