From a38f76d28a6d60a92e81c1daeef23d9c8ceae4cd Mon Sep 17 00:00:00 2001 From: Robert Baldyga Date: Thu, 2 Jan 2020 17:03:21 +0100 Subject: [PATCH] tests: Update TF - plugins Signed-off-by: Robert Baldyga --- test/functional/api/cas/git.py | 4 +- test/functional/api/cas/installer.py | 10 +-- .../external_plugins}/__init__.py | 0 test/functional/test-framework | 2 +- test/functional/tests/conftest.py | 77 ++++++------------- 5 files changed, 31 insertions(+), 62 deletions(-) rename test/functional/{plugins => lib/external_plugins}/__init__.py (100%) diff --git a/test/functional/api/cas/git.py b/test/functional/api/cas/git.py index 3d1e019..df868e5 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.usr.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.usr.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 1edfe09..1690898 100644 --- a/test/functional/api/cas/installer.py +++ b/test/functional/api/cas/installer.py @@ -14,14 +14,14 @@ from test_utils.output import CmdException 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.usr.repo_dir}/", + f"{TestRun.usr.working_dir}/", exclude_list=["test/functional/results/"], delete=True) TestRun.LOGGER.info("Building Open CAS") output = TestRun.executor.run( - f"cd {TestRun.plugins['opencas'].working_dir} && " + f"cd {TestRun.usr.working_dir} && " "./configure && " "make -j") if output.exit_code != 0: @@ -29,7 +29,7 @@ def install_opencas(): TestRun.LOGGER.info("Installing Open CAS") output = TestRun.executor.run( - f"cd {TestRun.plugins['opencas'].working_dir} && " + f"cd {TestRun.usr.working_dir} && " f"make install") if output.exit_code != 0: raise CmdException("Error while installing Open CAS", output) @@ -49,7 +49,7 @@ def uninstall_opencas(): raise CmdException("Open CAS is not properly installed", output) else: TestRun.executor.run( - f"cd {TestRun.plugins['opencas'].working_dir} && " + f"cd {TestRun.usr.working_dir} && " f"make uninstall") if output.exit_code != 0: raise CmdException("There was an error during uninstall process", output) diff --git a/test/functional/plugins/__init__.py b/test/functional/lib/external_plugins/__init__.py similarity index 100% rename from test/functional/plugins/__init__.py rename to test/functional/lib/external_plugins/__init__.py diff --git a/test/functional/test-framework b/test/functional/test-framework index 588d6d7..4b4c66d 160000 --- a/test/functional/test-framework +++ b/test/functional/test-framework @@ -1 +1 @@ -Subproject commit 588d6d72d93de63fbed334832ef529cb3ade0077 +Subproject commit 4b4c66db919bb44bba06de5998e2e81517c7ea4b diff --git a/test/functional/tests/conftest.py b/test/functional/tests/conftest.py index cc02119..c0c75d1 100644 --- a/test/functional/tests/conftest.py +++ b/test/functional/tests/conftest.py @@ -9,7 +9,6 @@ import sys import pytest import yaml import traceback -from IPy import IP sys.path.append(os.path.join(os.path.dirname(__file__), "../test-framework")) @@ -23,15 +22,8 @@ from test_tools.device_mapper import DeviceMapper 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) -try: - from test_wrapper import plugin as test_wrapper -except ImportError as e: - print(e) - -class OpencasPlugin(metaclass=Singleton): +class Opencas(metaclass=Singleton): def __init__(self, repo_dir, working_dir): self.repo_dir = repo_dir self.working_dir = working_dir @@ -48,48 +40,31 @@ def pytest_runtest_setup(item): # User can also have own test wrapper, which runs test prepare, cleanup, etc. # Then it should be placed in plugins package - TestRun.prepare(item) + try: + with open(item.config.getoption('--dut-config')) as cfg: + dut_config = yaml.safe_load(cfg) + except Exception: + raise Exception("You need to specify DUT config. See the example_dut_config.py file.") - test_name = item.name.split('[')[0] - TestRun.LOGGER = create_log(item.config.getoption('--log-path'), test_name) + dut_config['plugins_dir'] = os.path.join(os.path.dirname(__file__), "../lib") + dut_config['opt_plugins'] = {"test_wrapper": {}} - with TestRun.LOGGER.step("Dut prepare"): - try: - try: - with open(item.config.getoption('--dut-config')) as cfg: - dut_config = yaml.safe_load(cfg) - except Exception: - TestRun.block("You need to specify DUT config. See the example_dut_config.py file.") + try: + TestRun.prepare(item, dut_config) - if 'test_wrapper' in sys.modules: - if 'ip' in dut_config: - try: - IP(dut_config['ip']) - except ValueError: - raise ValueError( - "IP address from configuration file is in invalid format.") - try: - dut_config = test_wrapper.prepare(dut_config) - except Exception as ex: - raise Exception(f"Exception occurred on test wrapper prepare stage:\n" - f"{str(ex)}\n{traceback.format_exc()}") - try: - TestRun.setup(dut_config) - except Exception as ex: - raise Exception(f"Exception occurred during test setup:\n" - f"{str(ex)}\n{traceback.format_exc()}") + test_name = item.name.split('[')[0] + TestRun.LOGGER = create_log(item.config.getoption('--log-path'), test_name) - if 'test_wrapper' in sys.modules: - test_wrapper.try_setup_serial_log(dut_config) + TestRun.setup() + except Exception as ex: + raise Exception(f"Exception occurred during test setup:\n" + f"{str(ex)}\n{traceback.format_exc()}") - TestRun.plugins['opencas'] = OpencasPlugin( - repo_dir=os.path.join(os.path.dirname(__file__), "../../.."), - working_dir=dut_config['working_dir']) + TestRun.usr = Opencas( + repo_dir=os.path.join(os.path.dirname(__file__), "../../.."), + working_dir=dut_config['working_dir']) - except Exception as exception: - raise Exception(f"Conftest prepare exception:\n" - f"{str(exception)}\n{traceback.format_exc()}") - TestRun.LOGGER.info(f"DUT info: {TestRun.dut}") + TestRun.LOGGER.info(f"DUT info: {TestRun.dut}") base_prepare(item) TestRun.LOGGER.write_to_command_log("Test body") @@ -128,17 +103,11 @@ def pytest_runtest_teardown(): TestRun.LOGGER.warning(f"Exception occured during platform cleanup.\n" f"{str(ex)}\n{traceback.format_exc()}") - if 'test_wrapper' in sys.modules: - try: - test_wrapper.cleanup() - except Exception as ex: - TestRun.LOGGER.warning(f"Exception occured during test wrapper cleanup.\n{str(ex)}" - f"\n{traceback.format_exc()}") - TestRun.LOGGER.end() if TestRun.executor: TestRun.LOGGER.get_additional_logs() Log.destroy() + TestRun.teardown() def pytest_configure(config): @@ -200,11 +169,11 @@ def base_prepare(item): if not create_partition_table(disk, PartitionTable.gpt): raise Exception(f"Failed to remove partitions from {disk}") - if get_force_param(item) and not TestRun.plugins['opencas'].already_updated: + if get_force_param(item) and not TestRun.usr.already_updated: installer.reinstall_opencas() elif not installer.check_if_installed(): installer.install_opencas() - TestRun.plugins['opencas'].already_updated = True + TestRun.usr.already_updated = True TestRun.LOGGER.add_build_info(f'Commit hash:') TestRun.LOGGER.add_build_info(f"{git.get_current_commit_hash()}") TestRun.LOGGER.add_build_info(f'Commit message:')