-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: Add Parser LsinitrdKdumpImage (#3567)
* New Parser for lsinitrd kdump initramfs image Signed-off-by: Xinting Li <[email protected]> * Update custom_datasources_index.rst * Fix flake8 error * Fix doc test error * update multi_output in __init__.py * Use listdir instead of datasource Signed-off-by: Xinting Li <[email protected]> * Feat: Update spec command with using -k option and change to using datasource Signed-off-by: Xinting Li <[email protected]> * Fix: Fix the title underline is too short in custom_datasources_index.rst * fix: fix unexpected indentation in current_kernel_version * Fix: fix the title underline is too short and rename datasource * Fix: fix doc error * update the order of datasource Signed-off-by: Xinting Li <[email protected]> (cherry picked from commit 4121e94)
- Loading branch information
Showing
7 changed files
with
227 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
""" | ||
Custom datasource to get the current kernel version. | ||
""" | ||
|
||
from insights.core.context import HostContext | ||
from insights.core.plugins import datasource | ||
from insights.parsers.uname import Uname | ||
|
||
|
||
@datasource(Uname, HostContext) | ||
def current_version(broker): | ||
""" | ||
This datasource provides the current booting kernel version. | ||
Sample data returned:: | ||
'4.18.0-240.el8.x86_64' | ||
Returns: | ||
String: The current kernel version. | ||
Raises: | ||
UnameError: When there is a problem occurs with uname data. | ||
""" | ||
|
||
return broker[Uname].kernel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import pytest | ||
from insights.specs.datasources.kernel import current_version | ||
from insights.parsers.uname import Uname | ||
from insights.parsers import uname | ||
from insights.tests import context_wrap | ||
|
||
UNAME = """ | ||
Linux vm37-130.gsslab.pek2.redhat.com 5.14.0-160.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Aug 25 20:41:37 EDT 2022 x86_64 x86_64 x86_64 GNU/Linux | ||
""" | ||
|
||
UNAME_ERROR_BLANK = "" | ||
|
||
|
||
def test_current_kernel_version(): | ||
uname = Uname(context_wrap(UNAME)) | ||
|
||
broker = { | ||
Uname: uname | ||
} | ||
result = current_version(broker) | ||
assert result is not None | ||
assert result == '5.14.0-160.el9.x86_64' | ||
|
||
|
||
def test_current_kernel_version_without_uname(): | ||
with pytest.raises(uname.UnameError) as e_info: | ||
current_version({Uname: uname.Uname(context_wrap(UNAME_ERROR_BLANK))}) | ||
assert 'Empty uname line' in str(e_info.value) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters