From ca587b01192ce516ece7a7a46acc3b8832e1fef1 Mon Sep 17 00:00:00 2001 From: srijan-sivakumar Date: Fri, 23 Apr 2021 01:42:47 +0530 Subject: [PATCH] Cluster creation and glusterd start in framework The handling of cluster start and glusterd start will be done at the main level. If it is nonDisruptive TCs, then the cluster or glusterd working won't be tampered with unless and until there's some serious issue or a new bug. It is only for the disruptive cases wherein the cluster recreation and glusterd startup will come handy. Fixes: #220 Signed-off-by: srijan-sivakumar --- core/environ.py | 35 +++++++++++++++++++++++++++++++++++ core/redant_main.py | 8 +++++++- core/runner_thread.py | 5 +++-- core/test_runner.py | 2 +- tests/parent_test.py | 7 ++++--- 5 files changed, 50 insertions(+), 7 deletions(-) create mode 100644 core/environ.py diff --git a/core/environ.py b/core/environ.py new file mode 100644 index 000000000..d099fec30 --- /dev/null +++ b/core/environ.py @@ -0,0 +1,35 @@ +import sys +sys.path.insert(1, ".") +from common.mixin import RedantMixin + +class environ: + """ + Framework level control on the gluster environment. Controlling both + the setup and the complete cleanup. + """ + + def __init__(self, config_hashm : dict, log_path : str, log_level : str): + """ + Redant mixin obj to be used for server setup and teardown operations + has to be created. + """ + self.server_details = config_hashm['servers_info'] + machine_details = {**self.server_details} + self.redant = RedantMixin(machine_details) + self.redant.init_logger("environ", log_path, log_level) + self.redant.establish_connection() + + def setup_env(self): + """ + Setting up of the environment before the TC execution begins. + """ + self.redant.start_glusterd() + self.redant.create_cluster(list(self.server_details.keys())) + + def teardown_env(self): + """ + The teardown of the complete environment once the test framework + ends. + """ + pass + diff --git a/core/redant_main.py b/core/redant_main.py index 2cffc8eb6..7fcc2e8cf 100644 --- a/core/redant_main.py +++ b/core/redant_main.py @@ -13,7 +13,7 @@ from test_list_builder import TestListBuilder from test_runner import TestRunner from result_handler import ResultHandler - +from environ import environ def pars_args(): """ @@ -80,11 +80,17 @@ def main(): # Pre test run test list builder is modified. test_cases_dict = TestListBuilder.pre_test_run_list_modify(test_cases_dict) + # Environment setup. + env_obj = environ(config_hashmap, args.log_dir+"/main.log", args.log_level) + env_obj.setup_env() + # invoke the test_runner. TestRunner.init(test_cases_dict, config_hashmap, args.log_dir, args.log_level, args.semaphore_count) all_test_results = TestRunner.run_tests() + # Environment cleanup. TBD. + print(f"\nTotal time taken by the framework: {time.time()-start} sec") ResultHandler.handle_results(all_test_results, args.result_path) diff --git a/core/runner_thread.py b/core/runner_thread.py index 53a1cb6e6..9abcaefb2 100644 --- a/core/runner_thread.py +++ b/core/runner_thread.py @@ -11,10 +11,11 @@ class RunnerThread: """ def __init__(self, mname: str, tc_class, config_hashmap: dict, - volume_type: str, log_path: str, log_level: str): + volume_type: str, log_path: str, log_level: str, + thread_flag : bool): # Creating the test case object from the test case. self.tc_obj = tc_class(mname, config_hashmap, volume_type, - log_path, log_level) + thread_flag, log_path, log_level) self.run_test_func = getattr(self.tc_obj, "parent_run_test") self.terminate_test_func = getattr(self.tc_obj, "terminate") self.test_stats = { diff --git a/core/test_runner.py b/core/test_runner.py index 82b991fe7..2911cdad1 100644 --- a/core/test_runner.py +++ b/core/test_runner.py @@ -83,7 +83,7 @@ def _run_test(cls, test_dict: dict, thread_flag: bool): runner_thread_obj = RunnerThread(str(uuid.uuid1().int), tc_class, cls.config_hashmap, test_dict["volType"], tc_log_path, - cls.log_level) + cls.log_level, thread_flag) test_stats = runner_thread_obj.run_thread() test_stats['timeTaken'] = time.time() - start diff --git a/tests/parent_test.py b/tests/parent_test.py index a87bf7f30..be677090d 100644 --- a/tests/parent_test.py +++ b/tests/parent_test.py @@ -15,7 +15,7 @@ class ParentTest(metaclass=abc.ABCMeta): """ def __init__(self, mname: str, config_hashmap: dict, volume_type: str, - log_path: str, log_level: str = 'I'): + thread_flag: bool, log_path: str, log_level: str = 'I'): """ Creates volume And runs the specific component in the @@ -35,8 +35,9 @@ def __init__(self, mname: str, config_hashmap: dict, volume_type: str, self.server_list = list(server_details.keys()) self.client_list = list(client_details.keys()) - self.redant.start_glusterd() - self.redant.create_cluster(self.server_list) + if not thread_flag: + self.redant.start_glusterd() + self.redant.create_cluster(self.server_list) def _configure(self, mname: str, server_details: dict, client_details: dict, log_path: str, log_level: str):