Skip to content

Commit

Permalink
commit black updates
Browse files Browse the repository at this point in the history
Signed-off-by: Xiangce Liu <[email protected]>
  • Loading branch information
xiangce authored and JoySnow committed Jan 15, 2025
1 parent c0f5f36 commit 32a299e
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 19 deletions.
13 changes: 8 additions & 5 deletions insights/combiners/grubby.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""
Grubby
======
Combiner for command ``/usr/sbin/grubby`` parsers.
This combiner uses the parsers:
Expand All @@ -28,16 +27,20 @@ class Grubby(object):
Raises:
ParseException: when parsing into error.
"""

def __init__(self, grubby_info_all, grubby_default_index):
self.boot_entries = grubby_info_all.boot_entries
self.default_index = grubby_default_index.default_index

if self.default_index not in self.boot_entries:
raise ParseException("DEFAULT index %s not exist in parsed boot_entries: %s" %
(self.default_index, list(self.boot_entries.keys())))
raise ParseException(
"DEFAULT index %s not exist in parsed boot_entries: %s"
% (self.default_index, list(self.boot_entries.keys()))
)
self.default_boot_entry = self.boot_entries[self.default_index]

self.default_kernel = self.default_boot_entry.get("kernel")
if not self.default_kernel:
raise ParseException("DEFAULT kernel-path not exist in default-index: %s" %
self.default_index)
raise ParseException(
"DEFAULT kernel-path not exist in default-index: %s" % self.default_index
)
13 changes: 10 additions & 3 deletions insights/parsers/grubby.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
grubby - command ``/usr/sbin/grubby``
Grubby - command ``/usr/sbin/grubby``
=====================================
This is a collection of parsers that all deal with the command ``grubby``.
Expand All @@ -14,6 +14,7 @@
GrubbyInfoAll - command ``grubby --info=ALL``
---------------------------------------------
"""

from insights.core import CommandParser
from insights.core.exceptions import ParseException, SkipComponent
from insights.core.plugins import parser
Expand Down Expand Up @@ -41,6 +42,7 @@ class GrubbyDefaultIndex(CommandParser):
Attributes:
default_index (int): the numeric index of the current default boot entry, count from 0
"""

def parse_content(self, content):
if not content:
raise SkipComponent('Empty output')
Expand Down Expand Up @@ -74,9 +76,13 @@ class GrubbyDefaultKernel(CommandParser):
Attributes:
default_kernel(str): The default kernel name for next boot
"""

def __init__(self, context):
deprecated(GrubbyDefaultKernel,
"Please use the :class:`insights.combiners.grubby.Grubby` instead.", "3.7.0")
deprecated(
GrubbyDefaultKernel,
"Please use the :class:`insights.combiners.grubby.Grubby` instead.",
"3.7.0",
)
super(GrubbyDefaultKernel, self).__init__(context)

def parse_content(self, content):
Expand Down Expand Up @@ -145,6 +151,7 @@ class GrubbyInfoAll(CommandParser):
SkipComponent: When output is empty
ParseException: When output is invalid
"""

def parse_content(self, content):

def _parse_args(args):
Expand Down
4 changes: 3 additions & 1 deletion insights/tests/combiners/test_grubby.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ def test_grubby():
'crashkernel': ['1G-4G:192M,4G-64G:256M,64G-:512M'],
'resume': ['/dev/mapper/rhel-swap'],
'rd.lvm.lv': ['rhel/root', 'rhel/swap'],
'rhgb': [True], 'quiet': [True], 'retbleed': ['stuff'],
'rhgb': [True],
'quiet': [True],
'retbleed': ['stuff'],
},
root="/dev/mapper/rhel-root",
initrd="/boot/initramfs-5.14.0-162.6.1.el9_1.x86_64.img",
Expand Down
18 changes: 8 additions & 10 deletions insights/tests/parsers/test_grubby.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@

from insights.core.exceptions import ParseException, SkipComponent
from insights.parsers import grubby
from insights.parsers.grubby import (
GrubbyDefaultIndex,
GrubbyDefaultKernel,
GrubbyInfoAll
)
from insights.parsers.grubby import GrubbyDefaultIndex, GrubbyDefaultKernel, GrubbyInfoAll
from insights.tests import context_wrap

DEFAULT_INDEX_1 = '0'
Expand Down Expand Up @@ -179,7 +175,9 @@ def test_grubby_info_all():
'crashkernel': ['1G-4G:192M,4G-64G:256M,64G-:512M'],
'resume': ['/dev/mapper/rhel-swap'],
'rd.lvm.lv': ['rhel/root', 'rhel/swap'],
'rhgb': [True], 'quiet': [True], 'retbleed': ['stuff'],
'rhgb': [True],
'quiet': [True],
'retbleed': ['stuff'],
},
root="/dev/mapper/rhel-root",
initrd="/boot/initramfs-5.14.0-162.6.1.el9_1.x86_64.img",
Expand Down Expand Up @@ -216,9 +214,9 @@ def test_grubby_info_all_ab():

def test_doc_examples():
env = {
'grubby_default_index': GrubbyDefaultIndex(context_wrap(DEFAULT_INDEX_1)),
'grubby_default_kernel': GrubbyDefaultKernel(context_wrap(DEFAULT_KERNEL)),
'grubby_info_all': GrubbyInfoAll(context_wrap(GRUBBY_INFO_ALL_1)),
}
'grubby_default_index': GrubbyDefaultIndex(context_wrap(DEFAULT_INDEX_1)),
'grubby_default_kernel': GrubbyDefaultKernel(context_wrap(DEFAULT_KERNEL)),
'grubby_info_all': GrubbyInfoAll(context_wrap(GRUBBY_INFO_ALL_1)),
}
failed, total = doctest.testmod(grubby, globs=env)
assert failed == 0

0 comments on commit 32a299e

Please sign in to comment.