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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
|
from onapsdk.configuration import settings
from onapsdk.exceptions import APIError
from onapsdk.sdnc import VfModulePreload
from onapsdk.sdnc.preload import PreloadInformation
from onapsdk.sdnc.services import Service
from onaptests.utils.exceptions import OnapTestException
from ..base import BaseStep
class BaseSdncStep(BaseStep):
"""Basic SDNC step."""
def __init__(self, cleanup: bool = False):
"""Initialize step."""
super().__init__(cleanup=cleanup)
@property
def component(self) -> str:
"""Component name.
Name of component which step is related with.
Most is the name of ONAP component.
Returns:
str: Component name
"""
return "SDNC"
class ServiceCreateStep(BaseSdncStep):
"""Service creation step."""
def __init__(self, service: Service = None, cleanup: bool = False):
"""Initialize step."""
super().__init__(cleanup=cleanup)
self.service = service
@property
def description(self) -> str:
"""Step description."""
return "Create SDNC service."
@BaseStep.store_state
def execute(self):
"""Create service at SDNC."""
super().execute()
self._logger.info("Create new service instance in SDNC by GR-API")
try:
self.service = Service(
service_instance_id=settings.SERVICE_ID,
service_status=settings.SERVICE_STATUS,
service_data=settings.SERVICE_DATA
)
self.service.create()
self._logger.info("SDNC service is created.")
except APIError as exc:
if exc.response_status_code == 409:
self._logger.warning("SDNC service already exists.")
else:
raise OnapTestException("SDNC service creation failed.")
@BaseStep.store_state()
def cleanup(self) -> None:
"""Cleanup Service."""
if self.service is not None:
self.service.delete()
self._logger.info("SDNC service is deleted.")
super().cleanup()
class UpdateSdncService(BaseSdncStep):
"""Service update step.
The step needs in an existing SDNC service as a prerequisite.
"""
def __init__(self, cleanup=False):
"""Initialize step.
Sub steps:
- ServiceCreateStep.
"""
super().__init__(cleanup=cleanup)
self.add_step(ServiceCreateStep(cleanup=cleanup))
@property
def description(self) -> str:
"""Step description.
Used for reports
Returns:
str: Step description
"""
return "Update SDNC service"
@BaseStep.store_state
def execute(self):
super().execute()
self._logger.info("Get existing SDNC service instance and update it over GR-API")
try:
service = Service.get(settings.SERVICE_ID)
service.service_status = settings.SERVICE_CHANGED_STATUS
service.service_data = settings.SERVICE_CHANGED_DATA
service.update()
self._logger.info("SDNC service update is completed.")
except APIError:
raise OnapTestException("SDNC service update is failed.")
class UploadVfModulePreloadStep(BaseSdncStep):
"""Upload preload information for VfModule.
Upload preload information for VfModule over GR-API.
"""
def __init__(self, cleanup=False):
"""Initialize step."""
super().__init__(cleanup=cleanup)
@property
def description(self) -> str:
"""Step description.
Used for reports
Returns:
str: Step description
"""
return "Upload Preload information for VfModule"
@BaseStep.store_state
def execute(self):
super().execute()
self._logger.info("Upload VfModule preload information over GR-API")
VfModulePreload.upload_vf_module_preload(
{
"vnf_name": settings.VNF_NAME,
"vnf_type": settings.VNF_TYPE
},
settings.VF_MODULE_NAME,
None
)
class GetSdncPreloadStep(BaseSdncStep):
"""Get preload information from SDNC.
Get preload information from SDNC over GR-API.
"""
def __init__(self, cleanup=False):
"""Initialize step.
Sub steps:
- UploadVfModulePreloadStep.
"""
super().__init__(cleanup=cleanup)
self.add_step(UploadVfModulePreloadStep(cleanup=cleanup))
@property
def description(self) -> str:
"""Step description.
Used for reports
Returns:
str: Step description
"""
return "Get Preload information"
@BaseStep.store_state
def execute(self):
super().execute()
self._logger.info("Get existing SDNC service instance and update it over GR-API")
preloads = PreloadInformation.get_all()
for preload_information in preloads:
print(preload_information)
class TestSdncStep(BaseStep):
"""Top level step for SDNC tests."""
def __init__(self, cleanup=False):
"""Initialize step.
Sub steps:
- UpdateSdncService.
"""
super().__init__(cleanup=cleanup)
self.add_step(
UpdateSdncService(cleanup=cleanup)
)
self.add_step(
GetSdncPreloadStep(cleanup=cleanup)
)
@property
def description(self) -> str:
"""Step description.
Used for reports
Returns:
str: Step description
"""
return "Test SDNC functionality scenario step"
@property
def component(self) -> str:
"""Component name.
Name of component which step is related with.
Most is the name of ONAP component.
Returns:
str: Component name
"""
return "PythonSDK-tests"
|