Merge pull request #1311 from rafalste/dut_cas_version

Install particular CAS version on DUT before test
This commit is contained in:
Michał Mielewczyk 2022-08-18 15:34:33 +02:00 committed by GitHub
commit 711dc59a81
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 84 additions and 37 deletions

View File

@ -1,5 +1,5 @@
# #
# Copyright(c) 2019-2021 Intel Corporation # Copyright(c) 2019-2022 Intel Corporation
# SPDX-License-Identifier: BSD-3-Clause # SPDX-License-Identifier: BSD-3-Clause
# #
@ -7,6 +7,7 @@ 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
from test_utils.output import CmdException
def get_current_commit_hash(from_dut: bool = False): def get_current_commit_hash(from_dut: bool = False):
@ -25,6 +26,21 @@ def get_current_commit_message():
f'git show HEAD -s --pretty=format:"%B"').stdout f'git show HEAD -s --pretty=format:"%B"').stdout
def get_commit_hash(cas_version, 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
output = executor.run(
f"cd {repo_path} && "
f"git rev-parse {cas_version}")
if output.exit_code != 0:
raise CmdException(f"Failed to resolve '{cas_version}' to commit hash", output)
TestRun.LOGGER.info(f"Resolved '{cas_version}' as commit {output.stdout}")
return output.stdout
def get_release_tags(): def get_release_tags():
repo_path = os.path.join(TestRun.usr.working_dir, ".git") repo_path = os.path.join(TestRun.usr.working_dir, ".git")
output = TestRun.executor.run_expect_success(f"git --git-dir={repo_path} tag").stdout output = TestRun.executor.run_expect_success(f"git --git-dir={repo_path} tag").stdout
@ -36,29 +52,17 @@ def get_release_tags():
def checkout_cas_version(cas_version): def checkout_cas_version(cas_version):
from api.cas.version import CasVersion commit_hash = get_commit_hash(cas_version)
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}") TestRun.LOGGER.info(f"Checkout CAS to {commit_hash}")
output = TestRun.executor.run( output = TestRun.executor.run(
f"cd {TestRun.usr.working_dir} && " f"cd {TestRun.usr.working_dir} && "
f"git checkout --force {commit_hash}") f"git checkout --force {commit_hash}")
if output.exit_code != 0: if output.exit_code != 0:
raise CmdException(f"Failed to checkout to CAS {commit_hash}", output) raise CmdException(f"Failed to checkout to {commit_hash}", output)
output = TestRun.executor.run( output = TestRun.executor.run(
f"cd {TestRun.usr.working_dir} && " f"cd {TestRun.usr.working_dir} && "
f"git submodule update") f"git submodule update --force")
if output.exit_code != 0: if output.exit_code != 0:
raise CmdException(f"Failed to update submodules", output) raise CmdException(f"Failed to update submodules", output)

View File

@ -1,5 +1,5 @@
# #
# Copyright(c) 2019-2021 Intel Corporation # Copyright(c) 2019-2022 Intel Corporation
# SPDX-License-Identifier: BSD-3-Clause # SPDX-License-Identifier: BSD-3-Clause
# #
@ -8,8 +8,8 @@ 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, git
from api.cas import cas_module from api.cas.version import get_installed_cas_version
from test_utils import os_utils from test_utils import os_utils
from test_utils.output import CmdException from test_utils.output import CmdException
@ -48,24 +48,27 @@ def install_opencas():
f"cd {TestRun.usr.working_dir} && " f"cd {TestRun.usr.working_dir} && "
f"make install") f"make install")
if output.exit_code != 0: if output.exit_code != 0:
raise CmdException("Error while installing Open CAS", output) raise CmdException("Failed to install Open CAS", output)
output = TestRun.executor.run("rmmod cas_cache cas_disk; modprobe cas_cache")
if output.exit_code != 0:
raise CmdException("Failed to reload modules", output)
TestRun.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 CmdException("'casadm -V' command returned an error", output) raise CmdException("'casadm -V' command returned an error", output)
else:
TestRun.LOGGER.info(output.stdout) TestRun.LOGGER.info(output.stdout)
def set_up_opencas(version=None): def set_up_opencas(version: str = ""):
_clean_opencas_repo() _clean_opencas_repo()
if version: if version:
git.checkout_cas_version(version) git.checkout_cas_version(version)
build_opencas() build_opencas()
install_opencas() install_opencas()
@ -82,20 +85,35 @@ 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(version=None): def reinstall_opencas(version: str = ""):
if check_if_installed(): if check_if_installed():
uninstall_opencas() uninstall_opencas()
set_up_opencas(version) set_up_opencas(version)
def check_if_installed(): def check_if_installed(version: str = ""):
TestRun.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")
modules_loaded = os_utils.is_kernel_module_loaded(cas_module.CasModule.cache.value) modules_loaded = os_utils.is_kernel_module_loaded(cas_module.CasModule.cache.value)
if output.exit_code == 0 and modules_loaded: if output.exit_code != 0 or not modules_loaded:
TestRun.LOGGER.info("CAS is not installed")
return False
TestRun.LOGGER.info("CAS is installed") TestRun.LOGGER.info("CAS is installed")
return True if version:
TestRun.LOGGER.info("CAS not installed") TestRun.LOGGER.info(f"Check for requested CAS version: {version}")
cas_commit_expected = git.get_commit_hash(version)
cas_commit_installed = get_installed_cas_version()
if cas_commit_expected != cas_commit_installed:
TestRun.LOGGER.info(
f"CAS version '{version}' is not installed. "
f"Installed version found: {cas_commit_installed}"
)
return False return False
TestRun.LOGGER.info(f"CAS version '{version}' is installed")
return True

View File

@ -1,11 +1,13 @@
# #
# Copyright(c) 2019-2021 Intel Corporation # Copyright(c) 2019-2022 Intel Corporation
# SPDX-License-Identifier: BSD-3-Clause # SPDX-License-Identifier: BSD-3-Clause
# #
import re import re
from api.cas import git from api.cas import git
from core.test_run import TestRun
from test_utils.output import CmdException
class CasVersion: class CasVersion:
@ -43,3 +45,15 @@ def get_available_cas_versions():
versions = [CasVersion.from_git_tag(tag) for tag in release_tags] versions = [CasVersion.from_git_tag(tag) for tag in release_tags]
return versions return versions
def get_installed_cas_version():
output = TestRun.executor.run("grep -i '^LAST_COMMIT_HASH=' /var/lib/opencas/cas_version")
if output.exit_code != 0:
raise CmdException(
"Could not find commit hash of installed version. "
"Check if Open CAS Linux is properly installed.",
output,
)
return output.stdout.split("=")[1]

View File

@ -14,6 +14,15 @@ type: "local"
allow_disk_autoselect: False allow_disk_autoselect: False
working_dir: "/tmp/open-cas-linux/" working_dir: "/tmp/open-cas-linux/"
# CAS version to test.
# This version will be installed on DUT before test. Can be any string
# digestible by git-checkout. If not specified, by default current state
# of your controller's repo (HEAD) will be used as version to install.
# NOTE: Make sure to have a local master branch synced with upstream
# as the local repo will be taken for version reference. To do this
# simply run: `git fetch origin master:master`
cas_version: "master"
disks: disks:
- path: "/dev/device_name1" # disk device path - path: "/dev/device_name1" # disk device path
serial: "ABC" # disk serial number serial: "ABC" # disk serial number

View File

@ -275,12 +275,14 @@ def base_prepare(item):
disk.remove_partitions() disk.remove_partitions()
create_partition_table(disk, PartitionTable.gpt) create_partition_table(disk, PartitionTable.gpt)
cas_version = TestRun.config.get("cas_version") or git.get_current_commit_hash()
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.rsync_opencas_sources()
installer.reinstall_opencas() installer.reinstall_opencas(cas_version)
elif not installer.check_if_installed(): elif not installer.check_if_installed(cas_version):
installer.rsync_opencas_sources() installer.rsync_opencas_sources()
installer.set_up_opencas() installer.set_up_opencas(cas_version)
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()}")