test/api: Add functionality to install particular CAS version

Signed-off-by: Rafal Stefanowski <rafal.stefanowski@intel.com>
This commit is contained in:
Rafal Stefanowski 2022-08-16 15:39:03 +02:00
parent 9f66143b70
commit 824e086ffb
2 changed files with 49 additions and 17 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
#
@ -8,8 +8,8 @@ import logging
from tests import conftest
from core.test_run import TestRun
from api.cas import git
from api.cas import cas_module
from api.cas import cas_module, git
from api.cas.version import get_installed_cas_version
from test_utils import os_utils
from test_utils.output import CmdException
@ -48,24 +48,27 @@ def install_opencas():
f"cd {TestRun.usr.working_dir} && "
f"make install")
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.")
output = TestRun.executor.run("casadm -V")
if output.exit_code != 0:
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()
if version:
git.checkout_cas_version(version)
build_opencas()
install_opencas()
@ -82,20 +85,35 @@ def uninstall_opencas():
raise CmdException("There was an error during uninstall process", output)
def reinstall_opencas(version=None):
def reinstall_opencas(version: str = ""):
if check_if_installed():
uninstall_opencas()
set_up_opencas(version)
def check_if_installed():
TestRun.LOGGER.info("Check if Open-CAS-Linux is installed")
def check_if_installed(version: str = ""):
TestRun.LOGGER.info("Check if Open CAS Linux is installed")
output = TestRun.executor.run("which casadm")
modules_loaded = os_utils.is_kernel_module_loaded(cas_module.CasModule.cache.value)
if output.exit_code == 0 and modules_loaded:
TestRun.LOGGER.info("CAS is installed")
if output.exit_code != 0 or not modules_loaded:
TestRun.LOGGER.info("CAS is not installed")
return False
return True
TestRun.LOGGER.info("CAS not installed")
return False
TestRun.LOGGER.info("CAS is installed")
if version:
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
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
#
import re
from api.cas import git
from core.test_run import TestRun
from test_utils.output import CmdException
class CasVersion:
@ -43,3 +45,15 @@ def get_available_cas_versions():
versions = [CasVersion.from_git_tag(tag) for tag in release_tags]
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]