Skip to content

Commit

Permalink
Add integration tests
Browse files Browse the repository at this point in the history
Signed-off-by: Rodolfo Olivieri <[email protected]>
  • Loading branch information
r0x0d committed Feb 7, 2023
1 parent addbd1f commit cc26f2e
Show file tree
Hide file tree
Showing 3 changed files with 167 additions and 0 deletions.
8 changes: 8 additions & 0 deletions plans/tier1.fmf
Original file line number Diff line number Diff line change
Expand Up @@ -370,3 +370,11 @@
- name: reboot after conversion
how: ansible
playbook: tests/ansible_collections/roles/reboot/main.yml

/kernel_boot_files:
discover+:
test: kernel-boot-files
prepare+:
- name: reboot after conversion
how: ansible
playbook: tests/ansible_collections/roles/reboot/main.yml
36 changes: 36 additions & 0 deletions tests/integration/tier1/kernel-boot-files/main.fmf
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
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

0 comments on commit cc26f2e

Please sign in to comment.