|
| 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.Before) |
| 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') |
0 commit comments