-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Rodolfo Olivieri <[email protected]>
- Loading branch information
Showing
3 changed files
with
167 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
summary: Handle kernel boot files | ||
|
||
description: | | ||
Verify that Convert2RHEL can detect and handle the kernel boot files in | ||
case of failure. | ||
Verify that, if present, the kernel boot files are not corrupted. | ||
|
||
In any case, the conversion should not be inhibited. An warning will be | ||
shown to the user with instructions on how to fix it. | ||
|
||
tier: 1 | ||
|
||
tag+: | ||
- kernel | ||
- boot | ||
|
||
link: https://github.com/oamg/convert2rhel/pull/668 | ||
|
||
/missing_kernel_boot_files: | ||
# Test for missing initramfs and vmlinuz files. | ||
tag+: | ||
- misisng_kernel_boot_files | ||
test: | | ||
pytest -svv -m missing_kernel_boot_files | ||
|
||
/corrupted_initramfs_file: | ||
tag+: | ||
- corrupted-initramfs | ||
test: | | ||
pytest -svv -m corrupted_initramfs_file | ||
|
||
/check_boot_files_presence: | ||
tag+: | ||
- check-boot-files-presence | ||
test: | | ||
pytest -svv -m check_boot_files_presence |
123 changes: 123 additions & 0 deletions
123
tests/integration/tier1/kernel-boot-files/test_handle_kernel_boot_files.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
import os | ||
import platform | ||
import subprocess | ||
|
||
from multiprocessing import Pool | ||
|
||
import pytest | ||
|
||
from envparse import env | ||
|
||
|
||
# TODO(r0x0d): We need to update those tests when UEFI machines are available | ||
# throught testing farm. | ||
|
||
SYSTEM_VERSION = platform.platform() | ||
|
||
|
||
def get_latest_installed_kernel(): | ||
"""Small utility function to get the latest installed kernel.""" | ||
|
||
kernel_name = "kernel" | ||
if "centos-8" in SYSTEM_VERSION or "oracle-8" in SYSTEM_VERSION: | ||
kernel_name = "kernel-core" | ||
|
||
output = subprocess.check_output(["rpm", "-q", "--last", kernel_name]) | ||
latest_installed_kernel = output.split("\n", maxsplit=1)[0].split(" ")[0] | ||
latest_installed_kernel = latest_installed_kernel.split("%s-" % kernel_name)[-1] | ||
return output.output.strip() | ||
|
||
|
||
def get_booted_kernel_version(): | ||
"""Utility function to get the booted kernel version.""" | ||
kernel_version = subprocess.check_output(["uname", "-r"]) | ||
return kernel_version.decode("utf-8").strip() | ||
|
||
|
||
def fill_disk_space(): | ||
""" | ||
Small utility function to fill-up disk space when a certain file is not present anymore. | ||
""" | ||
kernel_version = get_booted_kernel_version() | ||
|
||
while True: | ||
if not os.path.exists("/boot/initramfs-%s.img" % kernel_version): | ||
cmd = "yes `dd if=/dev/urandom count=1 bs=1M|base64` > /boot/test" | ||
process = subprocess.run(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, check=True) | ||
if "No space left" in process.stdout.decode(): | ||
print("Done! The disk is now out of space.") | ||
return | ||
|
||
|
||
def corrupt_initramfs_file(): | ||
"""Small utility function to corrupt the initramfs file.""" | ||
latest_installed_kernel = get_latest_installed_kernel() | ||
|
||
while True: | ||
if os.path.exists("/boot/initramfs-%s.img" % latest_installed_kernel): | ||
cmd = "echo 'corrupted' > /boot/initramfs-%s.img" % latest_installed_kernel | ||
subprocess.run(cmd, shell=True, check=True) | ||
return | ||
|
||
|
||
@pytest.mark.missing_kernel_boot_files | ||
def test_missing_kernel_boot_files(convert2rhel): | ||
""" """ | ||
|
||
with convert2rhel( | ||
"-y --no-rpm-va --serverurl {} --username {} --password {} --pool {} --debug".format( | ||
env.str("RHSM_SERVER_URL"), | ||
env.str("RHSM_USERNAME"), | ||
env.str("RHSM_PASSWORD"), | ||
env.str("RHSM_POOL"), | ||
) | ||
) as c2r: | ||
c2r.expect("Convert: Replace system packages", timeout=600) == 0 | ||
with Pool(processes=1) as pool: | ||
watcher = pool.apply_async(fill_disk_space, ()) | ||
assert watcher.successful() is True | ||
|
||
assert c2r.expect("Couldn't verify the kernel boot files in the boot partition.", timeout=600) == 0 | ||
|
||
assert c2r.exitstatus == 0 | ||
|
||
|
||
@pytest.mark.corrupted_initramfs_file | ||
def test_corrupted_initramfs_file(convert2rhel): | ||
""" """ | ||
|
||
with convert2rhel( | ||
"-y --no-rpm-va --serverurl {} --username {} --password {} --pool {} --debug".format( | ||
env.str("RHSM_SERVER_URL"), | ||
env.str("RHSM_USERNAME"), | ||
env.str("RHSM_PASSWORD"), | ||
env.str("RHSM_POOL"), | ||
) | ||
) as c2r: | ||
# Start the watcher as soon as we hit this message. | ||
c2r.expect("Convert: Replace system packages", timeout=600) == 0 | ||
|
||
with Pool(processes=1) as pool: | ||
watcher = pool.apply_async(corrupt_initramfs_file, ()) | ||
assert watcher.successful() is True | ||
|
||
assert c2r.expect("Couldn't verify the kernel boot files in the boot partition.", timeout=600) == 0 | ||
|
||
assert c2r.exitstatus == 0 | ||
|
||
|
||
@pytest.mark.check_boot_files_presence | ||
def test_check_boot_files_presence(convert2rhel): | ||
""" """ | ||
|
||
with convert2rhel( | ||
"-y --no-rpm-va --serverurl {} --username {} --password {} --pool {} --debug".format( | ||
env.str("RHSM_SERVER_URL"), | ||
env.str("RHSM_USERNAME"), | ||
env.str("RHSM_PASSWORD"), | ||
env.str("RHSM_POOL"), | ||
) | ||
) as c2r: | ||
assert c2r.expect("Initramfs and vmlinuz files exists and are valid.") == 0 | ||
|
||
assert c2r.exitstatus == 0 |