[EXCEPTIONS] Distinguish onaptests and onapsdk exception
[testsuite/pythonsdk-tests.git] / src / onaptests / scenario / cds_blueprint_enrichment.py
1 #!/usr/bin/env python
2 """Simple CDS blueprint erichment test scenario."""
3
4 import logging
5 import time
6
7 from onapsdk.configuration import settings
8 from onapsdk.exceptions import SDKException
9 from xtesting.core import testcase
10
11 from onaptests.steps.onboard.cds import CbaEnrichStep
12 from onaptests.utils.exceptions import OnapTestException
13
14
15 class CDSBlueprintEnrichment(testcase.TestCase):
16     """Enrich simple blueprint using CDS blueprintprocessor."""
17
18     __logger = logging.getLogger(__name__)
19
20     def __init__(self, **kwargs):
21         """Init CDS blueprint enrichment use case."""
22         if "case_name" not in kwargs:
23             kwargs["case_name"] = 'basic_cds'
24         super(CDSBlueprintEnrichment, self).__init__(**kwargs)
25         self.__logger.debug("CDS blueprint enrichment initialization")
26         self.test = CbaEnrichStep(
27                 cleanup=settings.CLEANUP_FLAG)
28         self.start_time = None
29         self.stop_time = None
30         self.result = 0
31
32     def run(self):
33         self.__logger.debug("CDS blueprint enrichment run")
34         self.start_time = time.time()
35         try:
36             self.test.execute()
37             self.result = 100
38         except OnapTestException as exc:
39             self.result = 0
40             self.__logger.error(exc.error_message)
41         except SDKException:
42             self.result = 0
43             self.__logger.error("SDK Exception")
44         finally:
45             self.stop_time = time.time()
46
47     def clean(self):
48         """Clean Additional resources if needed."""
49         self.__logger.info("Generate Test report")
50         self.test.reports_collection.generate_report()