Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add spec sys_cpuset_cpus #3611

Merged
merged 5 commits into from
Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 35 additions & 5 deletions insights/parsers/cpuset_cpus.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
"""
CpuSetCpus - File ``/sys/fs/cgroup/cpuset/cpuset.cpus``
=======================================================
cpuset_cpus - File ``/sys/fs/cgroup/cpuset/cpuset.cpus``
========================================================

This parser reads the content of ``/sys/fs/cgroup/cpuset/cpuset.cpus``.
This file shows the default cgroup cpuset.cpu of system. The format
of the content is string including comma.
"""

from .. import parser, CommandParser
from insights.core import CommandParser, ContainerParser
from insights.core.plugins import parser
from insights.specs import Specs


Expand All @@ -28,8 +29,8 @@ class CpusetCpus(CommandParser):
Examples:
>>> type(cpusetinfo)
<class 'insights.parsers.cpuset_cpus.CpusetCpus'>
>>> cpusetinfo.cpuset
["0", "2", "3", "4", "7"]
>>> cpusetinfo.cpu_set
['0', '2', '3', '4', '7']
>>> cpusetinfo.cpu_number
5
"""
Expand All @@ -46,3 +47,32 @@ def parse_content(self, content):
else:
self.cpu_set.append(value)
self.cpu_number = len(self.cpu_set)


@parser(Specs.container_cpuset_cpus)
class ContainerCpusetCpus(ContainerParser, CpusetCpus):
"""
Class ``ContainerCpusetCpus`` parses the content of the ``/sys/fs/cgroup/cpuset/cpuset.cpus`` from containers.

Attributes:
cpu_set (list): It is used to show the list of allowed cpu.

cpu_number (int): It is used to display the number of allowed cpu.

A small sample of the content of this file looks like::

0,2-4,7

Examples:
>>> type(container_cpusetinfo)
<class 'insights.parsers.cpuset_cpus.ContainerCpusetCpus'>
>>> container_cpusetinfo.container_id
'2869b4e2541c'
>>> container_cpusetinfo.image
'registry.access.redhat.com/ubi8/nginx-120'
>>> container_cpusetinfo.cpu_set
['0', '2', '3', '4', '7']
>>> container_cpusetinfo.cpu_number
5
"""
pass
1 change: 1 addition & 0 deletions insights/specs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,7 @@ class Specs(SpecSet):
zipl_conf = RegistryPoint()

# container_specs
container_cpuset_cpus = RegistryPoint(multi_output=True)
container_dotnet_version = RegistryPoint(multi_output=True)
container_redhat_release = RegistryPoint(multi_output=True)
container_nginx_conf = RegistryPoint(multi_output=True)
Expand Down
1 change: 1 addition & 0 deletions insights/specs/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,7 @@ class DefaultSpecs(Specs):
zipl_conf = simple_file("/etc/zipl.conf")

# Container collection specs
container_cpuset_cpus = container_collect(running_rhel_containers, "/sys/fs/cgroup/cpuset/cpuset.cpus")
container_dotnet_version = container_execute(running_rhel_containers, "/usr/bin/dotnet --version")
container_installed_rpms = container_execute(running_rhel_containers, "/usr/bin/rpm -qa --qf '%s'" % _rpm_format, context=HostContext, signum=signal.SIGTERM)
container_nginx_conf = container_collect(container_nginx_conf_ds)
Expand Down
33 changes: 32 additions & 1 deletion insights/tests/parsers/test_cpuset_cpus.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import doctest
from insights.parsers import cpuset_cpus
from insights.tests import context_wrap

Expand All @@ -7,7 +8,37 @@
""".strip()


def test_init_process_cgroup():
def test_cpuset_cpu():
cpusetinfo = cpuset_cpus.CpusetCpus(context_wrap(CPUSET_CPU))
assert cpusetinfo.cpu_set == ["0", "2", "3", "4", "7"]
assert cpusetinfo.cpu_number == 5


def test_container_cpuset_cpu():
container_cpusetinfo = cpuset_cpus.ContainerCpusetCpus(
context_wrap(
CPUSET_CPU,
container_id='2869b4e2541c',
image='registry.access.redhat.com/ubi8/nginx-120',
engine='podman',
path='insights_containers/2869b4e2541c/sys/fs/cgroup/cpuset/cpuset.cpus'
)
)
assert container_cpusetinfo.cpu_set == ["0", "2", "3", "4", "7"]
assert container_cpusetinfo.cpu_number == 5


def test_doc():
env = {
"cpusetinfo": cpuset_cpus.CpusetCpus(context_wrap(CPUSET_CPU)),
"container_cpusetinfo": cpuset_cpus.ContainerCpusetCpus(
context_wrap(
CPUSET_CPU,
container_id='2869b4e2541c',
image='registry.access.redhat.com/ubi8/nginx-120',
engine='podman'
)
)
}
failed_count, total = doctest.testmod(cpuset_cpus, globs=env)
assert failed_count == 0