Skip to content

Commit 9f840f9

Browse files
authored
Merge pull request #32 from cloudlinux/clos-3211-local-cln-switch
Switch CLN channel locally until the last stage of the upgrade
2 parents 47d9065 + 1f86500 commit 9f840f9

File tree

11 files changed

+163
-286
lines changed

11 files changed

+163
-286
lines changed

packaging/leapp-repository.spec

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ Conflicts: leapp-upgrade-el7toel8
9494

9595
%endif
9696

97+
# Requires tools which allow switching between channels
98+
Requires: cln-switch-channel = 2
99+
97100
# IMPORTANT: every time the requirements are changed, increment number by one
98101
# - same for Provides in deps subpackage
99102
Requires: leapp-repository-dependencies = %{leapp_repo_deps}

repos/system_upgrade/cloudlinux/actors/checkcllicense/actor.py

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,6 @@
1313

1414
import os
1515

16-
RHN_CONFIG_DIR = '/etc/sysconfig/rhn'
17-
REQUIRED_PKGS = ['dnf-plugin-spacewalk', 'rhn-client-tools']
18-
19-
20-
def rhn_to_target_userspace():
21-
"""
22-
Produce messages to copy RHN configuration files and packages to the target userspace
23-
"""
24-
files_to_copy = []
25-
for dirpath, _, filenames in os.walk(RHN_CONFIG_DIR):
26-
for filename in filenames:
27-
src_path = os.path.join(dirpath, filename)
28-
if os.path.isfile(src_path):
29-
files_to_copy.append(CopyFile(src=src_path))
30-
31-
api.produce(TargetUserSpacePreupgradeTasks(install_rpms=REQUIRED_PKGS, copy_files=files_to_copy))
32-
api.produce(TargetUserSpaceUpgradeTasks(install_rpms=REQUIRED_PKGS, copy_files=files_to_copy))
33-
3416

3517
class CheckClLicense(Actor):
3618
"""
@@ -39,17 +21,12 @@ class CheckClLicense(Actor):
3921

4022
name = 'check_cl_license'
4123
consumes = ()
42-
produces = (Report, TargetUserSpacePreupgradeTasks, TargetUserSpaceUpgradeTasks)
24+
produces = (Report,)
4325
tags = (ChecksPhaseTag, IPUWorkflowTag)
4426

4527
system_id_path = '/etc/sysconfig/rhn/systemid'
4628
rhn_check_bin = '/usr/sbin/rhn_check'
4729

48-
# # Copy RHN data independent from RHSM config
49-
# if os.path.isdir('/etc/sysconfig/rhn'):
50-
# run(['rm', '-rf', os.path.join(target_etc, 'sysconfig/rhn')])
51-
# context.copytree_from('/etc/sysconfig/rhn', os.path.join(target_etc, 'sysconfig/rhn'))
52-
5330
@run_on_cloudlinux
5431
def process(self):
5532
res = None
@@ -69,5 +46,3 @@ def process(self):
6946
reporting.Groups([reporting.Groups.INHIBITOR]),
7047
reporting.Remediation(hint=remediation),
7148
])
72-
else:
73-
rhn_to_target_userspace()

repos/system_upgrade/cloudlinux/actors/checkrhnclienttools/actor.py

Lines changed: 0 additions & 61 deletions
This file was deleted.

repos/system_upgrade/cloudlinux/actors/checkrhnclienttools/libraries/version.py

Lines changed: 0 additions & 46 deletions
This file was deleted.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import os
2+
from leapp.actors import Actor
3+
from leapp.reporting import Report
4+
from leapp.tags import ChecksPhaseTag, IPUWorkflowTag
5+
from leapp.libraries.common.cllaunch import run_on_cloudlinux
6+
from leapp.libraries.stdlib import api
7+
from leapp.models import (
8+
TargetUserSpacePreupgradeTasks,
9+
CopyFile
10+
)
11+
12+
13+
RHN_CONFIG_DIR = '/etc/sysconfig/rhn'
14+
REQUIRED_PKGS = ['dnf-plugin-spacewalk', 'rhn-client-tools']
15+
16+
17+
class CopyClLicense(Actor):
18+
"""
19+
Produce task to copy CloudLinux license files to target system.
20+
"""
21+
22+
name = 'copy_rhn_client_tools_config'
23+
consumes = ()
24+
produces = (Report, TargetUserSpacePreupgradeTasks)
25+
tags = (ChecksPhaseTag, IPUWorkflowTag)
26+
27+
@run_on_cloudlinux
28+
def process(self):
29+
"""
30+
Produce artifacts to copy RHN configuration files
31+
and install packages to the target userspace,
32+
including up2date and systemid.
33+
"""
34+
files_to_copy = []
35+
for dirpath, _, filenames in os.walk(RHN_CONFIG_DIR):
36+
for filename in filenames:
37+
src_path = os.path.join(dirpath, filename)
38+
if os.path.isfile(src_path):
39+
files_to_copy.append(CopyFile(src=src_path))
40+
41+
api.produce(TargetUserSpacePreupgradeTasks(
42+
install_rpms=REQUIRED_PKGS,
43+
copy_files=files_to_copy
44+
))
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import json
2+
import os
3+
4+
from leapp.actors import Actor
5+
from leapp.libraries.stdlib import api
6+
from leapp.libraries.common.cllaunch import run_on_cloudlinux
7+
from leapp.libraries.common.cln_switch import get_target_userspace_path
8+
from leapp.tags import DownloadPhaseTag, IPUWorkflowTag
9+
from leapp.libraries.common.config.version import get_target_major_version
10+
11+
12+
class PinClnMirror(Actor):
13+
"""
14+
Save CLN mirror that was used last time.
15+
"""
16+
17+
name = 'pin_cln_mirror'
18+
consumes = ()
19+
produces = ()
20+
tags = (IPUWorkflowTag, DownloadPhaseTag.Before)
21+
22+
CLN_REPO_ID = "cloudlinux-x86_64-server-%s"
23+
DEFAULT_CLN_MIRROR = "https://xmlrpc.cln.cloudlinux.com/XMLRPC/"
24+
25+
@run_on_cloudlinux
26+
def process(self):
27+
"""Pin CLN mirror"""
28+
target_userspace = get_target_userspace_path()
29+
api.current_logger().info("Pin CLN mirror: target userspace=%s", target_userspace)
30+
31+
# load last mirror URL from dnf spacewalk plugin cache
32+
spacewalk_settings = {}
33+
34+
# find the mirror used in the last transaction
35+
# (expecting to find the one used in dnf_package_download actor)
36+
spacewalk_json_path = os.path.join(target_userspace, 'var/lib/dnf/_spacewalk.json')
37+
try:
38+
with open(spacewalk_json_path) as file:
39+
spacewalk_settings = json.load(file)
40+
except (OSError, IOError, ValueError):
41+
api.current_logger().error(
42+
"No spacewalk settings found in %s - can't identify the last used CLN mirror",
43+
spacewalk_json_path,
44+
)
45+
46+
mirror_url = spacewalk_settings.get(
47+
self.CLN_REPO_ID % get_target_major_version(), {}
48+
).get("url", [self.DEFAULT_CLN_MIRROR])[0]
49+
50+
# pin mirror
51+
mirrorlist_path = os.path.join(target_userspace, 'etc/mirrorlist')
52+
with open(mirrorlist_path, 'w') as file:
53+
file.write(mirror_url + '\n')
54+
api.current_logger().info("Pin CLN mirror %s in %s", mirror_url, mirrorlist_path)
55+
56+
up2date_path = os.path.join(target_userspace, 'etc/sysconfig/rhn/up2date')
57+
with open(up2date_path, 'a+') as file:
58+
file.write('\nmirrorURL[comment]=Set mirror URL to /etc/mirrorlist\nmirrorURL=file:///etc/mirrorlist\n')
59+
api.current_logger().info("Updated up2date_path %s", up2date_path)

repos/system_upgrade/cloudlinux/actors/switchclnchannelreset/actor.py renamed to repos/system_upgrade/cloudlinux/actors/switchclnchannel/actor.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,34 @@
11
from leapp.actors import Actor
22
from leapp.libraries.stdlib import api
3-
from leapp.tags import IPUWorkflowTag, TargetTransactionChecksPhaseTag
3+
from leapp.tags import FirstBootPhaseTag, IPUWorkflowTag
44
from leapp.libraries.stdlib import CalledProcessError
55
from leapp.libraries.common.cllaunch import run_on_cloudlinux
6-
from leapp.libraries.common.cln_switch import cln_switch
7-
from leapp.libraries.common.config.version import get_source_major_version
6+
from leapp.libraries.common.cln_switch import cln_switch, get_target_userspace_path
87
from leapp import reporting
98
from leapp.reporting import Report
9+
from leapp.libraries.common.config.version import get_target_major_version
1010

1111

12-
class SwitchClnChannelReset(Actor):
12+
class SwitchClnChannel(Actor):
1313
"""
14-
Reset the CLN channel to CL7 to keep the system state consistent before the main upgrade phase.
14+
Permanently switch CLN channel to target os version
15+
when upgrade is complete.
1516
"""
1617

17-
name = "switch_cln_channel_reset"
18+
name = "switch_cln_channel"
1819
consumes = ()
1920
produces = (Report,)
20-
tags = (IPUWorkflowTag, TargetTransactionChecksPhaseTag.After)
21+
tags = (FirstBootPhaseTag, IPUWorkflowTag)
2122

2223
@run_on_cloudlinux
2324
def process(self):
2425
try:
25-
cln_switch(target=get_source_major_version())
26+
cln_switch(target=int(get_target_major_version()))
2627
except CalledProcessError as e:
2728
reporting.create_report(
2829
[
2930
reporting.Title(
30-
"Failed to switch CloudLinux Network channel."
31+
"Failed to switch CloudLinux Network channel"
3132
),
3233
reporting.Summary(
3334
"Command {} failed with exit code {}."

0 commit comments

Comments
 (0)