Skip to content

Commit 6794bbb

Browse files
committed
Merge remote-tracking branch 'refs/remotes/origin/cloudlinux' into almalinux-ng
# Conflicts: # README.md # commands/upgrade/util.py # packaging/leapp-repository.spec # repos/system_upgrade/common/actors/checkenabledvendorrepos/actor.py # repos/system_upgrade/common/actors/checketcreleasever/libraries/checketcreleasever.py # repos/system_upgrade/common/actors/checkgrubcore/actor.py # repos/system_upgrade/common/actors/commonleappdracutmodules/files/dracut/85sys-upgrade-redhat/do-upgrade.sh # repos/system_upgrade/common/actors/commonleappdracutmodules/files/dracut/90sys-upgrade/initrd-system-upgrade-generator # repos/system_upgrade/common/actors/efibootorderfix/finalization/actor.py # repos/system_upgrade/common/actors/filterrpmtransactionevents/actor.py # repos/system_upgrade/common/actors/kernel/checkinstalledkernels/libraries/checkinstalledkernels.py # repos/system_upgrade/common/actors/peseventsscanner/actor.py # repos/system_upgrade/common/actors/peseventsscanner/libraries/peseventsscanner.py # repos/system_upgrade/common/actors/peseventsscanner/tests/unit_test_peseventsscanner.py # repos/system_upgrade/common/actors/redhatsignedrpmscanner/actor.py # repos/system_upgrade/common/actors/removeobsoletegpgkeys/libraries/removeobsoleterpmgpgkeys.py # repos/system_upgrade/common/actors/repositoriesmapping/libraries/repositoriesmapping.py # repos/system_upgrade/common/actors/scancustomrepofile/tests/test_scancustomrepofile.py # repos/system_upgrade/common/actors/scanvendorrepofiles/actor.py # repos/system_upgrade/common/actors/scanvendorrepofiles/libraries/scanvendorrepofiles.py # repos/system_upgrade/common/actors/setuptargetrepos/libraries/setuptargetrepos.py # repos/system_upgrade/common/actors/targetuserspacecreator/libraries/userspacegen.py # repos/system_upgrade/common/actors/vendorreposignaturescanner/actor.py # repos/system_upgrade/common/actors/vendorrepositoriesmapping/libraries/vendorrepositoriesmapping.py # repos/system_upgrade/common/libraries/config/version.py # repos/system_upgrade/common/libraries/dnfconfig.py # repos/system_upgrade/common/libraries/dnfplugin.py # repos/system_upgrade/common/libraries/overlaygen.py # repos/system_upgrade/common/libraries/repomaputils.py # repos/system_upgrade/common/libraries/rpms.py # repos/system_upgrade/el7toel8/actors/checkleftoverpackages/actor.py # repos/system_upgrade/el7toel8/actors/networkmanagerupdateconnections/tools/nm-update-client-ids.py # repos/system_upgrade/el7toel8/actors/opensshpermitrootlogincheck/actor.py # repos/system_upgrade/el7toel8/actors/opensshpermitrootlogincheck/libraries/opensshpermitrootlogincheck.py # repos/system_upgrade/el7toel8/actors/satellite_upgrade_facts/actor.py # repos/system_upgrade/el7toel8/actors/satellite_upgrade_facts/tests/unit_test_satellite_upgrade_facts.py
2 parents 52f3a15 + 88c8780 commit 6794bbb

File tree

123 files changed

+5888
-83
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

123 files changed

+5888
-83
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ install-deps:
292292
case $(_PYTHON_VENV) in python3*) yum install -y ${shell echo $(_PYTHON_VENV) | tr -d .}; esac
293293
@# in centos:7 python dependencies required gcc
294294
case $(_PYTHON_VENV) in python3*) yum install gcc -y; esac
295-
virtualenv --system-site-packages -p /usr/bin/$(_PYTHON_VENV) $(VENVNAME); \
295+
virtualenv -p /usr/bin/$(_PYTHON_VENV) $(VENVNAME); \
296296
. $(VENVNAME)/bin/activate; \
297297
pip install -U pip; \
298298
pip install --upgrade setuptools; \

README.md

Lines changed: 700 additions & 6 deletions
Large diffs are not rendered by default.

buildsys-pre-build

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env python2
2+
import subprocess
3+
import contextlib
4+
import os.path
5+
6+
7+
@contextlib.contextmanager
8+
def _rpmmacros_file_patched():
9+
path = os.path.expanduser("~/.rpmmacros")
10+
with open(path, "r") as f:
11+
content = f.read()
12+
with open(path, "w") as f:
13+
for line in content.splitlines():
14+
if line.startswith("%_rpmfilename"):
15+
line = "%_rpmfilename %{_build_name_fmt}"
16+
f.write(line + "\n")
17+
try:
18+
yield
19+
finally:
20+
with open(path, "w") as f:
21+
f.write(content)
22+
23+
24+
def _main():
25+
# NOTE: For reasons unknown, the Build System clones repository under 'mockbuild' user
26+
# but executes 'buildsys-pre-build' script as 'root'. As 'buildsys-pre-build' script
27+
# invokes Makefile, which in turn invokes 'git archive' command, the latter fails due
28+
# to 'dubious ownership' error. This hack sidesteps the problem but should be fixed on
29+
# the side of Build System in the long run.
30+
subprocess.call("git config --global --add safe.directory /srv/pre_build".split())
31+
# NOTE: CloudLinux Build System redefines some macros, including %_rpmfilename.
32+
# This makes an upstream Makefile target "sources" to fail as it expects that
33+
# RPMs are sorted into directories with names corresponding to architectures.
34+
# This patch makes the build system to temporary use the default value of %_rpmfilename
35+
# when Makefile is executed, while reverting it back for rpmbuild invocation from inside
36+
# the Build System.
37+
with _rpmmacros_file_patched():
38+
subprocess.call("make srpm".split())
39+
# NOTE: I wasn't able to make the Build System look for tarballs inside of custom directory
40+
# (_sourcedir macro redefinition led to some whired permission problems) so let's just
41+
# unpack everythin into the root of the repository.
42+
subprocess.call("""rpm2cpio `find . -name "leapp-repository-*.src.rpm" -print -quit` | cpio -idv""", shell=True)
43+
44+
45+
if __name__ == "__main__":
46+
# NOTE(zeronineseven): The grand idea behind this script is to delegate all the heavy lifting
47+
# to an upstream Makefile, which gives us ready-made SRPM back and then
48+
# simply unpack it so that the Build System can pick from there.
49+
_main()

buildsys-pre-build.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
dependencies:
3+
- git
4+
- python2

commands/command_utils.py

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,36 @@ def get_os_release_version_id(filepath):
7171
7272
:return: `str` version_id
7373
"""
74-
with open(filepath) as f:
75-
data = dict(l.strip().split('=', 1) for l in f.readlines() if '=' in l)
76-
return data.get('VERSION_ID', '').strip('"')
74+
try:
75+
with open(filepath) as f:
76+
data = dict(l.strip().split('=', 1) for l in f.readlines() if '=' in l)
77+
return data.get('VERSION_ID', '').strip('"')
78+
except OSError as e:
79+
raise CommandError(
80+
"Unable to read system OS release from file {}, "
81+
"error: {}".format(
82+
filepath,
83+
e.strerror
84+
))
85+
86+
87+
def get_os_release_id(filepath):
88+
"""
89+
Retrieve data about System OS ID from provided file.
90+
91+
:return: `str` version_id
92+
"""
93+
try:
94+
with open(filepath) as f:
95+
data = dict(l.strip().split('=', 1) for l in f.readlines() if '=' in l)
96+
return data.get('ID', '').strip('"')
97+
except OSError as e:
98+
raise CommandError(
99+
"Unable to read system OS ID from file {}, "
100+
"error: {}".format(
101+
filepath,
102+
e.strerror
103+
))
77104

78105

79106
def get_upgrade_paths_config():

commands/upgrade/__init__.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
@command('upgrade', help='Upgrade the current system to the next available major version.')
2020
@command_opt('resume', is_flag=True, help='Continue the last execution after it was stopped (e.g. after reboot)')
21+
@command_opt('nowarn', is_flag=True, help='Do not display interactive warnings')
2122
@command_opt('reboot', is_flag=True, help='Automatically performs reboot when requested.')
2223
@command_opt('whitelist-experimental', action='append', metavar='ActorName', help='Enable experimental actors')
2324
@command_opt('debug', is_flag=True, help='Enable debug mode', inherit=False)
@@ -92,7 +93,13 @@ def upgrade(args, breadcrumbs):
9293
workflow = repositories.lookup_workflow('IPUWorkflow')(auto_reboot=args.reboot)
9394
util.process_whitelist_experimental(repositories, workflow, configuration, logger)
9495
util.warn_if_unsupported(configuration)
95-
with beautify_actor_exception():
96+
97+
if not args.resume and not args.nowarn:
98+
if not util.ask_to_continue():
99+
logger.info("Upgrade cancelled by user")
100+
sys.exit(1)
101+
102+
with util.format_actor_exceptions(logger):
96103
logger.info("Using answerfile at %s", answerfile_path)
97104
workflow.load_answers(answerfile_path, userchoices_path)
98105

@@ -105,13 +112,16 @@ def upgrade(args, breadcrumbs):
105112

106113
logger.info("Answerfile will be created at %s", answerfile_path)
107114
workflow.save_answers(answerfile_path, userchoices_path)
115+
util.log_errors(workflow.errors, logger)
116+
util.log_inhibitors(context, logger)
108117
report_errors(workflow.errors)
109118
util.generate_report_files(context, report_schema)
110119
report_files = util.get_cfg_files('report', cfg)
111120
log_files = util.get_cfg_files('logs', cfg)
112121
report_info(context, report_files, log_files, answerfile_path, fail=workflow.failure, errors=workflow.errors)
113122

114123
if workflow.failure:
124+
logger.error("Upgrade workflow failed, check log for details")
115125
sys.exit(1)
116126

117127

commands/upgrade/util.py

Lines changed: 114 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,25 @@
22
import itertools
33
import json
44
import os
5+
import sys
56
import shutil
67
import tarfile
8+
import six.moves
79
from datetime import datetime
10+
from contextlib import contextmanager
11+
import six
812

913
from leapp.cli.commands import command_utils
1014
from leapp.cli.commands.config import get_config
11-
from leapp.exceptions import CommandError
15+
from leapp.exceptions import CommandError, LeappRuntimeError
1216
from leapp.repository.scan import find_and_scan_repositories
1317
from leapp.utils import audit
1418
from leapp.utils.audit import get_checkpoints, get_connection, get_messages
15-
from leapp.utils.output import report_unsupported
19+
from leapp.utils.output import report_unsupported, pretty_block_text, pretty_block, Color
1620
from leapp.utils.report import fetch_upgrade_report_messages, generate_report_file
21+
from leapp.models import ErrorModel
22+
23+
1724

1825

1926
def disable_database_sync():
@@ -167,6 +174,46 @@ def warn_if_unsupported(configuration):
167174
report_unsupported(devel_vars, configuration["whitelist_experimental"])
168175

169176

177+
def ask_to_continue():
178+
"""
179+
Pause before starting the upgrade, warn the user about potential conseqences
180+
and ask for confirmation.
181+
Only done on whitelisted OS.
182+
183+
:return: True if it's OK to continue, False if the upgrade should be interrupted.
184+
"""
185+
186+
ask_on_os = ['cloudlinux']
187+
os_id = command_utils.get_os_release_id('/etc/os-release')
188+
189+
if os_id not in ask_on_os:
190+
return True
191+
192+
with pretty_block(
193+
text="Upgrade workflow initiated",
194+
end_text="Continue?",
195+
target=sys.stdout,
196+
color=Color.bold,
197+
):
198+
warn_msg = (
199+
"Past this point, Leapp will begin making changes to your system.\n"
200+
"An improperly or incompletely configured upgrade may break the system, "
201+
"up to and including making it *completely inaccessible*.\n"
202+
"Even if you've followed all the preparation steps correctly, "
203+
"the chance of the upgrade going wrong remains non-zero.\n"
204+
"Make sure you've run the pre-check and checked the logs and reports.\n"
205+
"Do you confirm that you've successfully taken and tested a full backup of your server?\n"
206+
"Rollback will not be possible."
207+
)
208+
print(warn_msg)
209+
210+
response = ""
211+
while response not in ["y", "n"]:
212+
response = six.moves.input("Y/N> ").lower()
213+
214+
return response == "y"
215+
216+
170217
def handle_output_level(args):
171218
"""
172219
Set environment variables following command line arguments.
@@ -247,3 +294,68 @@ def process_whitelist_experimental(repositories, workflow, configuration, logger
247294
if logger:
248295
logger.error(msg)
249296
raise CommandError(msg)
297+
298+
299+
def process_report_schema(args, configuration):
300+
default_report_schema = configuration.get('report', 'schema')
301+
if args.report_schema and args.report_schema > default_report_schema:
302+
raise CommandError('--report-schema version can not be greater that the '
303+
'actual {} one.'.format(default_report_schema))
304+
return args.report_schema or default_report_schema
305+
306+
307+
# TODO: This and the following functions should eventually be placed into the
308+
# leapp.utils.output module.
309+
def pretty_block_log(string, logger_level, width=60):
310+
log_str = "\n{separator}\n{text}\n{separator}\n".format(
311+
separator="=" * width,
312+
text=string.center(width))
313+
logger_level(log_str)
314+
315+
316+
@contextmanager
317+
def format_actor_exceptions(logger):
318+
try:
319+
try:
320+
yield
321+
except LeappRuntimeError as err:
322+
msg = "{} - Please check the above details".format(err.message)
323+
sys.stderr.write("\n")
324+
sys.stderr.write(pretty_block_text(msg, color="", width=len(msg)))
325+
logger.error(err.message)
326+
finally:
327+
pass
328+
329+
330+
def log_errors(errors, logger):
331+
if errors:
332+
pretty_block_log("ERRORS", logger.info)
333+
334+
for error in errors:
335+
model = ErrorModel.create(json.loads(error['message']['data']))
336+
error_message = model.message
337+
if six.PY2:
338+
error_message = model.message.encode('utf-8', 'xmlcharrefreplace')
339+
340+
logger.error("{time} [{severity}] Actor: {actor}\nMessage: {message}\n".format(
341+
severity=model.severity.upper(),
342+
message=error_message, time=model.time, actor=model.actor))
343+
if model.details:
344+
print('Summary:')
345+
details = json.loads(model.details)
346+
for detail in details:
347+
print(' {k}: {v}'.format(
348+
k=detail.capitalize(),
349+
v=details[detail].rstrip().replace('\n', '\n' + ' ' * (6 + len(detail)))))
350+
351+
352+
def log_inhibitors(context_id, logger):
353+
from leapp.reporting import Flags # pylint: disable=import-outside-toplevel
354+
reports = fetch_upgrade_report_messages(context_id)
355+
inhibitors = [report for report in reports if Flags.INHIBITOR in report.get('flags', [])]
356+
if inhibitors:
357+
pretty_block_log("UPGRADE INHIBITED", logger.error)
358+
logger.error('Upgrade has been inhibited due to the following problems:')
359+
for position, report in enumerate(inhibitors, start=1):
360+
logger.error('{idx:5}. Inhibitor: {title}'.format(idx=position, title=report['title']))
361+
logger.info('Consult the pre-upgrade report for details and possible remediation.')

etc/leapp/transaction/to_remove

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
### List of packages (each on new line) to be removed from the upgrade transaction
22
# Removing initial-setup package to avoid it asking for EULA acceptance during upgrade - OAMG-1531
33
initial-setup
4+
5+
# temporary workaround for the file conflict symlink <-> dir (#2030627)
6+
rubygem-irb
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
* Thu Jul 04 2024 Roman Prilipskii <[email protected]> 0.16.0-10.cloudlinux
2+
- CLOS-2610: Add upgrade inhibitors for outdated GRUB and insufficient space in boot disk embedding area
3+
- CLOS-2670: Allow upgrades with the Plesk control panel
4+
- CLOS-2707: Allow upgrades with the DirectAdmin control panel and add DirectAdmin rebuild to the post-elevation steps if it's installed
5+
- CLOS-2759: Fix 'Cache-only enabled but no cache' errors for CLN repositories
6+
- Add a built-in signature for Fedora EPEL packages
7+
8+
* Wed May 29 2024 Roman Prilipskii <[email protected]> 0.16.0-9.cloudlinux
9+
- CLOS-2631: Improve algorithm of overlayfs creation and disk space estimation

packaging/leapp-repository.spec

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ py2_byte_compile "%1" "%2"}
4242

4343
Name: leapp-repository
4444
Version: 0.20.0
45-
Release: 1%{?dist}
45+
Release: 1%{?dist}.cloudlinux
4646
Summary: Repositories for leapp
4747

4848
License: ASL 2.0
@@ -238,6 +238,8 @@ rm -rf %{buildroot}%{leapp_python_sitelib}/leapp/cli/commands/tests
238238
rm -rf %{buildroot}%{repositorydir}/system_upgrade/el8toel9
239239
%else
240240
rm -rf %{buildroot}%{repositorydir}/system_upgrade/el7toel8
241+
# CloudLinux migration only supports el7 to el8
242+
rm -rf %{buildroot}%{repositorydir}/system_upgrade/cloudlinux
241243
%endif
242244

243245
# remove component/unit tests, Makefiles, ... stuff that related to testing only

0 commit comments

Comments
 (0)