diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/onaptests/configuration/basic_vm_macro_settings.py | 3 | ||||
-rw-r--r-- | src/onaptests/steps/onboard/cds.py | 52 | ||||
-rw-r--r-- | src/onaptests/steps/onboard/pnf.py | 40 | ||||
-rw-r--r-- | src/onaptests/steps/onboard/service.py | 34 | ||||
-rw-r--r-- | src/onaptests/steps/onboard/vf.py | 28 | ||||
-rw-r--r-- | src/onaptests/steps/simulator/pnf_simulator_cnf/pnf_register.py | 43 |
6 files changed, 114 insertions, 86 deletions
diff --git a/src/onaptests/configuration/basic_vm_macro_settings.py b/src/onaptests/configuration/basic_vm_macro_settings.py index 7bce5db..adf3cd3 100644 --- a/src/onaptests/configuration/basic_vm_macro_settings.py +++ b/src/onaptests/configuration/basic_vm_macro_settings.py @@ -1,6 +1,7 @@ import os import openstack from pathlib import Path +from uuid import uuid4 from yaml import load @@ -57,4 +58,4 @@ try: except (FileNotFoundError, ValueError): raise onap_test_exceptions.TestConfigurationException -SERVICE_INSTANCE_NAME = "basic_vm_macro_service_instance" +SERVICE_INSTANCE_NAME = f"basic_macro_{str(uuid4())}" diff --git a/src/onaptests/steps/onboard/cds.py b/src/onaptests/steps/onboard/cds.py index f137adb..3ef37f2 100644 --- a/src/onaptests/steps/onboard/cds.py +++ b/src/onaptests/steps/onboard/cds.py @@ -9,8 +9,10 @@ from kubernetes import client, config from onapsdk.cds import Blueprint, DataDictionarySet from onapsdk.cds.blueprint_processor import Blueprintprocessor from onapsdk.configuration import settings +import urllib3 from ..base import BaseStep +from onaptests.utils.exceptions import OnapTestException class CDSBaseStep(BaseStep, ABC): @@ -48,11 +50,15 @@ class ExposeCDSBlueprintprocessorNodePortStep(CDSBaseStep): super().execute() config.load_kube_config(settings.K8S_CONFIG) self.k8s_client = client.CoreV1Api() - self.k8s_client.patch_namespaced_service( - self.service_name, - settings.K8S_NAMESPACE, - {"spec": {"ports": [{"port": 8080, "nodePort": 30449}], "type": "NodePort"}} - ) + try: + self.k8s_client.patch_namespaced_service( + self.service_name, + settings.K8S_NAMESPACE, + {"spec": {"ports": [{"port": 8080, "nodePort": 30449}], "type": "NodePort"}} + ) + except urllib3.exceptions.HTTPError: + self._logger.exception("Can't connect with k8s") + raise OnapTestException def cleanup(self) -> None: """Step cleanup. @@ -60,22 +66,26 @@ class ExposeCDSBlueprintprocessorNodePortStep(CDSBaseStep): Restore CDS blueprintprocessor service. """ - self.k8s_client.patch_namespaced_service( - self.service_name, - settings.K8S_NAMESPACE, - [ - { - "op": "remove", - "path": "/spec/ports/0/nodePort" - }, - { - "op": "replace", - "path": "/spec/type", - "value": "ClusterIP" - } - ] - ) - return super().cleanup() + try: + self.k8s_client.patch_namespaced_service( + self.service_name, + settings.K8S_NAMESPACE, + [ + { + "op": "remove", + "path": "/spec/ports/0/nodePort" + }, + { + "op": "replace", + "path": "/spec/type", + "value": "ClusterIP" + } + ] + ) + return super().cleanup() + except urllib3.exceptions.HTTPError: + self._logger.exception("Can't connect with k8s") + raise OnapTestException class BootstrapBlueprintprocessor(CDSBaseStep): diff --git a/src/onaptests/steps/onboard/pnf.py b/src/onaptests/steps/onboard/pnf.py index 547e0c0..01f2248 100644 --- a/src/onaptests/steps/onboard/pnf.py +++ b/src/onaptests/steps/onboard/pnf.py @@ -49,14 +49,15 @@ class PnfOnboardStep(BaseStep): super().execute() vendor: Vendor = Vendor(name=settings.VENDOR_NAME) pnf: Pnf = Pnf(name=settings.PNF_NAME, vendor=vendor) - pnf.create() - pnf.add_deployment_artifact( - artifact_type=settings.PNF_ARTIFACT_TYPE, - artifact_name=settings.PNF_ARTIFACT_NAME, - artifact_label=settings.PNF_ARTIFACT_LABEL, - artifact=settings.PNF_ARTIFACT_FILE_PATH - ) - pnf.onboard() + if not pnf.created(): + pnf.create() + pnf.add_deployment_artifact( + artifact_type=settings.PNF_ARTIFACT_TYPE, + artifact_name=settings.PNF_ARTIFACT_NAME, + artifact_label=settings.PNF_ARTIFACT_LABEL, + artifact=settings.PNF_ARTIFACT_FILE_PATH + ) + pnf.onboard() class YamlTemplatePnfOnboardStep(YamlTemplateBaseStep): @@ -104,12 +105,17 @@ class YamlTemplatePnfOnboardStep(YamlTemplateBaseStep): if "pnfs" in self.yaml_template: vendor: Vendor = Vendor(name=settings.VENDOR_NAME) for pnf in self.yaml_template["pnfs"]: - pnf_obj: Pnf = Pnf(name=pnf["pnf_name"], vendor=vendor) - pnf_obj.create() - pnf_obj.add_deployment_artifact( - artifact_type=pnf["pnf_artifact_type"], - artifact_name=pnf["pnf_artifact_name"], - artifact_label=pnf["pnf_artifact_label"], - artifact=pnf["pnf_artifact_file_path"] - ) - pnf_obj.onboard() + if "heat_files_to_upload" in pnf: + vsp: Vsp = Vsp(name=f"{pnf['pnf_name']}_VSP") + else: + vsp = None + pnf_obj: Pnf = Pnf(name=pnf["pnf_name"], vendor=vendor, vsp=vsp) + if not pnf_obj.created(): + pnf_obj.create() + pnf_obj.add_deployment_artifact( + artifact_type=pnf["pnf_artifact_type"], + artifact_name=pnf["pnf_artifact_name"], + artifact_label=pnf["pnf_artifact_label"], + artifact=pnf["pnf_artifact_file_path"] + ) + pnf_obj.onboard() diff --git a/src/onaptests/steps/onboard/service.py b/src/onaptests/steps/onboard/service.py index 6300a43..8a7303b 100644 --- a/src/onaptests/steps/onboard/service.py +++ b/src/onaptests/steps/onboard/service.py @@ -55,16 +55,17 @@ class ServiceOnboardStep(BaseStep): """ super().execute() service: Service = Service(name=settings.SERVICE_NAME, instantiation_type=settings.SERVICE_INSTANTIATION_TYPE) - service.create() - if settings.VL_NAME != "": - vl: Vl = Vl(name=settings.VL_NAME) - service.add_resource(vl) - if settings.VF_NAME != "": - vf: Vf = Vf(name=settings.VF_NAME) - service.add_resource(vf) - if settings.PNF_NAME != "": - pnf: Pnf = Pnf(name=settings.PNF_NAME) - service.add_resource(pnf) + if not service.created(): + service.create() + if settings.VL_NAME != "": + vl: Vl = Vl(name=settings.VL_NAME) + service.add_resource(vl) + if settings.VF_NAME != "": + vf: Vf = Vf(name=settings.VF_NAME) + service.add_resource(vf) + if settings.PNF_NAME != "": + pnf: Pnf = Pnf(name=settings.PNF_NAME) + service.add_resource(pnf) # If the service is already distributed, do not try to checkin/onboard (replay of tests) # checkin is done if needed # If service is replayed, no need to try to re-onboard the model @@ -141,12 +142,13 @@ class YamlTemplateServiceOnboardStep(YamlTemplateBaseStep): else: instantiation_type: ServiceInstantiationType = ServiceInstantiationType.A_LA_CARTE service: Service = Service(name=self.service_name, instantiation_type=instantiation_type) - service.create() - self.declare_resources(service) - self.assign_properties(service) - # If the service is already distributed, do not try to checkin/onboard (replay of tests) - # checkin is done if needed - # If service is replayed, no need to try to re-onboard the model + if not service.created(): + service.create() + self.declare_resources(service) + self.assign_properties(service) + # If the service is already distributed, do not try to checkin/onboard (replay of tests) + # checkin is done if needed + # If service is replayed, no need to try to re-onboard the model if not service.distributed: try: service.checkin() diff --git a/src/onaptests/steps/onboard/vf.py b/src/onaptests/steps/onboard/vf.py index 5f5fc4d..c6582dd 100644 --- a/src/onaptests/steps/onboard/vf.py +++ b/src/onaptests/steps/onboard/vf.py @@ -40,7 +40,8 @@ class VfOnboardStep(BaseStep): super().execute() vsp: Vsp = Vsp(name=settings.VSP_NAME) vf: Vf = Vf(name=settings.VF_NAME, vsp=vsp) - vf.onboard() + if not vf.created(): + vf.onboard() class YamlTemplateVfOnboardStep(YamlTemplateBaseStep): @@ -85,15 +86,16 @@ class YamlTemplateVfOnboardStep(YamlTemplateBaseStep): for vnf in self.yaml_template["vnfs"]: vsp: Vsp = Vsp(name=f"{vnf['vnf_name']}_VSP") vf: Vf = Vf(name=vnf['vnf_name'], vsp=vsp) - if all([x in vnf for x in ["vnf_artifact_type", - "vnf_artifact_name", - "vnf_artifact_label", - "vnf_artifact_file_path"]]): - vf.create() - vf.add_deployment_artifact( - artifact_type=vnf["vnf_artifact_type"], - artifact_name=vnf["vnf_artifact_name"], - artifact_label=vnf["vnf_artifact_label"], - artifact=vnf["vnf_artifact_file_path"] - ) - vf.onboard() + if not vf.created(): + if all([x in vnf for x in ["vnf_artifact_type", + "vnf_artifact_name", + "vnf_artifact_label", + "vnf_artifact_file_path"]]): + vf.create() + vf.add_deployment_artifact( + artifact_type=vnf["vnf_artifact_type"], + artifact_name=vnf["vnf_artifact_name"], + artifact_label=vnf["vnf_artifact_label"], + artifact=vnf["vnf_artifact_file_path"] + ) + vf.onboard() diff --git a/src/onaptests/steps/simulator/pnf_simulator_cnf/pnf_register.py b/src/onaptests/steps/simulator/pnf_simulator_cnf/pnf_register.py index 4f14f01..f3e4583 100644 --- a/src/onaptests/steps/simulator/pnf_simulator_cnf/pnf_register.py +++ b/src/onaptests/steps/simulator/pnf_simulator_cnf/pnf_register.py @@ -7,6 +7,7 @@ from typing import Tuple import requests from kubernetes import client, config, watch from onapsdk.configuration import settings +import urllib3 from onaptests.steps.base import BaseStep from onaptests.steps.instantiate.msb_k8s import CreateInstanceStep @@ -35,8 +36,7 @@ class PnfSimulatorCnfRegisterStep(BaseStep): """Component name.""" return "Environment" - @staticmethod - def is_pnf_pod_running(timeout_seconds=120) -> bool: + def is_pnf_pod_running(self, timeout_seconds=120) -> bool: """Check if PNF simulator pod is running. Args: @@ -49,18 +49,21 @@ class PnfSimulatorCnfRegisterStep(BaseStep): config.load_kube_config(settings.K8S_CONFIG) k8s_client: "CoreV1API" = client.CoreV1Api() k8s_watch: "Watch" = watch.Watch() - for event in k8s_watch.stream(k8s_client.list_namespaced_pod, - namespace=settings.K8S_NAMESPACE, - timeout_seconds=timeout_seconds): - if event["object"].metadata.name == "pnf-simulator": - if not event["object"].status.phase in ["Pending", "Running"]: - # Invalid pod state - return False - return event["object"].status.phase == "Running" - return False - - @staticmethod - def get_ves_ip_and_port() -> Tuple[str, str]: + try: + for event in k8s_watch.stream(k8s_client.list_namespaced_pod, + namespace=settings.K8S_NAMESPACE, + timeout_seconds=timeout_seconds): + if event["object"].metadata.name == "pnf-simulator": + if not event["object"].status.phase in ["Pending", "Running"]: + # Invalid pod state + return False + return event["object"].status.phase == "Running" + return False + except urllib3.exceptions.HTTPError: + self._logger.error("Can't connect with k8s") + raise OnapTestException + + def get_ves_ip_and_port(self) -> Tuple[str, str]: """Static method to get VES ip address and port. Raises: @@ -72,10 +75,14 @@ class PnfSimulatorCnfRegisterStep(BaseStep): """ config.load_kube_config(settings.K8S_CONFIG) k8s_client: "CoreV1API" = client.CoreV1Api() - for service in k8s_client.list_namespaced_service(namespace=settings.K8S_NAMESPACE).items: - if service.metadata.name == "xdcae-ves-collector": - return service.spec.cluster_ip, service.spec.ports[0].port - raise EnvironmentPreparationException("Couldn't get VES ip and port") + try: + for service in k8s_client.list_namespaced_service(namespace=settings.K8S_NAMESPACE).items: + if service.metadata.name == settings.DCAE_VES_COLLECTOR_POD_NAME: + return service.spec.cluster_ip, service.spec.ports[0].port + raise EnvironmentPreparationException("Couldn't get VES ip and port") + except urllib3.exceptions.HTTPError: + self._logger.error("Can't connect with k8s") + raise OnapTestException @BaseStep.store_state def execute(self) -> None: |