1 """Instantiate basic cnf using SO macro flow."""
4 from yaml import load, SafeLoader
6 from onapsdk.configuration import settings
7 from onapsdk.exceptions import SDKException
8 from xtesting.core import testcase
10 from onaptests.steps.base import YamlTemplateBaseStep
11 from onaptests.steps.onboard.cds import CbaPublishStep
12 from onaptests.utils.exceptions import OnapTestException
13 from onaptests.steps.instantiate.service_macro import YamlTemplateServiceMacroInstantiateStep
16 class BasicCnfMacroStep(YamlTemplateBaseStep):
18 def __init__(self, cleanup=False):
23 - YamlTemplateServiceMacroInstantiateStep.
25 super().__init__(cleanup=cleanup)
26 self._yaml_template: dict = None
27 self.add_step(CbaPublishStep(
30 self.add_step(YamlTemplateServiceMacroInstantiateStep(
35 def description(self) -> str:
44 return "Basic CNF macro scenario step"
47 def component(self) -> str:
50 Name of component which step is related with.
51 Most is the name of ONAP component.
57 return "PythonSDK-tests"
60 def yaml_template(self) -> dict:
61 """YAML template abstract property.
63 Every YAML template step need to implement that property.
69 if not self._yaml_template:
70 with open(settings.SERVICE_YAML_TEMPLATE, "r") as yaml_template:
71 self._yaml_template: dict = load(yaml_template, SafeLoader)
72 return self._yaml_template
75 def model_yaml_template(self) -> dict:
79 def service_name(self) -> dict:
82 Get from YAML template.
88 return next(iter(self.yaml_template.keys()))
91 def service_instance_name(self) -> str:
92 """Service instance name.
95 str: Service instance name
98 return settings.SERVICE_INSTANCE_NAME
101 class BasicCnfMacro(testcase.TestCase):
102 """Instantiate a basic cnf macro."""
104 __logger = logging.getLogger()
106 def __init__(self, **kwargs):
107 """Init Basic Cnf Macro use case."""
108 if "case_name" not in kwargs:
109 kwargs["case_name"] = 'basic_cnf_macro'
110 super().__init__(**kwargs)
111 self.__logger.debug("Basic Cnf macro init started")
112 self.test = BasicCnfMacroStep(cleanup=settings.CLEANUP_FLAG)
115 """Run basic cnf macro test."""
116 self.start_time = time.time()
121 except OnapTestException as exc:
123 self.__logger.exception(exc.error_message)
126 self.__logger.exception("SDK Exception")
128 self.stop_time = time.time()
131 """Generate report."""
132 self.test.reports_collection.generate_report()