Skip to content

Commit fe679cc

Browse files
committed
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. If it exists, the `/etc/leapp/files/dnf.conf` config file will be copied to the target userspace. Target system compatible configuration can be specified there. If it doesn't exist, the `/etc/dnf/dnf.conf` from the source system will be copied instead. NOTE: The configuration is not copied onto the target system, only to the target userspace.
1 parent 17c88d9 commit fe679cc

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from leapp.actors import Actor
2+
from leapp.libraries.actor import dnfconfuserspacecopy
3+
from leapp.models import TargetUserSpacePreupgradeTasks
4+
from leapp.tags import FactsPhaseTag, IPUWorkflowTag
5+
6+
7+
class DNFConfUserspaceCopy(Actor):
8+
"""
9+
Copy dnf.conf to target userspace
10+
11+
Copies /etc/leapp/files/dnf.conf to target userspace. If it isn't available
12+
/etc/dnf/dnf.conf is copied instead. This allows specifying a different
13+
config for the target userspace, which might be required if the source
14+
system configuration file isn't compatible with the target one. One such
15+
example is incompatible proxy configuration between RHEL7 and RHEL8 DNF
16+
versions.
17+
"""
18+
name = "dnf_conf_userspace_copy"
19+
consumes = ()
20+
produces = (TargetUserSpacePreupgradeTasks,)
21+
tags = (FactsPhaseTag, IPUWorkflowTag)
22+
23+
def process(self):
24+
dnfconfuserspacecopy.process()
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import os
2+
3+
from leapp.libraries.stdlib import api
4+
from leapp.models import CopyFile, TargetUserSpacePreupgradeTasks
5+
6+
7+
def process():
8+
src = "/etc/dnf/dnf.conf"
9+
if os.path.exists("/etc/leapp/files/dnf.conf"):
10+
src = "/etc/leapp/files/dnf.conf"
11+
12+
api.current_logger().debug(
13+
"Copying dnf.conf at {} to the target userspace".format(src)
14+
)
15+
api.produce(
16+
TargetUserSpacePreupgradeTasks(
17+
copy_files=[CopyFile(src=src, dst="/etc/dnf/dnf.conf")]
18+
)
19+
)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import os
2+
3+
import pytest
4+
5+
from leapp.libraries.actor import dnfconfuserspacecopy
6+
from leapp.libraries.common.testutils import logger_mocked, produce_mocked
7+
8+
9+
@pytest.mark.parametrize(
10+
"userspace_conf_exists,expected",
11+
[(False, "/etc/dnf/dnf.conf"), (True, "/etc/leapp/files/dnf.conf")],
12+
)
13+
def test_copy_correct_dnf_conf(monkeypatch, userspace_conf_exists, expected):
14+
monkeypatch.setattr(os.path, "exists", lambda _: userspace_conf_exists)
15+
16+
mocked_produce = produce_mocked()
17+
monkeypatch.setattr(dnfconfuserspacecopy.api, 'produce', mocked_produce)
18+
monkeypatch.setattr(dnfconfuserspacecopy.api, 'current_logger', logger_mocked())
19+
20+
dnfconfuserspacecopy.process()
21+
22+
assert mocked_produce.called == 1
23+
assert len(mocked_produce.model_instances) == 1
24+
assert len(mocked_produce.model_instances[0].copy_files) == 1
25+
assert mocked_produce.model_instances[0].copy_files[0].src == expected
26+
assert mocked_produce.model_instances[0].copy_files[0].dst == "/etc/dnf/dnf.conf"

0 commit comments

Comments
 (0)