aboutsummaryrefslogtreecommitdiffstats
path: root/src/onaptests/steps/onboard/pnf.py
blob: 6250d7e6244737d7670b5c2a598c3a06485774ee (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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
"""PNF onboarding step module."""

from onapsdk.configuration import settings
from onapsdk.sdc.pnf import Pnf
from onapsdk.sdc.vendor import Vendor
from onapsdk.sdc.vsp import Vsp
from ..base import BaseStep, YamlTemplateBaseStep
from .vsp import VspOnboardStep, YamlTemplateVspOnboardStep


class PnfOnboardStep(BaseStep):
    """PNF onboard step."""

    def __init__(self, cleanup: bool = False) -> None:
        """Step initialization.

        Substeps:
            - VendorOnboardStep.

        Args:
            cleanup(bool, optional): Determines if cleanup action should be called.

        """
        super().__init__(cleanup=cleanup)
        self.add_step(VspOnboardStep(cleanup=cleanup))

    @property
    def description(self) -> str:
        """Step description."""
        return "Onboard pnf in SDC."

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

    @BaseStep.store_state
    def execute(self) -> None:
        """Onboard PNF in SDC.

        Use settings values:
         - VENDOR_NAME,
         - PNF_NAME,
         - PNF_ARTIFACT_TYPE,
         - PNF_ARTIFACT_NAME,
         - PNF_ARTIFACT_LABEL,
         - PNF_ARTIFACT_FILE_PATH

        """
        super().execute()
        vendor: Vendor = Vendor(name=settings.VENDOR_NAME)
        pnf: Pnf = Pnf(name=settings.PNF_NAME, vendor=vendor)
        pnf.create()
        pnf.add_deployment_artifact(
            artifact_type=settings.PNF_ARTIFACT_TYPE,
            artifact_name=settings.PNF_ARTIFACT_NAME,
            artifact_label=settings.PNF_ARTIFACT_LABEL,
            artifact=settings.PNF_ARTIFACT_FILE_PATH
        )
        pnf.onboard()


class YamlTemplatePnfOnboardStep(YamlTemplateBaseStep):
    """PNF onboard using YAML template step."""

    def __init__(self, cleanup: bool = False) -> None:
        """Step initialization.

        Substeps:
            - VendorOnboardStep.

        Args:
            cleanup(bool, optional): Determines if cleanup action should be called.

        """
        super().__init__(cleanup=cleanup)
        self.add_step(YamlTemplateVspOnboardStep(cleanup=cleanup))

    @property
    def description(self) -> str:
        """Step description."""
        return "Onboard pnf using YAML template in SDC."

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

    @property
    def yaml_template(self) -> dict:
        """YAML template.

        Get YAML template from parent using it's name.

        Returns:
            dict: YAML template

        """
        return self.parent.yaml_template[self.parent.service_name]

    @YamlTemplateBaseStep.store_state
    def execute(self):
        """Onboard PNFs from YAML template."""
        super().execute()
        if "pnfs" in self.yaml_template:
            vendor: Vendor = Vendor(name=settings.VENDOR_NAME)
            for pnf in self.yaml_template["pnfs"]:
                if "heat_files_to_upload" in pnf:
                    vsp: Vsp = Vsp(name=f"{pnf['pnf_name']}_VSP")
                else:
                    vsp = None
                pnf_obj: Pnf = Pnf(name=pnf["pnf_name"], vendor=vendor, vsp=vsp)
                pnf_obj.create()
                pnf_obj.add_deployment_artifact(
                    artifact_type=pnf["pnf_artifact_type"],
                    artifact_name=pnf["pnf_artifact_name"],
                    artifact_label=pnf["pnf_artifact_label"],
                    artifact=pnf["pnf_artifact_file_path"]
                )
                pnf_obj.onboard()