Merge pull request #172 from robertbaldyga/update-installer

tests: Update installer
This commit is contained in:
Michał Mielewczyk 2019-11-05 14:49:39 +01:00 committed by GitHub
commit 5d643a48d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 63 deletions

View File

@ -9,70 +9,51 @@ import logging
from tests import conftest from tests import conftest
from core.test_run import TestRun from core.test_run import TestRun
LOGGER = logging.getLogger(__name__)
opencas_repo_name = "open-cas-linux"
def install_opencas(): def install_opencas():
LOGGER.info("Cloning Open CAS repository.") TestRun.LOGGER.info("Copying Open CAS repository to DUT")
TestRun.executor.run(f"if [ -d {opencas_repo_name} ]; " TestRun.executor.rsync(
f"then rm -rf {opencas_repo_name}; fi") f"{TestRun.plugins['opencas']['repo_dir']}/",
output = TestRun.executor.run( f"{TestRun.plugins['opencas']['working_dir']}/",
"git clone --recursive https://github.com/Open-CAS/open-cas-linux.git") delete=True)
if output.exit_code != 0:
raise Exception(f"Error while cloning repository: {output.stdout}\n{output.stderr}")
TestRun.LOGGER.info("Building Open CAS")
output = TestRun.executor.run( output = TestRun.executor.run(
f"cd {opencas_repo_name} && " f"cd {TestRun.plugins['opencas']['working_dir']} && "
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 && "
"./configure && " "./configure && "
"make -j") "make -j")
if output.exit_code != 0: if output.exit_code != 0:
raise Exception( TestRun.exception(
f"Make command executed with nonzero status: {output.stdout}\n{output.stderr}") f"Make command executed with nonzero status: {output.stdout}\n{output.stderr}")
output = TestRun.executor.run(f"cd {opencas_repo_name} && " TestRun.LOGGER.info("Installing Open CAS")
f"make install") output = TestRun.executor.run(
f"cd {TestRun.plugins['opencas']['working_dir']} && "
f"make install")
if output.exit_code != 0: if output.exit_code != 0:
raise Exception( TestRun.exception(
f"Error while installing Open CAS: {output.stdout}\n{output.stderr}") 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") output = TestRun.executor.run("casadm -V")
if output.exit_code != 0: if output.exit_code != 0:
raise Exception( TestRun.exception(
f"'casadm -V' command returned an error: {output.stdout}\n{output.stderr}") f"'casadm -V' command returned an error: {output.stdout}\n{output.stderr}")
else: else:
LOGGER.info(output.stdout) TestRun.LOGGER.info(output.stdout)
def uninstall_opencas(): def uninstall_opencas():
LOGGER.info("Uninstalling Open CAS.") TestRun.LOGGER.info("Uninstalling Open CAS")
output = TestRun.executor.run("casadm -V") output = TestRun.executor.run("casadm -V")
if output.exit_code != 0: if output.exit_code != 0:
raise Exception("Open CAS is not properly installed.") TestRun.exception("Open CAS is not properly installed")
else: else:
TestRun.executor.run(f"cd {opencas_repo_name} && " TestRun.executor.run(
f"make uninstall") f"cd {TestRun.plugins['opencas']['working_dir']} && "
f"make uninstall")
if output.exit_code != 0: if output.exit_code != 0:
raise Exception( TestRun.exception(
f"There was an error during uninstall process: {output.stdout}\n{output.stderr}") f"There was an error during uninstall process: {output.stdout}\n{output.stderr}")
@ -83,11 +64,11 @@ def reinstall_opencas():
def check_if_installed(): 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") output = TestRun.executor.run("which casadm")
if output.exit_code == 0: if output.exit_code == 0:
LOGGER.info("CAS is installed") TestRun.LOGGER.info("CAS is installed")
return True return True
LOGGER.info("CAS not installed") TestRun.LOGGER.info("CAS not installed")
return False return False

View File

@ -27,15 +27,6 @@ except ImportError:
pass 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): def pytest_runtest_setup(item):
# There should be dut config file added to config package and # There should be dut config file added to config package and
# pytest should be executed with option --dut-config=conf_name'. # pytest should be executed with option --dut-config=conf_name'.
@ -74,6 +65,7 @@ def pytest_runtest_setup(item):
TestRun.plugins['opencas'] = { TestRun.plugins['opencas'] = {
'repo_dir': os.path.join(os.path.dirname(__file__), "../../.."), 'repo_dir': os.path.join(os.path.dirname(__file__), "../../.."),
'working_dir': dut_config['working_dir'],
'already_updated': False 'already_updated': False
} }
except Exception as e: except Exception as e:
@ -121,20 +113,10 @@ def pytest_addoption(parser):
parser.addoption("--dut-config", action="store", default="None") parser.addoption("--dut-config", action="store", default="None")
parser.addoption("--log-path", action="store", parser.addoption("--log-path", action="store",
default=f"{os.path.join(os.path.dirname(__file__), '../results')}") 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") parser.addoption("--force-reinstall", action="store", default="False")
# TODO: investigate whether it is possible to pass the last param as bool # 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(): def unmount_cas_devices():
output = TestRun.executor.run("cat /proc/mounts | grep cas") output = TestRun.executor.run("cat /proc/mounts | grep cas")
# If exit code is '1' but stdout is empty, there is no mounted cas devices # If exit code is '1' but stdout is empty, there is no mounted cas devices