diff options
author | 2024-01-28 19:45:44 +0100 | |
---|---|---|
committer | 2024-01-29 22:24:42 +0100 | |
commit | a7edeebc90bdd335361a7b36f5f5d12a14375554 (patch) | |
tree | 0e48ee456ef26471271c5412f3205aafcda41857 /src/onaptests/scenario | |
parent | 2479155376b6142e97163a7903632015fed50815 (diff) |
Enhanced validation of configuration of all tests
Issue-ID: TEST-402
Signed-off-by: Lukasz Rajewski <lukasz.rajewski@t-mobile.pl>
Change-Id: I2e4ef6365b44c33f4c0b3e72886a83f92c63e2f3
Diffstat (limited to 'src/onaptests/scenario')
-rw-r--r-- | src/onaptests/scenario/basic_cnf_macro.py | 9 | ||||
-rw-r--r-- | src/onaptests/scenario/basic_cps.py | 6 | ||||
-rw-r--r-- | src/onaptests/scenario/basic_vm_macro.py | 9 | ||||
-rw-r--r-- | src/onaptests/scenario/multi_vnf_macro.py | 13 | ||||
-rw-r--r-- | src/onaptests/scenario/pnf_macro.py | 7 | ||||
-rw-r--r-- | src/onaptests/scenario/scenario_base.py | 39 |
6 files changed, 59 insertions, 24 deletions
diff --git a/src/onaptests/scenario/basic_cnf_macro.py b/src/onaptests/scenario/basic_cnf_macro.py index 1fecd95..71b6863 100644 --- a/src/onaptests/scenario/basic_cnf_macro.py +++ b/src/onaptests/scenario/basic_cnf_macro.py @@ -1,13 +1,16 @@ """Instantiate basic cnf using SO macro flow.""" +from yaml import SafeLoader, load + from onapsdk.configuration import settings -from onaptests.scenario.scenario_base import BaseStep, ScenarioBase, YamlTemplateBaseScenarioStep +from onaptests.scenario.scenario_base import (BaseStep, ScenarioBase, + YamlTemplateBaseScenarioStep) from onaptests.steps.instantiate.service_macro import \ YamlTemplateServiceMacroInstantiateStep from onaptests.steps.onboard.cds import CbaPublishStep -from yaml import SafeLoader, load class BasicCnfMacroStep(YamlTemplateBaseScenarioStep): + """Main basic cnf macro scenario step.""" def __init__(self): """Initialize step. @@ -57,7 +60,7 @@ class BasicCnfMacroStep(YamlTemplateBaseScenarioStep): """ if not self._yaml_template: - with open(settings.SERVICE_YAML_TEMPLATE, "r") as yaml_template: + with open(settings.SERVICE_YAML_TEMPLATE, "r", encoding="utf-8") as yaml_template: self._yaml_template: dict = load(yaml_template, SafeLoader) return self._yaml_template diff --git a/src/onaptests/scenario/basic_cps.py b/src/onaptests/scenario/basic_cps.py index adfefb5..f6189da 100644 --- a/src/onaptests/scenario/basic_cps.py +++ b/src/onaptests/scenario/basic_cps.py @@ -1,12 +1,14 @@ #!/usr/bin/env python """Basic CPS test case.""" from onapsdk.configuration import settings -from onaptests.scenario.scenario_base import BaseStep, ScenarioBase +from onaptests.scenario.scenario_base import BaseStep, ScenarioBase, BaseScenarioStep from onaptests.steps.onboard.cps import (CheckPostgressDataBaseConnectionStep, QueryCpsAnchorNodeStep) -class BasicCpsStep(BaseStep): +class BasicCpsStep(BaseScenarioStep): + """Main basic cps scenario step.""" + def __init__(self): """Initialize step. diff --git a/src/onaptests/scenario/basic_vm_macro.py b/src/onaptests/scenario/basic_vm_macro.py index ec60e78..0045761 100644 --- a/src/onaptests/scenario/basic_vm_macro.py +++ b/src/onaptests/scenario/basic_vm_macro.py @@ -1,13 +1,16 @@ """Instantiate basic vm using SO macro flow.""" +from yaml import SafeLoader, load + from onapsdk.configuration import settings -from onaptests.scenario.scenario_base import BaseStep, ScenarioBase, YamlTemplateBaseScenarioStep +from onaptests.scenario.scenario_base import (BaseStep, ScenarioBase, + YamlTemplateBaseScenarioStep) from onaptests.steps.instantiate.service_macro import \ YamlTemplateServiceMacroInstantiateStep from onaptests.steps.onboard.cds import CbaPublishStep -from yaml import SafeLoader, load class BasicVmMacroStep(YamlTemplateBaseScenarioStep): + """Main basic vm macro scenario step.""" def __init__(self): """Initialize step. @@ -57,7 +60,7 @@ class BasicVmMacroStep(YamlTemplateBaseScenarioStep): """ if not self._yaml_template: - with open(settings.SERVICE_YAML_TEMPLATE, "r") as yaml_template: + with open(settings.SERVICE_YAML_TEMPLATE, "r", encoding="utf-8") as yaml_template: self._yaml_template: dict = load(yaml_template, SafeLoader) return self._yaml_template diff --git a/src/onaptests/scenario/multi_vnf_macro.py b/src/onaptests/scenario/multi_vnf_macro.py index fc00cec..47b1830 100644 --- a/src/onaptests/scenario/multi_vnf_macro.py +++ b/src/onaptests/scenario/multi_vnf_macro.py @@ -1,13 +1,16 @@ """Instantiate basic vm using SO macro flow.""" +from yaml import SafeLoader, load + from onapsdk.configuration import settings -from onaptests.scenario.scenario_base import BaseStep, ScenarioBase, YamlTemplateBaseScenarioStep +from onaptests.scenario.scenario_base import (BaseStep, ScenarioBase, + YamlTemplateBaseScenarioStep) from onaptests.steps.instantiate.service_macro import \ YamlTemplateServiceMacroInstantiateStep from onaptests.steps.onboard.cds import CbaPublishStep -from yaml import SafeLoader, load class MultiVnfUbuntuMacroStep(YamlTemplateBaseScenarioStep): + """Main step for multi vnf instantiation with macro method.""" def __init__(self): """Initialize step. @@ -58,15 +61,15 @@ class MultiVnfUbuntuMacroStep(YamlTemplateBaseScenarioStep): """ if not self._yaml_template: - with open(settings.SERVICE_YAML_TEMPLATE, "r") as yaml_template: + with open(settings.SERVICE_YAML_TEMPLATE, "r", encoding="utf-8") as yaml_template: self._yaml_template: dict = load(yaml_template, SafeLoader) return self._yaml_template @property def model_yaml_template(self) -> dict: if not self._model_yaml_template: - with open(settings.MODEL_YAML_TEMPLATE, "r") as model_yaml_template: - self._model_yaml_template: dict = load(model_yaml_template) + with open(settings.MODEL_YAML_TEMPLATE, "r", encoding="utf-8") as model_yaml_template: + self._model_yaml_template: dict = load(model_yaml_template, SafeLoader) return self._model_yaml_template @property diff --git a/src/onaptests/scenario/pnf_macro.py b/src/onaptests/scenario/pnf_macro.py index f8afad5..88d42d1 100644 --- a/src/onaptests/scenario/pnf_macro.py +++ b/src/onaptests/scenario/pnf_macro.py @@ -1,8 +1,9 @@ """Instantiate service with PNF using SO macro flow.""" -from onapsdk.configuration import settings from yaml import SafeLoader, load -from onaptests.scenario.scenario_base import BaseStep, ScenarioBase, YamlTemplateBaseScenarioStep +from onapsdk.configuration import settings +from onaptests.scenario.scenario_base import (BaseStep, ScenarioBase, + YamlTemplateBaseScenarioStep) from onaptests.steps.instantiate.pnf_register_ves import \ SendPnfRegisterVesEvent from onaptests.steps.instantiate.service_macro import \ @@ -66,7 +67,7 @@ class PnfMacroScenarioStep(YamlTemplateBaseScenarioStep): """ if not self._yaml_template: - with open(settings.SERVICE_YAML_TEMPLATE, "r") as yaml_template: + with open(settings.SERVICE_YAML_TEMPLATE, "r", encoding="utf-8") as yaml_template: self._yaml_template: dict = load(yaml_template, SafeLoader) return self._yaml_template diff --git a/src/onaptests/scenario/scenario_base.py b/src/onaptests/scenario/scenario_base.py index 179bea8..7069afb 100644 --- a/src/onaptests/scenario/scenario_base.py +++ b/src/onaptests/scenario/scenario_base.py @@ -1,11 +1,13 @@ import logging import time +from xtesting.core import testcase + from onapsdk.configuration import settings -from onapsdk.exceptions import SDKException +from onapsdk.exceptions import SDKException, SettingsError from onaptests.steps.base import BaseStep, YamlTemplateBaseStep -from onaptests.utils.exceptions import OnapTestException -from xtesting.core import testcase +from onaptests.utils.exceptions import (OnapTestException, + TestConfigurationException) class ScenarioBase(testcase.TestCase): @@ -17,18 +19,20 @@ class ScenarioBase(testcase.TestCase): """Init base scenario.""" if "case_name" not in kwargs: kwargs["case_name"] = case_name_override - self.scenario_name = kwargs["case_name"].replace("_", " ") + self.case_name = kwargs["case_name"] + self.scenario_name = self.case_name.replace("_", " ") self.scenario_name = str.title(self.scenario_name) self.__logger.info("%s Global Configuration:", self.scenario_name) - for val in settings._settings: - self.__logger.info("%s: %s", val, settings._settings[val]) + for val_name, val in settings._settings.items(): + self.__logger.info("%s: %s", val_name, val) self.__logger.debug("%s init started", self.scenario_name) super().__init__(**kwargs) self.general_exception = None + self.test: BaseStep = None - def run(self): + def run(self, **kwargs): """Run scenario and cleanup resources afterwards""" self.start_time = time.time() try: @@ -62,11 +66,29 @@ class ScenarioBase(testcase.TestCase): self.__logger.info("Generate %s Test report", self.scenario_name) self.test.reports_collection.generate_report() - def validate_execution(self): + def validate(self): + """Validate implementation of the scenario.""" + + self._validate_service_details() self.test.validate_execution() + self.test.validate_cleanup() + + def _validate_service_details(self): + self._check_setting("SERVICE_NAME") + self._check_setting("SERVICE_DETAILS") + + def _check_setting(self, name: str): + try: + if getattr(settings, name) == "": + raise TestConfigurationException( + f"[{self.case_name}] {name} setting is not defined") + except (KeyError, AttributeError, SettingsError) as exc: + raise TestConfigurationException( + f"[{self.case_name}] {name} setting is not defined") from exc class BaseScenarioStep(BaseStep): + """Main scenario step that has no own execution method.""" def __init__(self, cleanup=False): """Initialize BaseScenarioStep step.""" @@ -78,6 +100,7 @@ class BaseScenarioStep(BaseStep): class YamlTemplateBaseScenarioStep(YamlTemplateBaseStep, BaseScenarioStep): + """Main scenario yaml template step that has no own execution method.""" def __init__(self, cleanup=False): """Initialize YamlTemplateBaseScenarioStep step.""" |