From eedb4ded7ca5f99131eafd4b6ca13b311fc13e6e Mon Sep 17 00:00:00 2001 From: Katarzyna Lapinska Date: Tue, 5 Nov 2019 15:00:47 +0100 Subject: [PATCH] Make opencas plugin as singleton class --- test/functional/api/cas/git.py | 4 ++-- test/functional/api/cas/installer.py | 10 +++++----- test/functional/test-framework | 2 +- test/functional/tests/conftest.py | 21 ++++++++++++++------- 4 files changed, 22 insertions(+), 15 deletions(-) diff --git a/test/functional/api/cas/git.py b/test/functional/api/cas/git.py index 52da21c..3d1e019 100644 --- a/test/functional/api/cas/git.py +++ b/test/functional/api/cas/git.py @@ -10,12 +10,12 @@ from connection.local_executor import LocalExecutor def get_current_commit_hash(): local_executor = LocalExecutor() return local_executor.run( - f"cd {TestRun.plugins['opencas']['repo_dir']} &&" + f"cd {TestRun.plugins['opencas'].repo_dir} &&" f'git show HEAD -s --pretty=format:"%H"').stdout def get_current_commit_message(): local_executor = LocalExecutor() return local_executor.run( - f"cd {TestRun.plugins['opencas']['repo_dir']} &&" + f"cd {TestRun.plugins['opencas'].repo_dir} &&" f'git show HEAD -s --pretty=format:"%B"').stdout diff --git a/test/functional/api/cas/installer.py b/test/functional/api/cas/installer.py index 9255fe2..f3059a3 100644 --- a/test/functional/api/cas/installer.py +++ b/test/functional/api/cas/installer.py @@ -13,13 +13,13 @@ from core.test_run import TestRun def install_opencas(): TestRun.LOGGER.info("Copying Open CAS repository to DUT") TestRun.executor.rsync( - f"{TestRun.plugins['opencas']['repo_dir']}/", - f"{TestRun.plugins['opencas']['working_dir']}/", + f"{TestRun.plugins['opencas'].repo_dir}/", + f"{TestRun.plugins['opencas'].working_dir}/", delete=True) TestRun.LOGGER.info("Building Open CAS") output = TestRun.executor.run( - f"cd {TestRun.plugins['opencas']['working_dir']} && " + f"cd {TestRun.plugins['opencas'].working_dir} && " "./configure && " "make -j") if output.exit_code != 0: @@ -28,7 +28,7 @@ def install_opencas(): TestRun.LOGGER.info("Installing Open CAS") output = TestRun.executor.run( - f"cd {TestRun.plugins['opencas']['working_dir']} && " + f"cd {TestRun.plugins['opencas'].working_dir} && " f"make install") if output.exit_code != 0: TestRun.exception( @@ -50,7 +50,7 @@ def uninstall_opencas(): TestRun.exception("Open CAS is not properly installed") else: TestRun.executor.run( - f"cd {TestRun.plugins['opencas']['working_dir']} && " + f"cd {TestRun.plugins['opencas'].working_dir} && " f"make uninstall") if output.exit_code != 0: TestRun.exception( diff --git a/test/functional/test-framework b/test/functional/test-framework index b008160..b3f62cb 160000 --- a/test/functional/test-framework +++ b/test/functional/test-framework @@ -1 +1 @@ -Subproject commit b0081604becc2b9ae23e0de5c29427c59966d68d +Subproject commit b3f62cb3d65ea42c05f297340ca5a1e9ef70fab0 diff --git a/test/functional/tests/conftest.py b/test/functional/tests/conftest.py index cf6a1aa..b3b8db9 100644 --- a/test/functional/tests/conftest.py +++ b/test/functional/tests/conftest.py @@ -18,6 +18,7 @@ from api.cas import casadm from api.cas import git from test_utils.os_utils import Udev from log.logger import create_log, Log +from test_utils.singleton import Singleton plugins_dir = os.path.join(os.path.dirname(__file__), "../plugins") sys.path.append(plugins_dir) @@ -27,6 +28,13 @@ except ImportError: pass +class OpencasPlugin(metaclass=Singleton): + def __init__(self, repo_dir, working_dir): + self.repo_dir = repo_dir + self.working_dir = working_dir + self.already_updated = False + + def pytest_runtest_setup(item): # There should be dut config file added to config package and # pytest should be executed with option --dut-config=conf_name'. @@ -63,11 +71,10 @@ def pytest_runtest_setup(item): if 'test_wrapper' in sys.modules: test_wrapper.try_setup_serial_log(dut_config) - TestRun.plugins['opencas'] = { - 'repo_dir': os.path.join(os.path.dirname(__file__), "../../.."), - 'working_dir': dut_config['working_dir'], - 'already_updated': False - } + TestRun.plugins['opencas'] = OpencasPlugin( + repo_dir=os.path.join(os.path.dirname(__file__), "../../.."), + working_dir=dut_config['working_dir']) + except Exception as e: TestRun.LOGGER.exception(f"{str(e)}\n{traceback.format_exc()}") TestRun.LOGGER.info(f"DUT info: {TestRun.dut}") @@ -161,11 +168,11 @@ def base_prepare(item): except Exception: pass # TODO: Reboot DUT if test is executed remotely - if get_force_param(item) and not TestRun.plugins['opencas']['already_updated']: + if get_force_param(item) and not TestRun.plugins['opencas'].already_updated: installer.reinstall_opencas() elif not installer.check_if_installed(): installer.install_opencas() - TestRun.plugins['opencas']['already_updated'] = True + TestRun.plugins['opencas'].already_updated = True from api.cas import init_config init_config.create_default_init_config() TestRun.LOGGER.add_build_info(f'Commit hash:')