Merge pull request #424 from mmichal10/improve-installer
Improve installer
This commit is contained in:
commit
d11f434a76
@ -3,14 +3,18 @@
|
|||||||
# SPDX-License-Identifier: BSD-3-Clause-Clear
|
# SPDX-License-Identifier: BSD-3-Clause-Clear
|
||||||
#
|
#
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
from core.test_run import TestRun
|
from core.test_run import TestRun
|
||||||
from connection.local_executor import LocalExecutor
|
from connection.local_executor import LocalExecutor
|
||||||
|
|
||||||
|
|
||||||
def get_current_commit_hash():
|
def get_current_commit_hash(from_dut: bool = False):
|
||||||
local_executor = LocalExecutor()
|
executor = TestRun.executor if from_dut else LocalExecutor()
|
||||||
return local_executor.run(
|
repo_path = TestRun.usr.working_dir if from_dut else TestRun.usr.repo_dir
|
||||||
f"cd {TestRun.usr.repo_dir} &&"
|
|
||||||
|
return executor.run(
|
||||||
|
f"cd {repo_path} &&"
|
||||||
f'git show HEAD -s --pretty=format:"%H"').stdout
|
f'git show HEAD -s --pretty=format:"%H"').stdout
|
||||||
|
|
||||||
|
|
||||||
@ -19,3 +23,42 @@ def get_current_commit_message():
|
|||||||
return local_executor.run(
|
return local_executor.run(
|
||||||
f"cd {TestRun.usr.repo_dir} &&"
|
f"cd {TestRun.usr.repo_dir} &&"
|
||||||
f'git show HEAD -s --pretty=format:"%B"').stdout
|
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)
|
||||||
|
@ -8,12 +8,13 @@ import logging
|
|||||||
|
|
||||||
from tests import conftest
|
from tests import conftest
|
||||||
from core.test_run import TestRun
|
from core.test_run import TestRun
|
||||||
|
from api.cas import git
|
||||||
from api.cas import cas_module
|
from api.cas import cas_module
|
||||||
from test_utils import os_utils
|
from test_utils import os_utils
|
||||||
from test_utils.output import CmdException
|
from test_utils.output import CmdException
|
||||||
|
|
||||||
|
|
||||||
def install_opencas():
|
def rsync_opencas_sources():
|
||||||
TestRun.LOGGER.info("Copying Open CAS repository to DUT")
|
TestRun.LOGGER.info("Copying Open CAS repository to DUT")
|
||||||
TestRun.executor.rsync_to(
|
TestRun.executor.rsync_to(
|
||||||
f"{TestRun.usr.repo_dir}/",
|
f"{TestRun.usr.repo_dir}/",
|
||||||
@ -21,6 +22,17 @@ def install_opencas():
|
|||||||
exclude_list=["test/functional/results/"],
|
exclude_list=["test/functional/results/"],
|
||||||
delete=True)
|
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")
|
TestRun.LOGGER.info("Building Open CAS")
|
||||||
output = TestRun.executor.run(
|
output = TestRun.executor.run(
|
||||||
f"cd {TestRun.usr.working_dir} && "
|
f"cd {TestRun.usr.working_dir} && "
|
||||||
@ -29,6 +41,8 @@ def install_opencas():
|
|||||||
if output.exit_code != 0:
|
if output.exit_code != 0:
|
||||||
raise CmdException("Make command executed with nonzero status", output)
|
raise CmdException("Make command executed with nonzero status", output)
|
||||||
|
|
||||||
|
|
||||||
|
def install_opencas():
|
||||||
TestRun.LOGGER.info("Installing Open CAS")
|
TestRun.LOGGER.info("Installing Open CAS")
|
||||||
output = TestRun.executor.run(
|
output = TestRun.executor.run(
|
||||||
f"cd {TestRun.usr.working_dir} && "
|
f"cd {TestRun.usr.working_dir} && "
|
||||||
@ -44,6 +58,17 @@ def install_opencas():
|
|||||||
TestRun.LOGGER.info(output.stdout)
|
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():
|
def uninstall_opencas():
|
||||||
TestRun.LOGGER.info("Uninstalling Open CAS")
|
TestRun.LOGGER.info("Uninstalling Open CAS")
|
||||||
output = TestRun.executor.run("casadm -V")
|
output = TestRun.executor.run("casadm -V")
|
||||||
@ -57,10 +82,10 @@ def uninstall_opencas():
|
|||||||
raise CmdException("There was an error during uninstall process", output)
|
raise CmdException("There was an error during uninstall process", output)
|
||||||
|
|
||||||
|
|
||||||
def reinstall_opencas():
|
def reinstall_opencas(version=None):
|
||||||
if check_if_installed():
|
if check_if_installed():
|
||||||
uninstall_opencas()
|
uninstall_opencas()
|
||||||
install_opencas()
|
set_up_opencas(version)
|
||||||
|
|
||||||
|
|
||||||
def check_if_installed():
|
def check_if_installed():
|
||||||
|
32
test/functional/api/cas/version.py
Normal file
32
test/functional/api/cas/version.py
Normal 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()]
|
@ -172,9 +172,11 @@ def base_prepare(item):
|
|||||||
raise Exception(f"Failed to remove partitions from {disk}")
|
raise Exception(f"Failed to remove partitions from {disk}")
|
||||||
|
|
||||||
if get_force_param(item) and not TestRun.usr.already_updated:
|
if get_force_param(item) and not TestRun.usr.already_updated:
|
||||||
|
installer.rsync_opencas_sources()
|
||||||
installer.reinstall_opencas()
|
installer.reinstall_opencas()
|
||||||
elif not installer.check_if_installed():
|
elif not installer.check_if_installed():
|
||||||
installer.install_opencas()
|
installer.rsync_opencas_sources()
|
||||||
|
installer.set_up_opencas()
|
||||||
TestRun.usr.already_updated = True
|
TestRun.usr.already_updated = True
|
||||||
TestRun.LOGGER.add_build_info(f'Commit hash:')
|
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"{git.get_current_commit_hash()}")
|
||||||
|
Loading…
Reference in New Issue
Block a user