diff --git a/repos/system_upgrade/cloudlinux/actors/pinclnmirror/actor.py b/repos/system_upgrade/cloudlinux/actors/pinclnmirror/actor.py new file mode 100644 index 0000000000..842de42314 --- /dev/null +++ b/repos/system_upgrade/cloudlinux/actors/pinclnmirror/actor.py @@ -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.Before) + + 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') diff --git a/repos/system_upgrade/cloudlinux/actors/unpinclnmirror/actor.py b/repos/system_upgrade/cloudlinux/actors/unpinclnmirror/actor.py new file mode 100644 index 0000000000..f68642987d --- /dev/null +++ b/repos/system_upgrade/cloudlinux/actors/unpinclnmirror/actor.py @@ -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)