Merge pull request #424 from mmichal10/improve-installer

Improve installer
This commit is contained in:
Robert Baldyga 2020-05-27 16:26:27 +02:00 committed by GitHub
commit d11f434a76
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 110 additions and 8 deletions

View File

@ -3,14 +3,18 @@
# SPDX-License-Identifier: BSD-3-Clause-Clear
#
import os
from core.test_run import TestRun
from connection.local_executor import LocalExecutor
def get_current_commit_hash():
local_executor = LocalExecutor()
return local_executor.run(
f"cd {TestRun.usr.repo_dir} &&"
def get_current_commit_hash(from_dut: bool = False):
executor = TestRun.executor if from_dut else LocalExecutor()
repo_path = TestRun.usr.working_dir if from_dut else TestRun.usr.repo_dir
return executor.run(
f"cd {repo_path} &&"
f'git show HEAD -s --pretty=format:"%H"').stdout
@ -19,3 +23,42 @@ def get_current_commit_message():
return local_executor.run(
f"cd {TestRun.usr.repo_dir} &&"
f'git show HEAD -s --pretty=format:"%B"').stdout
def get_release_tags():
repo_path = os.path.join(TestRun.usr.working_dir, ".git")
output = TestRun.executor.run_expect_success(f"git --git-dir={repo_path} tag").stdout
# Tags containing '-' or '_' are not CAS release versions
tags = [v for v in output.splitlines() if "-" not in v and "_" not in v]
return tags
def checkout_cas_version(cas_version):
from api.cas.version import CasVersion
if isinstance(cas_version, CasVersion):
output = TestRun.executor.run(
f"cd {TestRun.usr.working_dir} && "
f"git rev-parse {cas_version}")
if output.exit_code != 0:
raise CmdException(f"Failed to resolve {cas_version} tag to commit hash", output)
TestRun.LOGGER.info(f"Resolved {cas_version} as commit {output.stdout}")
cas_version = output.stdout
_checkout_cas_commit(cas_version)
def _checkout_cas_commit(commit_hash):
TestRun.LOGGER.info(f"Checkout CAS to {commit_hash}")
output = TestRun.executor.run(
f"cd {TestRun.usr.working_dir} && "
f"git checkout --force {commit_hash}")
if output.exit_code != 0:
raise CmdException(f"Failed to checkout to CAS {commit_hash}", output)
output = TestRun.executor.run(
f"cd {TestRun.usr.working_dir} && "
f"git submodule update")
if output.exit_code != 0:
raise CmdException(f"Failed to update submodules", output)

View File

@ -8,12 +8,13 @@ import logging
from tests import conftest
from core.test_run import TestRun
from api.cas import git
from api.cas import cas_module
from test_utils import os_utils
from test_utils.output import CmdException
def install_opencas():
def rsync_opencas_sources():
TestRun.LOGGER.info("Copying Open CAS repository to DUT")
TestRun.executor.rsync_to(
f"{TestRun.usr.repo_dir}/",
@ -21,6 +22,17 @@ def install_opencas():
exclude_list=["test/functional/results/"],
delete=True)
def _clean_opencas_repo():
TestRun.LOGGER.info("Cleaning Open CAS repo")
output = TestRun.executor.run(
f"cd {TestRun.usr.working_dir} && "
"make distclean")
if output.exit_code != 0:
raise CmdException("make distclean command executed with nonzero status", output)
def build_opencas():
TestRun.LOGGER.info("Building Open CAS")
output = TestRun.executor.run(
f"cd {TestRun.usr.working_dir} && "
@ -29,6 +41,8 @@ def install_opencas():
if output.exit_code != 0:
raise CmdException("Make command executed with nonzero status", output)
def install_opencas():
TestRun.LOGGER.info("Installing Open CAS")
output = TestRun.executor.run(
f"cd {TestRun.usr.working_dir} && "
@ -44,6 +58,17 @@ def install_opencas():
TestRun.LOGGER.info(output.stdout)
def set_up_opencas(version=None):
_clean_opencas_repo()
if version:
git.checkout_cas_version(version)
build_opencas()
install_opencas()
def uninstall_opencas():
TestRun.LOGGER.info("Uninstalling Open CAS")
output = TestRun.executor.run("casadm -V")
@ -57,10 +82,10 @@ def uninstall_opencas():
raise CmdException("There was an error during uninstall process", output)
def reinstall_opencas():
def reinstall_opencas(version=None):
if check_if_installed():
uninstall_opencas()
install_opencas()
set_up_opencas(version)
def check_if_installed():

View File

@ -0,0 +1,32 @@
#
# Copyright(c) 2019-2020 Intel Corporation
# SPDX-License-Identifier: BSD-3-Clause-Clear
#
import os
from api.cas import git
from packaging import version
class CasVersion(version.Version):
def can_be_upgraded(self):
return self >= CasVersion("v20.1")
def __str__(self):
return f"v{super().__str__()}"
def __repr__(self):
return str(self)
def get_available_cas_versions():
release_tags = git.get_release_tags()
versions = [CasVersion(tag) for tag in release_tags]
return versions
def get_upgradable_cas_versions():
return [v for v in get_available_cas_versions() if v.can_be_upgraded()]

View File

@ -172,9 +172,11 @@ def base_prepare(item):
raise Exception(f"Failed to remove partitions from {disk}")
if get_force_param(item) and not TestRun.usr.already_updated:
installer.rsync_opencas_sources()
installer.reinstall_opencas()
elif not installer.check_if_installed():
installer.install_opencas()
installer.rsync_opencas_sources()
installer.set_up_opencas()
TestRun.usr.already_updated = True
TestRun.LOGGER.add_build_info(f'Commit hash:')
TestRun.LOGGER.add_build_info(f"{git.get_current_commit_hash()}")