From 1b96f9912524dddf6d656e096626800df32db0be Mon Sep 17 00:00:00 2001 From: Michal Jagiello Date: Wed, 10 Feb 2021 21:19:59 +0000 Subject: [INT] Catch all onaptests and onapsdk exceptions for scenarios Catch onaptests and onapsdk exceptions in scenario to generate test report if test fails Issue-ID: INT-1852 Signed-off-by: Michal Jagiello Change-Id: Id9772fea10dc5aa323437e72c6fe5ddb4c6caabb --- src/onaptests/scenario/basic_cnf.py | 5 +++-- src/onaptests/scenario/basic_network.py | 4 ++-- src/onaptests/scenario/basic_onboard.py | 5 +++-- src/onaptests/scenario/basic_vm.py | 6 ++---- src/onaptests/scenario/cds_blueprint_enrichment.py | 10 ++++++++-- src/onaptests/scenario/clearwater_ims.py | 5 +++-- src/onaptests/scenario/pnf_macro.py | 15 +++++++++++++-- 7 files changed, 34 insertions(+), 16 deletions(-) diff --git a/src/onaptests/scenario/basic_cnf.py b/src/onaptests/scenario/basic_cnf.py index 306205f..4d98398 100644 --- a/src/onaptests/scenario/basic_cnf.py +++ b/src/onaptests/scenario/basic_cnf.py @@ -5,9 +5,10 @@ import time from xtesting.core import testcase from onapsdk.configuration import settings +from onapsdk.exceptions import SDKException -import onaptests.utils.exceptions as onap_test_exceptions from onaptests.steps.instantiate.vf_module_ala_carte import YamlTemplateVfModuleAlaCarteInstantiateStep +from onaptests.utils.exceptions import OnapTestException class BasicCnf(testcase.TestCase): """Onboard then instantiate a simple CNF with ONAP.""" @@ -42,7 +43,7 @@ class BasicCnf(testcase.TestCase): else: self.__logger.info("No cleanup requested. Test completed.") self.result = 100 - except onap_test_exceptions.OnapTestException as exc: + except (OnapTestException, SDKException) as exc: self.result = 0 self.__logger.error(exc.error_message) finally: diff --git a/src/onaptests/scenario/basic_network.py b/src/onaptests/scenario/basic_network.py index 7a0b9f7..1b7bd14 100644 --- a/src/onaptests/scenario/basic_network.py +++ b/src/onaptests/scenario/basic_network.py @@ -7,8 +7,8 @@ from xtesting.core import testcase from onapsdk.configuration import settings from onapsdk.exceptions import SDKException -import onaptests.utils.exceptions as onap_test_exceptions from onaptests.steps.instantiate.vl_ala_carte import YamlTemplateVlAlaCarteInstantiateStep +from onaptests.utils.exceptions import OnapTestException class BasicNetwork(testcase.TestCase): """Onboard then instantiate a simple Network with ONAP.""" @@ -47,7 +47,7 @@ class BasicNetwork(testcase.TestCase): else: self.__logger.info("No cleanup requested. Test completed.") self.result = 100 - except onap_test_exceptions.OnapTestException as exc: + except (OnapTestException, SDKException) as exc: self.result = 0 self.__logger.error(exc.error_message) finally: diff --git a/src/onaptests/scenario/basic_onboard.py b/src/onaptests/scenario/basic_onboard.py index f81a38c..6277f9d 100644 --- a/src/onaptests/scenario/basic_onboard.py +++ b/src/onaptests/scenario/basic_onboard.py @@ -4,8 +4,9 @@ import logging import time from xtesting.core import testcase from onapsdk.configuration import settings -import onaptests.utils.exceptions as onap_test_exceptions +from onapsdk.exceptions import SDKException from onaptests.steps.onboard.service import YamlTemplateServiceOnboardStep +from onaptests.utils.exceptions import OnapTestException class BasicOnboard(testcase.TestCase): """Onboard a simple VM with ONAP.""" @@ -33,7 +34,7 @@ class BasicOnboard(testcase.TestCase): self.test.execute() self.__logger.info("VNF basic_vm successfully onboarded") self.result = 100 - except onap_test_exceptions.OnapTestException as exc: + except (OnapTestException, SDKException) as exc: self.result = 0 self.__logger.error(exc.error_message) finally: diff --git a/src/onaptests/scenario/basic_vm.py b/src/onaptests/scenario/basic_vm.py index 1dac176..b758088 100644 --- a/src/onaptests/scenario/basic_vm.py +++ b/src/onaptests/scenario/basic_vm.py @@ -7,8 +7,8 @@ from xtesting.core import testcase from onapsdk.configuration import settings from onapsdk.exceptions import SDKException -import onaptests.utils.exceptions as onap_test_exceptions from onaptests.steps.instantiate.vf_module_ala_carte import YamlTemplateVfModuleAlaCarteInstantiateStep +from onaptests.utils.exceptions import OnapTestException class BasicVm(testcase.TestCase): """Onboard then instantiate a simple VM with ONAP.""" @@ -43,11 +43,9 @@ class BasicVm(testcase.TestCase): else: self.__logger.info("No cleanup requested. Test completed.") self.result = 100 - except onap_test_exceptions.OnapTestException as exc: + except (OnapTestException, SDKException) as exc: self.result = 0 self.__logger.error(exc.error_message) - except SDKException as error: - self.__logger.info("service error {0}".format(error)) finally: self.stop_time = time.time() diff --git a/src/onaptests/scenario/cds_blueprint_enrichment.py b/src/onaptests/scenario/cds_blueprint_enrichment.py index 502c92d..c1df63e 100644 --- a/src/onaptests/scenario/cds_blueprint_enrichment.py +++ b/src/onaptests/scenario/cds_blueprint_enrichment.py @@ -5,9 +5,11 @@ import logging import time from onapsdk.configuration import settings +from onapsdk.exceptions import SDKException from xtesting.core import testcase from onaptests.steps.onboard.cds import CbaEnrichStep +from onaptests.utils.exceptions import OnapTestException class CDSBlueprintEnrichment(testcase.TestCase): @@ -30,8 +32,12 @@ class CDSBlueprintEnrichment(testcase.TestCase): def run(self): self.__logger.debug("CDS blueprint enrichment run") self.start_time = time.time() - self.test.execute() - self.result = 100 + try: + self.test.execute() + self.result = 100 + except (OnapTestException, SDKException) as exc: + self.result = 0 + self.__logger.error(exc.error_message) self.stop_time = time.time() def clean(self): diff --git a/src/onaptests/scenario/clearwater_ims.py b/src/onaptests/scenario/clearwater_ims.py index 8a68fa9..2a035bb 100644 --- a/src/onaptests/scenario/clearwater_ims.py +++ b/src/onaptests/scenario/clearwater_ims.py @@ -5,9 +5,10 @@ import time from xtesting.core import testcase from onapsdk.configuration import settings +from onapsdk.exceptions import SDKException -import onaptests.utils.exceptions as onap_test_exceptions from onaptests.steps.instantiate.vf_module_ala_carte import YamlTemplateVfModuleAlaCarteInstantiateStep +from onaptests.utils.exceptions import OnapTestException class ClearwaterIms(testcase.TestCase): """Onboard then instantiate a clearwater vIMS with ONAP.""" @@ -44,7 +45,7 @@ class ClearwaterIms(testcase.TestCase): self.__logger.info("No cleanup requested. Test completed.") self.result = 100 self.stop_time = time.time() - except onap_test_exceptions.OnapTestException as exc: + except (OnapTestException, SDKException) as exc: self.result = 0 self.__logger.error(exc.error_message) finally: diff --git a/src/onaptests/scenario/pnf_macro.py b/src/onaptests/scenario/pnf_macro.py index baa44b4..a045a37 100644 --- a/src/onaptests/scenario/pnf_macro.py +++ b/src/onaptests/scenario/pnf_macro.py @@ -1,13 +1,16 @@ """Instantiate service with PNF using SO macro flow.""" +import time from yaml import load from xtesting.core import testcase from onapsdk.configuration import settings +from onapsdk.exceptions import SDKException from onaptests.steps.base import YamlTemplateBaseStep from onaptests.steps.onboard.cds import CbaEnrichStep from onaptests.steps.simulator.pnf_simulator_cnf.pnf_register import PnfSimulatorCnfRegisterStep from onaptests.steps.instantiate.service_macro import YamlTemplateServiceMacroInstantiateStep +from onaptests.utils.exceptions import OnapTestException class PnfMacroScenarioStep(YamlTemplateBaseStep): @@ -107,8 +110,16 @@ class PnfMacro(testcase.TestCase): def run(self): """Run PNF macro test.""" - self.test.execute() - self.test.cleanup() + self.start_time = time.time() + try: + self.test.execute() + self.test.cleanup() + self.result = 100 + except (OnapTestException, SDKException) as exc: + self.result = 0 + self.__logger.error(exc.error_message) + finally: + self.stop_time = time.time() def clean(self): """Generate report.""" -- cgit 1.2.3-korg