diff options
author | Michal Jagiello <michal.jagiello@t-mobile.pl> | 2021-01-25 12:00:25 +0000 |
---|---|---|
committer | Michal Jagiello <michal.jagiello@t-mobile.pl> | 2021-01-25 14:40:39 +0000 |
commit | 5021508f4b6f8bf2bb6ef890b4bb960dc144484b (patch) | |
tree | 2451b62511bb2de23d0515684bf6555717100321 /src/onaptests/steps | |
parent | 511400315961caba0aa7b96d1ecf6aa2c912b4c4 (diff) |
PNF simulator CNF instantiation and registation steps
Use CNF of PNF simulator in pnf_macro scenario
Issue-ID: INT-1822
Signed-off-by: Michal Jagiello <michal.jagiello@t-mobile.pl>
Change-Id: Id7f70b45219a36b7fc70921a1438b0cbe57a1756
Diffstat (limited to 'src/onaptests/steps')
-rw-r--r-- | src/onaptests/steps/cloud/cloud_region_create.py | 51 | ||||
-rw-r--r-- | src/onaptests/steps/cloud/k8s_connectivity_info_create.py | 10 | ||||
-rw-r--r-- | src/onaptests/steps/cloud/register_cloud.py | 77 | ||||
-rw-r--r-- | src/onaptests/steps/instantiate/msb_k8s.py | 45 | ||||
-rw-r--r-- | src/onaptests/steps/onboard/cds.py | 9 | ||||
-rw-r--r-- | src/onaptests/steps/onboard/msb_k8s.py | 79 | ||||
-rw-r--r-- | src/onaptests/steps/simulator/pnf_simulator_cnf/__init__.py | 1 | ||||
-rw-r--r-- | src/onaptests/steps/simulator/pnf_simulator_cnf/pnf_register.py | 144 |
8 files changed, 368 insertions, 48 deletions
diff --git a/src/onaptests/steps/cloud/cloud_region_create.py b/src/onaptests/steps/cloud/cloud_region_create.py new file mode 100644 index 0000000..ba46466 --- /dev/null +++ b/src/onaptests/steps/cloud/cloud_region_create.py @@ -0,0 +1,51 @@ +"""A&AI cloud region creation module.""" +from onapsdk.aai.cloud_infrastructure import CloudRegion +from onapsdk.configuration import settings + +from ..base import BaseStep + + +class CloudRegionCreateStep(BaseStep): + """Cloud region creation step.""" + + @property + def description(self) -> str: + """Step description.""" + return "Create cloud region." + + @property + def component(self) -> str: + """Component name.""" + return "AAI" + + @BaseStep.store_state + def execute(self): + """Create cloud region. + + Use settings values: + - CLOUD_REGION_CLOUD_OWNER, + - CLOUD_REGION_ID, + - CLOUD_REGION_TYPE, + - CLOUD_REGION_VERSION, + - CLOUD_OWNER_DEFINED_TYPE, + - COMPLEX_PHYSICAL_LOCATION_ID. + + """ + super().execute() + self._logger.info("*Check if cloud region exists *") + try: + CloudRegion.get_by_id( + cloud_owner=settings.CLOUD_REGION_CLOUD_OWNER, + cloud_region_id=settings.CLOUD_REGION_ID, + ) + except ValueError: + CloudRegion.create( + cloud_owner=settings.CLOUD_REGION_CLOUD_OWNER, + cloud_region_id=settings.CLOUD_REGION_ID, + orchestration_disabled=False, + in_maint=False, + cloud_type=settings.CLOUD_REGION_TYPE, + cloud_region_version=settings.CLOUD_REGION_VERSION, + owner_defined_type=settings.CLOUD_OWNER_DEFINED_TYPE, + complex_name=settings.COMPLEX_PHYSICAL_LOCATION_ID + ) diff --git a/src/onaptests/steps/cloud/k8s_connectivity_info_create.py b/src/onaptests/steps/cloud/k8s_connectivity_info_create.py index 279ae0d..de0e683 100644 --- a/src/onaptests/steps/cloud/k8s_connectivity_info_create.py +++ b/src/onaptests/steps/cloud/k8s_connectivity_info_create.py @@ -1,3 +1,4 @@ +"""Connectivity info creation module.""" from onapsdk.configuration import settings from onapsdk.msb.k8s import ConnectivityInfo @@ -18,12 +19,12 @@ class K8SConnectivityInfoStep(BaseStep): @BaseStep.store_state def execute(self): - """Creation k8s connectivity information + """Creation k8s connectivity information. Use settings values: - CLOUD_REGION_ID, - CLOUD_REGION_CLOUD_OWNER, - - K8S_KUBECONFIG_FILE. + - K8S_CONFIG. """ super().execute() ######## Create Connectivity Info ######################################### @@ -34,11 +35,10 @@ class K8SConnectivityInfoStep(BaseStep): self._logger.info("Create the k8s connectivity information") ConnectivityInfo.create(settings.CLOUD_REGION_ID, settings.CLOUD_REGION_CLOUD_OWNER, - open(settings.K8S_KUBECONFIG_FILE, 'rb').read()) + open(settings.K8S_CONFIG, 'rb').read()) def cleanup(self) -> None: - """Cleanup K8S Connectivity information. - """ + """Cleanup K8S Connectivity information.""" self._logger.info("Clean the k8s connectivity information") super().cleanup() connectinfo = ConnectivityInfo.get_connectivity_info_by_region_id(settings.CLOUD_REGION_ID) diff --git a/src/onaptests/steps/cloud/register_cloud.py b/src/onaptests/steps/cloud/register_cloud.py index 341fc1c..72da4f7 100644 --- a/src/onaptests/steps/cloud/register_cloud.py +++ b/src/onaptests/steps/cloud/register_cloud.py @@ -1,3 +1,4 @@ +"""A&AI cloud region registstation module.""" import time from uuid import uuid4 @@ -5,11 +6,21 @@ from onapsdk.aai.cloud_infrastructure import CloudRegion from onapsdk.configuration import settings from ..base import BaseStep +from onaptests.steps.cloud.cloud_region_create import CloudRegionCreateStep class RegisterCloudRegionStep(BaseStep): """Cloud region registration step.""" + def __init__(self, cleanup: bool) -> None: + """Initialize step. + + Substeps: + - CloudRegionCreateStep. + """ + super().__init__(cleanup=cleanup) + self.add_step(CloudRegionCreateStep(cleanup=cleanup)) + @property def description(self) -> str: """Step description.""" @@ -22,39 +33,23 @@ class RegisterCloudRegionStep(BaseStep): @BaseStep.store_state def execute(self): - """Register cloud region + """Register cloud region. Use settings values: - CLOUD_REGION_CLOUD_OWNER, - CLOUD_REGION_ID, - CLOUD_DOMAIN, - - CLOUD_REGION_VERSION, - - CLOUD_OWNER_DEFINED_TYPE, - - COMPLEX_PHYSICAL_LOCATION_ID, - VIM_USERNAME, - VIM_PASSWORD, - VIM_SERVICE_URL, - TENANT_NAME. """ super().execute() - self._logger.info("*Check if cloud region exists *") - try: - cloud_region: CloudRegion = CloudRegion.get_by_id( - cloud_owner=settings.CLOUD_REGION_CLOUD_OWNER, - cloud_region_id=settings.CLOUD_REGION_ID, - ) - except ValueError: - self._logger.info("*Create the cloud region *") - cloud_region: CloudRegion = CloudRegion.create( - cloud_owner=settings.CLOUD_REGION_CLOUD_OWNER, - cloud_region_id=settings.CLOUD_REGION_ID, - orchestration_disabled=False, - in_maint=False, - cloud_type=settings.CLOUD_REGION_TYPE, - cloud_region_version=settings.CLOUD_REGION_VERSION, - owner_defined_type=settings.CLOUD_OWNER_DEFINED_TYPE, - complex_name=settings.COMPLEX_PHYSICAL_LOCATION_ID - ) + cloud_region: CloudRegion = CloudRegion.get_by_id( + cloud_owner=settings.CLOUD_REGION_CLOUD_OWNER, + cloud_region_id=settings.CLOUD_REGION_ID, + ) + if not list(cloud_region.esr_system_infos): cloud_region.add_esr_system_info( esr_system_info_id=str(uuid4()), user_name=settings.VIM_USERNAME, @@ -79,23 +74,23 @@ class RegisterCloudRegionStep(BaseStep): break nb_try += 1 - # Retrieve the tenant, created by multicloud registration - # if it does not exist, create it - try: - cloud_region.get_tenant(settings.TENANT_ID) - except ValueError: - self._logger.warning("Impossible to retrieve the Specificed Tenant") - self._logger.debug("If no multicloud selected, add the tenant") - cloud_region.add_tenant( - tenant_id=settings.TENANT_ID, - tenant_name=settings.TENANT_NAME) + # Retrieve the tenant, created by multicloud registration + # if it does not exist, create it + try: + cloud_region.get_tenant(settings.TENANT_ID) + except ValueError: + self._logger.warning("Impossible to retrieve the Specificed Tenant") + self._logger.debug("If no multicloud selected, add the tenant") + cloud_region.add_tenant( + tenant_id=settings.TENANT_ID, + tenant_name=settings.TENANT_NAME) - # be sure that an availability zone has been created - # if not, create it - try: - cloud_region.get_availability_zone_by_name( - settings.AVAILABILITY_ZONE_NAME) - except ValueError: - cloud_region.add_availability_zone( - settings.AVAILABILITY_ZONE_NAME, - settings.AVAILABILITY_ZONE_TYPE) + # be sure that an availability zone has been created + # if not, create it + try: + cloud_region.get_availability_zone_by_name( + settings.AVAILABILITY_ZONE_NAME) + except ValueError: + cloud_region.add_availability_zone( + settings.AVAILABILITY_ZONE_NAME, + settings.AVAILABILITY_ZONE_TYPE) diff --git a/src/onaptests/steps/instantiate/msb_k8s.py b/src/onaptests/steps/instantiate/msb_k8s.py new file mode 100644 index 0000000..eac8a75 --- /dev/null +++ b/src/onaptests/steps/instantiate/msb_k8s.py @@ -0,0 +1,45 @@ +"""MSB k8s instantiation module.""" +from onapsdk.configuration import settings +from onapsdk.msb.k8s import Instance + +from onaptests.steps.base import BaseStep +from onaptests.steps.onboard.msb_k8s import CreateProfileStep + + +class CreateInstanceStep(BaseStep): + """Create MSB k8s instance step.""" + + def __init__(self, cleanup: bool = False) -> None: + """Initialize step. + + Substeps: + - CreateProfileStep. + """ + super().__init__(cleanup=cleanup) + self.add_step(CreateProfileStep(cleanup=cleanup)) + self.instance: Instance = None + + @property + def description(self) -> str: + """Step description.""" + return "Create K8S instance." + + @property + def component(self) -> str: + """Component name.""" + return "K8S plugin" + + @BaseStep.store_state + def execute(self) -> None: + """Create instance using MSB K8S plugin.""" + super().execute() + self.instance = Instance.create(cloud_region_id=settings.CLOUD_REGION_ID, + profile_name=settings.PNF_PROFILE_NAME, + rb_name=settings.PNF_RB_NAME, + rb_version=settings.PNF_RB_VERSION) + + def cleanup(self) -> None: + """Delete instance.""" + if self.instance: + self.instance.delete() + return super().cleanup() diff --git a/src/onaptests/steps/onboard/cds.py b/src/onaptests/steps/onboard/cds.py index ed381ad..f7fc77a 100644 --- a/src/onaptests/steps/onboard/cds.py +++ b/src/onaptests/steps/onboard/cds.py @@ -52,6 +52,11 @@ class BootstrapBlueprintprocessor(CDSBaseStep): """Bootstrap blueprintsprocessor.""" def __init__(self, cleanup: bool = False) -> None: + """Initialize step. + + Substeps: + - ExposeCDSBlueprintprocessorNodePortStep. + """ super().__init__(cleanup=cleanup) self.add_step(ExposeCDSBlueprintprocessorNodePortStep(cleanup=cleanup)) @@ -62,7 +67,7 @@ class BootstrapBlueprintprocessor(CDSBaseStep): @BaseStep.store_state def execute(self) -> None: - """Bootsrap CDS blueprintprocessor""" + """Bootsrap CDS blueprintprocessor.""" super().execute() Blueprintprocessor.bootstrap() @@ -126,4 +131,4 @@ class CbaEnrichStep(CDSBaseStep): """ super().cleanup() - Path(settings.CDA_CBA_ENRICHED).unlink() + Path(settings.CDS_CBA_ENRICHED).unlink() diff --git a/src/onaptests/steps/onboard/msb_k8s.py b/src/onaptests/steps/onboard/msb_k8s.py new file mode 100644 index 0000000..cad471b --- /dev/null +++ b/src/onaptests/steps/onboard/msb_k8s.py @@ -0,0 +1,79 @@ +"""MSB k8s plugin module.""" +from onapsdk.configuration import settings +from onapsdk.msb.k8s import Definition, Profile + +from onaptests.steps.base import BaseStep +from onaptests.steps.cloud.cloud_region_create import CloudRegionCreateStep +from onaptests.steps.cloud.k8s_connectivity_info_create import K8SConnectivityInfoStep + + +class CreateDefinitionStep(BaseStep): + """Create definition step initialization.""" + + def __init__(self, cleanup: bool = False) -> None: + """Initialize step. + + Substeps: + - CloudRegionCreateStep, + - K8SConnectivityInfoStep. + """ + super().__init__(cleanup=cleanup) + self.add_step(CloudRegionCreateStep(cleanup=cleanup)) + self.add_step(K8SConnectivityInfoStep(cleanup=cleanup)) + self.definition: Definition = None + + @property + def description(self) -> str: + """Step description.""" + return "Create K8S definition." + + @property + def component(self) -> str: + """Component name.""" + return "K8S plugin" + + @BaseStep.store_state + def execute(self) -> None: + """Create definition.""" + super().execute() + with open(settings.PNF_DEFINITION_ATRIFACT_FILE_PATH, "rb") as definition_file: + self.definition = Definition.create(rb_name=settings.PNF_RB_NAME, + rb_version=settings.PNF_RB_VERSION) + self.definition.upload_artifact(definition_file.read()) + + +class CreateProfileStep(BaseStep): + """Create profile step.""" + + def __init__(self, cleanup: bool = False) -> None: + """Initialize step. + + Substeps: + - CreateDefinitionStep. + """ + super().__init__(cleanup=cleanup) + self.add_step(CreateDefinitionStep(cleanup=cleanup)) + self.profile: Profile = None + + @property + def description(self) -> str: + """Step description.""" + return "Create K8S profile." + + @property + def component(self) -> str: + """Component name.""" + return "K8S plugin" + + @BaseStep.store_state + def execute(self) -> None: + """Create profile.""" + super().execute() + definition: Definition = Definition.get_definition_by_name_version(\ + rb_name=settings.PNF_RB_NAME, + rb_version=settings.PNF_RB_VERSION) + with open(settings.PNF_PROFILE_ARTIFACT_FILE_PATH, "rb") as profile_file: + self.profile = definition.create_profile(profile_name=settings.PNF_PROFILE_NAME, + namespace=settings.K8S_NAMESPACE, + kubernetes_version=settings.K8S_VERSION) + self.profile.upload_artifact(profile_file.read()) diff --git a/src/onaptests/steps/simulator/pnf_simulator_cnf/__init__.py b/src/onaptests/steps/simulator/pnf_simulator_cnf/__init__.py new file mode 100644 index 0000000..477f7ae --- /dev/null +++ b/src/onaptests/steps/simulator/pnf_simulator_cnf/__init__.py @@ -0,0 +1 @@ +"""PNF simulator CNF package.""" diff --git a/src/onaptests/steps/simulator/pnf_simulator_cnf/pnf_register.py b/src/onaptests/steps/simulator/pnf_simulator_cnf/pnf_register.py new file mode 100644 index 0000000..7a0fbf2 --- /dev/null +++ b/src/onaptests/steps/simulator/pnf_simulator_cnf/pnf_register.py @@ -0,0 +1,144 @@ +# http://www.apache.org/licenses/LICENSE-2.0 +"""PNF simulator registration module.""" + +import time +from typing import Tuple + +import requests +from kubernetes import client, config, watch +from onapsdk.configuration import settings + +from onaptests.steps.base import BaseStep +from onaptests.steps.instantiate.msb_k8s import CreateInstanceStep +from onaptests.utils.exceptions import EnvironmentPreparationException + + +class PnfSimulatorCnfRegisterStep(BaseStep): + """PNF simulator registration step.""" + + def __init__(self, cleanup: bool = False) -> None: + """Initialize step. + + Substeps: + - CreateInstanceStep. + """ + super().__init__(cleanup=cleanup) + self.add_step(CreateInstanceStep(cleanup=cleanup)) + + @property + def description(self) -> str: + """Step description.""" + return "Register PNF simulator with VES." + + @property + def component(self) -> str: + """Component name.""" + return "Environment" + + @staticmethod + def is_pnf_pod_running(timeout_seconds=120) -> bool: + """Check if PNF simulator pod is running. + + Args: + timeout_seconds (int, optional): Timeout. Defaults to 120. + + Returns: + bool: True if PNF simulator pod is running, False otherwise + + """ + 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]: + """Static method to get VES ip address and port. + + Raises: + EnvironmentPreparationException: VES pod is not running + + Returns: + Tuple[str, str]: VES IP and port + + """ + 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") + + @BaseStep.store_state + def execute(self) -> None: + """Send PNF registration event.""" + super().execute() + if not self.is_pnf_pod_running(): + EnvironmentPreparationException("PNF simulator is not running") + time.sleep(5.0) # Let's still wait for PNF simulator to make sure it's initialized + ves_ip, ves_port = self.get_ves_ip_and_port() + response = requests.post( + "http://portal.api.simpledemo.onap.org:30999/simulator/event", + json={ + "vesServerUrl": f"https://{ves_ip}:{ves_port}/eventListener/v7", + "event": { + "event": { + "commonEventHeader": { + "domain": "pnfRegistration", + "eventId": "ORAN_SIM_400600927_2020-04-02T17:20:22.2Z", + "eventName": "pnfRegistration", + "eventType": "EventType5G", + "sequence": 0, + "priority": "Low", + "reportingEntityId": "", + "reportingEntityName": "ORAN_SIM_400600927", + "sourceId": "", + "sourceName": settings.SERVICE_INSTANCE_NAME, + "startEpochMicrosec": 94262132085746, + "lastEpochMicrosec": 94262132085746, + "nfNamingCode": "sdn controller", + "nfVendorName": "sdn", + "timeZoneOffset": "+00:00", + "version": "4.0.1", + "vesEventListenerVersion": "7.0.1" + }, + "pnfRegistrationFields": { + "pnfRegistrationFieldsVersion": "2.0", + "lastServiceDate": "2019-08-16", + "macAddress": "D7:64:C8:CC:E9:32", + "manufactureDate": "2019-08-16", + "modelNumber": "Simulated Device", + "oamV4IpAddress": "172.30.1.6", + "oamV6IpAddress": "0:0:0:0:0:ffff:a0a:011", + "serialNumber": "Simulated Device", + "softwareVersion": "2.3.5", + "unitFamily": "Simulated Device", + "unitType": "ntsim_oran", + "vendorName": "Melacon", + "additionalFields": { + "oamPort": "830", + "protocol": "SSH", + "username": "netconf", + "password": "netconf", + "reconnectOnChangedSchema": "false", + "sleep-factor": "1.5", + "tcpOnly": "false", + "connectionTimeout": "20000", + "maxConnectionAttempts": "100", + "betweenAttemptsTimeout": "2000", + "keepaliveDelay": "120" + } + } + } + } + } + ) + response.raise_for_status() |