Merge "Refactor code a bit to make status test able running on multiple namespaces"
[testsuite/pythonsdk-tests.git] / src / onaptests / scenario / basic_vm_macro.py
1 """Instantiate basic vm using SO macro flow."""
2 from onapsdk.configuration import settings
3 from yaml import SafeLoader, load
4
5 from onaptests.scenario.scenario_base import (BaseStep, ScenarioBase,
6                                               YamlTemplateBaseScenarioStep)
7 from onaptests.steps.instantiate.service_macro import \
8     YamlTemplateServiceMacroInstantiateStep
9 from onaptests.steps.onboard.cds import CbaPublishStep
10
11
12 class BasicVmMacroStep(YamlTemplateBaseScenarioStep):
13     """Main basic vm macro scenario step."""
14
15     def __init__(self):
16         """Initialize step.
17
18         Substeps:
19             - CbaPublishStep
20             - YamlTemplateServiceMacroInstantiateStep.
21         """
22         super().__init__(cleanup=BaseStep.HAS_NO_CLEANUP)
23         self._yaml_template: dict = None
24         self.add_step(CbaPublishStep())
25         self.add_step(YamlTemplateServiceMacroInstantiateStep())
26
27     @property
28     def description(self) -> str:
29         """Step description.
30
31         Used for reports
32
33         Returns:
34             str: Step description
35
36         """
37         return "Basic VM macro scenario step"
38
39     @property
40     def component(self) -> str:
41         """Component name.
42
43         Name of component which step is related with.
44             Most is the name of ONAP component.
45
46         Returns:
47             str: Component name
48
49         """
50         return "PythonSDK-tests"
51
52     @property
53     def yaml_template(self) -> dict:
54         """YAML template abstract property.
55
56         Every YAML template step need to implement that property.
57
58         Returns:
59             dict: YAML template
60
61         """
62         if not self._yaml_template:
63             with open(settings.SERVICE_YAML_TEMPLATE, "r", encoding="utf-8") as yaml_template:
64                 self._yaml_template: dict = load(yaml_template, SafeLoader)
65         return self._yaml_template
66
67     @property
68     def model_yaml_template(self) -> dict:
69         return {}
70
71     @property
72     def service_instance_name(self) -> str:
73         """Service instance name.
74
75         Returns:
76             str: Service instance name
77
78         """
79         return settings.SERVICE_INSTANCE_NAME
80
81
82 class BasicVmMacro(ScenarioBase):
83     """Instantiate a basic vm macro."""
84
85     def __init__(self, **kwargs):
86         """Init Basic Macro use case."""
87         super().__init__('basic_vm_macro', **kwargs)
88         self.test = BasicVmMacroStep()