7 import onaptests.utils.exceptions as onap_test_exceptions
10 def get_entrypoints():
11 config = configparser.ConfigParser()
12 config.read('setup.cfg')
13 entry_points = config['entry_points']['xtesting.testcase']
14 config = configparser.ConfigParser()
15 config.read_string(f"[entry_points]\n{entry_points}")
16 entry_points = config['entry_points']
17 entry_points_result = {}
18 for test_name, entrypoint in entry_points.items():
19 test_scenario_module, test_class = entrypoint.split(":")
20 entry_points_result[test_name] = {
21 "module": test_scenario_module,
24 return entry_points_result
26 def run_test(test_name, validation, entry_point, settings_module):
27 settings_env = "ONAP_PYTHON_SDK_SETTINGS"
29 validation_env = "PYTHON_SDK_TESTS_VALIDATION"
30 os.environ[validation_env] = "True"
31 os.environ[settings_env] = f"onaptests.configuration.{test_name}_settings"
32 if not settings_module:
33 settings_module = importlib.import_module("onapsdk.configuration")
35 settings_module = importlib.reload(settings_module)
36 settings = settings_module.settings
37 # logging configuration for onapsdk, it is not requested for onaptests
38 # Correction requested in onapsdk to avoid having this duplicate code
39 logging.config.dictConfig(settings.LOG_CONFIG)
40 logger = logging.getLogger(test_name)
41 logger.info(f"Running {test_name} test")
43 test_module = importlib.import_module(entry_point["module"])
45 test_instance = getattr(test_module, entry_point["class"])()
50 test_instance.validate_execution()
51 except onap_test_exceptions.TestConfigurationException:
52 logger.error("Status Check configuration error")
53 return settings_module
56 """Script is used to run one or all the tests.
58 You need to specify a name of the test like 'basic_cps' or
59 keyword 'all' that tells to run all the tests. You can also
60 pass a second argument of any value that tells the script to run
61 test(s) in the validation mode that checks only a basic setup of
62 steps (like cleanup) and their execution in a certain order.
65 - python run_test.py basic_vm_macro
66 - python run_test.py basic_cps validation
67 - python run_test.py all true
70 print("Required test name argument missing", file=sys.stderr)
71 print("\nExample: python run_test.py basic_cps\n")
73 validation = len(argv) > 1
75 entry_points = get_entrypoints()
76 if test_name == "all":
77 settings_module = None
78 for test_name, entry_point in entry_points.items():
79 settings_module = run_test(test_name, validation, entry_point, settings_module)
81 entry_point = entry_points[test_name]
82 run_test(test_name, validation, entry_point, None)
84 if __name__ == "__main__":