aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichal Jagiello <michal.jagiello@t-mobile.pl>2021-07-20 10:15:32 +0000
committerMichal Jagiello <michal.jagiello@t-mobile.pl>2021-09-02 13:10:42 +0000
commitc31b7fb464fbb8bb0c7d8d2b3dc7b20f4a04cff5 (patch)
tree20bf589edfc6cc5511f8417395234fbd60bad638
parentfd8334dd51d63df817a2057cb3298c125cf310b9 (diff)
[TEST] CDS resource-resolution test
Issue-ID: TEST-291 Signed-off-by: Michal Jagiello <michal.jagiello@t-mobile.pl> Change-Id: I5d9f55b67942c62f63e11282ef2383fe063d3137
-rw-r--r--setup.cfg1
-rw-r--r--src/onaptests/configuration/cds_resource_resolution_settings.py79
-rw-r--r--src/onaptests/scenario/cds_resource_resolution.py96
-rw-r--r--src/onaptests/steps/onboard/cds.py38
-rw-r--r--src/onaptests/steps/simulator/cds_mockserver.py62
-rw-r--r--src/onaptests/templates/artifacts/cds-resource-resolution/cds-mock-server.tar.gzbin0 -> 2376 bytes
-rw-r--r--src/onaptests/templates/artifacts/cds-resource-resolution/dd.json260
-rw-r--r--src/onaptests/templates/artifacts/cds-resource-resolution/resource-resolution.zipbin0 -> 6739 bytes
8 files changed, 534 insertions, 2 deletions
diff --git a/setup.cfg b/setup.cfg
index 3b9c670..5b3c6bf 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -54,3 +54,4 @@ xtesting.testcase =
basic_onboard = onaptests.scenario.basic_onboard:BasicOnboard
pnf_macro = onaptests.scenario.pnf_macro:PnfMacro
basic_clamp = onaptests.scenario.basic_clamp:BasicClamp
+ cds_resource_resolution = onaptests.scenario.cds_resource_resolution:CDSResourceResolution
diff --git a/src/onaptests/configuration/cds_resource_resolution_settings.py b/src/onaptests/configuration/cds_resource_resolution_settings.py
new file mode 100644
index 0000000..bb3b85b
--- /dev/null
+++ b/src/onaptests/configuration/cds_resource_resolution_settings.py
@@ -0,0 +1,79 @@
+from pathlib import Path
+from uuid import uuid4
+
+from .settings import * # pylint: disable=W0614
+
+CLEANUP_FLAG = True
+SERVICE_NAME = "CDS resource resolution"
+CLOUD_REGION_CLOUD_OWNER = "basicnf-owner" # must not contain _
+CLOUD_REGION_ID = "k8sregion"
+CLOUD_REGION_TYPE = "k8s"
+CLOUD_REGION_VERSION = "1.0"
+CLOUD_OWNER_DEFINED_TYPE = "N/A"
+COMPLEX_PHYSICAL_LOCATION_ID = "sdktests"
+
+PNF_DEFINITION_ATRIFACT_FILE_PATH = Path(Path(__file__).parent.parent,
+ "templates/artifacts/cds-resource-resolution/cds-mock-server.tar.gz")
+PNF_RB_NAME = f"cds-ms-rb-{str(uuid4())}"
+PNF_RB_VERSION = "v1"
+PNF_PROFILE_ARTIFACT_FILE_PATH = Path(Path(__file__).parent.parent,
+ "templates/artifacts/profile.tar.gz")
+PNF_PROFILE_NAME = f"cds-ms-prof-{str(uuid4())}"
+K8S_VERSION = "1.0"
+K8S_CONFIG = str(Path(Path(__file__).parent.parent, "templates/artifacts/config"))
+CDS_MOCKSERVER_EXPECTATIONS = [
+ {
+ "method": "GET",
+ "path": "/resource-resolution/get",
+ "response": '{"value": "A046E51D-44DC-43AE-BBA2-86FCA86C5265"}'
+ },
+ {
+ "method": "GET",
+ "path": "/resource-resolution/get/A046E51D-44DC-43AE-BBA2-86FCA86C5265/id",
+ "response": '{"value": "74FE67C6-50F5-4557-B717-030D79903908"}'
+ },
+ {
+ "method": "POST",
+ "path": "/resource-resolution/post",
+ "response": '{"value": "post:ok"}'
+ },
+ {
+ "method": "PUT",
+ "path": "/resource-resolution/put",
+ "response": '{"value": "put:ok"}'
+ },
+ {
+ "method": "PATCH",
+ "path": "/resource-resolution/patch",
+ "response": '{"value": "patch:ok"}'
+ },
+ {
+ "method": "DELETE",
+ "path": "/resource-resolution/delete",
+ "response": '{"value": "delete:ok"}'
+ }
+]
+
+CDS_DD_FILE = Path(Path(__file__).parent.parent, "templates/artifacts/cds-resource-resolution/dd.json")
+CDS_CBA_UNENRICHED = Path(Path(__file__).parent.parent, "templates/artifacts/cds-resource-resolution/resource-resolution.zip")
+CDS_CBA_ENRICHED = "/tmp/resource-resolution-enriched.zip"
+CDS_WORKFLOW_NAME = "resource-resolution"
+CDS_WORKFLOW_INPUT = {
+ "template-prefix": [
+ "helloworld-velocity",
+ "helloworld-jinja"
+ ],
+ "resolution-key": "regression-test",
+ "resource-resolution-properties": {
+ "v_input": "ok",
+ "j_input": "ok"
+ }
+}
+CDS_WORKFLOW_EXPECTED_OUTPUT = {
+ "resource-resolution-response": {
+ "meshed-template": {
+ "helloworld-velocity": "{\n \"default\": \"ok\",\n \"input\": \"ok\",\n \"script\": {\n \"python\": \"ok\",\n \"kotlin\": \"ok\"\n },\n \"db\": \"ok\",\n \"rest\": {\n \"GET\": \"A046E51D-44DC-43AE-BBA2-86FCA86C5265\",\n \"POST\": \"post:ok\",\n \"PUT\": \"put:ok\",\n \"PATCH\": \"patch:ok\",\n \"DELETE\": \"delete:ok\"\n }\n}\n",
+ "helloworld-jinja": "{\n \"default\": \"ok\",\n \"input\": \"ok\",\n \"script\": {\n \"python\": \"ok\",\n \"kotlin\": {\n \"base\": \"ok\"\n \"from suspend function\": \"ok\"\n }\n },\n \"db\": \"ok\",\n \"rest\": {\n \"GET\": \"A046E51D-44DC-43AE-BBA2-86FCA86C5265\",\n \"GET_ID\": \"74FE67C6-50F5-4557-B717-030D79903908\",\n \"POST\": \"post:ok\",\n \"PUT\": \"put:ok\",\n \"PATCH\": \"patch:ok\",\n \"DELETE\": \"delete:ok\"\n }\n}\n"
+ }
+ }
+}
diff --git a/src/onaptests/scenario/cds_resource_resolution.py b/src/onaptests/scenario/cds_resource_resolution.py
new file mode 100644
index 0000000..7e9635f
--- /dev/null
+++ b/src/onaptests/scenario/cds_resource_resolution.py
@@ -0,0 +1,96 @@
+#!/usr/bin/env python
+"""CDS resource resolution test scenario."""
+
+import logging
+import time
+
+from onapsdk.configuration import settings
+from onapsdk.exceptions import SDKException
+from xtesting.core import testcase
+
+from onaptests.steps.base import BaseStep
+from onaptests.steps.onboard.cds import CbaProcessStep
+from onaptests.steps.simulator.cds_mockserver import CdsMockserverCnfConfigureStep
+from onaptests.utils.exceptions import OnapTestException
+
+
+class CDSResourceResolutionStep(BaseStep):
+ """Step created to run scenario and generate report."""
+
+ def __init__(self, cleanup=False):
+ """Initialize step.
+
+ Substeps:
+ - CdsMockserverCnfConfigureStep,
+ - CbaProcessStep.
+ """
+ super().__init__(cleanup=cleanup)
+ self.add_step(CdsMockserverCnfConfigureStep(
+ cleanup=cleanup
+ ))
+ self.add_step(CbaProcessStep(
+ cleanup=cleanup
+ ))
+
+ @property
+ def description(self) -> str:
+ """Step description.
+
+ Used for reports
+
+ Returns:
+ str: Step description
+
+ """
+ return "CDS resource-resoulution base step"
+
+ @property
+ def component(self) -> str:
+ """Component name.
+
+ Name of the component this step relates to.
+ Usually the name of ONAP component.
+
+ Returns:
+ str: Component name
+
+ """
+ return "PythonSDK-tests"
+
+
+class CDSResourceResolution(testcase.TestCase):
+ """Enrich simple blueprint using CDS blueprintprocessor."""
+
+ __logger = logging.getLogger(__name__)
+
+ def __init__(self, **kwargs):
+ """Init CDS resource resolution use case."""
+ if "case_name" not in kwargs:
+ kwargs["case_name"] = 'basic_cds'
+ super().__init__(**kwargs)
+ self.__logger.debug("CDS resource resolution initialization")
+ self.test = CDSResourceResolutionStep(
+ cleanup=settings.CLEANUP_FLAG)
+ self.start_time = None
+ self.stop_time = None
+ self.result = 0
+
+ def run(self):
+ self.__logger.debug("CDS resource resolution run")
+ self.start_time = time.time()
+ try:
+ self.test.execute()
+ self.result = 100
+ except OnapTestException as exc:
+ self.result = 0
+ self.__logger.error(exc.error_message)
+ except SDKException:
+ self.result = 0
+ self.__logger.error("SDK Exception")
+ finally:
+ self.stop_time = time.time()
+
+ def clean(self):
+ """Clean Additional resources if needed."""
+ self.__logger.info("Generate Test report")
+ self.test.reports_collection.generate_report()
diff --git a/src/onaptests/steps/onboard/cds.py b/src/onaptests/steps/onboard/cds.py
index cbd69ce..9239c43 100644
--- a/src/onaptests/steps/onboard/cds.py
+++ b/src/onaptests/steps/onboard/cds.py
@@ -8,6 +8,7 @@ from typing import Any, Dict
from kubernetes import client, config
from kubernetes.client.exceptions import ApiException
from onapsdk.cds import Blueprint, DataDictionarySet
+from onapsdk.cds.blueprint import Workflow
from onapsdk.cds.blueprint_processor import Blueprintprocessor
from onapsdk.configuration import settings
import urllib3
@@ -222,12 +223,45 @@ class CbaPublishStep(CDSBaseStep):
@BaseStep.store_state
def execute(self) -> None:
- """Enrich CBA file.
+ """Publish CBA file.
Use settings values:
- - CDS_DD_FILE.
+ - CDS_CBA_ENRICHED.
"""
super().execute()
blueprint: Blueprint = Blueprint.load_from_file(settings.CDS_CBA_ENRICHED)
blueprint.publish()
+
+
+class CbaProcessStep(CDSBaseStep):
+ """Process CBA step."""
+
+ def __init__(self, cleanup=False) -> None:
+ """Initialize CBA process step."""
+ super().__init__(cleanup=cleanup)
+ self.add_step(CbaPublishStep(cleanup=cleanup))
+
+ @property
+ def description(self) -> str:
+ """Step description."""
+ return "Process CBA file."
+
+ @BaseStep.store_state
+ def execute(self) -> None:
+ """Process CBA file.
+
+ Check if output is equal to expected
+
+ Use settings values:
+ - CDS_CBA_ENRICHED,
+ - CDS_WORKFLOW_NAME,
+ - CDS_WORKFLOW_INPUT
+
+ """
+ super().execute()
+ blueprint: Blueprint = Blueprint.load_from_file(settings.CDS_CBA_ENRICHED)
+ workflow: Workflow = blueprint.get_workflow_by_name(settings.CDS_WORKFLOW_NAME)
+ output: Dict[str, Any] = workflow.execute(settings.CDS_WORKFLOW_INPUT)
+ if not output == settings.CDS_WORKFLOW_EXPECTED_OUTPUT:
+ raise OnapTestException("Response is not equal to the expected one")
diff --git a/src/onaptests/steps/simulator/cds_mockserver.py b/src/onaptests/steps/simulator/cds_mockserver.py
new file mode 100644
index 0000000..6933fa0
--- /dev/null
+++ b/src/onaptests/steps/simulator/cds_mockserver.py
@@ -0,0 +1,62 @@
+# http://www.apache.org/licenses/LICENSE-2.0
+"""CDS mockserver registration module."""
+
+import time
+
+import requests
+from onapsdk.configuration import settings
+
+from onaptests.steps.base import BaseStep
+from onaptests.steps.instantiate.msb_k8s import CreateInstanceStep
+from onaptests.utils.exceptions import OnapTestException
+
+
+class CdsMockserverCnfConfigureStep(BaseStep):
+ """Configure cds mockserver expectations."""
+
+ def __init__(self, cleanup: bool = False) -> None:
+ """Initialize step.
+
+ Substeps:
+ - CreateInstanceStep.
+ """
+ super().__init__(cleanup=cleanup)
+ self.add_step(CreateInstanceStep(cleanup=cleanup))
+
+ @property
+ def description(self) -> str:
+ """Step description."""
+ return "Configure cds-mockserver."
+
+ @property
+ def component(self) -> str:
+ """Component name."""
+ return "Environment"
+
+ @BaseStep.store_state
+ def execute(self) -> None:
+ """Create mockserver expectations.
+
+ Use settings values:
+ - CDS_MOCKSERVER_EXPECTATIONS.
+ """
+ super().execute()
+ time.sleep(60) # Wait for mockserver
+ for expectation in settings.CDS_MOCKSERVER_EXPECTATIONS:
+ try:
+ response = requests.put(
+ "http://portal.api.simpledemo.onap.org:30726/mockserver/expectation",
+ json={
+ "httpRequest" : {
+ "method": expectation["method"],
+ "path": expectation["path"]
+ },
+ "httpResponse" : {
+ "body": expectation["response"]
+ }
+ }
+ )
+ response.raise_for_status()
+ except (requests.ConnectionError, requests.HTTPError) as http_error:
+ self._logger.debug(f"Can't register cds-mockserver expectation: {str(http_error)}")
+ raise OnapTestException("CDS mockserver not configured")
diff --git a/src/onaptests/templates/artifacts/cds-resource-resolution/cds-mock-server.tar.gz b/src/onaptests/templates/artifacts/cds-resource-resolution/cds-mock-server.tar.gz
new file mode 100644
index 0000000..ad428fb
--- /dev/null
+++ b/src/onaptests/templates/artifacts/cds-resource-resolution/cds-mock-server.tar.gz
Binary files differ
diff --git a/src/onaptests/templates/artifacts/cds-resource-resolution/dd.json b/src/onaptests/templates/artifacts/cds-resource-resolution/dd.json
new file mode 100644
index 0000000..ead7f86
--- /dev/null
+++ b/src/onaptests/templates/artifacts/cds-resource-resolution/dd.json
@@ -0,0 +1,260 @@
+[
+ {
+ "name": "RT-db",
+ "data_type": "string",
+ "entry_schema": "string",
+ "description": "DB request for regression test",
+ "tags": "datetime",
+ "updatedBy": "Selfish",
+ "definition": {
+ "name": "RT-db",
+ "tags": "RT-db",
+ "updated-by": "Selffish",
+ "property": {
+ "description": "DB request for regression test",
+ "type": "string"
+ },
+ "sources": {
+ "processor-db": {
+ "type": "source-db",
+ "properties": {
+ "endpoint-selector": "db-endpoint",
+ "type": "SQL",
+ "query": "select sdnctl.RESOURCE_RESOLUTION.value from sdnctl.RESOURCE_RESOLUTION where value='ok'",
+ "input-key-mapping": {},
+ "output-key-mapping": {
+ "value": "value"
+ }
+ }
+ }
+ }
+ }
+ },
+ {
+ "name": "kotlin-script",
+ "data_type": "string",
+ "entry_schema": "string",
+ "description": "Kotlin script used to read properties.",
+ "tags": "kotlin-script",
+ "updatedBy": "Self-fish",
+ "definition": {
+ "name": "kotlin-script",
+ "updated-by": "Selffish",
+ "tags": "properties-capability-source",
+ "property": {
+ "description": "Kotlin script used to read properties.",
+ "type": "string"
+ },
+ "sources": {
+ "capability": {
+ "type": "source-capability",
+ "properties": {
+ "script-type": "kotlin",
+ "script-class-reference": "cba.cds.RT.ResolvPropertiesKt",
+ "instance-dependencies": []
+ }
+ }
+ }
+ }
+ },
+ {
+ "name": "RT-rest-delete",
+ "data_type": "string",
+ "entry_schema": "string",
+ "description": "Rest DELETE request for regression test",
+ "tags": "RT-rest-delete",
+ "updatedBy": "Selfish",
+ "definition": {
+ "name": "RT-rest-delete",
+ "tags": "RT-rest-delete",
+ "updated-by": "Selffish",
+ "property": {
+ "description": "Rest DELETE request for regression test",
+ "type": "string"
+ },
+ "sources": {
+ "sdnc": {
+ "type": "source-rest",
+ "properties": {
+ "type": "string",
+ "verb": "DELETE",
+ "url-path": "/delete",
+ "endpoint-selector": "rest-endpoint",
+ "path": "",
+ "input-key-mapping": {},
+ "output-key-mapping": {
+ "value": "value"
+ }
+ }
+ }
+ }
+ }
+ },
+ {
+ "name": "RT-rest-get-id",
+ "data_type": "string",
+ "entry_schema": "string",
+ "description": "Rest GET request using input key mapping",
+ "tags": "RT-rest-get-id",
+ "updatedBy": "Selfish",
+ "definition": {
+ "name": "RT-rest-get-id",
+ "tags": "RT-rest-get-id",
+ "updated-by": "Selffish",
+ "property": {
+ "description": "Rest GET request using input key mapping",
+ "type": "string"
+ },
+ "sources": {
+ "sdnc": {
+ "type": "source-rest",
+ "properties": {
+ "type": "string",
+ "verb": "GET",
+ "url-path": "/get/$id/id",
+ "endpoint-selector": "rest-endpoint",
+ "path": "",
+ "input-key-mapping": {
+ "id": "j_get"
+ },
+ "output-key-mapping": {
+ "value": "value"
+ }
+ }
+ }
+ }
+ }
+ },
+ {
+ "name": "RT-rest-get",
+ "data_type": "string",
+ "entry_schema": "string",
+ "description": "Rest GET request for regression test",
+ "tags": "RT-rest-get",
+ "updatedBy": "Selfish",
+ "definition": {
+ "name": "RT-rest-get",
+ "tags": "RT-rest-get",
+ "updated-by": "Selffish",
+ "property": {
+ "description": "Rest GET request for regression test",
+ "type": "string"
+ },
+ "sources": {
+ "sdnc": {
+ "type": "source-rest",
+ "properties": {
+ "type": "string",
+ "verb": "GET",
+ "url-path": "/get",
+ "endpoint-selector": "rest-endpoint",
+ "path": "",
+ "input-key-mapping": {},
+ "output-key-mapping": {
+ "value": "value"
+ }
+ }
+ }
+ }
+ }
+ },
+ {
+ "name": "RT-rest-patch",
+ "data_type": "string",
+ "entry_schema": "string",
+ "description": "Rest PATCH request for regression test",
+ "tags": "RT-rest-patch",
+ "updatedBy": "Selfish",
+ "definition": {
+ "name": "RT-rest-patch",
+ "tags": "RT-rest-patch",
+ "updated-by": "Selffish",
+ "property": {
+ "description": "Rest PATCH request for regression test",
+ "type": "string"
+ },
+ "sources": {
+ "sdnc": {
+ "type": "source-rest",
+ "properties": {
+ "type": "string",
+ "verb": "PATCH",
+ "url-path": "/patch",
+ "endpoint-selector": "rest-endpoint",
+ "path": "",
+ "input-key-mapping": {},
+ "output-key-mapping": {
+ "value": "value"
+ }
+ }
+ }
+ }
+ }
+ },
+ {
+ "name": "RT-rest-post",
+ "data_type": "string",
+ "entry_schema": "string",
+ "description": "Rest POST request for regression test",
+ "tags": "RT-rest-post",
+ "updatedBy": "Selfish",
+ "definition": {
+ "name": "RT-rest-post",
+ "tags": "RT-rest-post",
+ "updated-by": "Selffish",
+ "property": {
+ "description": "Rest POST request for regression test",
+ "type": "string"
+ },
+ "sources": {
+ "sdnc": {
+ "type": "source-rest",
+ "properties": {
+ "type": "string",
+ "verb": "POST",
+ "url-path": "/post",
+ "endpoint-selector": "rest-endpoint",
+ "path": "",
+ "input-key-mapping": {},
+ "output-key-mapping": {
+ "value": "value"
+ }
+ }
+ }
+ }
+ }
+ },
+ {
+ "name": "RT-rest-put",
+ "data_type": "string",
+ "entry_schema": "string",
+ "description": "Rest PUT request for regression test",
+ "tags": "RT-rest-put",
+ "updatedBy": "Selfish",
+ "definition": {
+ "name": "RT-rest-put",
+ "tags": "RT-rest-put",
+ "updated-by": "Selffish",
+ "property": {
+ "description": "Rest PUT request for regression test",
+ "type": "string"
+ },
+ "sources": {
+ "sdnc": {
+ "type": "source-rest",
+ "properties": {
+ "type": "string",
+ "verb": "PUT",
+ "url-path": "/put",
+ "endpoint-selector": "rest-endpoint",
+ "path": "",
+ "input-key-mapping": {},
+ "output-key-mapping": {
+ "value": "value"
+ }
+ }
+ }
+ }
+ }
+ }
+]
diff --git a/src/onaptests/templates/artifacts/cds-resource-resolution/resource-resolution.zip b/src/onaptests/templates/artifacts/cds-resource-resolution/resource-resolution.zip
new file mode 100644
index 0000000..43d8c4e
--- /dev/null
+++ b/src/onaptests/templates/artifacts/cds-resource-resolution/resource-resolution.zip
Binary files differ