aboutsummaryrefslogtreecommitdiffstats
path: root/src/onaptests/scenario/cds_resource_resolution.py
blob: cff04d8b5932b6730efd25f05896b5dcb5a3940f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/env python
"""CDS resource resolution test scenario."""

import logging
import time

from onapsdk.configuration import settings
from onapsdk.exceptions import SDKException
from xtesting.core import testcase

from onaptests.steps.base import BaseStep
from onaptests.steps.onboard.cds import CbaProcessStep
from onaptests.steps.simulator.cds_mockserver import CdsMockserverCnfConfigureStep
from onaptests.utils.exceptions import OnapTestException


class CDSResourceResolutionStep(BaseStep):
    """Step created to run scenario and generate report."""

    def __init__(self, cleanup=False):
        """Initialize step.

        Substeps:
            - CdsMockserverCnfConfigureStep,
            - CbaProcessStep.
        """
        super().__init__(cleanup=cleanup)
        self.add_step(CdsMockserverCnfConfigureStep(
            cleanup=cleanup
        ))
        self.add_step(CbaProcessStep(
            cleanup=cleanup
        ))

    @property
    def description(self) -> str:
        """Step description.

        Used for reports

        Returns:
            str: Step description

        """
        return "CDS resource-resoulution base step"

    @property
    def component(self) -> str:
        """Component name.

       Name of the component this step relates to.
            Usually the name of ONAP component.

        Returns:
            str: Component name

        """
        return "PythonSDK-tests"


class CDSResourceResolution(testcase.TestCase):
    """Enrich simple blueprint using CDS blueprintprocessor."""

    __logger = logging.getLogger(__name__)

    def __init__(self, **kwargs):
        """Init CDS resource resolution use case."""
        if "case_name" not in kwargs:
            kwargs["case_name"] = 'basic_cds'
        super().__init__(**kwargs)
        self.__logger.debug("CDS resource resolution initialization")
        self.test = CDSResourceResolutionStep(
                cleanup=settings.CLEANUP_FLAG)
        self.start_time = None
        self.stop_time = None
        self.result = 0

    def run(self):
        self.__logger.debug("CDS resource resolution run")
        self.start_time = time.time()
        try:
            for test_phase in (self.test.execute, self.test.cleanup):
                try:
                    test_phase()
                    self.result += 50
                except OnapTestException as exc:
                    self.__logger.exception(exc.error_message)
                except SDKException:
                    self.__logger.exception("SDK Exception")
        finally:
            self.stop_time = time.time()

    def clean(self):
        """Clean Additional resources if needed."""
        self.__logger.info("Generate Test report")
        self.test.reports_collection.generate_report()