Skip to content

Commit

Permalink
Feat: Add spec and parser for 'containers_policy' (#3394)
Browse files Browse the repository at this point in the history
* Feat: Add spec and parser for 'containers_policy'

Signed-off-by: shlao <[email protected]>

* Updated the class docstring

Signed-off-by: shlao <[email protected]>
(cherry picked from commit 6c47311)
  • Loading branch information
shlao authored and xiangce committed Apr 28, 2022
1 parent b406c89 commit e7754a0
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 0 deletions.
3 changes: 3 additions & 0 deletions docs/shared_parsers_catalog/containers_policy.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.. automodule:: insights.parsers.containers_policy
:members:
:show-inheritance:
59 changes: 59 additions & 0 deletions insights/parsers/containers_policy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
"""
ContainersPolicy - file ``/etc/containers/policy.json``
=======================================================
"""
from insights import JSONParser, parser
from insights.specs import Specs


@parser(Specs.containers_policy)
class ContainersPolicy(JSONParser):
"""
Class for converting file ``/etc/containers/policy.json``
into a dictionary that matches the JSON string in the file.
Sample file content::
{
"default": [
{
"type": "insecureAcceptAnything"
}
],
"transports": {
"docker": {
"registry.access.redhat.com": [
{
"type": "signedBy",
"keyType": "GPGKeys",
"keyPath": "/etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release"
}
],
"registry.redhat.io/redhat/redhat-operator-index": [
{
"type": "insecureAcceptAnything"
}
],
"registry.redhat.io": [
{
"type": "signedBy",
"keyType": "GPGKeys",
"keyPath": "/etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release"
}
]
},
"docker-daemon": {
"": [
{
"type": "insecureAcceptAnything"
}
]
}
}
}
Examples:
>>> len(containers_policy["default"])
1
"""
pass
64 changes: 64 additions & 0 deletions insights/parsers/tests/test_containers_policy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import doctest

from insights.parsers import containers_policy
from insights.parsers.containers_policy import ContainersPolicy
from insights.parsers.tests import skip_exception_check
from insights.tests import context_wrap

CONTAINERS_POLICY_FILE = '''
{
"default": [
{
"type": "insecureAcceptAnything"
}
],
"transports": {
"docker": {
"registry.access.redhat.com": [
{
"type": "signedBy",
"keyType": "GPGKeys",
"keyPath": "/etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release"
}
],
"registry.redhat.io/redhat/redhat-operator-index": [
{
"type": "insecureAcceptAnything"
}
],
"registry.redhat.io": [
{
"type": "signedBy",
"keyType": "GPGKeys",
"keyPath": "/etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release"
}
]
},
"docker-daemon": {
"": [
{
"type": "insecureAcceptAnything"
}
]
}
}
}
'''.strip()


def test_doc_examples():
env = {
'containers_policy': ContainersPolicy(context_wrap(CONTAINERS_POLICY_FILE)),
}
failed, total = doctest.testmod(containers_policy, globs=env)
assert failed == 0


def test_containers_policy():
conf = ContainersPolicy(context_wrap(CONTAINERS_POLICY_FILE))
assert len(conf["default"]) == 1
assert conf["default"][0]["type"] == "insecureAcceptAnything"


def test_containers_policy_empty():
assert 'Empty output.' in skip_exception_check(ContainersPolicy)
1 change: 1 addition & 0 deletions insights/specs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class Specs(SpecSet):
cni_podman_bridge_conf = RegistryPoint()
cobbler_modules_conf = RegistryPoint()
cobbler_settings = RegistryPoint()
containers_policy = RegistryPoint()
corosync = RegistryPoint()
corosync_cmapctl = RegistryPoint(multi_output=True)
corosync_conf = RegistryPoint()
Expand Down
1 change: 1 addition & 0 deletions insights/specs/sos_archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class SosSpecs(Specs):
cni_podman_bridge_conf = simple_file("/etc/cni/net.d/87-podman-bridge.conflist")
cobbler_settings = first_file(["/etc/cobbler/settings", "/conf/cobbler/settings"])
cobbler_modules_conf = first_file(["/etc/cobbler/modules.conf", "/conf/cobbler/modules.conf"])
containers_policy = simple_file("/etc/containers/policy.json")
corosync_cmapctl = glob_file("sos_commands/corosync/corosync-cmapctl*")
cpe = simple_file("/etc/system-release-cpe")
cpu_smt_control = simple_file("sys/devices/system/cpu/smt/control")
Expand Down

0 comments on commit e7754a0

Please sign in to comment.