diff options
author | Michal Jagiello <michal.jagiello@t-mobile.pl> | 2021-03-23 18:23:48 +0000 |
---|---|---|
committer | morganrol <morgan.richomme@orange.com> | 2021-04-02 08:48:50 +0200 |
commit | 0a315a1b542a96d62fea12f49b353bca54464ee7 (patch) | |
tree | 9ec0f7d973c87e2aa79ec8db339b5fec07f76ddf /src/onaptests/scenario | |
parent | 612848c7353ced7aa0f16ff90ad3afffa65e8aed (diff) |
Basic VM macro
Issue-ID: INT-1894
Signed-off-by: Michal Jagiello <michal.jagiello@t-mobile.pl>
Change-Id: Idd977cf3082587746fe27718a284197fda4afe5c
Diffstat (limited to 'src/onaptests/scenario')
-rw-r--r-- | src/onaptests/scenario/basic_vm_macro.py | 125 |
1 files changed, 125 insertions, 0 deletions
diff --git a/src/onaptests/scenario/basic_vm_macro.py b/src/onaptests/scenario/basic_vm_macro.py new file mode 100644 index 0000000..c90d48b --- /dev/null +++ b/src/onaptests/scenario/basic_vm_macro.py @@ -0,0 +1,125 @@ +"""Instantiate basic vm using SO macro flow.""" +import logging +import time +from yaml import load + +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 BasicVmMacroStep(YamlTemplateBaseStep): + + def __init__(self, cleanup=False): + """Initialize step. + + Substeps: + - CbaPublishStep + - YamlTemplateServiceAlaCarteInstantiateStep. + """ + super().__init__(cleanup=cleanup) + self._yaml_template: dict = None + self.add_step(CbaPublishStep( + cleanup=settings.CLEANUP_FLAG + )) + self.add_step(YamlTemplateServiceMacroInstantiateStep( + cleanup=settings.CLEANUP_FLAG + )) + + @property + def description(self) -> str: + """Step description. + + Used for reports + + Returns: + str: Step description + + """ + return "Basic VM 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) + return self._yaml_template + + @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 BasicVmMacro(testcase.TestCase): + """Instantiate a basic vm macro.""" + + __logger = logging.getLogger(__name__) + + def __init__(self, **kwargs): + """Init Basic Macro use case.""" + if "case_name" not in kwargs: + kwargs["case_name"] = 'basic_vm_macro' + super().__init__(**kwargs) + self.__logger.debug("Basic VM macro init started") + self.test = BasicVmMacroStep(cleanup=settings.CLEANUP_FLAG) + + def run(self): + """Run basic vm macro test.""" + self.start_time = time.time() + try: + self.test.execute() + self.test.cleanup() + self.result = 100 + except (OnapTestException, SDKException) as exc: + self.result = 0 + self.__logger.error(exc.error_message) + finally: + self.stop_time = time.time() + + def clean(self): + """Generate report.""" + self.test.reports_collection.generate_report() |