aboutsummaryrefslogtreecommitdiffstats
path: root/src/onaptests/steps/instantiate
diff options
context:
space:
mode:
authorLukasz Rajewski <lukasz.rajewski@t-mobile.pl>2024-01-28 19:45:44 +0100
committerLukasz Rajewski <lukasz.rajewski@t-mobile.pl>2024-01-29 22:24:42 +0100
commita7edeebc90bdd335361a7b36f5f5d12a14375554 (patch)
tree0e48ee456ef26471271c5412f3205aafcda41857 /src/onaptests/steps/instantiate
parent2479155376b6142e97163a7903632015fed50815 (diff)
Enhanced validation of configuration of all tests
Issue-ID: TEST-402 Signed-off-by: Lukasz Rajewski <lukasz.rajewski@t-mobile.pl> Change-Id: I2e4ef6365b44c33f4c0b3e72886a83f92c63e2f3
Diffstat (limited to 'src/onaptests/steps/instantiate')
-rw-r--r--src/onaptests/steps/instantiate/k8s_profile_create.py9
-rw-r--r--src/onaptests/steps/instantiate/sdnc_service.py12
-rw-r--r--src/onaptests/steps/instantiate/service_ala_carte.py99
-rw-r--r--src/onaptests/steps/instantiate/service_macro.py15
-rw-r--r--src/onaptests/steps/instantiate/vf_module_ala_carte.py10
-rw-r--r--src/onaptests/steps/instantiate/vl_ala_carte.py12
-rw-r--r--src/onaptests/steps/instantiate/vnf_ala_carte.py10
7 files changed, 49 insertions, 118 deletions
diff --git a/src/onaptests/steps/instantiate/k8s_profile_create.py b/src/onaptests/steps/instantiate/k8s_profile_create.py
index d3798e2..4be5684 100644
--- a/src/onaptests/steps/instantiate/k8s_profile_create.py
+++ b/src/onaptests/steps/instantiate/k8s_profile_create.py
@@ -48,7 +48,7 @@ class K8SProfileStep(BaseStep):
"""
if self.is_root:
if not self._yaml_template:
- with open(settings.SERVICE_YAML_TEMPLATE, "r") as yaml_template:
+ with open(settings.SERVICE_YAML_TEMPLATE, "r", encoding="utf-8") as yaml_template:
self._yaml_template: dict = load(yaml_template, SafeLoader)
return self._yaml_template
return self.parent.yaml_template
@@ -152,7 +152,8 @@ class K8SProfileStep(BaseStep):
k8s_profile_namespace,
settings.K8S_PROFILE_K8S_VERSION)
# Upload artifact for created profile
- profile.upload_artifact(open(settings.K8S_PROFILE_ARTIFACT_PATH, 'rb').read())
+ with open(settings.K8S_PROFILE_ARTIFACT_PATH, 'rb') as k8s_profile:
+ profile.upload_artifact(k8s_profile.read())
@BaseStep.store_state(cleanup=True)
def cleanup(self) -> None:
@@ -179,7 +180,7 @@ class K8SProfileStep(BaseStep):
try:
profile = rbdef.get_profile_by_name(k8s_profile_name)
profile.delete()
- except APIError:
+ except APIError as exc:
self._logger.error("K8s profile deletion %s failed", k8s_profile_name)
- raise onap_test_exceptions.ProfileCleanupException
+ raise onap_test_exceptions.ProfileCleanupException from exc
super().cleanup()
diff --git a/src/onaptests/steps/instantiate/sdnc_service.py b/src/onaptests/steps/instantiate/sdnc_service.py
index 1c2437f..851902a 100644
--- a/src/onaptests/steps/instantiate/sdnc_service.py
+++ b/src/onaptests/steps/instantiate/sdnc_service.py
@@ -1,3 +1,5 @@
+import logging
+
from onapsdk.configuration import settings
from onapsdk.exceptions import APIError
from onapsdk.sdnc import VfModulePreload
@@ -59,7 +61,7 @@ class ServiceCreateStep(BaseSdncStep):
if exc.response_status_code == 409:
self._logger.warning("SDNC service already exists.")
else:
- raise OnapTestException("SDNC service creation failed.")
+ raise OnapTestException("SDNC service creation failed.") from exc
@BaseStep.store_state(cleanup=True)
def cleanup(self) -> None:
@@ -107,8 +109,8 @@ class UpdateSdncService(BaseSdncStep):
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.")
+ except APIError as exc:
+ raise OnapTestException("SDNC service update is failed.") from exc
class UploadVfModulePreloadStep(BaseSdncStep):
@@ -153,6 +155,8 @@ class GetSdncPreloadStep(BaseSdncStep):
Get preload information from SDNC over GR-API.
"""
+ __logger = logging.getLogger(__name__)
+
def __init__(self):
"""Initialize step.
@@ -180,7 +184,7 @@ class GetSdncPreloadStep(BaseSdncStep):
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)
+ self.__logger.debug(preload_information)
class TestSdncStep(BaseScenarioStep):
diff --git a/src/onaptests/steps/instantiate/service_ala_carte.py b/src/onaptests/steps/instantiate/service_ala_carte.py
index 528215d..4a0a4c1 100644
--- a/src/onaptests/steps/instantiate/service_ala_carte.py
+++ b/src/onaptests/steps/instantiate/service_ala_carte.py
@@ -3,7 +3,6 @@ from uuid import uuid4
from yaml import load, SafeLoader
from onapsdk.aai.cloud_infrastructure import CloudRegion, Tenant
-from onapsdk.aai.business import Customer
from onapsdk.aai.business.owning_entity import OwningEntity as AaiOwningEntity
from onapsdk.configuration import settings
from onapsdk.exceptions import ResourceNotFound
@@ -11,82 +10,9 @@ from onapsdk.sdc.service import Service
from onapsdk.so.instantiation import ServiceInstantiation
import onaptests.utils.exceptions as onap_test_exceptions
-from ..base import BaseStep, YamlTemplateBaseStep
+from ..base import YamlTemplateBaseStep
from ..cloud.connect_service_subscription_to_cloud_region import ConnectServiceSubToCloudRegionStep
-from ..onboard.service import ServiceOnboardStep, YamlTemplateServiceOnboardStep
-
-
-class ServiceAlaCarteInstantiateStep(BaseStep):
- """Instantiate service a'la carte."""
-
- def __init__(self, cleanup=False):
- """Initialize step.
-
- Substeps:
- - ServiceOnboardStep,
- - ConnectServiceSubToCloudRegionStep.
- """
- super().__init__(cleanup=cleanup)
- if not settings.ONLY_INSTANTIATE:
- self.add_step(ServiceOnboardStep(cleanup))
- self.add_step(ConnectServiceSubToCloudRegionStep(cleanup))
-
- @property
- def description(self) -> str:
- """Step description."""
- return "Instantiate service using SO a'la carte method."
-
- @property
- def component(self) -> str:
- """Component name."""
- return "SO"
-
- @BaseStep.store_state
- def execute(self):
- """Instantiate service.
-
- Use settings values:
- - SERVICE_NAME,
- - GLOBAL_CUSTOMER_ID,
- - CLOUD_REGION_CLOUD_OWNER,
- - CLOUD_REGION_ID,
- - TENANT_ID,
- - OWNING_ENTITY,
- - PROJECT,
- - SERVICE_INSTANCE_NAME.
- """
- super().execute()
- service = Service(settings.SERVICE_NAME)
- customer: Customer = Customer.get_by_global_customer_id(settings.GLOBAL_CUSTOMER_ID)
- cloud_region: CloudRegion = CloudRegion.get_by_id(
- cloud_owner=settings.CLOUD_REGION_CLOUD_OWNER,
- cloud_region_id=settings.CLOUD_REGION_ID,
- )
- tenant: Tenant = cloud_region.get_tenant(settings.TENANT_ID)
- try:
- owning_entity = AaiOwningEntity.get_by_owning_entity_name(
- settings.OWNING_ENTITY)
- except ResourceNotFound:
- self._logger.info("Owning entity not found, create it")
- owning_entity = AaiOwningEntity.create(settings.OWNING_ENTITY)
-
- service_instantiation = ServiceInstantiation.instantiate_ala_carte(
- service,
- cloud_region,
- tenant,
- customer,
- owning_entity,
- settings.PROJECT,
- service_instance_name=settings.SERVICE_INSTANCE_NAME
- )
- try:
- service_instantiation.wait_for_finish(settings.ORCHESTRATION_REQUEST_TIMEOUT)
- except TimeoutError:
- self._logger.error("Service instantiation %s timed out", self.service_instance_name)
- raise onap_test_exceptions.ServiceInstantiateException
- if service_instantiation.failed:
- self._logger.error("Service instantiation %s failed", self.service_instance_name)
- raise onap_test_exceptions.ServiceInstantiateException
+from ..onboard.service import YamlTemplateServiceOnboardStep
class YamlTemplateServiceAlaCarteInstantiateStep(YamlTemplateBaseStep):
@@ -128,7 +54,7 @@ class YamlTemplateServiceAlaCarteInstantiateStep(YamlTemplateBaseStep):
"""
if self.is_root:
if not self._yaml_template:
- with open(settings.SERVICE_YAML_TEMPLATE, "r") as yaml_template:
+ with open(settings.SERVICE_YAML_TEMPLATE, "r", encoding="utf-8") as yaml_template:
self._yaml_template: dict = load(yaml_template, SafeLoader)
return self._yaml_template
return self.parent.yaml_template
@@ -198,9 +124,9 @@ class YamlTemplateServiceAlaCarteInstantiateStep(YamlTemplateBaseStep):
service.name)
break
self._logger.info(
- "Service Distribution for %s ongoing, Wait for 60 s",
- service.name)
- time.sleep(60)
+ "Service Distribution for %s ongoing, Wait for %d s",
+ service.name, settings.SERVICE_DISTRIBUTION_SLEEP_TIME)
+ time.sleep(settings.SERVICE_DISTRIBUTION_SLEEP_TIME)
nb_try += 1
if distribution_completed is False:
@@ -220,15 +146,14 @@ class YamlTemplateServiceAlaCarteInstantiateStep(YamlTemplateBaseStep):
)
try:
service_instantiation.wait_for_finish(settings.ORCHESTRATION_REQUEST_TIMEOUT)
- except TimeoutError:
+ except TimeoutError as exc:
self._logger.error("Service instantiation %s timed out", self.service_instance_name)
- raise onap_test_exceptions.ServiceCleanupException
+ raise onap_test_exceptions.ServiceCleanupException from exc
if service_instantiation.failed:
self._logger.error("Service instantiation %s failed", self.service_instance_name)
raise onap_test_exceptions.ServiceInstantiateException
- else:
- self._load_customer_and_subscription(reload=True)
- self._load_service_instance()
+ self._load_customer_and_subscription(reload=True)
+ self._load_service_instance()
@YamlTemplateBaseStep.store_state(cleanup=True)
def cleanup(self) -> None:
@@ -244,9 +169,9 @@ class YamlTemplateServiceAlaCarteInstantiateStep(YamlTemplateBaseStep):
service_deletion = self._service_instance.delete(a_la_carte=True)
try:
service_deletion.wait_for_finish(settings.ORCHESTRATION_REQUEST_TIMEOUT)
- except TimeoutError:
+ except TimeoutError as exc:
self._logger.error("Service deletion %s timed out", self._service_instance_name)
- raise onap_test_exceptions.ServiceCleanupException
+ raise onap_test_exceptions.ServiceCleanupException from exc
if service_deletion.finished:
self._logger.info("Service %s deleted", self._service_instance_name)
else:
diff --git a/src/onaptests/steps/instantiate/service_macro.py b/src/onaptests/steps/instantiate/service_macro.py
index 4211cbf..a513d1e 100644
--- a/src/onaptests/steps/instantiate/service_macro.py
+++ b/src/onaptests/steps/instantiate/service_macro.py
@@ -77,7 +77,7 @@ class YamlTemplateServiceMacroInstantiateStep(YamlTemplateBaseStep):
"""
if self.is_root:
if not self._yaml_template:
- with open(settings.SERVICE_YAML_TEMPLATE, "r") as yaml_template:
+ with open(settings.SERVICE_YAML_TEMPLATE, "r", encoding="utf-8") as yaml_template:
self._yaml_template: dict = load(yaml_template, SafeLoader)
return self._yaml_template
return self.parent.yaml_template
@@ -94,8 +94,9 @@ class YamlTemplateServiceMacroInstantiateStep(YamlTemplateBaseStep):
"""
if self.is_root:
if not self._model_yaml_template:
- with open(settings.MODEL_YAML_TEMPLATE, "r") as model_yaml_template:
- self._model_yaml_template: dict = load(model_yaml_template)
+ with open(settings.MODEL_YAML_TEMPLATE, "r",
+ encoding="utf-8") as model_yaml_template:
+ self._model_yaml_template: dict = load(model_yaml_template, SafeLoader)
return self._model_yaml_template
return self.parent.model_yaml_template
@@ -215,9 +216,9 @@ class YamlTemplateServiceMacroInstantiateStep(YamlTemplateBaseStep):
)
try:
service_instantiation.wait_for_finish(timeout=settings.ORCHESTRATION_REQUEST_TIMEOUT)
- except TimeoutError:
+ except TimeoutError as exc:
self._logger.error("Service instantiation %s timed out", self.service_instance_name)
- raise onap_test_exceptions.ServiceInstantiateException
+ raise onap_test_exceptions.ServiceInstantiateException from exc
if service_instantiation.failed:
self._logger.error("Service instantiation %s failed", self.service_instance_name)
raise onap_test_exceptions.ServiceInstantiateException
@@ -239,9 +240,9 @@ class YamlTemplateServiceMacroInstantiateStep(YamlTemplateBaseStep):
service_deletion = self._service_instance.delete(a_la_carte=False)
try:
service_deletion.wait_for_finish(timeout=settings.ORCHESTRATION_REQUEST_TIMEOUT)
- except TimeoutError:
+ except TimeoutError as exc:
self._logger.error("Service deletion %s timed out", self._service_instance_name)
- raise onap_test_exceptions.ServiceCleanupException
+ raise onap_test_exceptions.ServiceCleanupException from exc
if service_deletion.finished:
self._logger.info("Service %s deleted", self._service_instance_name)
else:
diff --git a/src/onaptests/steps/instantiate/vf_module_ala_carte.py b/src/onaptests/steps/instantiate/vf_module_ala_carte.py
index 1682536..e148e4c 100644
--- a/src/onaptests/steps/instantiate/vf_module_ala_carte.py
+++ b/src/onaptests/steps/instantiate/vf_module_ala_carte.py
@@ -54,7 +54,7 @@ class YamlTemplateVfModuleAlaCarteInstantiateStep(YamlTemplateBaseStep):
"""
if self.is_root:
if not self._yaml_template:
- with open(settings.SERVICE_YAML_TEMPLATE, "r") as yaml_template:
+ with open(settings.SERVICE_YAML_TEMPLATE, "r", encoding="utf-8") as yaml_template:
self._yaml_template: dict = load(yaml_template, SafeLoader)
return self._yaml_template
return self.parent.yaml_template
@@ -135,9 +135,9 @@ class YamlTemplateVfModuleAlaCarteInstantiateStep(YamlTemplateBaseStep):
if vf_module_instantiation.failed:
self._logger.error("VfModule instantiation %s failed", vf_module.name)
raise onap_test_exceptions.VfModuleInstantiateException
- except TimeoutError:
+ except TimeoutError as exc:
self._logger.error("VfModule instantiation %s timed out", vf_module.name)
- raise onap_test_exceptions.VfModuleInstantiateException
+ raise onap_test_exceptions.VfModuleInstantiateException from exc
@YamlTemplateBaseStep.store_state(cleanup=True)
def cleanup(self) -> None:
@@ -163,7 +163,7 @@ class YamlTemplateVfModuleAlaCarteInstantiateStep(YamlTemplateBaseStep):
self._logger.error("VfModule deletion %s failed", vf_module.name)
raise onap_test_exceptions.VfModuleCleanupException
self._logger.info("VfModule %s deleted", vf_module.name)
- except TimeoutError:
+ except TimeoutError as exc:
self._logger.error("VfModule deletion %s timed out", vf_module.name)
- raise onap_test_exceptions.VfModuleCleanupException
+ raise onap_test_exceptions.VfModuleCleanupException from exc
super().cleanup()
diff --git a/src/onaptests/steps/instantiate/vl_ala_carte.py b/src/onaptests/steps/instantiate/vl_ala_carte.py
index 7c2f4d9..72dcb2f 100644
--- a/src/onaptests/steps/instantiate/vl_ala_carte.py
+++ b/src/onaptests/steps/instantiate/vl_ala_carte.py
@@ -48,7 +48,7 @@ class YamlTemplateVlAlaCarteInstantiateStep(YamlTemplateBaseStep):
"""
if self.is_root:
if not self._yaml_template:
- with open(settings.SERVICE_YAML_TEMPLATE, "r") as yaml_template:
+ with open(settings.SERVICE_YAML_TEMPLATE, "r", encoding="utf-8") as yaml_template:
self._yaml_template: dict = load(yaml_template, SafeLoader)
return self._yaml_template
return self.parent.yaml_template
@@ -89,7 +89,7 @@ class YamlTemplateVlAlaCarteInstantiateStep(YamlTemplateBaseStep):
for net in self.yaml_template[self.service_name]["networks"]:
if net["vl_name"] == network_name:
if net['subnets'] is None:
- print("No Subnet defined")
+ self._logger.warning("No Subnet defined")
else:
for subnet in net['subnets']:
yield Subnet(
@@ -128,9 +128,9 @@ class YamlTemplateVlAlaCarteInstantiateStep(YamlTemplateBaseStep):
if net_instantiation.failed:
self._logger.error("VL instantiation %s failed", net_instantiation.name)
raise onap_test_exceptions.NetworkInstantiateException
- except TimeoutError:
+ except TimeoutError as exc:
self._logger.error("VL instantiation %s timed out", net_instantiation.name)
- raise onap_test_exceptions.NetworkInstantiateException
+ raise onap_test_exceptions.NetworkInstantiateException from exc
@YamlTemplateBaseStep.store_state(cleanup=True)
def cleanup(self) -> None:
@@ -148,7 +148,7 @@ class YamlTemplateVlAlaCarteInstantiateStep(YamlTemplateBaseStep):
if net_deletion.failed:
self._logger.error("VL deletion %s failed", net_instance.name)
raise onap_test_exceptions.NetworkCleanupException
- except TimeoutError:
+ except TimeoutError as exc:
self._logger.error("VL deletion %s timed out", net_instance.name)
- raise onap_test_exceptions.NetworkCleanupException
+ raise onap_test_exceptions.NetworkCleanupException from exc
super().cleanup()
diff --git a/src/onaptests/steps/instantiate/vnf_ala_carte.py b/src/onaptests/steps/instantiate/vnf_ala_carte.py
index 2aa5e5e..e45f71e 100644
--- a/src/onaptests/steps/instantiate/vnf_ala_carte.py
+++ b/src/onaptests/steps/instantiate/vnf_ala_carte.py
@@ -46,7 +46,7 @@ class YamlTemplateVnfAlaCarteInstantiateStep(YamlTemplateBaseStep):
"""
if self.is_root:
if not self._yaml_template:
- with open(settings.SERVICE_YAML_TEMPLATE, "r") as yaml_template:
+ with open(settings.SERVICE_YAML_TEMPLATE, "r", encoding="utf-8") as yaml_template:
self._yaml_template: dict = load(yaml_template, SafeLoader)
return self._yaml_template
return self.parent.yaml_template
@@ -106,9 +106,9 @@ class YamlTemplateVnfAlaCarteInstantiateStep(YamlTemplateBaseStep):
if vnf_instantiation.failed:
self._logger.error("VNF instantiation %s failed", vnf.name)
raise onap_test_exceptions.VnfInstantiateException
- except TimeoutError:
+ except TimeoutError as exc:
self._logger.error("VNF instantiation %s timed out", vnf.name)
- raise onap_test_exceptions.VnfInstantiateException
+ raise onap_test_exceptions.VnfInstantiateException from exc
@YamlTemplateBaseStep.store_state(cleanup=True)
def cleanup(self) -> None:
@@ -127,7 +127,7 @@ class YamlTemplateVnfAlaCarteInstantiateStep(YamlTemplateBaseStep):
if vnf_deletion.failed:
self._logger.error("VNF deletion %s failed", vnf_instance.name)
raise onap_test_exceptions.VnfCleanupException
- except TimeoutError:
+ except TimeoutError as exc:
self._logger.error("VNF deletion %s timed out", vnf_instance.name)
- raise onap_test_exceptions.VnfCleanupException
+ raise onap_test_exceptions.VnfCleanupException from exc
super().cleanup()