add crashkernel auto for arm and fix test

(cherry picked from commit 36be1117ea0a536bf03c09dceee3c3a4339c5ea4)
This commit is contained in:
yangl777 2024-03-06 06:48:32 +00:00 committed by openeuler-sync-bot
parent e2a3b4c983
commit 0800a41061
6 changed files with 620 additions and 1 deletions

View File

@ -0,0 +1,314 @@
From fb83e0d26a2f6a64820ddd5724aa270f1600f288 Mon Sep 17 00:00:00 2001
From: huzunhao <huzunhao2@huawei.com>
Date: Tue, 4 Apr 2023 15:47:51 +0800
Subject: [PATCH] Add crashkernel auto for Arm
---
com_redhat_kdump/common.py | 7 ++-
com_redhat_kdump/gui/spokes/kdump.glade | 54 ++++++++++++++++++++++++
com_redhat_kdump/gui/spokes/kdump.py | 43 ++++++++++++++++---
com_redhat_kdump/service/installation.py | 2 +-
com_redhat_kdump/service/kdump.py | 4 +-
com_redhat_kdump/service/kickstart.py | 27 ++++++------
com_redhat_kdump/tui/spokes/kdump.py | 4 +-
po/zh_CN.po | 12 +++---
8 files changed, 123 insertions(+), 30 deletions(-)
diff --git a/com_redhat_kdump/common.py b/com_redhat_kdump/common.py
index 1b79186..b8450c8 100644
--- a/com_redhat_kdump/common.py
+++ b/com_redhat_kdump/common.py
@@ -65,10 +65,15 @@ def getMemoryBounds():
totalMemory = getTotalMemory()
- if blivet.arch.get_arch() == 'ppc64':
+ arch = blivet.arch.get_arch()
+ if arch.startswith('ppc64'):
lowerBound = 256
minUsable = 1024
step = 1
+ elif arch == 'aarch64':
+ lowerBound = 768
+ minUsable = 768
+ step = 1
else:
lowerBound = 128
minUsable = 256
diff --git a/com_redhat_kdump/gui/spokes/kdump.glade b/com_redhat_kdump/gui/spokes/kdump.glade
index fdcfdfb..aebc211 100644
--- a/com_redhat_kdump/gui/spokes/kdump.glade
+++ b/com_redhat_kdump/gui/spokes/kdump.glade
@@ -14,6 +14,7 @@
<property name="spacing">6</property>
<child internal-child="nav_box">
<object class="GtkEventBox" id="AnacondaSpokeWindow-nav_box1">
+ <property name="name">nav-box</property>
<property name="can_focus">False</property>
<child internal-child="nav_area">
<object class="GtkGrid" id="AnacondaSpokeWindow-nav_area1">
@@ -190,6 +191,59 @@
<property name="height">1</property>
</packing>
</child>
+ <child>
+ <object class="GtkLabel" id="reservationTypeLabel">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">Kdump Memory Reservation:</property>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">2</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkRadioButton" id="autoButton">
+ <property name="label" translatable="yes">_Automatic</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="use_underline">True</property>
+ <property name="xalign">0</property>
+ <property name="active">True</property>
+ <property name="draw_indicator">True</property>
+ <signal name="toggled" handler="on_reservation_toggled" swapped="no"/>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="top_attach">2</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkRadioButton" id="manualButton">
+ <property name="label" translatable="yes">_Manual</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="use_underline">True</property>
+ <property name="xalign">0</property>
+ <property name="active">True</property>
+ <property name="draw_indicator">True</property>
+ <property name="group">autoButton</property>
+ <signal name="toggled" handler="on_reservation_toggled" swapped="no"/>
+ </object>
+ <packing>
+ <property name="left_attach">2</property>
+ <property name="top_attach">2</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
<child>
<placeholder/>
</child>
diff --git a/com_redhat_kdump/gui/spokes/kdump.py b/com_redhat_kdump/gui/spokes/kdump.py
index 9420755..c229485 100644
--- a/com_redhat_kdump/gui/spokes/kdump.py
+++ b/com_redhat_kdump/gui/spokes/kdump.py
@@ -66,6 +66,9 @@ class KdumpSpoke(NormalSpoke):
self._fadumpButton.show()
else:
self._fadumpButton.hide()
+ self._reservationTypeLabel = self.builder.get_object("reservationTypeLabel")
+ self._autoButton = self.builder.get_object("autoButton")
+ self._manualButton = self.builder.get_object("manualButton")
self._toBeReservedLabel = self.builder.get_object("toBeReservedLabel")
self._toBeReservedSpin = self.builder.get_object("toBeReservedSpin")
self._totalMemLabel = self.builder.get_object("totalMemLabel")
@@ -82,11 +85,12 @@ class KdumpSpoke(NormalSpoke):
def refresh(self):
# If a reserve amount is requested, set it in the spin button
# Strip the trailing 'M'
- reserveMB = self._proxy.ReservedMemory
- if reserveMB and reserveMB[-1] == 'M':
- reserveMB = reserveMB[:-1]
- if reserveMB:
- self._toBeReservedSpin.set_value(int(reserveMB))
+ if self._proxy.ReservedMemory != "auto":
+ reserveMB = self._proxy.ReservedMemory
+ if reserveMB and reserveMB[-1] == 'M':
+ reserveMB = reserveMB[:-1]
+ if reserveMB:
+ self._toBeReservedSpin.set_value(int(reserveMB))
# Set the various labels. Use the spin button signal handler to set the
# usable memory label once the other two have been set.
@@ -97,6 +101,13 @@ class KdumpSpoke(NormalSpoke):
# the sensitivities on the related widgets. Set the radio button first,
# since the radio buttons' bailiwick is a subset of that of the
# enable/disable checkbox.
+ if self._proxy.ReservedMemory == "auto":
+ self._autoButton.set_active(True)
+ self._manualButton.set_active(False)
+ else:
+ self._autoButton.set_active(False)
+ self._manualButton.set_active(True)
+
if self._proxy.KdumpEnabled:
self._enableButton.set_active(True)
else:
@@ -110,7 +121,10 @@ class KdumpSpoke(NormalSpoke):
def apply(self):
# Copy the GUI state into the AddonData object
self._proxy.KdumpEnabled = self._enableButton.get_active()
- self._proxy.ReservedMemory = "%dM" % self._toBeReservedSpin.get_value_as_int()
+ if self._autoButton.get_active():
+ self._proxy.ReservedMemory = "auto"
+ else:
+ self._proxy.ReservedMemory = "%dM" % self._toBeReservedSpin.get_value_as_int()
self._proxy.FadumpEnabled = self._fadumpButton.get_active()
@property
@@ -147,10 +161,27 @@ class KdumpSpoke(NormalSpoke):
self._totalMemMB.set_sensitive(status)
self._usableMemLabel.set_sensitive(status)
self._usableMemMB.set_sensitive(status)
+ self._autoButton.set_sensitive(status)
+ self._manualButton.set_sensitive(status)
self._fadumpButton.set_sensitive(status)
if not status:
self._fadumpButton.set_active(False)
+ if status:
+ self._autoButton.emit("toggled")
+
+ def on_reservation_toggled(self, radiobutton, user_data=None):
+ status = self._manualButton.get_active()
+
+ # If setting to auto, disable the manual config spinner and
+ # the total/usable memory labels
+ fancy_set_sensitive(self._toBeReservedSpin, status)
+ self._totalMemLabel.set_sensitive(status)
+ self._totalMemMB.set_sensitive(status)
+ self._usableMemLabel.set_sensitive(status)
+ self._usableMemMB.set_sensitive(status)
+
+
def on_enable_fadump_toggled(self, checkbutton, user_data=None):
if self._enableButton.get_active():
self.enablefadump = self._fadumpButton.get_active()
diff --git a/com_redhat_kdump/service/installation.py b/com_redhat_kdump/service/installation.py
index d2f4d75..64638a9 100644
--- a/com_redhat_kdump/service/installation.py
+++ b/com_redhat_kdump/service/installation.py
@@ -58,7 +58,7 @@ class KdumpConfigurationTask(Task):
# Copy our reserved amount to the bootloader arguments.
if self._kdump_enabled:
# Ensure that the amount is an amount in MB.
- if self._reserved_memory[-1] != 'M':
+ if self._reserved_memory != "auto" and self._reserved_memory[-1] != 'M':
self._reserved_memory += 'M'
args.append('crashkernel=%s' % self._reserved_memory)
diff --git a/com_redhat_kdump/service/kdump.py b/com_redhat_kdump/service/kdump.py
index f4811df..ff902b7 100644
--- a/com_redhat_kdump/service/kdump.py
+++ b/com_redhat_kdump/service/kdump.py
@@ -41,14 +41,14 @@ class KdumpService(KickstartService):
def __init__(self):
"""Create a service."""
super().__init__()
- self._kdump_enabled = False
+ self._kdump_enabled = True
self.kdump_enabled_changed = Signal()
self._fadump_enabled = False
self.fadump_enabled_changed = Signal()
+ self.reserveMB = "auto"
lower, upper, step = getMemoryBounds()
- self._reserved_memory = "%d" % lower
self.reserved_memory_changed = Signal()
def publish(self):
diff --git a/com_redhat_kdump/service/kickstart.py b/com_redhat_kdump/service/kickstart.py
index 41ba6eb..28d8a23 100644
--- a/com_redhat_kdump/service/kickstart.py
+++ b/com_redhat_kdump/service/kickstart.py
@@ -88,19 +88,20 @@ class KdumpKickstartData(AddonData):
opts = op.parse_args(args=args, lineno=line_number)
- # Validate the reserve-mb argument
- # Allow a final 'M' for consistency with the crashkernel kernel
- # parameter. Strip it if found. And strip quotes.
- opts.reserve_mb = opts.reserve_mb.strip("'\"")
-
- if opts.reserve_mb and opts.reserve_mb[-1] == 'M':
- opts.reserve_mb = opts.reserve_mb[:-1]
-
- try:
- _test = int(opts.reserve_mb)
- except ValueError:
- msg = _("Invalid value '%s' for --reserve-mb") % opts.reserve_mb
- raise KickstartParseError(msg, lineno=line_number)
+ if opts.reserve_mb != "auto":
+ # Validate the reserve-mb argument
+ # Allow a final 'M' for consistency with the crashkernel kernel
+ # parameter. Strip it if found. And strip quotes.
+ opts.reserve_mb = opts.reserve_mb.strip("'\"")
+
+ if opts.reserve_mb and opts.reserve_mb[-1] == 'M':
+ opts.reserve_mb = opts.reserve_mb[:-1]
+
+ try:
+ _test = int(opts.reserve_mb)
+ except ValueError:
+ msg = _("Invalid value '%s' for --reserve-mb") % opts.reserve_mb
+ raise KickstartParseError(msg, lineno=line_number)
# Store the parsed arguments
self.enabled = opts.enabled
diff --git a/com_redhat_kdump/tui/spokes/kdump.py b/com_redhat_kdump/tui/spokes/kdump.py
index 58106ba..dc1d73d 100644
--- a/com_redhat_kdump/tui/spokes/kdump.py
+++ b/com_redhat_kdump/tui/spokes/kdump.py
@@ -48,7 +48,7 @@ class KdumpSpoke(NormalTUISpoke):
self._lower, self._upper, self._step = getMemoryBounds()
# Allow a string of digits optionally followed by 'M'
- self._reserve_check_re = re.compile(r'^(\d+M?)$')
+ self._reserve_check_re = re.compile(r'^((auto)|(\d+M?))$')
self._proxy = KDUMP.get_proxy()
@@ -116,6 +116,8 @@ class KdumpSpoke(NormalTUISpoke):
def _check_reserve_valid(self, key, report_func):
if self._reserve_check_re.match(key):
+ if key == "auto":
+ return True
if key[-1] == 'M':
key = key[:-1]
key = int(key)
diff --git a/po/zh_CN.po b/po/zh_CN.po
index ed13cbd..fb63e9b 100644
--- a/po/zh_CN.po
+++ b/po/zh_CN.po
@@ -79,11 +79,11 @@ msgstr "启用 kdump_E"
msgid "_Enable dump mode fadump"
msgstr "启用转储模式 fadump_E"
-#~ msgid "Kdump Memory Reservation:"
-#~ msgstr "为 Kdump 保留的内存:"
+msgid "Kdump Memory Reservation:"
+msgstr "为 Kdump 保留的内存:"
-#~ msgid "_Automatic"
-#~ msgstr "自动_A"
+msgid "_Automatic"
+msgstr "自动_A"
-#~ msgid "_Manual"
-#~ msgstr "手动_M"
+msgid "_Manual"
+msgstr "手动_M"
--
2.19.1

View File

@ -0,0 +1,45 @@
From 09ab1debcc752ed7d9dbff5731450f9a0df7761a Mon Sep 17 00:00:00 2001
From: zhangqiumiao <zhangqiumiao1@huawei.com>
Date: Wed, 23 Sep 2020 11:23:11 +0800
Subject: [PATCH] enable kdump and set default reserve memory 512M
---
com_redhat_kdump/common.py | 2 +-
com_redhat_kdump/service/kdump.py | 7 ++++++-
2 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/com_redhat_kdump/common.py b/com_redhat_kdump/common.py
index b8450c8..992d63e 100644
--- a/com_redhat_kdump/common.py
+++ b/com_redhat_kdump/common.py
@@ -71,7 +71,7 @@ def getMemoryBounds():
minUsable = 1024
step = 1
elif arch == 'aarch64':
- lowerBound = 768
+ lowerBound = 512
minUsable = 768
step = 1
else:
diff --git a/com_redhat_kdump/service/kdump.py b/com_redhat_kdump/service/kdump.py
index ff902b7..2764e6a 100644
--- a/com_redhat_kdump/service/kdump.py
+++ b/com_redhat_kdump/service/kdump.py
@@ -47,8 +47,13 @@ class KdumpService(KickstartService):
self._fadump_enabled = False
self.fadump_enabled_changed = Signal()
- self.reserveMB = "auto"
lower, upper, step = getMemoryBounds()
+ # set default reserveMB
+ # ensure that 512M is not out of MemoryBounds
+ if (upper > 512):
+ self._reserved_memory = "512"
+ else:
+ self._reserved_memory = "%d" % lower
self.reserved_memory_changed = Signal()
def publish(self):
--
2.19.1

View File

@ -0,0 +1,46 @@
From bdbe716c042bac9fd7c4cfb422403ef61884b86e Mon Sep 17 00:00:00 2001
From: sun_hai_10 <sunhai10@huawei.com>
Date: Tue, 4 Apr 2023 12:39:06 +0800
Subject: [PATCH] fix test failed due to default value change
---
test/unit_tests/test_common.py | 2 +-
test/unit_tests/test_kickstart.py | 6 +++---
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/test/unit_tests/test_common.py b/test/unit_tests/test_common.py
index 16c973c..92a2ba3 100644
--- a/test/unit_tests/test_common.py
+++ b/test/unit_tests/test_common.py
@@ -54,7 +54,7 @@ class KdumpCommonTestCase(TestCase):
@patch("builtins.open", MockFileRead(AARCH64_INFO_FIXTURE))
@patch("blivet.arch.get_arch", return_value="aarch64")
def test_memory_bound_aarch64(self, _mock_read):
- self.assertEqual((128, 64 * 1024 - 256, 1), common.getMemoryBounds())
+ self.assertEqual((512, 64 * 1024 - 768, 1), common.getMemoryBounds())
@patch("builtins.open", MockFileRead(PPC64_INFO_FIXTURE))
@patch("blivet.arch.get_arch", return_value="ppc64")
diff --git a/test/unit_tests/test_kickstart.py b/test/unit_tests/test_kickstart.py
index 0dd78ed..058c9ae 100644
--- a/test/unit_tests/test_kickstart.py
+++ b/test/unit_tests/test_kickstart.py
@@ -26,12 +26,12 @@ class KdumpKickstartTestCase(TestCase):
self.assertEqual(output.strip(), dedent(ks_out).strip())
def test_ks_default(self):
- self.assertEqual(self._service.kdump_enabled, False)
+ self.assertEqual(self._service.kdump_enabled, True)
self.assertEqual(self._service.fadump_enabled, False)
- self.assertEqual(self._service.reserved_memory, "128")
+ self.assertEqual(self._service.reserved_memory, "512")
self._check_ks_output("""
- %addon com_redhat_kdump --disable
+ %addon com_redhat_kdump --enable --reserve-mb='512'
%end
""")
--
2.33.0

View File

@ -0,0 +1,128 @@
From bdbe716c042bac9fd7c4cfb422403ef61884b86e Mon Sep 17 00:00:00 2001
From: sun_hai_10 <sunhai10@huawei.com>
Date: Tue, 4 Apr 2023 12:39:06 +0800
Subject: [PATCH] fix test failed due to default value change
---
test/unit_tests/test_common.py | 2 +-
test/unit_tests/test_installation.py | 6 ++-
test/unit_tests/test_kickstart.py | 60 ++++++++++++++++++++++++++--
3 files changed, 62 insertions(+), 6 deletions(-)
diff --git a/test/unit_tests/test_common.py b/test/unit_tests/test_common.py
index 16c973c..92a2ba3 100644
--- a/test/unit_tests/test_common.py
+++ b/test/unit_tests/test_common.py
@@ -54,7 +54,7 @@ class KdumpCommonTestCase(TestCase):
@patch("builtins.open", MockFileRead(AARCH64_INFO_FIXTURE))
@patch("blivet.arch.get_arch", return_value="aarch64")
def test_memory_bound_aarch64(self, _mock_read):
- self.assertEqual((128, 64 * 1024 - 256, 1), common.getMemoryBounds())
+ self.assertEqual((512, 64 * 1024 - 768, 1), common.getMemoryBounds())
@patch("builtins.open", MockFileRead(PPC64_INFO_FIXTURE))
@patch("blivet.arch.get_arch", return_value="ppc64")
diff --git a/test/unit_tests/test_installation.py b/test/unit_tests/test_installation.py
index b2deb4b..92c0954 100644
--- a/test/unit_tests/test_installation.py
+++ b/test/unit_tests/test_installation.py
@@ -69,7 +69,11 @@ class KdumpInstallationTestCase(TestCase):
kdump_enabled=False
)
task.run()
- mock_util.execWithRedirect.assert_not_called()
+ mock_util.execWithRedirect.assert_called_once_with(
+ "systemctl",
+ ["disable", "kdump.service"],
+ root="/mnt/sysroot"
+ )
@patch("com_redhat_kdump.service.installation.util")
def test_installation_kdump_enabled(self, mock_util):
diff --git a/test/unit_tests/test_kickstart.py b/test/unit_tests/test_kickstart.py
index 0dd78ed..69b57d0 100644
--- a/test/unit_tests/test_kickstart.py
+++ b/test/unit_tests/test_kickstart.py
@@ -1,8 +1,45 @@
from textwrap import dedent
from unittest.case import TestCase
+from unittest.mock import patch, MagicMock
from com_redhat_kdump import common
from com_redhat_kdump.service.kdump import KdumpService
+SYS_CRASH_SIZE = '/sys/kernel/kexec_crash_size'
+PROC_MEMINFO = '/proc/meminfo'
+
+X86_INFO_FIXTURE = {
+ SYS_CRASH_SIZE: "167772160", # 160MB
+ PROC_MEMINFO:"""MemTotal: 4030464 kB
+""" # 4GB - 160MB
+}
+
+AARCH64_INFO_FIXTURE = {
+ SYS_CRASH_SIZE: "536870912", # 512MB
+ PROC_MEMINFO:"""MemTotal: 66584576 kB
+""" # 64GB - 512MB
+}
+
+PPC64_INFO_FIXTURE = {
+ SYS_CRASH_SIZE: "1073741824", # 1024MB
+ PROC_MEMINFO:"""MemTotal: 66060288 kB
+""" # 64GB - 1GB
+}
+
+class MockFileRead(MagicMock):
+ def __init__(self, file_read_map):
+ MagicMock.__init__(self, name=open, spec=open)
+ self.file_read_map = file_read_map
+
+ handle = MagicMock()
+ handle.__enter__.return_value = handle
+ handle.read.return_value = None
+
+ def reset_choose_file(filename, *args, **kwargs):
+ handle.read.return_value = self.file_read_map[filename]
+ return handle
+
+ self.side_effect = reset_choose_file
+
class KdumpKickstartTestCase(TestCase):
@@ -25,13 +62,28 @@ class KdumpKickstartTestCase(TestCase):
output = self._service.generate_kickstart()
self.assertEqual(output.strip(), dedent(ks_out).strip())
- def test_ks_default(self):
- self.assertEqual(self._service.kdump_enabled, False)
+ @patch("builtins.open", MockFileRead(X86_INFO_FIXTURE))
+ @patch("blivet.arch.get_arch", return_value="x86_64")
+ def test_ks_default_x86(self, _mock_read):
+ self.assertEqual(self._service.kdump_enabled, True)
self.assertEqual(self._service.fadump_enabled, False)
- self.assertEqual(self._service.reserved_memory, "128")
+ self.assertEqual(self._service.reserved_memory, "512")
self._check_ks_output("""
- %addon com_redhat_kdump --disable
+ %addon com_redhat_kdump --enable --reserve-mb='512'
+
+ %end
+ """)
+
+ @patch("builtins.open", MockFileRead(AARCH64_INFO_FIXTURE))
+ @patch("blivet.arch.get_arch", return_value="aarch64")
+ def test_ks_default_arrch64(self, _mock_read):
+ 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
""")
--
2.19.1

View File

@ -1,13 +1,24 @@
Name: kdump-anaconda-addon
Version: 006
Release: 1
Release: 2
Summary: Anaconda addon for configuring kdump.
License: GPLv2
URL: https://github.com/rhinstaller/kdump-anaconda-addon
Source0: https://github.com/rhinstaller/kdump-anaconda-addon/archive/%{version}.tar.gz
Source1: set-addon-default-on-and-close-service-when-ks-set-disable.patch
Source2: fix-test-failed-due-to-default-value-change.patch
Patch0: backport-use-pytest-to-run-the-unit-tests.patch
Patch1: Add-crashkernel-auto-for-Arm.patch
Patch2: enable-kdump-and-set-default-reserve-memory-512M.patch
%if %{?openEuler:1}0
Patch3: fix-test-failed-due-to-default-value-change-1.patch
%else
Patch4: set-addon-default-on-and-close-service-when-ks-set-disable.patch
Patch5: fix-test-failed-due-to-default-value-change.patch
%endif
BuildRequires: intltool gettext python3-pytest python3-blivet anaconda
Requires: anaconda >= 34.13 hicolor-icon-theme
@ -51,6 +62,14 @@ make unittest
%{_datadir}/icons/hicolor/scalable/apps/kdump.svg
%changelog
* Wed Mar 06 2024 yanglu <yanglu72@h-partners.com> - 006-2
- Type:enhancement
- CVE:NA
- SUG:NA
- DESC:Add crashkernel auto for Arm
enable kdump and set default reserve memory 512MB
fix test failed due to default value change
* Tue Nov 08 2022 yanglu <yanglu72@h-partners.com> - 006-1
- DESC: update kdump-anaconda-addon version to 006

View File

@ -0,0 +1,67 @@
From f610873cd3590a0cb77287c01b7a025dc83a547a Mon Sep 17 00:00:00 2001
From: sun_hai_10 <sunhai10@huawei.com>
Date: Thu, 6 Apr 2023 18:26:19 +0800
Subject: [PATCH] set addon defalut on and close service when ks set disable
Signed-off-by: yangzhuangzhuang <yangzhuangzhuang1@huawei.com>
Signed-off-by: zhangruifang <zhangruifang1@huawei.com>
---
com_redhat_kdump/service/initialization.py | 18 +++++++++++++++++-
com_redhat_kdump/service/installation.py | 8 +++++---
2 files changed, 22 insertions(+), 4 deletions(-)
diff --git a/com_redhat_kdump/service/initialization.py b/com_redhat_kdump/service/initialization.py
index 2bdbe6e..310a504 100644
--- a/com_redhat_kdump/service/initialization.py
+++ b/com_redhat_kdump/service/initialization.py
@@ -25,8 +25,24 @@ log = logging.getLogger(__name__)
__all__ = ["check_initial_conditions"]
+def kdump_is_enabled():
+ """Return boolean value for the given argument.
+
+ Rules:
+ - 0, off -> False
+ - the rest, not present -> True
+ """
+ # None is stored when arg is present but had no value when parsing.
+ # So the "miss" value must be something else.
+ val = kernel_arguments.get("kdump_addon", True)
+ if val in ["0", "off"]:
+ return False
+ else:
+ return True
+
+
def check_initial_conditions():
"""Can the Kdump service run?"""
- if not kernel_arguments.is_enabled("kdump_addon"):
+ if not kdump_is_enabled():
log.debug("The kdump add-on is disabled. Quit.")
sys.exit(1)
diff --git a/com_redhat_kdump/service/installation.py b/com_redhat_kdump/service/installation.py
index 64638a9..d93b51a 100644
--- a/com_redhat_kdump/service/installation.py
+++ b/com_redhat_kdump/service/installation.py
@@ -85,12 +85,14 @@ class KdumpInstallationTask(Task):
def run(self):
"""Run the task."""
+ action = "enable"
if not self._kdump_enabled:
- log.debug("Kdump is disabled. Skipping.")
- return
+ log.debug("Kdump is disabled.")
+ # unknow kdump.service default set
+ action = "disable"
util.execWithRedirect(
"systemctl",
- ["enable", "kdump.service"],
+ [action, "kdump.service"],
root=self._sysroot
)
--
2.19.1