Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pin CLN mirror during conversion #18

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions repos/system_upgrade/cloudlinux/actors/pinclnmirror/actor.py
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.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')
34 changes: 34 additions & 0 deletions repos/system_upgrade/cloudlinux/actors/unpinclnmirror/actor.py
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)
Loading