From 22664610f99038223f996ef1c1661872a92e4ee4 Mon Sep 17 00:00:00 2001 From: Lukasz Rajewski Date: Thu, 23 Dec 2021 13:40:11 +0100 Subject: [TEST] Basic CNF macro Basic CNF macro added with refactoring that enables debugging under IDE Also SDK upgraded to 9.2 what required adaptation in existing tests Issue-ID: TEST-376 Signed-off-by: Lukasz Rajewski Change-Id: I697857bc0c13e86b88b71c3b46e0c4b59751939c Signed-off-by: mrichomme --- src/onaptests/scenario/basic_cnf_macro.py | 132 ++++++++++++++++++++++++++++++ src/onaptests/scenario/basic_vm_macro.py | 6 +- src/onaptests/scenario/multi_vnf_macro.py | 4 +- src/onaptests/scenario/pnf_macro.py | 4 +- 4 files changed, 139 insertions(+), 7 deletions(-) create mode 100644 src/onaptests/scenario/basic_cnf_macro.py (limited to 'src/onaptests/scenario') diff --git a/src/onaptests/scenario/basic_cnf_macro.py b/src/onaptests/scenario/basic_cnf_macro.py new file mode 100644 index 0000000..2784782 --- /dev/null +++ b/src/onaptests/scenario/basic_cnf_macro.py @@ -0,0 +1,132 @@ +"""Instantiate basic cnf using SO macro flow.""" +import logging +import time +from yaml import load, SafeLoader + +from onapsdk.configuration import settings +from onapsdk.exceptions import SDKException +from xtesting.core import testcase + +from onaptests.steps.base import YamlTemplateBaseStep +from onaptests.steps.onboard.cds import CbaPublishStep +from onaptests.utils.exceptions import OnapTestException +from onaptests.steps.instantiate.service_macro import YamlTemplateServiceMacroInstantiateStep + + +class BasicCnfMacroStep(YamlTemplateBaseStep): + + def __init__(self, cleanup=False): + """Initialize step. + + Substeps: + - CbaPublishStep + - YamlTemplateServiceMacroInstantiateStep. + """ + super().__init__(cleanup=cleanup) + self._yaml_template: dict = None + self.add_step(CbaPublishStep( + cleanup=cleanup + )) + self.add_step(YamlTemplateServiceMacroInstantiateStep( + cleanup=cleanup + )) + + @property + def description(self) -> str: + """Step description. + + Used for reports + + Returns: + str: Step description + + """ + return "Basic CNF macro scenario step" + + @property + def component(self) -> str: + """Component name. + + Name of component which step is related with. + Most is the name of ONAP component. + + Returns: + str: Component name + + """ + return "PythonSDK-tests" + + @property + def yaml_template(self) -> dict: + """YAML template abstract property. + + Every YAML template step need to implement that property. + + Returns: + dict: YAML template + + """ + if not self._yaml_template: + with open(settings.SERVICE_YAML_TEMPLATE, "r") as yaml_template: + self._yaml_template: dict = load(yaml_template, SafeLoader) + return self._yaml_template + + @property + def model_yaml_template(self) -> dict: + return {} + + @property + def service_name(self) -> dict: + """Service name. + + Get from YAML template. + + Returns: + str: Service name + + """ + return next(iter(self.yaml_template.keys())) + + @property + def service_instance_name(self) -> str: + """Service instance name. + + Returns: + str: Service instance name + + """ + return settings.SERVICE_INSTANCE_NAME + + +class BasicCnfMacro(testcase.TestCase): + """Instantiate a basic cnf macro.""" + + __logger = logging.getLogger() + + def __init__(self, **kwargs): + """Init Basic Cnf Macro use case.""" + if "case_name" not in kwargs: + kwargs["case_name"] = 'basic_cnf_macro' + super().__init__(**kwargs) + self.__logger.debug("Basic Cnf macro init started") + self.test = BasicCnfMacroStep(cleanup=settings.CLEANUP_FLAG) + + def run(self): + """Run basic cnf macro test.""" + self.start_time = time.time() + try: + self.test.execute() + self.test.cleanup() + 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): + """Generate report.""" + self.test.reports_collection.generate_report() diff --git a/src/onaptests/scenario/basic_vm_macro.py b/src/onaptests/scenario/basic_vm_macro.py index 8bbf0b7..b849831 100644 --- a/src/onaptests/scenario/basic_vm_macro.py +++ b/src/onaptests/scenario/basic_vm_macro.py @@ -1,7 +1,7 @@ """Instantiate basic vm using SO macro flow.""" import logging import time -from yaml import load +from yaml import load, SafeLoader from onapsdk.configuration import settings from onapsdk.exceptions import SDKException @@ -20,7 +20,7 @@ class BasicVmMacroStep(YamlTemplateBaseStep): Substeps: - CbaPublishStep - - YamlTemplateServiceAlaCarteInstantiateStep. + - YamlTemplateServiceMacroInstantiateStep. """ super().__init__(cleanup=cleanup) self._yaml_template: dict = None @@ -68,7 +68,7 @@ class BasicVmMacroStep(YamlTemplateBaseStep): """ if not self._yaml_template: with open(settings.SERVICE_YAML_TEMPLATE, "r") as yaml_template: - self._yaml_template: dict = load(yaml_template) + self._yaml_template: dict = load(yaml_template, SafeLoader) return self._yaml_template @property diff --git a/src/onaptests/scenario/multi_vnf_macro.py b/src/onaptests/scenario/multi_vnf_macro.py index 404c785..41833e6 100644 --- a/src/onaptests/scenario/multi_vnf_macro.py +++ b/src/onaptests/scenario/multi_vnf_macro.py @@ -2,7 +2,7 @@ import logging import time -from yaml import load +from yaml import load, SafeLoader from onapsdk.configuration import settings from onapsdk.exceptions import SDKException @@ -70,7 +70,7 @@ class MultiVnfUbuntuMacroStep(YamlTemplateBaseStep): """ if not self._yaml_template: with open(settings.SERVICE_YAML_TEMPLATE, "r") as yaml_template: - self._yaml_template: dict = load(yaml_template) + self._yaml_template: dict = load(yaml_template, SafeLoader) return self._yaml_template @property diff --git a/src/onaptests/scenario/pnf_macro.py b/src/onaptests/scenario/pnf_macro.py index 7b7c219..931a332 100644 --- a/src/onaptests/scenario/pnf_macro.py +++ b/src/onaptests/scenario/pnf_macro.py @@ -1,7 +1,7 @@ """Instantiate service with PNF using SO macro flow.""" import logging import time -from yaml import load +from yaml import load, SafeLoader from xtesting.core import testcase from onapsdk.configuration import settings @@ -72,7 +72,7 @@ class PnfMacroScenarioStep(YamlTemplateBaseStep): """ if not self._yaml_template: with open(settings.SERVICE_YAML_TEMPLATE, "r") as yaml_template: - self._yaml_template: dict = load(yaml_template) + self._yaml_template: dict = load(yaml_template, SafeLoader) return self._yaml_template @property -- cgit 1.2.3-korg