1 from onapsdk.sdnc.services import Service
2 from onapsdk.configuration import settings
3 from onapsdk.exceptions import APIError
5 from ..base import BaseStep
7 from onaptests.utils.exceptions import OnapTestException
10 class ServiceCreateStep(BaseStep):
11 """Service creation step."""
13 def __init__(self, service: Service = None, cleanup: bool = False):
14 """Initialize step."""
15 super().__init__(cleanup=cleanup)
16 self.service = service
19 def description(self) -> str:
20 """Step description."""
21 return "Create SDNC service."
24 def component(self) -> str:
30 """Create service at SDNC."""
31 self._logger.info("Create new service instance in SDNC by GR-API")
34 self.service = Service(
35 service_instance_id=settings.SERVICE_ID,
36 service_status=settings.SERVICE_STATUS,
37 service_data=settings.SERVICE_DATA
40 self._logger.info("SDNC service is created.")
42 raise OnapTestException("SDNC service creation failed.")
44 @BaseStep.store_state()
45 def cleanup(self) -> None:
46 """Cleanup Service."""
47 if self.service is not None:
49 self._logger.info("SDNC service is deleted.")
53 class UpdateSdncService(BaseStep):
54 """Service update step.
56 The step needs in an existing SDNC service as a prerequisite.
59 def __init__(self, cleanup=False):
65 super().__init__(cleanup=cleanup)
66 self.add_step(ServiceCreateStep(cleanup=cleanup))
69 def description(self) -> str:
78 return "Update SDNC service"
81 def component(self) -> str:
84 Name of component which step is related with.
85 Most is the name of ONAP component.
95 self._logger.info("Get existing SDNC service instance and update it over GR-API")
98 service = Service.get(settings.SERVICE_ID)
99 service.service_status = settings.SERVICE_CHANGED_STATUS
100 service.service_data = settings.SERVICE_CHANGED_DATA
102 self._logger.info("SDNC service update is checked.")
104 raise OnapTestException("SDNC service update is failed.")