aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormrichomme <morgan.richomme@orange.com>2020-10-13 12:52:24 +0200
committermrichomme <morgan.richomme@orange.com>2020-10-14 11:27:35 +0200
commitb7b9796d16a2e53e0e58ae9888dade1e89a0cc19 (patch)
tree379944906ed2c5a837dc1e09810235fd03a37e8b
parent6276bed4df9b8458c4b6805edab81652fb15de76 (diff)
Improve xtesting integration
All the exceptions shall be caught by the use case Issue-ID: TEST-257 Signed-off-by: mrichomme <morgan.richomme@orange.com> Change-Id: Ie2762ad869d8984ce2125db4a8ef4990ee50f82a Signed-off-by: mrichomme <morgan.richomme@orange.com>
-rw-r--r--src/onaptests/configuration/clearwater_ims_nomulticloud_settings.py32
-rw-r--r--src/onaptests/configuration/ubuntu16_nomulticloud_settings.py38
-rw-r--r--src/onaptests/scenario/basic_vm.py48
-rw-r--r--src/onaptests/scenario/clearwater_ims.py34
-rw-r--r--src/onaptests/steps/instantiate/service_ala_carte.py7
-rw-r--r--src/onaptests/steps/instantiate/vf_module_ala_carte.py5
-rw-r--r--src/onaptests/steps/instantiate/vnf_ala_carte.py5
-rw-r--r--src/onaptests/steps/reports_collection.py6
-rw-r--r--src/onaptests/utils/__init__.py1
-rw-r--r--src/onaptests/utils/exceptions.py51
10 files changed, 144 insertions, 83 deletions
diff --git a/src/onaptests/configuration/clearwater_ims_nomulticloud_settings.py b/src/onaptests/configuration/clearwater_ims_nomulticloud_settings.py
index 0b13762..1a1cb3c 100644
--- a/src/onaptests/configuration/clearwater_ims_nomulticloud_settings.py
+++ b/src/onaptests/configuration/clearwater_ims_nomulticloud_settings.py
@@ -31,7 +31,6 @@ try:
SERVICE_NAME = next(iter(yaml_config_file.keys()))
except ValueError:
SERVICE_NAME = "" # Fill me
- VSP_FILE_PATH = "" # Fill me
CLOUD_REGION_CLOUD_OWNER = "clearwater-ims-cloud-owner"
CLOUD_REGION_TYPE = "openstack"
@@ -55,26 +54,11 @@ SERVICE_INSTANCE_NAME = "clearwater-ims_service_instance"
# 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
+cloud = openstack.connect(cloud=TEST_CLOUD)
+VIM_USERNAME = cloud.config.auth.get('username','Fill me')
+VIM_PASSWORD = cloud.config.auth.get('password','Fill me')
+VIM_SERVICE_URL = cloud.config.auth.get('auth_url','Fill me')
+TENANT_ID = cloud.config.auth.get('project_id','Fill me')
+TENANT_NAME = cloud.config.auth.get('project_name','Fill me')
+CLOUD_REGION_ID = cloud.config.get('region_name','RegionOne')
+CLOUD_DOMAIN = cloud.config.auth.get('project_domain_name','Default')
diff --git a/src/onaptests/configuration/ubuntu16_nomulticloud_settings.py b/src/onaptests/configuration/ubuntu16_nomulticloud_settings.py
index 310fafc..21795ac 100644
--- a/src/onaptests/configuration/ubuntu16_nomulticloud_settings.py
+++ b/src/onaptests/configuration/ubuntu16_nomulticloud_settings.py
@@ -3,6 +3,7 @@ import openstack
import sys
from yaml import load
+import onaptests.utils.exceptions as onap_test_exceptions
from .settings import * # pylint: disable=W0614
""" Specific ubuntu16 without multicloud."""
@@ -11,6 +12,7 @@ from .settings import * # pylint: disable=W0614
# The ONAP part
SERVICE_DETAILS="Onboarding, distribution and instanitation of an Ubuntu VM using à la carte"
SERVICE_COMPONENTS="SDC, DMAAP, AAI, SO, SDNC"
+
USE_MULTICLOUD = False
# Set ONLY_INSTANTIATE to true to run an instantiation without repeating
# onboarding and related AAI configuration (Cloud config)
@@ -26,8 +28,8 @@ try:
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
+except (FileNotFoundError, ValueError):
+ raise onap_test_exceptions.TestConfigurationException
CLEANUP_FLAG = True
CLEANUP_ACTIVITY_TIMER = 10 # nb of seconds before cleanup in case cleanup option is set
@@ -58,26 +60,12 @@ SERVICE_INSTANCE_NAME = "basicvm_ubuntu16_service_instance"
# 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
+TEST_CLOUD = os.getenv('OS_TEST_CLOUD')
+cloud = openstack.connect(cloud=TEST_CLOUD)
+VIM_USERNAME = cloud.config.auth.get('username','Fill me')
+VIM_PASSWORD = cloud.config.auth.get('password','Fill me')
+VIM_SERVICE_URL = cloud.config.auth.get('auth_url','Fill me')
+TENANT_ID = cloud.config.auth.get('project_id','Fill me')
+TENANT_NAME = cloud.config.auth.get('project_name','Fill me')
+CLOUD_REGION_ID = cloud.config.auth.get('region_name','RegionOne')
+CLOUD_DOMAIN = cloud.config.auth.get('project_domain_name','Default')
diff --git a/src/onaptests/scenario/basic_vm.py b/src/onaptests/scenario/basic_vm.py
index 48fd169..35cedbc 100644
--- a/src/onaptests/scenario/basic_vm.py
+++ b/src/onaptests/scenario/basic_vm.py
@@ -5,6 +5,7 @@ import time
from xtesting.core import testcase
from onapsdk.configuration import settings
+import onaptests.utils.exceptions as onap_test_exceptions
from onaptests.steps.instantiate.vf_module_ala_carte import YamlTemplateVfModuleAlaCarteInstantiateStep
class BasicVm(testcase.TestCase):
@@ -29,18 +30,41 @@ class BasicVm(testcase.TestCase):
"""Run onap_tests with ubuntu16 VM."""
self.start_time = time.time()
self.__logger.debug("start time")
- self.test.execute()
- self.__logger.info("VNF basic_vm successfully created")
- self.stop_time = time.time()
- # The cleanup is part of the test, not only a teardown action
- if settings.CLEANUP_FLAG:
- self.__logger.info("VNF basic_vm cleanup called")
- time.sleep(settings.CLEANUP_ACTIVITY_TIMER)
- self.test.cleanup()
- self.result = 100
- else:
- self.__logger.info("No cleanup requested. Test completed.")
- self.result = 100
+ try:
+ self.test.execute()
+ self.__logger.info("VNF basic_vm successfully created")
+ # The cleanup is part of the test, not only a teardown action
+ if settings.CLEANUP_FLAG:
+ self.__logger.info("VNF basic_vm cleanup called")
+ time.sleep(settings.CLEANUP_ACTIVITY_TIMER)
+ self.test.cleanup()
+ self.result = 100
+ else:
+ self.__logger.info("No cleanup requested. Test completed.")
+ self.result = 100
+ except onap_test_exceptions.TestConfigurationException:
+ self.result = 0
+ self.__logger.error("Basic VM configuration error")
+ except onap_test_exceptions.ServiceInstantiateException:
+ self.result = 0
+ self.__logger.error("Basic VM instantiation error")
+ except onap_test_exceptions.ServiceCleanupException:
+ self.result = 0
+ self.__logger.error("Basic VM instance cleanup error")
+ except onap_test_exceptions.VnfInstantiateException:
+ self.result = 0
+ self.__logger.error("Basic VM Vnf instantiation error")
+ except onap_test_exceptions.VnfCleanupException:
+ self.result = 0
+ self.__logger.error("Basic VM Vnf instance cleanup error")
+ except onap_test_exceptions.VfModuleInstantiateException:
+ self.result = 0
+ self.__logger.error("Basic VM Module instantiation error")
+ except onap_test_exceptions.VfModuleCleanupException:
+ self.__logger.error("Basic VM Module cleanup failed.")
+ self.result = 0
+ finally:
+ self.stop_time = time.time()
def clean(self):
"""Clean Additional resources if needed."""
diff --git a/src/onaptests/scenario/clearwater_ims.py b/src/onaptests/scenario/clearwater_ims.py
index 83a654e..0177e02 100644
--- a/src/onaptests/scenario/clearwater_ims.py
+++ b/src/onaptests/scenario/clearwater_ims.py
@@ -29,19 +29,27 @@ class ClearwaterIms(testcase.TestCase):
"""Run vIMS test."""
self.start_time = time.time()
self.__logger.debug("start time")
- self.test.execute()
- self.__logger.info("VNF clearwater IMS successfully created")
- self.stop_time = time.time()
- # The cleanup is part of the test, not only a teardown action
- if settings.CLEANUP_FLAG:
- self.__logger.info("VNF clearwater IMS cleanup called")
- time.sleep(settings.CLEANUP_ACTIVITY_TIMER)
- self.test.cleanup()
- self.result = 100
- else:
- self.__logger.info("No cleanup requested. Test completed.")
- self.result = 100
+ try:
+ self.test.execute()
+ self.__logger.info("VNF clearwater IMS successfully created")
+ # The cleanup is part of the test, not only a teardown action
+ if settings.CLEANUP_FLAG:
+ self.__logger.info("VNF clearwater IMS cleanup called")
+ time.sleep(settings.CLEANUP_ACTIVITY_TIMER)
+ self.test.cleanup()
+ self.result = 100
+ else:
+ self.__logger.info("No cleanup requested. Test completed.")
+ self.result = 100
+ self.stop_time = time.time()
+ except:
+ self.__logger.error("Clearwater IMS test case failed.")
+ self.result = 0
+ self.stop_time = time.time()
def clean(self):
"""Clean Additional resources if needed."""
- pass
+ try:
+ self.test.reports_collection.generate_report()
+ except:
+ self.__logger.error("Impossible to generate reporting")
diff --git a/src/onaptests/steps/instantiate/service_ala_carte.py b/src/onaptests/steps/instantiate/service_ala_carte.py
index b3b56c4..3a99f4d 100644
--- a/src/onaptests/steps/instantiate/service_ala_carte.py
+++ b/src/onaptests/steps/instantiate/service_ala_carte.py
@@ -10,6 +10,7 @@ from onapsdk.sdc.service import Service
from onapsdk.so.instantiation import ServiceInstantiation
from onapsdk.vid import Project
+import onaptests.utils.exceptions as onap_test_exceptions
from ..base import BaseStep, YamlTemplateBaseStep
from ..cloud.connect_service_subscription_to_cloud_region import ConnectServiceSubToCloudRegionStep
from ..onboard.service import ServiceOnboardStep, YamlTemplateServiceOnboardStep
@@ -192,7 +193,7 @@ class YamlTemplateServiceAlaCarteInstantiateStep(YamlTemplateBaseStep):
if distribution_completed is False:
self._logger.error(
"Service Distribution for %s failed !!",service.name)
- exit(1)
+ raise onap_test_exceptions.ServiceDistributionException
service_instantiation = ServiceInstantiation.instantiate_so_ala_carte(
service,
@@ -206,7 +207,7 @@ class YamlTemplateServiceAlaCarteInstantiateStep(YamlTemplateBaseStep):
while not service_instantiation.finished:
time.sleep(10)
if service_instantiation.failed:
- raise Exception("Service instantiation failed")
+ raise onap_test_exceptions.ServiceInstantiateException
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)
@@ -231,4 +232,4 @@ class YamlTemplateServiceAlaCarteInstantiateStep(YamlTemplateBaseStep):
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")
+ raise onap_test_exceptions.ServiceCleanupException
diff --git a/src/onaptests/steps/instantiate/vf_module_ala_carte.py b/src/onaptests/steps/instantiate/vf_module_ala_carte.py
index 14ef2d8..b5fd7eb 100644
--- a/src/onaptests/steps/instantiate/vf_module_ala_carte.py
+++ b/src/onaptests/steps/instantiate/vf_module_ala_carte.py
@@ -8,6 +8,7 @@ from onapsdk.aai.business import Customer, ServiceInstance, ServiceSubscription
from onapsdk.configuration import settings
from onapsdk.so.instantiation import VnfParameter
+import onaptests.utils.exceptions as onap_test_exceptions
from ..base import YamlTemplateBaseStep
from .vnf_ala_carte import YamlTemplateVnfAlaCarteInstantiateStep
@@ -129,7 +130,7 @@ class YamlTemplateVfModuleAlaCarteInstantiateStep(YamlTemplateBaseStep):
while not vf_module_instantiation.finished:
time.sleep(10)
if vf_module_instantiation.failed:
- raise Exception("Vf module instantiation failed")
+ raise onap_test_exceptions.VfModuleInstantiateException
def cleanup(self) -> None:
@@ -159,4 +160,4 @@ class YamlTemplateVfModuleAlaCarteInstantiateStep(YamlTemplateBaseStep):
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")
+ raise onap_test_exceptions.VfModuleCleanupException
diff --git a/src/onaptests/steps/instantiate/vnf_ala_carte.py b/src/onaptests/steps/instantiate/vnf_ala_carte.py
index 0ab498d..d529219 100644
--- a/src/onaptests/steps/instantiate/vnf_ala_carte.py
+++ b/src/onaptests/steps/instantiate/vnf_ala_carte.py
@@ -8,6 +8,7 @@ from onapsdk.configuration import settings
from onapsdk.sdc.service import Service
from onapsdk.vid import LineOfBusiness, Platform
+import onaptests.utils.exceptions as onap_test_exceptions
from ..base import YamlTemplateBaseStep
from .service_ala_carte import YamlTemplateServiceAlaCarteInstantiateStep
@@ -110,7 +111,7 @@ class YamlTemplateVnfAlaCarteInstantiateStep(YamlTemplateBaseStep):
while not vnf_instantiation.finished:
time.sleep(10)
if vnf_instantiation.failed:
- raise Exception("Vnf instantiation failed")
+ raise onap_test_exceptions.VnfInstantiateException
def cleanup(self) -> None:
"""Cleanup VNF.
@@ -134,4 +135,4 @@ class YamlTemplateVnfAlaCarteInstantiateStep(YamlTemplateBaseStep):
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")
+ raise onap_test_exceptions.VnfCleanupException
diff --git a/src/onaptests/steps/reports_collection.py b/src/onaptests/steps/reports_collection.py
index 62c0447..bcb199f 100644
--- a/src/onaptests/steps/reports_collection.py
+++ b/src/onaptests/steps/reports_collection.py
@@ -43,12 +43,14 @@ class ReportsCollection:
usecase = settings.SERVICE_NAME
try:
details = settings.SERVICE_DETAILS
- except:
+ except NameError:
details = ""
+
try:
components = settings.SERVICE_COMPONENTS
- except:
+ except NameError:
components = ""
+
log_path = settings.LOG_CONFIG['handlers']['file']['filename']
jinja_env = Environment(
autoescape=select_autoescape(['html']),
diff --git a/src/onaptests/utils/__init__.py b/src/onaptests/utils/__init__.py
new file mode 100644
index 0000000..a9de3b8
--- /dev/null
+++ b/src/onaptests/utils/__init__.py
@@ -0,0 +1 @@
+"""Scenario package."""
diff --git a/src/onaptests/utils/exceptions.py b/src/onaptests/utils/exceptions.py
new file mode 100644
index 0000000..f80fc09
--- /dev/null
+++ b/src/onaptests/utils/exceptions.py
@@ -0,0 +1,51 @@
+#!/usr/bin/env python
+
+# Copyright (c) 2018 Orange and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+"""Module to define pythonsdk-test exceptions."""
+
+__author__ = ("Morgan Richomme <morgan.richomme@orange.com>")
+
+
+class TestConfigurationException(Exception):
+ """Raise when configutation of the use cases is not complete or buggy."""
+
+
+class ServiceDistributionException(Exception):
+ """Service not properly distributed."""
+
+
+class ServiceInstantiateException(Exception):
+ """Service cannot be instantiate."""
+
+
+class ServiceCleanupException(Exception):
+ """Service cannot be cleaned."""
+
+
+class VnfInstantiateException(Exception):
+ """VNF cannot be instantiate."""
+
+
+class VnfCleanupException(Exception):
+ """VNF cannot be cleaned."""
+
+
+class VfModuleInstantiateException(Exception):
+ """VF Module cannot be instantiate."""
+
+
+class VfModuleCleanupException(Exception):
+ """VF Module cannot be instantiate."""
+
+
+class NetworkInstantiateException(Exception):
+ """Network cannot be instantiate."""
+
+
+class NetworkCleanupException(Exception):
+ """Network cannot be cleaned."""