Merge "Refactor code a bit to make status test able running on multiple namespaces"
[testsuite/pythonsdk-tests.git] / src / onaptests / scenario / basic_cnf.py
1 #!/usr/bin/env python
2 """Basic CNF test case."""
3 import logging
4 import time
5
6 from xtesting.core import testcase
7 from onapsdk.configuration import settings
8 from onapsdk.exceptions import SDKException
9
10 from onaptests.steps.instantiate.vf_module_ala_carte import YamlTemplateVfModuleAlaCarteInstantiateStep
11 from onaptests.utils.exceptions import OnapTestException
12
13 class BasicCnf(testcase.TestCase):
14     """Onboard then instantiate a simple CNF with ONAP."""
15
16     __logger = logging.getLogger(__name__)
17
18     def __init__(self, **kwargs):
19         """Init BasicCnf."""
20         if "case_name" not in kwargs:
21             kwargs["case_name"] = 'basic_cnf'
22         super(BasicCnf, self).__init__(**kwargs)
23         self.__logger.debug("BasicCnf init started")
24         self.test = YamlTemplateVfModuleAlaCarteInstantiateStep(
25                 cleanup=settings.CLEANUP_FLAG)
26         self.start_time = None
27         self.stop_time = None
28         self.result = 0
29
30     def run(self):
31         """Run onap_tests with basic_cnf VM."""
32         self.start_time = time.time()
33         self.__logger.debug("start time")
34         try:
35             self.test.execute()
36             self.__logger.info("basic_cnf successfully created")
37             # The cleanup is part of the test, not only a teardown action
38             if settings.CLEANUP_FLAG:
39                 self.__logger.info("basic_cnf cleanup called")
40                 time.sleep(settings.CLEANUP_ACTIVITY_TIMER)
41                 self.test.cleanup()
42                 self.result = 100
43             else:
44                 self.__logger.info("No cleanup requested. Test completed.")
45                 self.result = 100
46         except OnapTestException as exc:
47             self.result = 0
48             self.__logger.error(exc.error_message)
49         except SDKException:
50             self.result = 0
51             self.__logger.error("SDK exception")
52         finally:
53             self.stop_time = time.time()
54
55     def clean(self):
56         """Clean Additional resources if needed."""
57         self.__logger.info("Generate Test report")
58         self.test.reports_collection.generate_report()