Skip to content

Commit

Permalink
transitionsystemdservicesstates: Do not handle libvirt and virt* serv…
Browse files Browse the repository at this point in the history
…ices on 8->9+

Beginning with RHEL8 there are two possible configurations (monolithic
and modular) for the libvirt and virt* (virtqemud, virtlockd,
virtproxyd, ...) services. The generic strategy implemented in the
transitionsystemdservicesstates actor cannot handle such setup
and leaves the upgraded system with a an incorrect combination of these
configurations. Therefore these services are ignored by the actor and
their state transition will be done by the services (and other related
units) themselves.

Jira: RHEL-22597
  • Loading branch information
matejmatuska authored and pirat89 committed Feb 8, 2024
1 parent c63ccbb commit 5518ae0
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from leapp import reporting
from leapp.exceptions import StopActorExecutionError
from leapp.libraries.common.config import version
from leapp.libraries.stdlib import api
from leapp.models import (
SystemdServicesInfoSource,
Expand Down Expand Up @@ -78,9 +79,43 @@ def _get_service_preset(service_name, presets):
return preset


def _filter_services(services_source, services_target):
def _filter_ignored_services(services_source):
"""
Filter out services that should be ignored i.e. not handled
"""
to_ignore = []
if int(version.get_source_major_version()) >= 8:
to_ignore.extend([
"libvirtd.service",
"virtqemud.service",
"virtinterfaced.service",
"virtnetworkd.service",
"virtnodedevd.service",
"virtnwfilterd.service",
"virtsecretd.service",
"virtstoraged.service",
"virtproxyd.service",
"virtlockd.service",
"virtlogd.service",
"libvirt-guests.service",
])

for s in to_ignore:
# It's sufficient to remove just from the source system services,
# because if a service is not present on the source system it's not handled either way
if services_source.pop(s, None):
api.current_logger().debug("Ignored service {} found on the source system".format(s))


def _filter_irrelevant_services(services_source, services_target):
"""
Filter out irrelevant services
Irrelevant services are those that cannot be enabled/disabled,
those that do not exist on the source system and those in masked-runtime state.
:return: Target system services without the irrelevant ones.
:rtype: list
"""
filtered = []
for service in services_target:
Expand Down Expand Up @@ -197,7 +232,8 @@ def process():
presets_source = {p.service: p.state for p in presets_source}
presets_target = {p.service: p.state for p in presets_target}

services_target = _filter_services(services_source, services_target)
_filter_ignored_services(services_source)
services_target = _filter_irrelevant_services(services_source, services_target)

desired_states = _get_desired_states(
services_source, presets_source, services_target, presets_target
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from leapp import reporting
from leapp.libraries.actor import transitionsystemdservicesstates
from leapp.libraries.common.config import version
from leapp.libraries.common.testutils import create_report_mocked, CurrentActorMocked, produce_mocked
from leapp.libraries.stdlib import api
from leapp.models import (
Expand Down Expand Up @@ -68,7 +69,7 @@ def _get_desired_service_state_mocked(*args):
assert tasks == expected


def test_filter_services_services_filtered():
def test_filter_irrelevant_services_services_filtered():
services_source = {
"test2.service": "static",
"test3.service": "masked",
Expand All @@ -85,14 +86,14 @@ def test_filter_services_services_filtered():
SystemdServiceFile(name="test6.service", state="masked-runtime"),
]

filtered = transitionsystemdservicesstates._filter_services(
filtered = transitionsystemdservicesstates._filter_irrelevant_services(
services_source, services_target
)

assert not filtered


def test_filter_services_services_not_filtered():
def test_filter_irrelevant_services_services_not_filtered():
services_source = {
"test1.service": "enabled",
"test2.service": "disabled",
Expand All @@ -106,7 +107,7 @@ def test_filter_services_services_not_filtered():
SystemdServiceFile(name="test4.service", state="enabled"),
]

filtered = transitionsystemdservicesstates._filter_services(
filtered = transitionsystemdservicesstates._filter_irrelevant_services(
services_source, services_target
)

Expand Down Expand Up @@ -238,3 +239,34 @@ def test_report_newly_enabled(monkeypatch):

assert created_reports.called
assert all([s in created_reports.report_fields["summary"] for s in newly_enabled])


@pytest.mark.parametrize(
"source_major_ver,expected", (
(
7,
{
'abc.service': 'enabled',
'virtqemud.service': 'enabled',
'virtlogd.service': 'disabled',
'virtproxyd.service': 'masked',
}
),
(8, {'abc.service': 'enabled'}),
(9, {'abc.service': 'enabled'}),
)
)
def test_filter_ignored_services(monkeypatch, source_major_ver, expected):
services = {
'abc.service': 'enabled',
'virtqemud.service': 'enabled',
'virtlogd.service': 'disabled',
'virtproxyd.service': 'masked',
}
monkeypatch.setattr(
version,
"get_source_major_version",
lambda: source_major_ver,
)
transitionsystemdservicesstates._filter_ignored_services(services)
assert services == expected

0 comments on commit 5518ae0

Please sign in to comment.