forked from AlmaLinux/leapp-repository
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Grigory Ponomarenko
committed
Jul 5, 2024
1 parent
a17bd9e
commit 3fc69cb
Showing
2 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
repos/system_upgrade/cloudlinux/actors/pinclnmirror/actor.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import json | ||
import os.path | ||
|
||
from leapp.actors import Actor | ||
from leapp.libraries.common.cllaunch import run_on_cloudlinux | ||
from leapp.libraries.stdlib import api | ||
from leapp.tags import DownloadPhaseTag, IPUWorkflowTag | ||
|
||
|
||
class PinClnMirror(Actor): | ||
""" | ||
Pin CLN mirror. | ||
In Spacewalk plugin new mirror (new repo URI) may be choosen on each `dnf` invocation. | ||
Dnf caches packages per repo URI. That all may lead to a situation when package is downloaded from a mirror | ||
but dnf can't find it in the cache on the next invocation. To fix that, we pin the mirror during the upgrade. | ||
Mirror is unpinned by UninClnMirror actor. | ||
""" | ||
|
||
name = 'pin_cln_mirror' | ||
consumes = () | ||
produces = () | ||
tags = (IPUWorkflowTag, DownloadPhaseTag.After) | ||
|
||
CLN_REPO_ID = "cloudlinux-x86_64-server-8" | ||
DEFAULT_CLN_MIRROR = "https://xmlrpc.cln.cloudlinux.com/XMLRPC/" | ||
NEW_ROOT = '/var/lib/leapp/el8userspace' | ||
|
||
@run_on_cloudlinux | ||
def process(self): | ||
# load last mirror URL from dnf spacewalk plugin cache | ||
spacewalk_settings = {} | ||
|
||
try: | ||
with open(os.path.join(self.NEW_ROOT, '/var/lib/dnf/_spacewalk.json')) as file: | ||
spacewalk_settings = json.load(file) | ||
except (OSError, IOError, json.JSONDecodeError): | ||
api.current_logger().error("No spacewalk settings found") | ||
|
||
mirror_url = spacewalk_settings.get(self.CLN_REPO_ID, {}).get("url", [self.DEFAULT_CLN_MIRROR])[0] | ||
api.current_logger().info("Pin CLN mirror: %s", mirror_url) | ||
|
||
# pin mirror | ||
with open(os.path.join(self.NEW_ROOT, '/etc/mirrorlist'), 'w') as file: | ||
file.write(mirror_url + '\n') | ||
|
||
with open(os.path.join(self.NEW_ROOT, '/etc/sysconfig/rhn/up2date'), 'a+') as file: | ||
file.write('\nmirrorURL=file:///etc/mirrorlist\n') |
34 changes: 34 additions & 0 deletions
34
repos/system_upgrade/cloudlinux/actors/unpinclnmirror/actor.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import os | ||
|
||
from leapp.actors import Actor | ||
from leapp.libraries.common.cllaunch import run_on_cloudlinux | ||
from leapp.tags import FirstBootPhaseTag, IPUWorkflowTag | ||
|
||
class UnpinClnMirror(Actor): | ||
""" | ||
Remove pinned CLN mirror | ||
""" | ||
|
||
name = 'unpin_cln_mirror' | ||
consumes = () | ||
produces = () | ||
tags = (IPUWorkflowTag, FirstBootPhaseTag) | ||
|
||
CLN_REPO_ID = "cloudlinux-x86_64-server-8" | ||
DEFAULT_CLN_MIRROR = "https://xmlrpc.cln.cloudlinux.com/XMLRPC/" | ||
MIRRORLIST_PATH = '/var/lib/leapp/el8userspace/etc/mirrorlist' | ||
UP2DATE_PATH = '/var/lib/leapp/el8userspace/etc/sysconfig/rhn/up2date' | ||
|
||
@run_on_cloudlinux | ||
def process(self): | ||
try: | ||
os.remove(self.MIRRORLIST_PATH) | ||
except FileNotFoundError: | ||
self.log.info('mirrorlist does not exist, doing nothing.') | ||
|
||
with open(self.UP2DATE_PATH, 'r') as file: | ||
lines = [ | ||
line for line in file.readlines() if 'mirrorURL=file:///etc/mirrorlist' not in line | ||
] | ||
with open(self.UP2DATE_PATH, 'w') as file: | ||
file.writelines(lines) |