forked from AlmaLinux/leapp-repository
-
Notifications
You must be signed in to change notification settings - Fork 5
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
Make CLN package repositories properly supported by the upgrade process #9
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1817c48
Make CLN package repositories properly supported by the upgrade process
prilr 1806b58
Correct CLN channel switch report tags
prilr f6e940e
Replace direct CLN registration with a check
prilr e92cc47
Replace outdated model usage in CLN-related tasks
prilr 32582d3
Move MySQL data backup to an earlier stage
prilr 7152f41
Add actors working with marker files for CLN dnf plugin for the isola…
prilr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
25 changes: 25 additions & 0 deletions
25
repos/system_upgrade/cloudlinux/actors/setclncacheonlyflag/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,25 @@ | ||
from leapp.actors import Actor | ||
from leapp.tags import PreparationPhaseTag, IPUWorkflowTag | ||
from leapp.libraries.common.cllaunch import run_on_cloudlinux | ||
|
||
|
||
class SetClnCacheOnlyFlag(Actor): | ||
""" | ||
Set a flag for the dnf-spacewalk-plugin to not attempt to contact the CLN server during transaction, | ||
as it will fail and remove CLN-based package repos from the list. | ||
|
||
When this flag exists, the plugin will act as if there's no network connection, | ||
only using the local cache. | ||
""" | ||
|
||
name = 'set_cln_cache_only_flag' | ||
consumes = () | ||
produces = () | ||
tags = (IPUWorkflowTag, PreparationPhaseTag) | ||
|
||
@run_on_cloudlinux | ||
def process(self): | ||
# TODO: Use a more reliable method to detect if we're running from the isolated userspace | ||
# TODO: Replace hardcoded path with a constant (from target_userspace_creator.constants?) | ||
with open('/var/lib/leapp/el8userspace/etc/cln_leapp_in_progress', 'w') as file: | ||
file.write('1') |
19 changes: 19 additions & 0 deletions
19
repos/system_upgrade/cloudlinux/actors/unsetclncacheonlyflag/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,19 @@ | ||
from leapp.actors import Actor | ||
from leapp.tags import PreparationPhaseTag, IPUWorkflowTag | ||
from leapp.libraries.common.cllaunch import run_on_cloudlinux | ||
|
||
import os | ||
|
||
class UnsetClnCacheOnlyFlag(Actor): | ||
""" | ||
Remove the flag for the dnf-spacewalk-plugin to not attempt to contact the CLN server during transaction. | ||
""" | ||
|
||
name = 'unset_cln_cache_only_flag' | ||
consumes = () | ||
produces = () | ||
tags = (IPUWorkflowTag, PreparationPhaseTag) | ||
|
||
@run_on_cloudlinux | ||
def process(self): | ||
os.remove('/var/lib/leapp/el8userspace/etc/cln_leapp_in_progress', 'w') |
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 |
---|---|---|
|
@@ -133,6 +133,35 @@ def _backup_to_persistent_package_cache(userspace_dir): | |
target_context.copytree_from('/var/cache/dnf', PERSISTENT_PACKAGE_CACHE_DIR) | ||
|
||
|
||
def enable_spacewalk_module(context): | ||
enabled_repos = ["cloudlinux8-baseos"] | ||
target_major_version = get_target_major_version() | ||
repos_opt = [['--enablerepo', repo] for repo in enabled_repos] | ||
repos_opt = list(itertools.chain(*repos_opt)) | ||
|
||
api.current_logger().debug('Enabling module for target userspace: satellite-5-client') | ||
|
||
cmd = ['dnf', | ||
'module', | ||
'enable', | ||
'satellite-5-client', | ||
'-y', | ||
'--nogpgcheck', | ||
'--setopt=module_platform_id=platform:el{}'.format(target_major_version), | ||
'--setopt=keepcache=1', | ||
'--releasever', api.current_actor().configuration.version.target, | ||
'--installroot', '/el{}target'.format(target_major_version), | ||
'--disablerepo', '*' | ||
] + repos_opt | ||
try: | ||
context.call(cmd, callback_raw=utils.logging_handler) | ||
except CalledProcessError as exc: | ||
raise StopActorExecutionError( | ||
message='Unable to activate spacewalk module.', | ||
details={'details': str(exc), 'stderr': exc.stderr} | ||
) | ||
|
||
|
||
def prepare_target_userspace(context, userspace_dir, enabled_repos, packages): | ||
""" | ||
Implement the creation of the target userspace. | ||
|
@@ -147,6 +176,14 @@ def prepare_target_userspace(context, userspace_dir, enabled_repos, packages): | |
): | ||
_restore_persistent_package_cache(userspace_dir) | ||
|
||
api.current_logger().debug('Installing cloudlinux-release') | ||
context.call(['rpm', '--import', 'https://repo.cloudlinux.com/cloudlinux/security/RPM-GPG-KEY-CloudLinux'], callback_raw=utils.logging_handler) | ||
context.call(['dnf', '-y', 'localinstall', 'https://repo.cloudlinux.com/cloudlinux/migrate/release-files/cloudlinux/8/x86_64/cloudlinux8-release-current.x86_64.rpm'], callback_raw=utils.logging_handler) | ||
|
||
enable_spacewalk_module(context) | ||
|
||
api.current_logger().debug('Installing packages into target userspace: {}'.format(packages)) | ||
|
||
repos_opt = [['--enablerepo', repo] for repo in enabled_repos] | ||
repos_opt = list(itertools.chain(*repos_opt)) | ||
cmd = ['dnf', | ||
|
@@ -171,6 +208,26 @@ def prepare_target_userspace(context, userspace_dir, enabled_repos, packages): | |
details={'details': str(exc), 'stderr': exc.stderr} | ||
) | ||
|
||
api.current_logger().debug('Checking the CLN registration status') | ||
context.call(['rhn_check'], callback_raw=utils.logging_handler) | ||
switch_bin = "/usr/sbin/cln-switch-channel" | ||
switch_cmd = [switch_bin, "-t", "8", "-o", "-f"] | ||
context.call(switch_cmd, callback_raw=utils.logging_handler) | ||
|
||
reporting.create_report([ | ||
reporting.Title('CLN channel switched to CL8.'), | ||
reporting.Summary( | ||
'The CLN channel for this system has been switched from CL7 to CL8.' | ||
'This is required to pull the correct packages for the upgrade.' | ||
'However, if the upgrade stops at a later stage, you may want to switch back to the original channel.' | ||
), | ||
reporting.Tags([reporting.Tags.UPGRADE_PROCESS, reporting.Tags.AUTHENTICATION]), | ||
reporting.Severity(reporting.Severity.MEDIUM), | ||
reporting.Remediation(hint=( | ||
'Set the channel back to CL7 using the command: cln-switch-channel -t 7 -o -f' | ||
)), | ||
]) | ||
|
||
|
||
def _get_all_rhui_pkgs(): | ||
""" | ||
|
@@ -231,6 +288,23 @@ def _prep_repository_access(context, target_userspace): | |
run(['rm', '-rf', os.path.join(target_etc, 'rhsm')]) | ||
context.copytree_from('/etc/pki', os.path.join(target_etc, 'pki')) | ||
context.copytree_from('/etc/rhsm', os.path.join(target_etc, 'rhsm')) | ||
|
||
# Copy RHN data independent from RHSM config | ||
if os.path.isdir('/etc/sysconfig/rhn'): | ||
context.call(['/usr/sbin/rhn_check'], callback_raw=utils.logging_handler) | ||
run(['rm', '-rf', os.path.join(target_etc, 'sysconfig/rhn')]) | ||
context.copytree_from('/etc/sysconfig/rhn', os.path.join(target_etc, 'sysconfig/rhn')) | ||
# Set up spacewalk plugin config | ||
with open(os.path.join(target_etc, 'dnf/plugins/spacewalk.conf'), 'r') as f: | ||
lines = f.readlines() | ||
new_lines = [] | ||
for line in lines: | ||
if 'enabled' in line: | ||
line = 'enabled = 1\n' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if |
||
new_lines.append(line) | ||
with open(os.path.join(target_etc, 'dnf/plugins/spacewalk.conf'), 'w') as f: | ||
f.writelines(new_lines) | ||
|
||
# NOTE: we cannot just remove the original target yum.repos.d dir | ||
# as e.g. in case of RHUI a special RHUI repofiles are installed by a pkg | ||
# when the target userspace container is created. Removing these files we loose | ||
|
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 |
---|---|---|
|
@@ -124,11 +124,16 @@ def configure(self): | |
self.base.conf.tsflags.append("test") | ||
|
||
enabled_repos = self.plugin_data['dnf_conf']['enable_repos'] | ||
print("All DNF repos: {}".format(self.base.repos.all())) | ||
self.base.repos.all().disable() | ||
|
||
aws_region = None | ||
|
||
for repo in self.base.repos.all(): | ||
# we always want to have CLN repos enabled | ||
if type(repo).__name__ == "SpacewalkRepo": | ||
repo.enable() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
if repo.id in enabled_repos: | ||
repo.skip_if_unavailable = False | ||
if not self.base.conf.gpgcheck: | ||
|
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shutil.rmtree(os.path.join(target_etc, 'sysconfig/rhn'))
could be slightly faster