+"""SDNC service instantiation and health check steps."""
+
import base64
import logging
from typing import Dict
from onaptests.scenario.scenario_base import BaseScenarioStep
from onaptests.steps.base import BaseStep
-from onaptests.utils.exceptions import (EnvironmentPreparationException,
- OnapTestException)
+from onaptests.utils.exceptions import (
+ EnvironmentPreparationException,
+ OnapTestException,
+)
class BaseSdncStep(BaseStep):
def get_database_credentials(self):
"""Resolve SDNC datbase credentials from k8s secret."""
-
if settings.IN_CLUSTER:
config.load_incluster_config()
else:
api_instance = client.CoreV1Api()
try:
secret = api_instance.read_namespaced_secret(
- settings.SDNC_SECRET_NAME, settings.K8S_TESTS_NAMESPACE)
+ settings.SDNC_SECRET_NAME, settings.K8S_TESTS_NAMESPACE
+ )
if secret.data:
- if (self.SDNC_DB_LOGIN in secret.data and self.SDNC_DB_PASSWORD in secret.data):
+ if (
+ self.SDNC_DB_LOGIN in secret.data
+ and self.SDNC_DB_PASSWORD in secret.data
+ ):
login_base64 = secret.data[self.SDNC_DB_LOGIN]
self.login = base64.b64decode(login_base64).decode("utf-8")
password_base64 = secret.data[self.SDNC_DB_PASSWORD]
self.password = base64.b64decode(password_base64).decode("utf-8")
else:
raise EnvironmentPreparationException(
- "Login key or password key not found in secret")
+ "Login key or password key not found in secret"
+ )
else:
raise EnvironmentPreparationException("Secret data not found in secret")
except client.rest.ApiException as e:
host=settings.SDNC_DB_PRIMARY_HOST,
port=settings.SDNC_DB_PORT,
user=self.login,
- password=self.password)
+ password=self.password,
+ )
self._check_query(conn, self.SDNC_QUERY_LOGIC)
self._check_query(conn, self.SDNC_QUERY_MODEL)
- except (mysql.errors.ProgrammingError,
- mysql.errors.DatabaseError) as e:
+ except (mysql.errors.ProgrammingError, mysql.errors.DatabaseError) as e:
raise OnapTestException(e) from e
except Exception as e:
raise OnapTestException("Cannot connect to SDNC Database") from e
self.service = Service(
service_instance_id=settings.SERVICE_ID,
service_status=settings.SERVICE_STATUS,
- service_data=settings.SERVICE_DATA
+ service_data=settings.SERVICE_DATA,
)
self.service.create()
self._logger.info("SDNC service is created.")
@BaseSdncStep.store_state
def execute(self) -> None:
+ """Execute SDNC service update step."""
super().execute()
- self._logger.info("Get existing SDNC service instance and update it over GR-API")
+ 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
@BaseSdncStep.store_state
def execute(self) -> None:
+ """Execute VF module preload upload step."""
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
- },
+ {"vnf_name": settings.VNF_NAME, "vnf_type": settings.VNF_TYPE},
settings.VF_MODULE_NAME,
- None
+ None,
)
@BaseSdncStep.store_state
def execute(self) -> None:
+ """Execute SDNC health check step."""
super().execute()
- result = self.send_message_json(
+
+ response = self.send_message(
"POST",
"SDNC SLI API Healthcheck",
- f"{self.base_url}/rests/operations/SLI-API:healthcheck")
- message = ""
- if result and result["SLI-API:output"]:
- if result["SLI-API:output"]["response-code"] == "200":
- return
- message = result["SLI-API:output"]["response-message"]
- raise OnapTestException("SDNC is not healthy. %s" % message)
+ f"{self.base_url}/rests/operations/SLI-API:healthcheck",
+ )
+ if response and response.status_code == 204:
+ return
+ raise OnapTestException(
+ "SDNC is not healthy. Status code %s" % response.status_code
+ )
class GetSdncPreloadStep(BaseSdncStep):
@BaseSdncStep.store_state
def execute(self) -> None:
+ """Execute SDNC preload information retrieval step."""
super().execute()
- self._logger.info("Get existing SDNC service instance and update it over GR-API")
+ self._logger.info(
+ "Get existing SDNC service instance and update it over GR-API"
+ )
preloads = PreloadInformation.get_all()
for preload_information in preloads:
self.__logger.debug(preload_information)