Skip to content

Commit 93075b8

Browse files
committed
split actor that switches channel and pins mirror
1 parent 23db389 commit 93075b8

File tree

3 files changed

+116
-101
lines changed

3 files changed

+116
-101
lines changed
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)
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import os
2+
import json
3+
4+
from leapp.actors import Actor
5+
from leapp.libraries.stdlib import api
6+
from leapp.tags import FinalizationPhaseTag, IPUWorkflowTag
7+
from leapp.libraries.stdlib import CalledProcessError
8+
from leapp.libraries.common.cllaunch import run_on_cloudlinux
9+
from leapp.libraries.common.cln_switch import cln_switch, get_target_userspace_path
10+
from leapp import reporting
11+
from leapp.reporting import Report
12+
from leapp.libraries.common.config.version import get_target_major_version
13+
14+
15+
DEFAULT_CLN_MIRROR = "https://xmlrpc.cln.cloudlinux.com/XMLRPC/"
16+
17+
18+
class SwitchClnChannelDownload(Actor):
19+
"""
20+
Permanently switch CLN channel to target os version.
21+
"""
22+
23+
name = "switch_cln_channel"
24+
consumes = ()
25+
produces = (Report,)
26+
tags = (FinalizationPhaseTag, IPUWorkflowTag)
27+
28+
@run_on_cloudlinux
29+
def process(self):
30+
try:
31+
cln_switch(target=int(get_target_major_version()))
32+
except CalledProcessError as e:
33+
reporting.create_report(
34+
[
35+
reporting.Title(
36+
"Failed to switch CloudLinux Network channel from 7 to 8."
37+
),
38+
reporting.Summary(
39+
"Command {} failed with exit code {}."
40+
" The most probable cause of that is a problem with this system's"
41+
" CloudLinux Network registration.".format(e.command, e.exit_code)
42+
),
43+
reporting.Remediation(
44+
hint="Check the state of this system's registration with \'rhn_check\'."
45+
" Attempt to re-register the system with \'rhnreg_ks --force\'."
46+
),
47+
reporting.Severity(reporting.Severity.HIGH),
48+
reporting.Groups(
49+
[reporting.Groups.OS_FACTS, reporting.Groups.AUTHENTICATION]
50+
),
51+
reporting.Groups([reporting.Groups.INHIBITOR]),
52+
]
53+
)
54+
except OSError as e:
55+
api.current_logger().error(
56+
"Could not call RHN command: Message: %s", str(e), exc_info=True
57+
)

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

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

0 commit comments

Comments
 (0)