1 """Instantiate service with PNF using SO macro flow."""
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(
29 cleanup=settings.CLEANUP_FLAG
31 self.add_step(CbaEnrichStep(
32 cleanup=settings.CLEANUP_FLAG
34 self.add_step(YamlTemplateServiceMacroInstantiateStep(
35 cleanup=settings.CLEANUP_FLAG
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)
76 return self._yaml_template
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 PnfMacro(testcase.TestCase):
102 """Run PNF simulator and onboard then instantiate a service with PNF."""
104 __logger = logging.getLogger(__name__)
106 def __init__(self, **kwargs):
107 """Init Basic Network use case."""
108 if "case_name" not in kwargs:
109 kwargs["case_name"] = 'pnf_macro'
110 super().__init__(**kwargs)
111 self.__logger.debug("PnfMacro init started")
112 self.test = PnfMacroScenarioStep(cleanup=settings.CLEANUP_FLAG)
115 """Run PNF macro test."""
116 self.start_time = time.time()
121 except (OnapTestException, SDKException) as exc:
123 self.__logger.error(exc.error_message)
125 self.stop_time = time.time()
128 """Generate report."""
129 self.test.reports_collection.generate_report()