Skip to content

Commit 21a5ba7

Browse files
committed
fix channel override
override channel only after all files are copied to target namespace
1 parent 2c5c019 commit 21a5ba7

File tree

2 files changed

+30
-14
lines changed

2 files changed

+30
-14
lines changed

repos/system_upgrade/common/actors/targetuserspacecreator/libraries/userspacegen.py

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from leapp.libraries.common.config import get_env, get_product_type
1111
from leapp.libraries.common.config.version import get_target_major_version
1212
from leapp.libraries.common.gpg import get_path_to_gpg_certs, is_nogpgcheck_set
13-
from leapp.libraries.common.cln_switch import cln_switch
13+
from leapp.libraries.common.cln_switch import override_channel
1414
from leapp.libraries.stdlib import api, CalledProcessError, config, run
1515
from leapp.models import RequiredTargetUserspacePackages # deprecated
1616
from leapp.models import TMPTargetRepositoriesFacts # deprecated all the time
@@ -330,14 +330,6 @@ def prepare_target_userspace(context, userspace_dir, enabled_repos, packages):
330330

331331
raise StopActorExecutionError(message=message, details=details)
332332

333-
api.current_logger().debug('Checking the CLN registration status')
334-
context.call(['rhn_check'], callback_raw=utils.logging_handler)
335-
336-
# To get packages from Spacewalk repos (aka CLN) we need to switch the CLN channel.
337-
# localonly flag switches channel only inside of the overlayfs
338-
api.current_logger().debug('Switching channel to %s' % target_major_version)
339-
context.call(['cln-switch-channel', '-t', str(target_major_version), '--localonly'])
340-
341333

342334
def _query_rpm_for_pkg_files(context, pkgs):
343335
files_owned_by_rpm = set()
@@ -689,11 +681,7 @@ def _prep_repository_access(context, target_userspace):
689681
run(['rm', '-rf', os.path.join(target_etc, 'rhsm')])
690682
context.copytree_from('/etc/rhsm', os.path.join(target_etc, 'rhsm'))
691683

692-
# Copy RHN data independent from RHSM config
693684
if os.path.isdir('/etc/sysconfig/rhn'):
694-
context.call(['/usr/sbin/rhn_check'], callback_raw=utils.logging_handler)
695-
run(['rm', '-rf', os.path.join(target_etc, 'sysconfig/rhn')])
696-
context.copytree_from('/etc/sysconfig/rhn', os.path.join(target_etc, 'sysconfig/rhn'))
697685
# Set up spacewalk plugin config
698686
with open(os.path.join(target_etc, 'dnf/plugins/spacewalk.conf'), 'r') as f:
699687
lines = f.readlines()
@@ -1182,6 +1170,11 @@ def _create_target_userspace(context, packages, files, target_repoids):
11821170
_copy_files(target_context, files)
11831171
dnfplugin.install(_get_target_userspace())
11841172

1173+
# do not switch channel before this stage because _copy_files above copies
1174+
# related configuration files from host to target userspace
1175+
target_major_version = get_target_major_version()
1176+
override_channel(os.path.join(_get_target_userspace(), 'etc/sysconfig/rhn/up2date'), target_major_version)
1177+
11851178
# and do not forget to set the rhsm into the container mode again
11861179
with mounting.NspawnActions(_get_target_userspace()) as target_context:
11871180
rhsm.set_container_mode(target_context)
@@ -1283,4 +1276,4 @@ def perform():
12831276
api.produce(TargetUserSpaceInfo(
12841277
path=_get_target_userspace(),
12851278
scratch=constants.SCRATCH_DIR,
1286-
mounts=constants.MOUNTS_DIR))
1279+
mounts=constants.MOUNTS_DIR))

repos/system_upgrade/common/libraries/cln_switch.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def get_cln_cacheonly_flag_path():
3333
"""
3434
return os.path.join(get_target_userspace_path(), CLN_CACHEONLY_MARKER.lstrip('/'))
3535

36+
3637
def cln_switch(target):
3738
"""
3839
Switch the CloudLinux Network channel to the specified target OS.
@@ -47,3 +48,25 @@ def cln_switch(target):
4748
api.current_logger().debug('Channel switch result: %s', res)
4849
res = run(yum_clean_cmd) # required to update the repolist
4950
api.current_logger().debug('yum cleanup result: %s', res)
51+
52+
53+
def override_channel(config_path, target):
54+
"""
55+
Override cln channel locally (not affecting information on CLN side)
56+
aboit which channel we must use for upgrade.
57+
"""
58+
replaced = False
59+
with open(config_path, 'r') as f:
60+
lines = f.readlines()
61+
new_lines = []
62+
for line in lines:
63+
if line.startswith('channelOverride'):
64+
line = 'channelOverride = cloudlinux-x86_64-server-%s\n' % target
65+
replaced = True
66+
new_lines.append(line)
67+
68+
if not replaced:
69+
new_lines.append('channelOverride = cloudlinux-x86_64-server-%s\n' % target)
70+
71+
with open(config_path, 'w') as f:
72+
f.writelines(new_lines)

0 commit comments

Comments
 (0)