diff --git a/repos/system_upgrade/common/actors/systemd/transitionsystemdservicesstates/libraries/transitionsystemdservicesstates.py b/repos/system_upgrade/common/actors/systemd/transitionsystemdservicesstates/libraries/transitionsystemdservicesstates.py index b487366b90..53f53fb570 100644 --- a/repos/system_upgrade/common/actors/systemd/transitionsystemdservicesstates/libraries/transitionsystemdservicesstates.py +++ b/repos/system_upgrade/common/actors/systemd/transitionsystemdservicesstates/libraries/transitionsystemdservicesstates.py @@ -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, @@ -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: @@ -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 diff --git a/repos/system_upgrade/common/actors/systemd/transitionsystemdservicesstates/tests/test_transitionsystemdservicesstates.py b/repos/system_upgrade/common/actors/systemd/transitionsystemdservicesstates/tests/test_transitionsystemdservicesstates.py index e0611859ec..6964a65ba4 100644 --- a/repos/system_upgrade/common/actors/systemd/transitionsystemdservicesstates/tests/test_transitionsystemdservicesstates.py +++ b/repos/system_upgrade/common/actors/systemd/transitionsystemdservicesstates/tests/test_transitionsystemdservicesstates.py @@ -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 ( @@ -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", @@ -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", @@ -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 ) @@ -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