diff options
Diffstat (limited to 'src/onaptests/steps')
-rw-r--r-- | src/onaptests/steps/onboard/cds.py | 38 | ||||
-rw-r--r-- | src/onaptests/steps/simulator/cds_mockserver.py | 62 |
2 files changed, 98 insertions, 2 deletions
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") |