aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormrichomme <morgan.richomme@orange.com>2020-09-14 18:16:26 +0200
committermrichomme <morgan.richomme@orange.com>2020-09-16 17:54:32 +0200
commitb6f965609e956d9d26f3359b75ef2aaf1d596a5f (patch)
tree2204eb1557e22b2a46645ffa7566da3efe7d8ea8
parenta85a306fb5ee8259b09c392c03ac499c828b5597 (diff)
Add cleanup function
Issue-ID: TEST-240 Signed-off-by: mrichomme <morgan.richomme@orange.com> Change-Id: I784e958f869a0cbee702c915509fe80d37d44b65 Signed-off-by: mrichomme <morgan.richomme@orange.com>
-rw-r--r--run_basicvm_nomulticloud.py11
-rw-r--r--src/onaptests/configuration/clearwater_ims_nomulticloud_settings.py74
-rw-r--r--src/onaptests/configuration/ubuntu16_nomulticloud_settings.py11
-rw-r--r--src/onaptests/steps/instantiate/service_ala_carte.py29
-rw-r--r--src/onaptests/steps/instantiate/vf_module_ala_carte.py55
-rw-r--r--src/onaptests/steps/instantiate/vnf_ala_carte.py41
-rw-r--r--templates/vnf-services/clearwater-ims-service.yaml36
7 files changed, 242 insertions, 15 deletions
diff --git a/run_basicvm_nomulticloud.py b/run_basicvm_nomulticloud.py
index 03246cc..e6be410 100644
--- a/run_basicvm_nomulticloud.py
+++ b/run_basicvm_nomulticloud.py
@@ -1,4 +1,5 @@
import logging.config
+import time
from onapsdk.configuration import settings
from onaptests.steps.instantiate.vf_module_ala_carte import YamlTemplateVfModuleAlaCarteInstantiateStep
@@ -8,6 +9,14 @@ if __name__ == "__main__":
# logging configuration for onapsdk, it is not requested for onaptests
# Correction requested in onapsdk to avoid having this duplicate code
logging.config.dictConfig(settings.LOG_CONFIG)
+ logger = logging.getLogger("Instantiate Basic VM without multicloud")
- basic_vm_instantiate = YamlTemplateVfModuleAlaCarteInstantiateStep()
+ basic_vm_instantiate = YamlTemplateVfModuleAlaCarteInstantiateStep(
+ cleanup=settings.CLEANUP_FLAG)
basic_vm_instantiate.execute()
+ if settings.CLEANUP_FLAG:
+ time.sleep(settings.CLEANUP_ACTIVITY_TIMER)
+ try:
+ basic_vm_instantiate.cleanup()
+ except ValueError as error:
+ logger.info("service instance deleted as expected {0}".format(error))
diff --git a/src/onaptests/configuration/clearwater_ims_nomulticloud_settings.py b/src/onaptests/configuration/clearwater_ims_nomulticloud_settings.py
new file mode 100644
index 0000000..d640894
--- /dev/null
+++ b/src/onaptests/configuration/clearwater_ims_nomulticloud_settings.py
@@ -0,0 +1,74 @@
+import os
+import openstack
+from yaml import load
+
+from .settings import * # pylint: disable=W0614
+
+""" Specific clearwater IMS without multicloud."""
+
+# pylint: disable=bad-whitespace
+# The ONAP part
+USE_MULTICLOUD = False
+SERVICE_YAML_TEMPLATE = "templates/vnf-services/clearwater-ims-service.yaml"
+CLEANUP_FLAG = True
+CLEANUP_ACTIVITY_TIMER = 60 # nb of seconds before cleanup in case cleanup option is set
+VENDOR_NAME = "clearwater-ims_vendor"
+
+VF_NAME = "clearwater-ims_ubuntu_vf"
+VSP_NAME = "clearwater-ims_ubuntu_vsp"
+try:
+ # Try to retrieve the SERVICE NAME from the yaml file
+ with open(SERVICE_YAML_TEMPLATE, "r") as yaml_template:
+ yaml_config_file = load(yaml_template)
+ SERVICE_NAME = next(iter(yaml_config_file.keys()))
+except ValueError:
+ SERVICE_NAME = "" # Fill me
+
+CLOUD_REGION_CLOUD_OWNER = "clearwater-ims-cloud-owner"
+CLOUD_REGION_TYPE = "openstack"
+CLOUD_REGION_VERSION = "openstack"
+
+AVAILABILITY_ZONE_NAME = "clearwater-ims-availability-zone"
+AVAILABILITY_ZONE_TYPE = "nova"
+COMPLEX_PHYSICAL_LOCATION_ID = "lannion"
+COMPLEX_DATA_CENTER_CODE = "1234-5"
+
+GLOBAL_CUSTOMER_ID = "clearwater-ims-customer"
+
+OWNING_ENTITY = "clearwater-ims-oe"
+PROJECT = "clearwater-ims-project"
+LINE_OF_BUSINESS = "clearwater-ims-lob"
+PLATFORM = "clearwater-ims-platform"
+
+SERVICE_INSTANCE_NAME = "clearwater-ims_service_instance_7"
+
+VSP_FILE_PATH = "templates/heat_files/clearwater_ims/clearwater_ims.zip"
+
+
+# The cloud Part
+# Assuming a cloud.yaml is available, use the openstack client
+# to retrieve cloud info and avoid data duplication
+TEST_CLOUD = os.getenv('OS_TEST_CLOUD')
+try:
+ if TEST_CLOUD is not None:
+ cloud = openstack.connect(cloud=TEST_CLOUD)
+ VIM_USERNAME = cloud.config.auth['username']
+ VIM_PASSWORD = cloud.config.auth['password']
+ VIM_SERVICE_URL = cloud.config.auth['auth_url']
+ TENANT_ID = cloud.config.auth['project_id']
+ TENANT_NAME = cloud.config.auth['project_name']
+ CLOUD_REGION_ID = cloud.config.region_name
+ CLOUD_DOMAIN = cloud.config.auth['project_domain_name']
+ else:
+ raise KeyError
+except KeyError:
+ # If you do not use the cloud.yaml as imput for your openstack
+ # put the input data here
+ # Note if 1 parameter is missing in the clouds.yaml, we fallback here
+ TENANT_ID = "" # Fill me
+ TENANT_NAME = "" # Fill me
+ VIM_USERNAME = "" # Fill me
+ VIM_PASSWORD = "" # Fill me
+ VIM_SERVICE_URL = "" # Fill me
+ CLOUD_REGION_ID = "RegionOne" # Update me if needed
+ CLOUD_DOMAIN = "Default" # Update me if needed
diff --git a/src/onaptests/configuration/ubuntu16_nomulticloud_settings.py b/src/onaptests/configuration/ubuntu16_nomulticloud_settings.py
index ae716e7..84f994a 100644
--- a/src/onaptests/configuration/ubuntu16_nomulticloud_settings.py
+++ b/src/onaptests/configuration/ubuntu16_nomulticloud_settings.py
@@ -4,14 +4,17 @@ from yaml import load
from .settings import * # pylint: disable=W0614
-""" Specific ubuntu16 without multicloud and without yaml config scenario."""
+""" Specific ubuntu16 without multicloud."""
# pylint: disable=bad-whitespace
# The ONAP part
USE_MULTICLOUD = False
SERVICE_YAML_TEMPLATE = "templates/vnf-services/ubuntu16test-service.yaml"
-
+CLEANUP_FLAG = True
+CLEANUP_ACTIVITY_TIMER = 10 # nb of seconds before cleanup in case cleanup option is set
VENDOR_NAME = "basicvm_vendor"
+
+VF_NAME = "basicvm_ubuntu_vf"
VSP_NAME = "basicvm_ubuntu_vsp"
try:
# Try to retrieve the SERVICE NAME from the yaml file
@@ -21,8 +24,6 @@ try:
except ValueError:
SERVICE_NAME = "" # Fill me
-VF_NAME = "basicvm_ubuntu_vf"
-
CLOUD_REGION_CLOUD_OWNER = "basicvm-cloud-owner"
CLOUD_REGION_TYPE = "openstack"
CLOUD_REGION_VERSION = "openstack"
@@ -39,7 +40,7 @@ PROJECT = "basicvm-project"
LINE_OF_BUSINESS = "basicvm-lob"
PLATFORM = "basicvm-platform"
-SERVICE_INSTANCE_NAME = "basicvm_ubuntu16_service_instance_3"
+SERVICE_INSTANCE_NAME = "basicvm_ubuntu16_service_instance"
VSP_FILE_PATH = "templates/heat_files/ubuntu16/ubuntu16.zip"
diff --git a/src/onaptests/steps/instantiate/service_ala_carte.py b/src/onaptests/steps/instantiate/service_ala_carte.py
index 4742d61..249a171 100644
--- a/src/onaptests/steps/instantiate/service_ala_carte.py
+++ b/src/onaptests/steps/instantiate/service_ala_carte.py
@@ -3,7 +3,7 @@ from uuid import uuid4
from yaml import load
from onapsdk.aai.cloud_infrastructure import CloudRegion, Tenant
-from onapsdk.aai.business import Customer
+from onapsdk.aai.business import Customer, ServiceInstance, ServiceSubscription
from onapsdk.aai.business.owning_entity import OwningEntity as AaiOwningEntity
from onapsdk.configuration import settings
from onapsdk.sdc.service import Service
@@ -84,6 +84,8 @@ class YamlTemplateServiceAlaCarteInstantiateStep(YamlTemplateBaseStep):
super().__init__(cleanup=cleanup)
self._yaml_template: dict = None
self._service_instance_name: str = None
+ self._service_instance: str = None
+
self.add_step(YamlTemplateServiceOnboardStep(cleanup))
self.add_step(ConnectServiceSubToCloudRegionStep(cleanup))
@@ -178,3 +180,28 @@ class YamlTemplateServiceAlaCarteInstantiateStep(YamlTemplateBaseStep):
time.sleep(10)
if service_instantiation.failed:
raise Exception("Service instantiation failed")
+ else:
+ service_subscription: ServiceSubscription = customer.get_service_subscription_by_service_type(self.service_name)
+ self._service_instance: ServiceInstance = service_subscription.get_service_instance_by_name(self.service_instance_name)
+
+
+ def cleanup(self) -> None:
+ """Cleanup Service.
+
+ Raises:
+ Exception: Service cleaning failed
+
+ """
+ super().cleanup()
+ service_deletion = self._service_instance.delete()
+ nb_try = 0
+ nb_try_max = 30
+ while not service_deletion.finished and nb_try < nb_try_max:
+ self._logger.info("Wait for Service deletion")
+ nb_try += 1
+ time.sleep(15)
+ if service_deletion.finished:
+ self._logger.info("Service %s deleted", self._service_instance_name)
+ else:
+ self._logger.error("Service deletion %s failed", self._service_instance_name)
+ raise Exception("Service cleanup failed")
diff --git a/src/onaptests/steps/instantiate/vf_module_ala_carte.py b/src/onaptests/steps/instantiate/vf_module_ala_carte.py
index b4ff002..3a22159 100644
--- a/src/onaptests/steps/instantiate/vf_module_ala_carte.py
+++ b/src/onaptests/steps/instantiate/vf_module_ala_carte.py
@@ -3,6 +3,7 @@ from typing import Iterable
from uuid import uuid4
from yaml import load
+from onapsdk.aai.cloud_infrastructure import CloudRegion, Tenant
from onapsdk.aai.business import Customer, ServiceInstance, ServiceSubscription
from onapsdk.configuration import settings
from onapsdk.so.instantiation import VnfParameter
@@ -10,7 +11,6 @@ from onapsdk.so.instantiation import VnfParameter
from ..base import YamlTemplateBaseStep
from .vnf_ala_carte import YamlTemplateVnfAlaCarteInstantiateStep
-
class YamlTemplateVfModuleAlaCarteInstantiateStep(YamlTemplateBaseStep):
"""Instantiate vf module a'la carte using YAML template."""
@@ -21,8 +21,10 @@ class YamlTemplateVfModuleAlaCarteInstantiateStep(YamlTemplateBaseStep):
- YamlTemplateVnfAlaCarteInstantiateStep.
"""
super().__init__(cleanup=cleanup)
+
self._yaml_template: dict = None
self._service_instance_name: str = None
+ self._service_instance: ServiceInstance = None
self.add_step(YamlTemplateVnfAlaCarteInstantiateStep(cleanup))
@property
@@ -107,12 +109,53 @@ class YamlTemplateVfModuleAlaCarteInstantiateStep(YamlTemplateBaseStep):
super().execute()
customer: Customer = Customer.get_by_global_customer_id(settings.GLOBAL_CUSTOMER_ID)
service_subscription: ServiceSubscription = customer.get_service_subscription_by_service_type(self.service_name)
- service_instance: ServiceInstance = service_subscription.get_service_instance_by_name(self.service_instance_name)
- for vnf_instance in service_instance.vnf_instances:
- vf_module_instantiation = vnf_instance.add_vf_module(
- vnf_instance.vnf.vf_module,
- vnf_parameters= self.get_vnf_parameters(vnf_instance.vnf.name))
+ self._service_instance: ServiceInstance = service_subscription.get_service_instance_by_name(self.service_instance_name)
+ 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)
+
+ for vnf_instance in self._service_instance.vnf_instances:
+ # possible to have several moduels for 1 VNF
+ for vf_module in vnf_instance.vnf.vf_modules:
+ vf_module_instantiation = vnf_instance.add_vf_module(
+ vf_module,
+ cloud_region,
+ tenant,
+ self._service_instance_name,
+ vnf_parameters= self.get_vnf_parameters(vnf_instance.vnf.name))
while not vf_module_instantiation.finished:
time.sleep(10)
if vf_module_instantiation.failed:
raise Exception("Vf module instantiation failed")
+
+
+ def cleanup(self) -> None:
+ """Cleanup Vf module.
+
+ Raises:
+ Exception: Vf module cleaning failed
+
+ """
+ super().cleanup()
+ for vnf_instance in self._service_instance.vnf_instances:
+ self._logger.debug("VNF instance %s found in Service Instance ",
+ vnf_instance.name)
+ self._logger.info("Get VF Modules")
+ for vf_module in vnf_instance.vf_modules:
+ self._logger.info("Delete VF Module %s",
+ vf_module.name)
+ vf_module_deletion = vf_module.delete()
+ nb_try = 0
+ nb_try_max = 30
+
+ while not vf_module_deletion.finished and nb_try < nb_try_max:
+ self._logger.info("Wait for vf module deletion")
+ nb_try += 1
+ time.sleep(20)
+ if vf_module_deletion.finished:
+ self._logger.info("VfModule %s deleted", vf_module.name)
+ else:
+ self._logger.error("VfModule deletion %s failed", vf_module.name)
+ raise Exception("Vf module cleanup failed")
diff --git a/src/onaptests/steps/instantiate/vnf_ala_carte.py b/src/onaptests/steps/instantiate/vnf_ala_carte.py
index 7701630..f52857d 100644
--- a/src/onaptests/steps/instantiate/vnf_ala_carte.py
+++ b/src/onaptests/steps/instantiate/vnf_ala_carte.py
@@ -2,6 +2,7 @@ import time
from uuid import uuid4
from yaml import load
+from onapsdk.aai.cloud_infrastructure import CloudRegion, Tenant
from onapsdk.aai.business import Customer, ServiceInstance, ServiceSubscription
from onapsdk.configuration import settings
from onapsdk.sdc.service import Service
@@ -23,6 +24,7 @@ class YamlTemplateVnfAlaCarteInstantiateStep(YamlTemplateBaseStep):
super().__init__(cleanup=cleanup)
self._yaml_template: dict = None
self._service_instance_name: str = None
+ self._service_instance: ServiceInstance = None
self.add_step(YamlTemplateServiceAlaCarteInstantiateStep(cleanup))
@property
@@ -88,12 +90,47 @@ class YamlTemplateVnfAlaCarteInstantiateStep(YamlTemplateBaseStep):
service: Service = Service(self.service_name)
customer: Customer = Customer.get_by_global_customer_id(settings.GLOBAL_CUSTOMER_ID)
service_subscription: ServiceSubscription = customer.get_service_subscription_by_service_type(self.service_name)
- service_instance: ServiceInstance = service_subscription.get_service_instance_by_name(self.service_instance_name)
+ self._service_instance: ServiceInstance = service_subscription.get_service_instance_by_name(self.service_instance_name)
line_of_business: LineOfBusiness = LineOfBusiness(settings.LINE_OF_BUSINESS)
platform: Platform = Platform(settings.PLATFORM)
+ 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)
for idx, vnf in enumerate(service.vnfs):
- vnf_instantiation = service_instance.add_vnf(vnf, line_of_business, platform, f"{self.service_instance_name}_vnf_{idx}")
+ vnf_instantiation = self._service_instance.add_vnf(
+ vnf,
+ line_of_business,
+ platform,
+ cloud_region,
+ tenant,
+ f"{self.service_instance_name}_vnf_{idx}")
while not vnf_instantiation.finished:
time.sleep(10)
if vnf_instantiation.failed:
raise Exception("Vnf instantiation failed")
+
+ def cleanup(self) -> None:
+ """Cleanup VNF.
+
+ Raises:
+ Exception: VNF cleaning failed
+
+ """
+ super().cleanup()
+
+ for vnf_instance in self._service_instance.vnf_instances:
+ vnf_deletion = vnf_instance.delete()
+ nb_try = 0
+ nb_try_max = 30
+
+ while not vnf_deletion.finished and nb_try < nb_try_max:
+ self._logger.info("Wait for vnf deletion")
+ nb_try += 1
+ time.sleep(15)
+ if vnf_deletion.finished:
+ self._logger.info("VNF %s deleted", vnf_instance.name)
+ else:
+ self._logger.error("VNF deletion %s failed", vnf_instance.name)
+ raise Exception("VNF Cleanup failed")
diff --git a/templates/vnf-services/clearwater-ims-service.yaml b/templates/vnf-services/clearwater-ims-service.yaml
new file mode 100644
index 0000000..51543da
--- /dev/null
+++ b/templates/vnf-services/clearwater-ims-service.yaml
@@ -0,0 +1,36 @@
+---
+clearwater_ims:
+ vnfs:
+ - vnf_name: clearwater_ims_vnf
+ heat_files_to_upload: templates/heat_files/clearwater_ims/clearwater_ims.zip
+ vnf_parameters: [
+ {"name": "public_net_id",
+ "value": "8b0fb448-0daf-4344-a958-74852c5a0530"},
+ {"name": "bono_image_name",
+ "value": "ubuntu-16.04-daily"},
+ {"name": "dime_image_name",
+ "value": "ubuntu-16.04-daily"},
+ {"name": "dns_image_name",
+ "value": "ubuntu-16.04-daily"},
+ {"name": "ellis_image_name",
+ "value": "ubuntu-16.04-daily"},
+ {"name": "homer_image_name",
+ "value": "ubuntu-16.04-daily"},
+ {"name": "robot_image_name",
+ "value": "ubuntu-16.04-daily"},
+ {"name": "sprout_image_name",
+ "value": "ubuntu-16.04-daily"},
+ {"name": "vellum_image_name",
+ "value": "ubuntu-16.04-daily"},
+ {"name": "dns_ip",
+ "value": "8.8.8.8"},
+ {"name": "clearwater_pub_key",
+ "value": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAA\
+BAQDY15cdBmIs2XOpe4EiFCsaY6bmUmK/GysMoLl4UG51JCfJwvwoWCoA+6mDIbymZxhxq9IGx\
+ilp/yTA6WQ9s/5pBag1cUMJmFuda9PjOkXl04jgqh5tR6I+GZ97AvCg93KAECis5ubSqw1xOCj4\
+utfEUtPoF1OuzqM/lE5mY4N6VKXn+fT7pCD6cifBEs6JHhVNvs5OLLp/tO8Pa3kKYQOdyS0xc3r\
+h+t2lrzvKUSWGZbX+dLiFiEpjsUL3tDqzkEMNUn4pdv69OJuzWHCxRWPfdrY9Wg0j3mJesP29EBh\
+t+w+EC9/kBKq+1VKdmsXUXAcjEvjovVL8l1BrX3BY0R8D imported-openssh-key"
+ },
+ {"name": "clearwater_key_name",
+ "value": "cleouverte"}]