1 from onapsdk.configuration import settings
2 from onapsdk.exceptions import APIError
3 from onapsdk.sdnc import VfModulePreload
4 from onapsdk.sdnc.preload import PreloadInformation
5 from onapsdk.sdnc.services import Service
6 from onaptests.utils.exceptions import OnapTestException
8 from ..base import BaseStep
11 class BaseSdncStep(BaseStep):
12 """Basic SDNC step."""
14 def __init__(self, cleanup: bool = False):
15 """Initialize step."""
16 super().__init__(cleanup=cleanup)
19 def component(self) -> str:
22 Name of component which step is related with.
23 Most is the name of ONAP component.
32 class ServiceCreateStep(BaseSdncStep):
33 """Service creation step."""
35 def __init__(self, service: Service = None, cleanup: bool = False):
36 """Initialize step."""
37 super().__init__(cleanup=cleanup)
38 self.service = service
41 def description(self) -> str:
42 """Step description."""
43 return "Create SDNC service."
47 """Create service at SDNC."""
49 self._logger.info("Create new service instance in SDNC by GR-API")
51 self.service = Service(
52 service_instance_id=settings.SERVICE_ID,
53 service_status=settings.SERVICE_STATUS,
54 service_data=settings.SERVICE_DATA
57 self._logger.info("SDNC service is created.")
58 except APIError as exc:
59 if exc.response_status_code == 409:
60 self._logger.warning("SDNC service already exists.")
62 raise OnapTestException("SDNC service creation failed.")
64 @BaseStep.store_state()
65 def cleanup(self) -> None:
66 """Cleanup Service."""
67 if self.service is not None:
69 self._logger.info("SDNC service is deleted.")
73 class UpdateSdncService(BaseSdncStep):
74 """Service update step.
76 The step needs in an existing SDNC service as a prerequisite.
79 def __init__(self, cleanup=False):
85 super().__init__(cleanup=cleanup)
86 self.add_step(ServiceCreateStep(cleanup=cleanup))
89 def description(self) -> str:
98 return "Update SDNC service"
100 @BaseStep.store_state
103 self._logger.info("Get existing SDNC service instance and update it over GR-API")
105 service = Service.get(settings.SERVICE_ID)
106 service.service_status = settings.SERVICE_CHANGED_STATUS
107 service.service_data = settings.SERVICE_CHANGED_DATA
109 self._logger.info("SDNC service update is completed.")
111 raise OnapTestException("SDNC service update is failed.")
114 class UploadVfModulePreloadStep(BaseSdncStep):
115 """Upload preload information for VfModule.
117 Upload preload information for VfModule over GR-API.
120 def __init__(self, cleanup=False):
121 """Initialize step."""
122 super().__init__(cleanup=cleanup)
125 def description(self) -> str:
131 str: Step description
134 return "Upload Preload information for VfModule"
136 @BaseStep.store_state
139 self._logger.info("Upload VfModule preload information over GR-API")
140 VfModulePreload.upload_vf_module_preload(
142 "vnf_name": settings.VNF_NAME,
143 "vnf_type": settings.VNF_TYPE
145 settings.VF_MODULE_NAME,
150 class GetSdncPreloadStep(BaseSdncStep):
151 """Get preload information from SDNC.
153 Get preload information from SDNC over GR-API.
156 def __init__(self, cleanup=False):
160 - UploadVfModulePreloadStep.
162 super().__init__(cleanup=cleanup)
163 self.add_step(UploadVfModulePreloadStep(cleanup=cleanup))
166 def description(self) -> str:
172 str: Step description
175 return "Get Preload information"
177 @BaseStep.store_state
180 self._logger.info("Get existing SDNC service instance and update it over GR-API")
181 preloads = PreloadInformation.get_all()
182 for preload_information in preloads:
183 print(preload_information)
186 class TestSdncStep(BaseStep):
187 """Top level step for SDNC tests."""
189 def __init__(self, cleanup=False):
195 super().__init__(cleanup=cleanup)
197 UpdateSdncService(cleanup=cleanup)
200 GetSdncPreloadStep(cleanup=cleanup)
204 def description(self) -> str:
210 str: Step description
213 return "Test SDNC functionality scenario step"
216 def component(self) -> str:
219 Name of component which step is related with.
220 Most is the name of ONAP component.
226 return "PythonSDK-tests"