675b135d626ad36631eba7a5ad6874b761f437f0
[testsuite/pythonsdk-tests.git] / src / onaptests / scenario / cds_resource_resolution.py
1 #!/usr/bin/env python
2 """CDS resource resolution test scenario."""
3
4 import logging
5 import time
6
7 from onapsdk.configuration import settings
8 from onapsdk.exceptions import SDKException
9 from onaptests.scenario.scenario_base import ScenarioBase
10 from onaptests.steps.base import BaseStep
11 from onaptests.steps.onboard.cds import CbaProcessStep
12 from onaptests.steps.simulator.cds_mockserver import \
13     CdsMockserverCnfConfigureStep
14 from onaptests.utils.exceptions import OnapTestException
15
16
17
18 class CDSResourceResolutionStep(BaseStep):
19     """Step created to run scenario and generate report."""
20
21     def __init__(self, cleanup=False):
22         """Initialize step.
23
24         Substeps:
25             - CdsMockserverCnfConfigureStep,
26             - CbaProcessStep.
27         """
28         super().__init__(cleanup=cleanup)
29         self.add_step(CdsMockserverCnfConfigureStep(
30             cleanup=cleanup
31         ))
32         self.add_step(CbaProcessStep(
33             cleanup=cleanup
34         ))
35
36     @property
37     def description(self) -> str:
38         """Step description.
39
40         Used for reports
41
42         Returns:
43             str: Step description
44
45         """
46         return "CDS resource-resoulution base step"
47
48     @property
49     def component(self) -> str:
50         """Component name.
51
52        Name of the component this step relates to.
53             Usually the name of ONAP component.
54
55         Returns:
56             str: Component name
57
58         """
59         return "PythonSDK-tests"
60
61
62 class CDSResourceResolution(ScenarioBase):
63     """Enrich simple blueprint using CDS blueprintprocessor."""
64
65     __logger = logging.getLogger(__name__)
66
67     def __init__(self, **kwargs):
68         """Init CDS resource resolution use case."""
69         super().__init__('basic_cds', **kwargs)
70         self.test = CDSResourceResolutionStep(
71             cleanup=settings.CLEANUP_FLAG)
72         self.start_time = None
73         self.stop_time = None
74         self.result = 0
75
76     def run(self):
77         self.__logger.debug("CDS resource resolution run")
78         self.start_time = time.time()
79         try:
80             for test_phase in (self.test.execute, self.test.cleanup):
81                 try:
82                     test_phase()
83                     self.result += 50
84                 except OnapTestException as exc:
85                     self.__logger.exception(exc.error_message)
86                 except SDKException:
87                     self.__logger.exception("SDK Exception")
88         finally:
89             self.stop_time = time.time()
90
91     def clean(self):
92         """Clean Additional resources if needed."""
93         self.__logger.info("Generate Test report")
94         self.test.reports_collection.generate_report()