diff --git a/repos/system_upgrade/common/actors/dnfconfuserspacecopy/actor.py b/repos/system_upgrade/common/actors/dnfconfuserspacecopy/actor.py new file mode 100644 index 0000000000..50117ea32d --- /dev/null +++ b/repos/system_upgrade/common/actors/dnfconfuserspacecopy/actor.py @@ -0,0 +1,24 @@ +from leapp.actors import Actor +from leapp.libraries.actor import copycustomdnfconf +from leapp.models import TargetUserSpacePreupgradeTasks +from leapp.tags import FactsPhaseTag, IPUWorkflowTag + + +class DNFConfUserspaceCopy(Actor): + """ + Copy dnf.conf to target userspace + + Copies /etc/leapp/files/dnf.conf to target userspace. If it isn't available + /etc/dnf/dnf.conf is copied instead. This allows specifying a different + config for the target userspace, which might be required if the source + system configuration file isn't compatible with the target one. One such + example is incompatible proxy configuration between RHEL7 and RHEL8 DNF + versions. + """ + name = "dnf_conf_userspace_copy" + consumes = () + produces = (TargetUserSpacePreupgradeTasks,) + tags = (FactsPhaseTag, IPUWorkflowTag) + + def process(self): + copycustomdnfconf.process() diff --git a/repos/system_upgrade/common/actors/dnfconfuserspacecopy/libraries/dnfconfuserspacecopy.py b/repos/system_upgrade/common/actors/dnfconfuserspacecopy/libraries/dnfconfuserspacecopy.py new file mode 100644 index 0000000000..8003559646 --- /dev/null +++ b/repos/system_upgrade/common/actors/dnfconfuserspacecopy/libraries/dnfconfuserspacecopy.py @@ -0,0 +1,18 @@ +import os +from leapp.libraries.stdlib import api +from leapp.models import CopyFile, TargetUserSpacePreupgradeTasks + + +def process(): + src = "/etc/dnf/dnf.conf" + if os.path.exists("/etc/leapp/files/dnf.conf"): + src = "/etc/leapp/files/dnf.conf" + + api.current_logger().debug( + "Copying dnf.conf at {} to the target userspace".format(src) + ) + api.produce( + TargetUserSpacePreupgradeTasks( + copy_files=[CopyFile(src=src, dst="/etc/dnf/dnf.conf")] + ) + ) diff --git a/repos/system_upgrade/common/actors/dnfconfuserspacecopy/tests/test_dnfconfuserspacecopy.py b/repos/system_upgrade/common/actors/dnfconfuserspacecopy/tests/test_dnfconfuserspacecopy.py new file mode 100644 index 0000000000..6a370d32a8 --- /dev/null +++ b/repos/system_upgrade/common/actors/dnfconfuserspacecopy/tests/test_dnfconfuserspacecopy.py @@ -0,0 +1,26 @@ +import os + +import pytest + +from leapp.libraries.actor import copycustomdnfconf +from leapp.libraries.common.testutils import CurrentActorMocked, logger_mocked, produce_mocked + + +@pytest.mark.parametrize( + "userspace_conf_exists,expected", + [(False, "/etc/dnf/dnf.conf"), (True, "/etc/leapp/files/dnf.conf")], +) +def test_copy_correct_dnf_conf(monkeypatch, userspace_conf_exists, expected): + monkeypatch.setattr(os.path, "exists", lambda _: userspace_conf_exists) + + mocked_produce = produce_mocked() + monkeypatch.setattr(copycustomdnfconf.api, 'produce', mocked_produce) + monkeypatch.setattr(copycustomdnfconf.api, 'current_logger', logger_mocked()) + + copycustomdnfconf.process() + + assert mocked_produce.called == 1 + assert len(mocked_produce.model_instances) == 1 + assert len(mocked_produce.model_instances[0].copy_files) == 1 + assert mocked_produce.model_instances[0].copy_files[0].src == expected + assert mocked_produce.model_instances[0].copy_files[0].dst == "/etc/dnf/dnf.conf"