-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Copy dnf.conf to target userspace and allow a custom one
This change allows working around the fact that source and target `dnf.conf` files might be incompatible. For example some of the proxy configuration between RHEL7 and RHEL8. Target system compatible configuration can be specified in /etc/leapp/files/dnf.conf. If this file is present it is copied into the target userspace and also applied to the target system. If it doesn't exist, the `/etc/dnf/dnf.conf` from the source system will be copied instead. Errors that could be caused by incompatible/incorrect proxy configuration now contain a hint with a remediation with the steps above mentioned. * [email protected]: Updated text in the error msg. Jira: OAMG-6544
- Loading branch information
1 parent
5a3bded
commit fa4b4b9
Showing
8 changed files
with
163 additions
and
5 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
repos/system_upgrade/common/actors/applycustomdnfconf/actor.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from leapp.actors import Actor | ||
from leapp.libraries.actor import applycustomdnfconf | ||
from leapp.tags import ApplicationsPhaseTag, IPUWorkflowTag | ||
|
||
|
||
class ApplyCustomDNFConf(Actor): | ||
""" | ||
Move /etc/leapp/files/dnf.conf to /etc/dnf/dnf.conf if it exists | ||
An actor in FactsPhase copies this file to the target userspace if present. | ||
In such case we also want to use the file on the target system. | ||
""" | ||
name = "apply_custom_dnf_conf" | ||
consumes = () | ||
produces = () | ||
tags = (ApplicationsPhaseTag, IPUWorkflowTag) | ||
|
||
def process(self): | ||
applycustomdnfconf.process() |
15 changes: 15 additions & 0 deletions
15
repos/system_upgrade/common/actors/applycustomdnfconf/libraries/applycustomdnfconf.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import os | ||
|
||
from leapp.libraries.stdlib import api, CalledProcessError, run | ||
|
||
CUSTOM_DNF_CONF_PATH = "/etc/leapp/files/dnf.conf" | ||
|
||
|
||
def process(): | ||
if os.path.exists(CUSTOM_DNF_CONF_PATH): | ||
try: | ||
run(["mv", CUSTOM_DNF_CONF_PATH, "/etc/dnf/dnf.conf"]) | ||
except (CalledProcessError, OSError) as e: | ||
api.current_logger().debug( | ||
"Failed to move /etc/leapp/files/dnf.conf to /etc/dnf/dnf.conf: {}".format(e) | ||
) |
23 changes: 23 additions & 0 deletions
23
repos/system_upgrade/common/actors/applycustomdnfconf/tests/test_applycustomdnfconf.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import os | ||
|
||
import pytest | ||
|
||
from leapp.libraries.actor import applycustomdnfconf | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"exists,should_move", | ||
[(False, False), (True, True)], | ||
) | ||
def test_copy_correct_dnf_conf(monkeypatch, exists, should_move): | ||
monkeypatch.setattr(os.path, "exists", lambda _: exists) | ||
|
||
run_called = [False] | ||
|
||
def mocked_run(_): | ||
run_called[0] = True | ||
|
||
monkeypatch.setattr(applycustomdnfconf, 'run', mocked_run) | ||
|
||
applycustomdnfconf.process() | ||
assert run_called[0] == should_move |
24 changes: 24 additions & 0 deletions
24
repos/system_upgrade/common/actors/copydnfconfintotargetuserspace/actor.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from leapp.actors import Actor | ||
from leapp.libraries.actor import copydnfconfintotargetuserspace | ||
from leapp.models import TargetUserSpacePreupgradeTasks | ||
from leapp.tags import FactsPhaseTag, IPUWorkflowTag | ||
|
||
|
||
class CopyDNFConfIntoTargetUserspace(Actor): | ||
""" | ||
Copy dnf.conf into 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 = "copy_dnf_conf_into_target_userspace" | ||
consumes = () | ||
produces = (TargetUserSpacePreupgradeTasks,) | ||
tags = (FactsPhaseTag, IPUWorkflowTag) | ||
|
||
def process(self): | ||
copydnfconfintotargetuserspace.process() |
19 changes: 19 additions & 0 deletions
19
.../common/actors/copydnfconfintotargetuserspace/libraries/copydnfconfintotargetuserspace.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
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")] | ||
) | ||
) |
26 changes: 26 additions & 0 deletions
26
...m_upgrade/common/actors/copydnfconfintotargetuserspace/tests/test_dnfconfuserspacecopy.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import os | ||
|
||
import pytest | ||
|
||
from leapp.libraries.actor import copydnfconfintotargetuserspace | ||
from leapp.libraries.common.testutils import 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(copydnfconfintotargetuserspace.api, 'produce', mocked_produce) | ||
monkeypatch.setattr(copydnfconfintotargetuserspace.api, 'current_logger', logger_mocked()) | ||
|
||
copydnfconfintotargetuserspace.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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters