Skip to content

Commit 3fc69cb

Browse files
author
Grigory Ponomarenko
committed
Pin CLN mirror during conversion
1 parent a17bd9e commit 3fc69cb

File tree

2 files changed

+82
-0
lines changed
  • repos/system_upgrade/cloudlinux/actors

2 files changed

+82
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import json
2+
import os.path
3+
4+
from leapp.actors import Actor
5+
from leapp.libraries.common.cllaunch import run_on_cloudlinux
6+
from leapp.libraries.stdlib import api
7+
from leapp.tags import DownloadPhaseTag, IPUWorkflowTag
8+
9+
10+
class PinClnMirror(Actor):
11+
"""
12+
Pin CLN mirror.
13+
14+
In Spacewalk plugin new mirror (new repo URI) may be choosen on each `dnf` invocation.
15+
Dnf caches packages per repo URI. That all may lead to a situation when package is downloaded from a mirror
16+
but dnf can't find it in the cache on the next invocation. To fix that, we pin the mirror during the upgrade.
17+
Mirror is unpinned by UninClnMirror actor.
18+
"""
19+
20+
name = 'pin_cln_mirror'
21+
consumes = ()
22+
produces = ()
23+
tags = (IPUWorkflowTag, DownloadPhaseTag.After)
24+
25+
CLN_REPO_ID = "cloudlinux-x86_64-server-8"
26+
DEFAULT_CLN_MIRROR = "https://xmlrpc.cln.cloudlinux.com/XMLRPC/"
27+
NEW_ROOT = '/var/lib/leapp/el8userspace'
28+
29+
@run_on_cloudlinux
30+
def process(self):
31+
# load last mirror URL from dnf spacewalk plugin cache
32+
spacewalk_settings = {}
33+
34+
try:
35+
with open(os.path.join(self.NEW_ROOT, '/var/lib/dnf/_spacewalk.json')) as file:
36+
spacewalk_settings = json.load(file)
37+
except (OSError, IOError, json.JSONDecodeError):
38+
api.current_logger().error("No spacewalk settings found")
39+
40+
mirror_url = spacewalk_settings.get(self.CLN_REPO_ID, {}).get("url", [self.DEFAULT_CLN_MIRROR])[0]
41+
api.current_logger().info("Pin CLN mirror: %s", mirror_url)
42+
43+
# pin mirror
44+
with open(os.path.join(self.NEW_ROOT, '/etc/mirrorlist'), 'w') as file:
45+
file.write(mirror_url + '\n')
46+
47+
with open(os.path.join(self.NEW_ROOT, '/etc/sysconfig/rhn/up2date'), 'a+') as file:
48+
file.write('\nmirrorURL=file:///etc/mirrorlist\n')
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import os
2+
3+
from leapp.actors import Actor
4+
from leapp.libraries.common.cllaunch import run_on_cloudlinux
5+
from leapp.tags import FirstBootPhaseTag, IPUWorkflowTag
6+
7+
class UnpinClnMirror(Actor):
8+
"""
9+
Remove pinned CLN mirror
10+
"""
11+
12+
name = 'unpin_cln_mirror'
13+
consumes = ()
14+
produces = ()
15+
tags = (IPUWorkflowTag, FirstBootPhaseTag)
16+
17+
CLN_REPO_ID = "cloudlinux-x86_64-server-8"
18+
DEFAULT_CLN_MIRROR = "https://xmlrpc.cln.cloudlinux.com/XMLRPC/"
19+
MIRRORLIST_PATH = '/var/lib/leapp/el8userspace/etc/mirrorlist'
20+
UP2DATE_PATH = '/var/lib/leapp/el8userspace/etc/sysconfig/rhn/up2date'
21+
22+
@run_on_cloudlinux
23+
def process(self):
24+
try:
25+
os.remove(self.MIRRORLIST_PATH)
26+
except FileNotFoundError:
27+
self.log.info('mirrorlist does not exist, doing nothing.')
28+
29+
with open(self.UP2DATE_PATH, 'r') as file:
30+
lines = [
31+
line for line in file.readlines() if 'mirrorURL=file:///etc/mirrorlist' not in line
32+
]
33+
with open(self.UP2DATE_PATH, 'w') as file:
34+
file.writelines(lines)

0 commit comments

Comments
 (0)