Skip to content

Commit

Permalink
check 'reserve-mb' number with kickstart
Browse files Browse the repository at this point in the history
  • Loading branch information
iasunsea committed May 9, 2023
1 parent 70c84eb commit 95b07c2
Show file tree
Hide file tree
Showing 3 changed files with 191 additions and 2 deletions.
12 changes: 12 additions & 0 deletions com_redhat_kdump/service/kdump.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def __init__(self):

self._reserved_memory = "auto"
self.reserved_memory_changed = Signal()
self._lower, self._upper, self._step = getMemoryBounds()

def publish(self):
"""Publish the DBus objects."""
Expand Down Expand Up @@ -85,6 +86,17 @@ def reserved_memory(self):

@reserved_memory.setter
def reserved_memory(self, value):
if value != "auto":
suffix = False
if value[-1] == 'M':
value = value[:-1]
suffix = True
if int(value) > self._upper:
value = self._upper
if int(value) < self._lower:
value = self._lower
if suffix:
value += 'M'
self._reserved_memory = value
self.reserved_memory_changed.emit()
log.debug("Reserved memory is set to '%s'.", value)
Expand Down
45 changes: 44 additions & 1 deletion test/unit_tests/test_interface.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,35 @@
from unittest.case import TestCase
from unittest.mock import patch
from unittest.mock import Mock

from com_redhat_kdump import common
from .mock import MockBuiltinRead
from com_redhat_kdump.constants import KDUMP
from com_redhat_kdump.service.kdump import KdumpService
from com_redhat_kdump.service.kdump_interface import KdumpInterface

SYS_CRASH_SIZE = '/sys/kernel/kexec_crash_size'
PROC_MEMINFO = '/proc/meminfo'
CRASHKERNEL_DEFAULT = '/usr/lib/modules/{}/crashkernel.default'

X86_INFO_FIXTURE = {
SYS_CRASH_SIZE: "167772160", # 160MB
PROC_MEMINFO:"""MemTotal: 1048576 kB
""" # 1GB - 160MB
}

AARCH64_NFO_FIXTURE = {
SYS_CRASH_SIZE: "536870912", # 512MB
PROC_MEMINFO:"""MemTotal: 2097152 kB
""" # 2GB - 512MB
}

PPC64_INFO_FIXTURE = {
SYS_CRASH_SIZE: "1073741824", # 1024MB
PROC_MEMINFO:"""MemTotal: 66060288 kB
""" # 64GB - 1GB
}


class PropertiesChangedCallback(Mock):

Expand Down Expand Up @@ -48,7 +72,26 @@ def test_fadump_enabled(self):
self._check_properties_changed("FadumpEnabled", True)
self.assertEqual(self._interface.FadumpEnabled, True)

def test_reserved_memory(self):
@patch("builtins.open", MockBuiltinRead(AARCH64_NFO_FIXTURE))
@patch("blivet.arch.get_arch", return_value="aarch64")
def test_reserved_memory_aarch64(self):
self._service.__init__()
self._interface.ReservedMemory = "256"
self._check_properties_changed("ReservedMemory", "512")
self.assertEqual(self._interface.ReservedMemory, "512")

@patch("builtins.open", MockBuiltinRead(X86_INFO_FIXTURE))
@patch("blivet.arch.get_arch", return_value="aarch64")
def test_reserved_memory_aarch64(self):
self._service.__init__()
self._interface.ReservedMemory = "256"
self._check_properties_changed("ReservedMemory", "256")
self.assertEqual(self._interface.ReservedMemory, "256")

@patch("builtins.open", MockBuiltinRead(PPC64_INFO_FIXTURE))
@patch("blivet.arch.get_arch", return_value="aarch64")
def test_reserved_memory_aarch64(self):
self._service.__init__()
self._interface.ReservedMemory = "256"
self._check_properties_changed("ReservedMemory", "384")
self.assertEqual(self._interface.ReservedMemory, "384")
136 changes: 135 additions & 1 deletion test/unit_tests/test_kickstart.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,44 @@
from textwrap import dedent
from unittest.case import TestCase
from unittest.mock import patch
from com_redhat_kdump import common
from .mock import MockBuiltinRead
from com_redhat_kdump.service.kdump import KdumpService

SYS_CRASH_SIZE = '/sys/kernel/kexec_crash_size'
PROC_MEMINFO = '/proc/meminfo'
CRASHKERNEL_DEFAULT = '/usr/lib/modules/{}/crashkernel.default'

X86_INFO_FIXTURE = {
SYS_CRASH_SIZE: "167772160", # 160MB
PROC_MEMINFO:"""MemTotal: 4030464 kB
""" # 4GB - 160MB
}

X86_LOWER_INFO_FIXTURE = {
SYS_CRASH_SIZE: "167772160", # 160MB
PROC_MEMINFO:"""MemTotal: 1048576 kB
""" # 1GB - 160MB
}

AARCH64_INFO_FIXTURE = {
SYS_CRASH_SIZE: "536870912", # 512MB
PROC_MEMINFO:"""MemTotal: 66584576 kB
""" # 64GB - 512MB
}

AARCH64_LOWER_NFO_FIXTURE = {
SYS_CRASH_SIZE: "536870912", # 512MB
PROC_MEMINFO:"""MemTotal: 2097152 kB
""" # 2GB - 512MB
}

PPC64_INFO_FIXTURE = {
SYS_CRASH_SIZE: "1073741824", # 1024MB
PROC_MEMINFO:"""MemTotal: 66060288 kB
""" # 64GB - 1GB
}


class KdumpKickstartTestCase(TestCase):

Expand Down Expand Up @@ -68,7 +104,29 @@ def test_ks_disable(self):
%end
""")

def test_ks_reserve_mb(self):
@patch("builtins.open", MockBuiltinRead(X86_INFO_FIXTURE))
@patch("blivet.arch.get_arch", return_value="x86_64")
def test_ks_reserve_mb_x86_with_low(self, _mock_read):
self._service.__init__()
self._check_ks_input("""
%addon com_redhat_kdump --enable --reserve-mb=80
%end
""")

self.assertEqual(self._service.kdump_enabled, True)
self.assertEqual(self._service.fadump_enabled, False)
self.assertEqual(self._service.reserved_memory, "160")

self._check_ks_output("""
%addon com_redhat_kdump --enable --reserve-mb='160'
%end
""")

@patch("builtins.open", MockBuiltinRead(X86_INFO_FIXTURE))
@patch("blivet.arch.get_arch", return_value="x86_64")
def test_ks_reserve_mb_x86_with_normal(self, _mock_read):
self._service.__init__()
self._check_ks_input("""
%addon com_redhat_kdump --enable --reserve-mb=256
%end
Expand All @@ -84,6 +142,82 @@ def test_ks_reserve_mb(self):
%end
""")

@patch("builtins.open", MockBuiltinRead(X86_LOWER_INFO_FIXTURE))
@patch("blivet.arch.get_arch", return_value="x86_64")
def test_ks_reserve_mb_x86_with_up(self, _mock_read):
self._service.__init__()
self._check_ks_input("""
%addon com_redhat_kdump --enable --reserve-mb=600
%end
""")

self.assertEqual(self._service.kdump_enabled, True)
self.assertEqual(self._service.fadump_enabled, False)
self.assertEqual(self._service.reserved_memory, "512") # upper = 1024M - 512M

self._check_ks_output("""
%addon com_redhat_kdump --enable --reserve-mb='512'
%end
""")

@patch("builtins.open", MockBuiltinRead(AARCH64_INFO_FIXTURE))
@patch("blivet.arch.get_arch", return_value="aarch64")
def test_ks_reserve_mb_aarch64_with_low(self, _mock_read):
self._service.__init__()
self._check_ks_input("""
%addon com_redhat_kdump --enable --reserve-mb=256
%end
""")

self.assertEqual(self._service.kdump_enabled, True)
self.assertEqual(self._service.fadump_enabled, False)
self.assertEqual(self._service.reserved_memory, "512")

self._check_ks_output("""
%addon com_redhat_kdump --enable --reserve-mb='512'
%end
""")

@patch("builtins.open", MockBuiltinRead(AARCH64_INFO_FIXTURE))
@patch("blivet.arch.get_arch", return_value="aarch64")
def test_ks_reserve_mb_aarch64_with_normal(self, _mock_read):
self._service.__init__()
self._check_ks_input("""
%addon com_redhat_kdump --enable --reserve-mb=1024
%end
""")

self.assertEqual(self._service.kdump_enabled, True)
self.assertEqual(self._service.fadump_enabled, False)
self.assertEqual(self._service.reserved_memory, "1024")

self._check_ks_output("""
%addon com_redhat_kdump --enable --reserve-mb='1024'
%end
""")

@patch("builtins.open", MockBuiltinRead(AARCH64_LOWER_NFO_FIXTURE))
@patch("blivet.arch.get_arch", return_value="aarch64")
def test_ks_reserve_mb_aarch64_with_up(self, _mock_read):
self._service.__init__()
self._check_ks_input("""
%addon com_redhat_kdump --enable --reserve-mb=1600
%end
""")

self.assertEqual(self._service.kdump_enabled, True)
self.assertEqual(self._service.fadump_enabled, False)
self.assertEqual(self._service.reserved_memory, "1536") # upper = 2*1024M - 512M

self._check_ks_output("""
%addon com_redhat_kdump --enable --reserve-mb='1536'
%end
""")

def test_ks_reserve_auto(self):
self._check_ks_input("""
%addon com_redhat_kdump --enable --reserve-mb=auto
Expand Down

0 comments on commit 95b07c2

Please sign in to comment.