From 055027ba9410ae5a855587939e8fb86e7a8ea6b2 Mon Sep 17 00:00:00 2001 From: Lukasz Rajewski Date: Thu, 15 Jun 2023 20:26:48 +0000 Subject: Enhanced SDNC test to cover SVC logic check Issue-ID: TEST-395 Signed-off-by: Lukasz Rajewski Change-Id: I1e49e8652d06b4c0147e8e1280ccbac9af83b8d4 --- src/onaptests/configuration/basic_sdnc_settings.py | 6 + src/onaptests/scenario/basic_sdnc.py | 6 +- src/onaptests/steps/instantiate/sdnc_service.py | 174 ++++++++++++++++++--- 3 files changed, 157 insertions(+), 29 deletions(-) diff --git a/src/onaptests/configuration/basic_sdnc_settings.py b/src/onaptests/configuration/basic_sdnc_settings.py index e6bbdcc..6cf2046 100644 --- a/src/onaptests/configuration/basic_sdnc_settings.py +++ b/src/onaptests/configuration/basic_sdnc_settings.py @@ -67,3 +67,9 @@ SERVICE_CHANGED_DATA = { "service-instance-name": "gnb-93100002" } } + +VF_MODULE_NAME = "sdnc-sanity-vf-module" + +VNF_NAME = "sdnc-sanity-vnf-name" + +VNF_TYPE = "sdnc-sanity-vnf-type" diff --git a/src/onaptests/scenario/basic_sdnc.py b/src/onaptests/scenario/basic_sdnc.py index d791080..328a175 100644 --- a/src/onaptests/scenario/basic_sdnc.py +++ b/src/onaptests/scenario/basic_sdnc.py @@ -1,11 +1,11 @@ import logging import time + from xtesting.core import testcase from onapsdk.configuration import settings from onapsdk.exceptions import SDKException - -from onaptests.steps.instantiate.sdnc_service import UpdateSdncService +from onaptests.steps.instantiate.sdnc_service import TestSdncStep from onaptests.utils.exceptions import OnapTestException @@ -22,7 +22,7 @@ class BasicSdnc(testcase.TestCase): kwargs["case_name"] = 'basic_SDNC' super().__init__(**kwargs) self.__logger.debug("Basic SDNC init started") - self.test = UpdateSdncService(cleanup=settings.CLEANUP_FLAG) + self.test = TestSdncStep(cleanup=settings.CLEANUP_FLAG) def run(self): """Run basic SDNC test.""" diff --git a/src/onaptests/steps/instantiate/sdnc_service.py b/src/onaptests/steps/instantiate/sdnc_service.py index c5308d6..7b6be14 100644 --- a/src/onaptests/steps/instantiate/sdnc_service.py +++ b/src/onaptests/steps/instantiate/sdnc_service.py @@ -1,13 +1,35 @@ -from onapsdk.sdnc.services import Service 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 -from onaptests.utils.exceptions import OnapTestException +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. -class ServiceCreateStep(BaseStep): + Returns: + str: Component name + + """ + return "SDNC" + + +class ServiceCreateStep(BaseSdncStep): """Service creation step.""" def __init__(self, service: Service = None, cleanup: bool = False): @@ -20,16 +42,11 @@ class ServiceCreateStep(BaseStep): """Step description.""" return "Create SDNC service." - @property - def component(self) -> str: - """Component name.""" - return "SDNC" - @BaseStep.store_state def execute(self): """Create service at SDNC.""" - self._logger.info("Create new service instance in SDNC by GR-API") super().execute() + self._logger.info("Create new service instance in SDNC by GR-API") try: self.service = Service( service_instance_id=settings.SERVICE_ID, @@ -38,8 +55,11 @@ class ServiceCreateStep(BaseStep): ) self.service.create() self._logger.info("SDNC service is created.") - except APIError: - raise OnapTestException("SDNC service creation failed.") + 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: @@ -50,7 +70,7 @@ class ServiceCreateStep(BaseStep): super().cleanup() -class UpdateSdncService(BaseStep): +class UpdateSdncService(BaseSdncStep): """Service update step. The step needs in an existing SDNC service as a prerequisite. @@ -77,6 +97,121 @@ class UpdateSdncService(BaseStep): """ 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. @@ -88,17 +223,4 @@ class UpdateSdncService(BaseStep): str: Component name """ - return "SDNC" - - @BaseStep.store_state - def execute(self): - self._logger.info("Get existing SDNC service instance and update it over GR-API") - super().execute() - 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 checked.") - except APIError: - raise OnapTestException("SDNC service update is failed.") + return "PythonSDK-tests" -- cgit 1.2.3-korg