Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
name: kdump-anaconda
name: kdump-anaconda-addon tests

on: pull_request

jobs:
lint-check:
runs-on: ubuntu-latest
container: ghcr.io/coiby/kdump_anaconda:f38
container: docker.io/fedora:latest
steps:
- uses: actions/checkout@v2
- run: make runpylint
- name: Install dependent packages for tests
run: dnf install anaconda python-pytest python-blivet pylint make -yq

- name: Check out repository
uses: actions/checkout@v4

- name: lint check
run: make runpylint

- name: unit tests
run: make unittest

unit-tests:
runs-on: ubuntu-latest
container: ghcr.io/coiby/kdump_anaconda:f38
steps:
- uses: actions/checkout@v2
- run: make unittest
3 changes: 2 additions & 1 deletion com_redhat_kdump/gui/spokes/kdump.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from pyanaconda.ui.gui.spokes import NormalSpoke
from pyanaconda.ui.gui.utils import fancy_set_sensitive
from pyanaconda.ui.communication import hubQ
import blivet.arch

from com_redhat_kdump.i18n import _, N_
from com_redhat_kdump.constants import FADUMP_CAPABLE_FILE, KDUMP, ENCRYPTION_WARNING
Expand Down Expand Up @@ -135,7 +136,7 @@ def refresh(self):
self._enableButton.emit("toggled")

self.clear_info()
if self._luks_devs:
if self._luks_devs and blivet.arch.get_arch() != "x86_64":
Comment thread
coiby marked this conversation as resolved.
self.set_warning(_(ENCRYPTION_WARNING))

def apply(self):
Expand Down
42 changes: 39 additions & 3 deletions com_redhat_kdump/service/installation.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#
import logging
import os
import shutil

from pyanaconda.core import util
from pyanaconda.modules.common.constants.objects import BOOTLOADER
Expand All @@ -30,7 +29,7 @@

log = logging.getLogger(__name__)

__all__ = ["KdumpBootloaderConfigurationTask", "KdumpInstallationTask"]
__all__ = ["KdumpBootloaderConfigurationTask", "KdumpInstallationTask", "KdumpCrypttabSetupTask"]


class KdumpBootloaderConfigurationTask(Task):
Expand Down Expand Up @@ -143,7 +142,7 @@ def run(self):
# Anaconda may be used to create minimal container image which doesn't
# have systemd installed
# https://issues.redhat.com/browse/RHEL-41082?focusedId=26969576&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-26969576
if not shutil.which(self._sysroot + "/systemctl"):
if not os.path.exists(self._sysroot + "/usr/bin/systemctl"):
log.debug("systemd not installed, skip KdumpInstallationTask")
return

Expand All @@ -157,3 +156,40 @@ def run(self):
[systemctl_action, "kdump.service"],
root=self._sysroot
)


class KdumpCrypttabSetupTask(Task):
"""The task for setting up crypttab for kdump."""

def __init__(self, sysroot):
"""Create a task."""
super().__init__()
self._sysroot = sysroot

@property
def name(self):
return "Setup crypttab for kdump"

def _has_setup_crypttab_command(self):
"""Check if kdumpctl has setup-crypttab subcommand by checking help output."""
try:
help_output = util.execWithCapture("kdumpctl", ["help"], root=self._sysroot)
return "setup-crypttab" in help_output
except FileNotFoundError:
log.debug("kdumpctl command not found")
return False
except Exception as e:
log.warning("Failed to check kdumpctl help: %s", e)
return False

def run(self):
"""Run the task."""
if not self._has_setup_crypttab_command():
log.debug("kdumpctl setup-crypttab command not available, skipping")
return

try:
util.execWithRedirect("kdumpctl", ["setup-crypttab"], root=self._sysroot)
log.debug("Successfully executed kdumpctl setup-crypttab")
except Exception as e:
log.warning("Failed to execute kdumpctl setup-crypttab: %s", e)
14 changes: 12 additions & 2 deletions com_redhat_kdump/service/kdump.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@

from com_redhat_kdump.common import getMemoryBounds
from com_redhat_kdump.constants import KDUMP
from com_redhat_kdump.service.installation import KdumpBootloaderConfigurationTask, KdumpInstallationTask
from com_redhat_kdump.service.installation import KdumpBootloaderConfigurationTask, KdumpInstallationTask, KdumpCrypttabSetupTask
from com_redhat_kdump.service.kdump_interface import KdumpInterface
from com_redhat_kdump.service.kickstart import KdumpKickstartSpecification
import blivet.arch

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -137,13 +138,22 @@ def install_with_tasks(self):

:return: a list of tasks
"""
return [
tasks = [
KdumpInstallationTask(
sysroot=conf.target.system_root,
kdump_enabled=self.kdump_enabled,
)
]

if self.kdump_enabled and blivet.arch.get_arch() == "x86_64":
tasks.append(
KdumpCrypttabSetupTask(
sysroot=conf.target.system_root
)
)

return tasks

def configure_bootloader_with_tasks(self, kernels):
return [
KdumpBootloaderConfigurationTask(
Expand Down
72 changes: 62 additions & 10 deletions test/unit_tests/test_installation.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from unittest.case import TestCase
from unittest.mock import patch
from com_redhat_kdump.constants import FADUMP_CAPABLE_FILE
from com_redhat_kdump.service.installation import KdumpBootloaderConfigurationTask, KdumpInstallationTask
from com_redhat_kdump.service.installation import KdumpBootloaderConfigurationTask, KdumpInstallationTask, KdumpCrypttabSetupTask

SYSROOT = "/sysroot"

Expand Down Expand Up @@ -181,9 +181,9 @@ def test_configuration_kdump_crashkernel_auto_fallback_legacy(self, mock_storage
assert mock_exec.call_count == 2

@patch("com_redhat_kdump.service.installation.util")
@patch("shutil.which")
def test_installation_kdump_disabled(self, mock_shutil, mock_util):
mock_shutil.return_value = True
@patch("os.path.exists")
def test_installation_kdump_disabled(self, mock_os_path, mock_util):
mock_os_path.return_value = True
task = KdumpInstallationTask(
sysroot="/mnt/sysroot",
kdump_enabled=False
Expand All @@ -196,9 +196,9 @@ def test_installation_kdump_disabled(self, mock_shutil, mock_util):
)

@patch("com_redhat_kdump.service.installation.util")
@patch("shutil.which")
def test_installation_kdump_enabled(self, mock_shutil, mock_util):
mock_shutil.return_value = True
@patch("os.path.exists")
def test_installation_kdump_enabled(self, mock_os_path, mock_util):
mock_os_path.return_value = True
task = KdumpInstallationTask(
sysroot="/mnt/sysroot",
kdump_enabled=True
Expand All @@ -211,12 +211,64 @@ def test_installation_kdump_enabled(self, mock_shutil, mock_util):
)

@patch("com_redhat_kdump.service.installation.util")
@patch("shutil.which")
def test_installation_kdump_disable_no_systemctl(self, mock_shutil, mock_util):
mock_shutil.return_value = False
@patch("os.path.exists")
def test_installation_kdump_disable_no_systemctl(self, mock_os_path, mock_util):
mock_os_path.return_value = False
task = KdumpInstallationTask(
sysroot="/mnt/sysroot",
kdump_enabled=False
)
task.run()
mock_util.execWithRedirect.assert_not_called()

@patch("pyanaconda.core.util.execWithCapture")
def test_crypttab_setup_check_help_with_setup_crypttab(self, mock_exec):
mock_exec.return_value = "setup-crypttab Setup crypttab for kdump"
task = KdumpCrypttabSetupTask(sysroot="/mnt/sysroot")
result = task._has_setup_crypttab_command()
mock_exec.assert_called_once_with("kdumpctl", ["help"], root="/mnt/sysroot")
assert result is True

@patch("pyanaconda.core.util.execWithCapture")
def test_crypttab_setup_check_help_without_setup_crypttab(self, mock_exec):
mock_exec.return_value = "start Start kdump\nstop Stop kdump"
task = KdumpCrypttabSetupTask(sysroot="/mnt/sysroot")
result = task._has_setup_crypttab_command()
mock_exec.assert_called_once_with("kdumpctl", ["help"], root="/mnt/sysroot")
assert result is False

@patch("pyanaconda.core.util.execWithCapture")
def test_crypttab_setup_check_help_kdumpctl_not_found(self, mock_exec):
mock_exec.side_effect = FileNotFoundError()
task = KdumpCrypttabSetupTask(sysroot="/mnt/sysroot")
result = task._has_setup_crypttab_command()
mock_exec.assert_called_once_with("kdumpctl", ["help"], root="/mnt/sysroot")
assert result is False

@patch("pyanaconda.core.util.execWithRedirect")
@patch("com_redhat_kdump.service.installation.KdumpCrypttabSetupTask._has_setup_crypttab_command")
def test_crypttab_setup_run_with_command_available(self, mock_has_command, mock_exec):
mock_has_command.return_value = True
task = KdumpCrypttabSetupTask(sysroot="/mnt/sysroot")
task.run()
mock_has_command.assert_called_once()
mock_exec.assert_called_once_with("kdumpctl", ["setup-crypttab"], root="/mnt/sysroot")

@patch("pyanaconda.core.util.execWithRedirect")
@patch("com_redhat_kdump.service.installation.KdumpCrypttabSetupTask._has_setup_crypttab_command")
def test_crypttab_setup_run_without_command_available(self, mock_has_command, mock_exec):
mock_has_command.return_value = False
task = KdumpCrypttabSetupTask(sysroot="/mnt/sysroot")
task.run()
mock_has_command.assert_called_once()
mock_exec.assert_not_called()

@patch("pyanaconda.core.util.execWithRedirect")
@patch("com_redhat_kdump.service.installation.KdumpCrypttabSetupTask._has_setup_crypttab_command")
def test_crypttab_setup_run_execution_failure(self, mock_has_command, mock_exec):
mock_has_command.return_value = True
mock_exec.side_effect = Exception("Command failed")
task = KdumpCrypttabSetupTask(sysroot="/mnt/sysroot")
task.run()
mock_has_command.assert_called_once()
mock_exec.assert_called_once_with("kdumpctl", ["setup-crypttab"], root="/mnt/sysroot")