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 combiner rhel for edge #3526

Merged
merged 10 commits into from
Sep 22, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 3 additions & 0 deletions docs/shared_combiners_catalog/rhel_for_edge.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.. automodule:: insights.combiners.rhel_for_edge
:members:
:show-inheritance:
70 changes: 70 additions & 0 deletions insights/combiners/rhel_for_edge.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
"""
Combiner for edge computing systems
===================================
This combiner uses the following parsers to determine if the system is an edge computing systems.

* :py:class:`insights.parsers.installed_rpms.InstalledRpms`
* :py:class:`insights.parsers.cmdline.CmdLine`
* :py:class:`insights.parsers.systemd.unitfiles.ListUnits`
* :py:class:`insights.parsers.redhat_release.RedhatRelease`
"""
from insights.core.plugins import combiner
from insights.parsers.installed_rpms import InstalledRpms
from insights.parsers.cmdline import CmdLine
from insights.parsers.systemd.unitfiles import ListUnits
from insights.parsers.redhat_release import RedhatRelease


@combiner(InstalledRpms, CmdLine, ListUnits, RedhatRelease)
class RhelForEdge(list):
"""
Combiner for checking if the system is an edge computing systems.
jobselko marked this conversation as resolved.
Show resolved Hide resolved
Edge computing system packages are managed via rpm-ostree.
Red Hat CoreOS is also managed via rpm-ostree, use the string "Red Hat Enterprise Linux release"
from "/etc/redhat-release" to determine if it is an edge computing system as it is "Red Hat Enterprise Linux CoreOS release"
on RedHat CoreOs.

When an edge computing system create by console edge image is configured to use automated management,
the output of "rhc status" is the following:

Connection status for test.localhost:
- Connected to Red Hat Subscription Management
- The Red Hat connector daemon is active

If a system can upload insights archive, it must be connected to Red Hat Subscription Management, rhcd service running
means an edge computing system is configured to use automated management. Note: it is able to run rhcd service on the
edge system created corkpit edge image, "is_automated" is only for front-end resolution surface, it is used when
customers determine that the image is from console.

wushiqinlou marked this conversation as resolved.
Show resolved Hide resolved
Examples:
>>> type(rhel_for_edge_obj)
<class 'insights.combiners.rhel_for_edge.RhelForEdge'>
>>> rhel_for_edge_obj.is_edge
True
>>> rhel_for_edge_obj.is_automated
True

Attributes:
is_edge (bool): True when it is an edge computing system
is_automated (bool): True when the the edge computing system is configured to use automated management
"""

def __init__(self, rpms, cmdline, units, redhatrelease):
self.is_edge = False
self.is_automated = False

if 'rpm-ostree' in rpms and 'yum' not in rpms and 'ostree' in cmdline and "red hat enterprise linux release" in redhatrelease.raw.lower():
xiangce marked this conversation as resolved.
Show resolved Hide resolved
jobselko marked this conversation as resolved.
Show resolved Hide resolved
self.is_edge = True
if units.is_running("rhcd.service"):
self.is_automated = True

def gen_edge_return_data(self, update_target_packages, install_target_packages, target_repos):
wushiqinlou marked this conversation as resolved.
Show resolved Hide resolved
edge_data = dict()
if update_target_packages:
edge_data["update_target_packages"] = update_target_packages
if install_target_packages:
edge_data["install_target_packages"] = install_target_packages
if target_repos:
edge_data["target_repos"] = target_repos
edge_data["is_automated"] = self.is_automated
return edge_data
119 changes: 119 additions & 0 deletions insights/tests/combiners/test_rhel_for_edge.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
from insights.parsers.installed_rpms import InstalledRpms
from insights.parsers.cmdline import CmdLine
from insights.parsers.systemd.unitfiles import ListUnits
from insights.parsers.redhat_release import RedhatRelease
from insights.combiners.rhel_for_edge import RhelForEdge
from insights.combiners import rhel_for_edge
from insights.tests import context_wrap
import doctest

CONTENT_REDHAT_RELEASE_RHEL = """
Red Hat Enterprise Linux release 8.4 (Ootpa)
""".strip()

CONTENT_REDHAT_RELEASE_COREOS = """
Red Hat Enterprise Linux CoreOS release 4.12
""".strip()

CMDLINE_RHEL = """
BOOT_IMAGE=/vmlinuz-4.18.0-80.el8.x86_64 root=/dev/mapper/rootvg-rootlv ro crashkernel=184M rd.lvm.lv=rootvg/rootlv biosdevname=0 printk.time=1 numa=off audit=1 transparent_hugepage=always LANG=en_US.UTF-8
""".strip()

CMDLINE_EDGE = """
BOOT_IMAGE=(hd0,msdos1)/ostree/rhel-323453435435234234232534534/vmlinuz-4.18.0-348.20.1.el8_5.x86_64 root=/dev/mapper/rhel-root ro crashkernel=auto rd.lvm.lv=rhel/root rd.lvm.lv=rhel/swap ostree=/ostree/boot.1/rhel/08987978979/0 rhgb quiet LANG=en_US.UTF-8
""".strip()

CONTENT_SYSTEMCTL_LIST_UNITS_NO_AUTOMATED = """
postgresql.service loaded active running PostgreSQL database server
""".strip()

CONTENT_SYSTEMCTL_LIST_UNITS_AUTOMATED = """
postgresql.service loaded active running PostgreSQL database server
rhcd.service loaded active running Red Hat connector daemon
""".strip()

CONTENT_INSTALLED_RPMS_RHEL = """
kernel-4.18.0-305.19.1.el8_4.x86_64
""".strip()

CONTENT_INSTALLED_RPMS_EDGE = """
kernel-4.18.0-305.19.1.el8_4.x86_64
rpm-ostree-2021.5-2.el8.x86_64
""".strip()


def test_rhel_for_edge_true_1():
jobselko marked this conversation as resolved.
Show resolved Hide resolved
install_rpms = InstalledRpms(context_wrap(CONTENT_INSTALLED_RPMS_EDGE))
cmdline = CmdLine(context_wrap(CMDLINE_EDGE))
list_units = ListUnits(context_wrap(CONTENT_SYSTEMCTL_LIST_UNITS_NO_AUTOMATED))
redhat_release = RedhatRelease(context_wrap(CONTENT_REDHAT_RELEASE_RHEL))

result = RhelForEdge(install_rpms, cmdline, list_units, redhat_release)
assert result.is_edge is True
assert result.is_automated is False

edge_dage = result.gen_edge_return_data(None, ['tuned-profiles-spectrumscale'], ['https://cdn.redhat.com/content/dist/layered/rhel8/x86_64/fast-datapath/os'])
assert edge_dage['install_target_packages'] == ['tuned-profiles-spectrumscale']
assert edge_dage['target_repos'] == ['https://cdn.redhat.com/content/dist/layered/rhel8/x86_64/fast-datapath/os']
assert edge_dage['is_automated'] is False


def test_rhel_for_edge_true_2():
install_rpms = InstalledRpms(context_wrap(CONTENT_INSTALLED_RPMS_EDGE))
cmdline = CmdLine(context_wrap(CMDLINE_EDGE))
list_units = ListUnits(context_wrap(CONTENT_SYSTEMCTL_LIST_UNITS_AUTOMATED))
redhat_release = RedhatRelease(context_wrap(CONTENT_REDHAT_RELEASE_RHEL))

result = RhelForEdge(install_rpms, cmdline, list_units, redhat_release)
assert result.is_edge is True
assert result.is_automated is True

edge_dage = result.gen_edge_return_data(['kernel'], None, None)
assert edge_dage['update_target_packages'] == ['kernel']
assert edge_dage['is_automated'] is True


def test_rhel_for_edge_false_1():
install_rpms = InstalledRpms(context_wrap(CONTENT_INSTALLED_RPMS_RHEL))
cmdline = CmdLine(context_wrap(CMDLINE_EDGE))
list_units = ListUnits(context_wrap(CONTENT_SYSTEMCTL_LIST_UNITS_AUTOMATED))
redhat_release = RedhatRelease(context_wrap(CONTENT_REDHAT_RELEASE_RHEL))

result = RhelForEdge(install_rpms, cmdline, list_units, redhat_release)
assert result.is_edge is False
assert result.is_automated is False


def test_rhel_for_edge_false_2():
install_rpms = InstalledRpms(context_wrap(CONTENT_INSTALLED_RPMS_EDGE))
cmdline = CmdLine(context_wrap(CMDLINE_RHEL))
list_units = ListUnits(context_wrap(CONTENT_SYSTEMCTL_LIST_UNITS_AUTOMATED))
redhat_release = RedhatRelease(context_wrap(CONTENT_REDHAT_RELEASE_RHEL))

result = RhelForEdge(install_rpms, cmdline, list_units, redhat_release)
assert result.is_edge is False
assert result.is_automated is False


def test_rhel_for_edge_false_3():
install_rpms = InstalledRpms(context_wrap(CONTENT_INSTALLED_RPMS_EDGE))
cmdline = CmdLine(context_wrap(CMDLINE_EDGE))
list_units = ListUnits(context_wrap(CONTENT_SYSTEMCTL_LIST_UNITS_AUTOMATED))
redhat_release = RedhatRelease(context_wrap(CONTENT_REDHAT_RELEASE_COREOS))

result = RhelForEdge(install_rpms, cmdline, list_units, redhat_release)
assert result.is_edge is False
assert result.is_automated is False


def test_doc_examples():
install_rpms = InstalledRpms(context_wrap(CONTENT_INSTALLED_RPMS_EDGE))
cmdline = CmdLine(context_wrap(CMDLINE_EDGE))
list_units = ListUnits(context_wrap(CONTENT_SYSTEMCTL_LIST_UNITS_AUTOMATED))
redhat_release = RedhatRelease(context_wrap(CONTENT_REDHAT_RELEASE_RHEL))

env = {
'rhel_for_edge_obj': RhelForEdge(install_rpms, cmdline, list_units, redhat_release)
}
failed, total = doctest.testmod(rhel_for_edge, globs=env)
assert failed == 0