-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
parsers: add parser for image builder facts (RHINENG-13943) (#4261)
Signed-off-by: Sanne Raymaekers <[email protected]>
- Loading branch information
1 parent
ccabd1e
commit 4280fd0
Showing
3 changed files
with
84 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.. automodule:: insights.parsers.image_builder_facts | ||
:members: | ||
:show-inheritance: |
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,43 @@ | ||
""" | ||
ImageBuilderFacts - file ``/etc/rhsm/facts/osbuild.facts`` | ||
========================================================== | ||
This module provides parsing for the ``/etc/rhsm/facts/osbuild.facts`` file. | ||
The ``ImageBuilderFacts`` class is based on a shared class which processes the JSON | ||
information into a dictionary. | ||
""" | ||
|
||
from insights.core import JSONParser | ||
from insights.core.plugins import parser | ||
from insights.specs import Specs | ||
|
||
|
||
@parser(Specs.image_builder_facts) | ||
class ImageBuilderFacts(JSONParser): | ||
""" | ||
Parses the ``/etc/rhsm/facts/osbuild.facts`` file. | ||
Sample input:: | ||
{ | ||
"image-builder.insights.compliance-policy-id": "61812cce-c884-4d52-bf05-15b41370db23", | ||
"image-builder.insights.compliance-profile-id": "xccdf_org.ssgproject.content_profile_cis", | ||
"image-builder.osbuild-composer.api-type": "cloudapi-v2" | ||
} | ||
Output will be a python object with the same structure as the JSON:: | ||
{ | ||
"image-builder.insights.compliance-policy-id": "61812cce-c884-4d52-bf05-15b41370db23", | ||
"image-builder.insights.compliance-profile-id": "xccdf_org.ssgproject.content_profile_cis", | ||
"image-builder.osbuild-composer.api-type": "cloudapi-v2" | ||
} | ||
Example: | ||
>>> type(image_builder_facts) | ||
<class 'insights.parsers.image_builder_facts.ImageBuilderFacts'> | ||
>>> image_builder_facts["image-builder.insights.compliance-policy-id"] == "61812cce-c884-4d52-bf05-15b41370db23" | ||
True | ||
""" | ||
pass |
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,38 @@ | ||
import doctest | ||
|
||
from insights.parsers import image_builder_facts | ||
from insights.parsers.image_builder_facts import ImageBuilderFacts | ||
from insights.tests import context_wrap | ||
from insights.tests.parsers import skip_component_check | ||
|
||
|
||
IB_FACTS = """ | ||
{ | ||
"image-builder.insights.compliance-policy-id": "61812cce-c884-4d52-bf05-15b41370db23", | ||
"image-builder.insights.compliance-profile-id": "xccdf_org.ssgproject.content_profile_cis", | ||
"image-builder.osbuild-composer.api-type": "cloudapi-v2" | ||
} | ||
""".strip() | ||
|
||
|
||
def test_image_builder_facts(): | ||
result = ImageBuilderFacts(context_wrap(IB_FACTS)) | ||
|
||
assert result.data == { | ||
"image-builder.insights.compliance-policy-id": "61812cce-c884-4d52-bf05-15b41370db23", | ||
"image-builder.insights.compliance-profile-id": "xccdf_org.ssgproject.content_profile_cis", | ||
"image-builder.osbuild-composer.api-type": "cloudapi-v2" | ||
} | ||
|
||
|
||
def test_image_builder_facts_empty(): | ||
assert 'Empty output.' in skip_component_check(ImageBuilderFacts) | ||
|
||
|
||
def test_image_builder_facts_doc_examples(): | ||
env = { | ||
'ImageBuilderFacts': ImageBuilderFacts, | ||
'image_builder_facts': ImageBuilderFacts(context_wrap(IB_FACTS)), | ||
} | ||
failed, total = doctest.testmod(image_builder_facts, globs=env) | ||
assert failed == 0 |