Log exception stack trace on test failure
[testsuite/pythonsdk-tests.git] / src / onaptests / scenario / basic_vm_macro_stability.py
1 """Instantiate basic vm using SO macro flow."""
2 import logging
3 import time
4
5 from onapsdk.configuration import settings
6 from onapsdk.exceptions import SDKException
7 from xtesting.core import testcase
8
9 from onaptests.utils.exceptions import OnapTestException
10 from onaptests.steps.instantiate.service_macro import YamlTemplateServiceMacroInstantiateStep
11
12
13 class BasicVmMacroStability(testcase.TestCase):
14     """Instantiate a basic vm macro."""
15
16     __logger = logging.getLogger(__name__)
17
18     def __init__(self, **kwargs):
19         """Init Basic Macro use case."""
20         if "case_name" not in kwargs:
21             kwargs["case_name"] = 'basic_vm_macro_stability'
22         super().__init__(**kwargs)
23         self.__logger.debug("Basic VM macro stability init started")
24         self.test = YamlTemplateServiceMacroInstantiateStep(cleanup=settings.CLEANUP_FLAG)
25
26     def run(self):
27         """Run basic vm macro test."""
28         self.start_time = time.time()
29         try:
30             self.test.execute()
31             self.test.cleanup()
32             self.result = 100
33         except OnapTestException as exc:
34             self.result = 0
35             self.__logger.exception(exc.error_message)
36         except SDKException:
37             self.result = 0
38             self.__logger.exception("SDK Exception")
39         finally:
40             self.stop_time = time.time()
41
42     def clean(self):
43         """Generate report."""
44         self.test.reports_collection.generate_report()