From e4a31f51a5db5ffcfa19e58ccd67492aa8c716b4 Mon Sep 17 00:00:00 2001 From: Robert Baldyga Date: Wed, 30 Oct 2019 16:00:37 +0100 Subject: [PATCH 1/3] Set working dir Signed-off-by: Robert Baldyga --- test/functional/tests/conftest.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test/functional/tests/conftest.py b/test/functional/tests/conftest.py index 9ae61f6..3f1b9bd 100644 --- a/test/functional/tests/conftest.py +++ b/test/functional/tests/conftest.py @@ -74,6 +74,7 @@ def pytest_runtest_setup(item): TestRun.plugins['opencas'] = { 'repo_dir': os.path.join(os.path.dirname(__file__), "../../.."), + 'working_dir': dut_config['working_dir'], 'already_updated': False } except Exception as e: From 01cd284a485fe91c831f081d82161dbd0b68f3d1 Mon Sep 17 00:00:00 2001 From: Robert Baldyga Date: Tue, 29 Oct 2019 18:22:22 +0100 Subject: [PATCH 2/3] Update installer to use local repository As tests are now part of OCL repository, we prefer to always run tests from local repository version on the same version of OCL, so instead of cloning OCL from GitHub we just copy local repository to DUT. This also simplifies running remote tests in development environment without need to push work-in-progress commits to GitHub or installing OCL manually on DUT. Signed-off-by: Robert Baldyga --- test/functional/api/cas/installer.py | 69 ++++++++++------------------ test/functional/test-framework | 2 +- 2 files changed, 26 insertions(+), 45 deletions(-) diff --git a/test/functional/api/cas/installer.py b/test/functional/api/cas/installer.py index dd0f021..9255fe2 100644 --- a/test/functional/api/cas/installer.py +++ b/test/functional/api/cas/installer.py @@ -9,70 +9,51 @@ import logging from tests import conftest from core.test_run import TestRun -LOGGER = logging.getLogger(__name__) - -opencas_repo_name = "open-cas-linux" - def install_opencas(): - LOGGER.info("Cloning Open CAS repository.") - TestRun.executor.run(f"if [ -d {opencas_repo_name} ]; " - f"then rm -rf {opencas_repo_name}; fi") - output = TestRun.executor.run( - "git clone --recursive https://github.com/Open-CAS/open-cas-linux.git") - if output.exit_code != 0: - raise Exception(f"Error while cloning repository: {output.stdout}\n{output.stderr}") + TestRun.LOGGER.info("Copying Open CAS repository to DUT") + TestRun.executor.rsync( + 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 {opencas_repo_name} && " - f"git fetch --all && " - f"git fetch --tags {conftest.get_remote()} +refs/pull/*:refs/remotes/origin/pr/*") - if output.exit_code != 0: - raise Exception( - f"Failed to fetch: " - f"{output.stdout}\n{output.stderr}") - - output = TestRun.executor.run(f"cd {opencas_repo_name} && " - f"git checkout {conftest.get_branch()}") - if output.exit_code != 0: - raise Exception( - f"Failed to checkout to {conftest.get_branch()}: {output.stdout}\n{output.stderr}") - - LOGGER.info("Open CAS make and make install.") - output = TestRun.executor.run( - f"cd {opencas_repo_name} && " - "git submodule update --init --recursive && " + f"cd {TestRun.plugins['opencas']['working_dir']} && " "./configure && " "make -j") if output.exit_code != 0: - raise Exception( + TestRun.exception( f"Make command executed with nonzero status: {output.stdout}\n{output.stderr}") - output = TestRun.executor.run(f"cd {opencas_repo_name} && " - f"make install") + TestRun.LOGGER.info("Installing Open CAS") + output = TestRun.executor.run( + f"cd {TestRun.plugins['opencas']['working_dir']} && " + f"make install") if output.exit_code != 0: - raise Exception( + TestRun.exception( f"Error while installing Open CAS: {output.stdout}\n{output.stderr}") - LOGGER.info("Check if casadm is properly installed.") + TestRun.LOGGER.info("Check if casadm is properly installed.") output = TestRun.executor.run("casadm -V") if output.exit_code != 0: - raise Exception( + TestRun.exception( f"'casadm -V' command returned an error: {output.stdout}\n{output.stderr}") else: - LOGGER.info(output.stdout) + TestRun.LOGGER.info(output.stdout) def uninstall_opencas(): - LOGGER.info("Uninstalling Open CAS.") + TestRun.LOGGER.info("Uninstalling Open CAS") output = TestRun.executor.run("casadm -V") if output.exit_code != 0: - raise Exception("Open CAS is not properly installed.") + TestRun.exception("Open CAS is not properly installed") else: - TestRun.executor.run(f"cd {opencas_repo_name} && " - f"make uninstall") + TestRun.executor.run( + f"cd {TestRun.plugins['opencas']['working_dir']} && " + f"make uninstall") if output.exit_code != 0: - raise Exception( + TestRun.exception( f"There was an error during uninstall process: {output.stdout}\n{output.stderr}") @@ -83,11 +64,11 @@ def reinstall_opencas(): def check_if_installed(): - LOGGER.info("Check if Open-CAS-Linux is installed.") + TestRun.LOGGER.info("Check if Open-CAS-Linux is installed") output = TestRun.executor.run("which casadm") if output.exit_code == 0: - LOGGER.info("CAS is installed") + TestRun.LOGGER.info("CAS is installed") return True - LOGGER.info("CAS not installed") + TestRun.LOGGER.info("CAS not installed") return False diff --git a/test/functional/test-framework b/test/functional/test-framework index de0721e..b008160 160000 --- a/test/functional/test-framework +++ b/test/functional/test-framework @@ -1 +1 @@ -Subproject commit de0721eb52fbe548a8e7810913151e2e37c66d1c +Subproject commit b0081604becc2b9ae23e0de5c29427c59966d68d From 7dd5a6fc1255476e9474ac764039aea22d72cb60 Mon Sep 17 00:00:00 2001 From: Robert Baldyga Date: Wed, 30 Oct 2019 16:44:30 +0100 Subject: [PATCH 3/3] tests: Remove unused adoptions Signed-off-by: Robert Baldyga --- test/functional/tests/conftest.py | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/test/functional/tests/conftest.py b/test/functional/tests/conftest.py index 3f1b9bd..97eaffc 100644 --- a/test/functional/tests/conftest.py +++ b/test/functional/tests/conftest.py @@ -27,15 +27,6 @@ except ImportError: pass -pytest_options = {} - - -@pytest.fixture(scope="session", autouse=True) -def get_pytest_options(request): - pytest_options["remote"] = request.config.getoption("--remote") - pytest_options["branch"] = request.config.getoption("--repo-tag") - - 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'. @@ -121,20 +112,10 @@ def pytest_addoption(parser): parser.addoption("--dut-config", action="store", default="None") parser.addoption("--log-path", action="store", default=f"{os.path.join(os.path.dirname(__file__), '../results')}") - parser.addoption("--remote", action="store", default="origin") - parser.addoption("--repo-tag", action="store", default="master") parser.addoption("--force-reinstall", action="store", default="False") # TODO: investigate whether it is possible to pass the last param as bool -def get_remote(): - return pytest_options["remote"] - - -def get_branch(): - return pytest_options["branch"] - - def unmount_cas_devices(): output = TestRun.executor.run("cat /proc/mounts | grep cas") # If exit code is '1' but stdout is empty, there is no mounted cas devices