-
Notifications
You must be signed in to change notification settings - Fork 97
Add test for installing OpenCAS from RPM package #391
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
bf50bad
952b477
64f399c
7e3a02b
724a5c8
c103fbc
cdc3872
728316e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,99 +3,146 @@ | |
| # SPDX-License-Identifier: BSD-3-Clause-Clear | ||
| # | ||
|
|
||
| from datetime import timedelta | ||
|
|
||
| import logging | ||
|
|
||
| from tests import conftest | ||
| from api.cas.cas_module import CasModule | ||
| 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 test_tools.rpm import Rpm | ||
| from test_utils import os_utils | ||
| from test_utils.output import CmdException | ||
|
|
||
|
|
||
| def rsync_opencas_sources(): | ||
| TestRun.LOGGER.info("Copying Open CAS repository to DUT") | ||
| TestRun.executor.rsync_to( | ||
| f"{TestRun.usr.repo_dir}/", | ||
| f"{TestRun.usr.working_dir}/", | ||
| 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} && " | ||
| "./configure && " | ||
| "make -j") | ||
| 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} && " | ||
| f"make install") | ||
| if output.exit_code != 0: | ||
| raise CmdException("Error while installing Open CAS", 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) | ||
| class Installer: | ||
| @staticmethod | ||
| def rsync_opencas(): | ||
| TestRun.LOGGER.info("Copying OpenCAS repository to DUT") | ||
| Installer._rsync_opencas(TestRun.usr.repo_dir) | ||
|
|
||
| @staticmethod | ||
| def _rsync_opencas(source: str, timeout: timedelta = timedelta(minutes=5)): | ||
| TestRun.executor.rsync_to( | ||
| f"{source}/", | ||
| f"{TestRun.usr.working_dir}/", | ||
| exclude_list=["test/functional/results/"], | ||
| delete=True, | ||
| timeout=timeout | ||
| ) | ||
|
|
||
| @staticmethod | ||
| 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("Cleaning Open CAS repo executed with nonzero status", output) | ||
|
|
||
| @staticmethod | ||
| def build_opencas(): | ||
| TestRun.LOGGER.info("Building Open CAS") | ||
| output = TestRun.executor.run( | ||
| f"cd {TestRun.usr.working_dir} && " | ||
| "./configure && " | ||
| "make -j") | ||
| if output.exit_code != 0: | ||
| raise CmdException("Make command executed with nonzero status", output) | ||
|
|
||
| def set_up_opencas(version=None): | ||
| _clean_opencas_repo() | ||
| @staticmethod | ||
| def install_opencas(): | ||
| TestRun.LOGGER.info("Installing Open CAS") | ||
| output = TestRun.executor.run( | ||
| f"cd {TestRun.usr.working_dir} && " | ||
| f"make install") | ||
| if output.exit_code != 0 or not Installer._is_casadm_installed(): | ||
| raise CmdException("Error while installing Open CAS", output) | ||
|
|
||
| if version: | ||
| git.checkout_cas_version(version) | ||
| @staticmethod | ||
| def set_up_opencas(version=None): | ||
| Installer._clean_opencas_repo() | ||
|
|
||
| build_opencas() | ||
| if version: | ||
| git.checkout_cas_version(version) | ||
|
|
||
| install_opencas() | ||
| Installer.build_opencas() | ||
|
|
||
| Installer.install_opencas() | ||
|
|
||
| def uninstall_opencas(): | ||
| TestRun.LOGGER.info("Uninstalling Open CAS") | ||
| output = TestRun.executor.run("casadm -V") | ||
| if output.exit_code != 0: | ||
| raise CmdException("Open CAS is not properly installed", output) | ||
| else: | ||
| TestRun.executor.run( | ||
| f"cd {TestRun.usr.working_dir} && " | ||
| f"make uninstall") | ||
| @staticmethod | ||
| def uninstall_opencas(): | ||
| TestRun.LOGGER.info("Uninstalling Open CAS") | ||
| output = TestRun.executor.run(f"cd {TestRun.usr.working_dir} && make uninstall") | ||
| if output.exit_code != 0: | ||
| raise CmdException("There was an error during uninstall process", output) | ||
|
|
||
|
|
||
| def reinstall_opencas(version=None): | ||
| if check_if_installed(): | ||
| uninstall_opencas() | ||
| set_up_opencas(version) | ||
|
|
||
|
|
||
| def check_if_installed(): | ||
| 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") | ||
|
|
||
| return True | ||
| TestRun.LOGGER.info("CAS not installed") | ||
| return False | ||
| @staticmethod | ||
| def reinstall_opencas(version=None): | ||
| if Installer.check_if_installed(): | ||
| Installer.uninstall_opencas() | ||
| Installer.set_up_opencas(version) | ||
|
|
||
| @staticmethod | ||
| def check_if_installed(): | ||
| TestRun.LOGGER.info("Check if Open-CAS-Linux is installed") | ||
| casadm_loaded = Installer._is_casadm_installed() | ||
| modules_loaded = os_utils.is_kernel_module_loaded(cas_module.CasModule.cache.value) | ||
|
|
||
| if casadm_loaded and modules_loaded: | ||
| TestRun.LOGGER.info("CAS is installed") | ||
| return True | ||
|
|
||
| TestRun.LOGGER.info("CAS not installed") | ||
| return False | ||
|
|
||
| @staticmethod | ||
| def _is_casadm_installed(): | ||
| TestRun.LOGGER.info("Check if 'casadm' is properly installed.") | ||
| output = TestRun.executor.run("casadm -V") | ||
| if output.exit_code != 0: | ||
| return False | ||
| else: | ||
| TestRun.LOGGER.info(output.stdout) | ||
| return True | ||
|
Comment on lines
+99
to
+105
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'which casadm' does the job, and we don't need output from casadm here |
||
|
|
||
|
|
||
| class RpmInstaller(Installer): | ||
| @staticmethod | ||
| def rsync_opencas(): | ||
| if TestRun.usr.rpm_dir is not None: | ||
| TestRun.LOGGER.info("Copying OpenCAS RPM package to DUT") | ||
| Installer._rsync_opencas(TestRun.usr.rpm_dir) | ||
| else: | ||
| Installer.rsync_opencas() | ||
|
|
||
| @staticmethod | ||
| def set_up_opencas(version=None): | ||
| if not TestRun.usr.rpm_dir: | ||
| Installer._clean_opencas_repo() | ||
|
|
||
| if version: | ||
| git.checkout_cas_version(version) | ||
|
|
||
| rpm = Rpm("open-cas-linux") | ||
|
|
||
| if TestRun.usr.rpm_dir is not None: | ||
| rpm.packages_dir = TestRun.usr.rpm_dir | ||
| else: | ||
| rpm.make_rpm(TestRun.usr.working_dir) | ||
|
|
||
| rpm.update_packages_to_install() | ||
| rpm.install_packages() | ||
| os_utils.load_kernel_module(CasModule.cache.value) | ||
|
|
||
| @staticmethod | ||
| def uninstall_opencas(): | ||
| TestRun.LOGGER.info("Uninstalling OpenCAS") | ||
| if Rpm.is_package_installed("open-cas-linux"): | ||
| Rpm("open-cas-linux").uninstall_packages() | ||
| else: | ||
| Installer.uninstall_opencas() | ||
|
|
||
| @staticmethod | ||
| def reinstall_opencas(version=None): | ||
| if Installer.check_if_installed(): | ||
| RpmInstaller.uninstall_opencas() | ||
| RpmInstaller.set_up_opencas(version) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,9 +14,8 @@ | |
| sys.path.append(os.path.join(os.path.dirname(__file__), "../test-framework")) | ||
|
|
||
| from core.test_run_utils import TestRun | ||
| from api.cas import installer | ||
| from api.cas import casadm | ||
| from api.cas import git | ||
| from api.cas import casadm, git | ||
| from api.cas.installer import Installer, RpmInstaller | ||
| from test_utils.os_utils import Udev, kill_all_io | ||
| from test_tools.disk_utils import PartitionTable, create_partition_table | ||
| from test_tools.device_mapper import DeviceMapper | ||
|
|
@@ -25,9 +24,10 @@ | |
|
|
||
|
|
||
| class Opencas(metaclass=Singleton): | ||
| def __init__(self, repo_dir, working_dir): | ||
| def __init__(self, repo_dir, working_dir, rpm_dir): | ||
| self.repo_dir = repo_dir | ||
| self.working_dir = working_dir | ||
| self.rpm_dir = rpm_dir | ||
| self.already_updated = False | ||
|
|
||
|
|
||
|
|
@@ -72,7 +72,9 @@ def pytest_runtest_setup(item): | |
|
|
||
| TestRun.usr = Opencas( | ||
| repo_dir=os.path.join(os.path.dirname(__file__), "../../.."), | ||
| working_dir=dut_config['working_dir']) | ||
| working_dir=dut_config['working_dir'], | ||
| rpm_dir=dut_config.get('rpm_dir') | ||
| ) | ||
|
|
||
| TestRun.LOGGER.info(f"DUT info: {TestRun.dut}") | ||
|
|
||
|
|
@@ -102,7 +104,7 @@ def pytest_runtest_teardown(): | |
| Udev.enable() | ||
| kill_all_io() | ||
| unmount_cas_devices() | ||
| if installer.check_if_installed(): | ||
| if Installer.check_if_installed(): | ||
| casadm.remove_all_detached_cores() | ||
| casadm.stop_all_caches() | ||
| from api.cas.init_config import InitConfig | ||
|
|
@@ -120,6 +122,7 @@ def pytest_runtest_teardown(): | |
|
|
||
|
|
||
| def pytest_configure(config): | ||
| add_marks(config) | ||
| TestRun.configure(config) | ||
|
|
||
|
|
||
|
|
@@ -133,6 +136,7 @@ def pytest_addoption(parser): | |
| parser.addoption("--log-path", action="store", | ||
| default=f"{os.path.join(os.path.dirname(__file__), '../results')}") | ||
| parser.addoption("--force-reinstall", action="store_true", default=False) | ||
| parser.addoption("--rpm-install", action="store_true", default=False) | ||
|
|
||
|
|
||
| def unmount_cas_devices(): | ||
|
|
@@ -161,36 +165,57 @@ def get_force_param(item): | |
| return item.config.getoption("--force-reinstall") | ||
|
|
||
|
|
||
| def get_rpm_param(item): | ||
| return item.config.getoption("--rpm-install") | ||
|
|
||
|
|
||
| def base_prepare(item): | ||
| with TestRun.LOGGER.step("Cleanup before test"): | ||
| TestRun.executor.run("pkill --signal=SIGKILL fsck") | ||
| Udev.enable() | ||
| kill_all_io() | ||
| DeviceMapper.remove_all() | ||
|
|
||
| if installer.check_if_installed(): | ||
| uninstall_cas = list(TestRun.item.iter_markers(name="uninstall_cas")) | ||
| installer = RpmInstaller if get_rpm_param(item) else Installer | ||
| opencas_installed = installer.check_if_installed() | ||
|
|
||
| if opencas_installed: | ||
| try: | ||
| from api.cas.init_config import InitConfig | ||
| InitConfig.create_default_init_config() | ||
| unmount_cas_devices() | ||
| casadm.stop_all_caches() | ||
| casadm.remove_all_detached_cores() | ||
| except Exception: | ||
| pass # TODO: Reboot DUT if test is executed remotely | ||
| if TestRun.executor.is_remote(): | ||
| TestRun.executor.reboot() | ||
|
|
||
| for disk in TestRun.dut.disks: | ||
| disk.umount_all_partitions() | ||
| disk.remove_partitions() | ||
| create_partition_table(disk, PartitionTable.gpt) | ||
|
|
||
| if get_force_param(item) and not TestRun.usr.already_updated: | ||
| installer.rsync_opencas_sources() | ||
| # sources should be up-to-date on DUT even if installation is skipped | ||
| installer.rsync_opencas() | ||
|
|
||
|
Ostrokrzew marked this conversation as resolved.
|
||
| if uninstall_cas: | ||
| if opencas_installed: | ||
| RpmInstaller.uninstall_opencas() | ||
| elif get_force_param(item) and not TestRun.usr.already_updated: | ||
| installer.reinstall_opencas() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If RPM is installed and we want to reinstall from sources then installer.reinstall_opencas() will try to remove only source-based installation (and fail), and then will try to install from sources although RPM would still be installed. |
||
| elif not installer.check_if_installed(): | ||
| installer.rsync_opencas_sources() | ||
| elif not opencas_installed and not uninstall_cas: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. uninstall_cas is always False here |
||
| 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()}") | ||
| TestRun.LOGGER.add_build_info(f'Commit message:') | ||
| TestRun.LOGGER.add_build_info(f'{git.get_current_commit_message()}') | ||
|
|
||
|
|
||
| def add_marks(config): | ||
| config.addinivalue_line( | ||
| "markers", | ||
| "uninstall_cas: don't install OpenCAS and if already installed, uninstall it" | ||
| ) | ||
Uh oh!
There was an error while loading. Please reload this page.