Skip to content

Commit

Permalink
parsers: add parser for image builder facts (RHINENG-13943) (#4261)
Browse files Browse the repository at this point in the history
Signed-off-by: Sanne Raymaekers <[email protected]>
  • Loading branch information
croissanne authored Oct 31, 2024
1 parent ccabd1e commit 4280fd0
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
3 changes: 3 additions & 0 deletions docs/shared_parsers_catalog/image_builder_facts.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.. automodule:: insights.parsers.image_builder_facts
:members:
:show-inheritance:
43 changes: 43 additions & 0 deletions insights/parsers/image_builder_facts.py
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
38 changes: 38 additions & 0 deletions insights/tests/parsers/test_image_builder_facts.py
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

0 comments on commit 4280fd0

Please sign in to comment.