1 """Instantiate service with PNF using SO macro flow."""
4 from yaml import load, SafeLoader
6 from xtesting.core import testcase
7 from onapsdk.configuration import settings
8 from onapsdk.exceptions import SDKException
10 from onaptests.steps.base import YamlTemplateBaseStep
11 from onaptests.steps.onboard.cds import CbaEnrichStep
12 from onaptests.steps.simulator.pnf_simulator_cnf.pnf_register import PnfSimulatorCnfRegisterStep
13 from onaptests.steps.instantiate.service_macro import YamlTemplateServiceMacroInstantiateStep
14 from onaptests.utils.exceptions import OnapTestException
17 class PnfMacroScenarioStep(YamlTemplateBaseStep):
18 """Step created to run scenarion and generate report."""
20 def __init__(self, cleanup=False):
24 - YamlTemplateServiceAlaCarteInstantiateStep.
26 super().__init__(cleanup=cleanup)
27 self._yaml_template: dict = None
28 self.add_step(PnfSimulatorCnfRegisterStep(
31 self.add_step(CbaEnrichStep(
34 self.add_step(YamlTemplateServiceMacroInstantiateStep(
39 def description(self) -> str:
48 return "PNF macro scenario step"
51 def component(self) -> str:
54 Name of component which step is related with.
55 Most is the name of ONAP component.
61 return "PythonSDK-tests"
64 def yaml_template(self) -> dict:
65 """YAML template abstract property.
67 Every YAML template step need to implement that property.
73 if not self._yaml_template:
74 with open(settings.SERVICE_YAML_TEMPLATE, "r") as yaml_template:
75 self._yaml_template: dict = load(yaml_template, SafeLoader)
76 return self._yaml_template
79 def model_yaml_template(self) -> dict:
83 def service_name(self) -> dict:
86 Get from YAML template.
92 return next(iter(self.yaml_template.keys()))
95 def service_instance_name(self) -> str:
96 """Service instance name.
99 str: Service instance name
102 return settings.SERVICE_INSTANCE_NAME
105 class PnfMacro(testcase.TestCase):
106 """Run PNF simulator and onboard then instantiate a service with PNF."""
108 __logger = logging.getLogger(__name__)
110 def __init__(self, **kwargs):
111 """Init Basic Network use case."""
112 if "case_name" not in kwargs:
113 kwargs["case_name"] = 'pnf_macro'
114 super().__init__(**kwargs)
115 self.__logger.debug("PnfMacro init started")
116 self.test = PnfMacroScenarioStep(cleanup=settings.CLEANUP_FLAG)
119 """Run PNF macro test."""
120 self.start_time = time.time()
122 for test_phase in (self.test.execute, self.test.cleanup):
126 except OnapTestException as exc:
127 self.__logger.exception(exc.error_message)
129 self.__logger.exception("SDK Exception")
131 self.stop_time = time.time()
134 """Generate report."""
135 self.test.reports_collection.generate_report()