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

[RHELC-1169] Advise users to back up their system #1235

Merged
merged 29 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
c98f96e
Added the log message for the user system backup
Andrew-ang9 May 21, 2024
7239776
Moved the log outside the print_data_collection()
Andrew-ang9 May 22, 2024
fc4c425
Moved the confirmation of user backup
Andrew-ang9 May 30, 2024
04a92e5
Made a function for the user back up check
Andrew-ang9 Jun 12, 2024
8722fdb
Moved the confirm_user_backup() to main.py
Andrew-ang9 Jun 26, 2024
ea55420
Finnished the uint test for Confirm_user_backup()
Andrew-ang9 Jun 28, 2024
2fde33a
Removed leftover imports from breadcrumbs_test.py
Andrew-ang9 Jul 3, 2024
ad0f23d
Draft used the mock for the users input
Andrew-ang9 Jul 10, 2024
b5cc721
Added the assert for the message
Andrew-ang9 Jul 16, 2024
105c536
Added a mock to ask_to_continue() in
Andrew-ang9 Aug 21, 2024
472b4de
Draft for the fix for the sanity tests
Andrew-ang9 Sep 11, 2024
886547b
Draft added in the rest of the fixes for the tests
Andrew-ang9 Sep 17, 2024
e18da44
Added the second prompt for the intergration test
Andrew-ang9 Sep 18, 2024
f60d80f
added some more fixes for the intergration tests
Andrew-ang9 Sep 24, 2024
e0abaa3
Added in some more cases for the intergration test
Andrew-ang9 Sep 25, 2024
9c74bb7
added in two yes prompts for the intergartion test
Andrew-ang9 Oct 8, 2024
3b08ad9
Added in input for test_pre_registered.py
Andrew-ang9 Oct 9, 2024
6607a58
Removed one of the c2r.expect lines from a test
Andrew-ang9 Oct 10, 2024
011bdc0
Added a prompt to another intergration test
Andrew-ang9 Oct 17, 2024
308feb0
removed the commit in confirm_user_backup
Andrew-ang9 Oct 18, 2024
a37bb0c
Removed the rebase markers
Andrew-ang9 Oct 18, 2024
39138a4
Changed how we are calling toolopts.CLI()
Andrew-ang9 Oct 18, 2024
4293d95
Removed some old code from a rebase
Oct 21, 2024
6f74781
fully removed the test_confirm_user_backup() from breadcrumbs_test
Oct 21, 2024
b9e4db7
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 21, 2024
42a484d
Draft trying to just pass the input for the test
Oct 21, 2024
ed1ccd2
draft Commited out the extra prompt
Andrew-ang9 Oct 22, 2024
b5860a6
Removed some of the prompts as they are not needed
Andrew-ang9 Oct 23, 2024
fe6fc06
draft added in a prompt
Andrew-ang9 Oct 24, 2024
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
1 change: 0 additions & 1 deletion convert2rhel/breadcrumbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ def print_data_collection(self):
"- Convert2RHEL related environment variables\n\n",
RHSM_CUSTOM_FACTS_FILE,
)

utils.ask_to_continue()


Expand Down
12 changes: 12 additions & 0 deletions convert2rhel/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,17 @@ def _handle_inhibitors_found_exception():
return ConversionExitCodes.INHIBITORS_FOUND


def confirm_user_backup():
loggerinst.warning(
"Convert2RHEL modifies the systems during the analysis and then rolls back these "
"changes when the analysis is complete. In rare cases, this rollback can fail. "
"By continuing, you confirm that you have made a system backup and verified that "
"you can restore from the backup."
)

utils.ask_to_continue()


#
# Boilerplate Tasks
#
Expand All @@ -327,6 +338,7 @@ def perform_boilerplate():

loggerinst.task("Prepare: Inform about data collection")
breadcrumbs.breadcrumbs.print_data_collection()
confirm_user_backup()


def show_eula():
Expand Down
1 change: 1 addition & 0 deletions convert2rhel/unit_tests/breadcrumbs_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import pytest
import six


from convert2rhel import breadcrumbs, pkghandler, pkgmanager
from convert2rhel.unit_tests import create_pkg_information, create_pkg_obj
from convert2rhel.unit_tests.conftest import centos7
Expand Down
39 changes: 37 additions & 2 deletions convert2rhel/unit_tests/main_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ def test_main(monkeypatch, global_tool_opts, tmp_path):
assert raise_for_skipped_failures_mock.call_count == 2
assert report_summary_mock.call_count == 2
assert clear_versionlock_mock.call_count == 1
assert ask_to_continue_mock.call_count == 1
assert ask_to_continue_mock.call_count == 2
assert restart_system_mock.call_count == 1
assert summary_as_json_mock.call_count == 1
assert summary_as_txt_mock.call_count == 1
Expand Down Expand Up @@ -315,6 +315,8 @@ def test_main_rollback_post_cli_phase(self, monkeypatch, caplog, tmp_path):
assert "No changes were made to the system." in caplog.records[-2].message

def test_main_traceback_in_clear_versionlock(self, caplog, monkeypatch, tmp_path):
ask_to_continue_mock = mock.Mock(return_value=True)

monkeypatch.setattr(applock, "_DEFAULT_LOCK_DIR", str(tmp_path))
monkeypatch.setattr(utils, "require_root", RequireRootMocked())
monkeypatch.setattr(main, "initialize_file_logging", InitializeFileLoggingMocked())
Expand All @@ -334,6 +336,8 @@ def test_main_traceback_in_clear_versionlock(self, caplog, monkeypatch, tmp_path
),
)

monkeypatch.setattr(utils, "ask_to_continue", ask_to_continue_mock)

# Mock rollback items
monkeypatch.setattr(main, "rollback_changes", RollbackChangesMocked())
monkeypatch.setattr(main, "provide_status_after_rollback", PrintInfoAfterRollbackMocked())
Expand All @@ -349,6 +353,7 @@ def test_main_traceback_in_clear_versionlock(self, caplog, monkeypatch, tmp_path
assert system_info.resolve_system_info.call_count == 1
assert breadcrumbs.collect_early_data.call_count == 1
assert pkghandler.clear_versionlock.call_count == 1
assert ask_to_continue_mock.call_count == 1

assert main.rollback_changes.call_count == 0
assert main.provide_status_after_rollback.call_count == 0
Expand All @@ -372,6 +377,7 @@ def test_main_traceback_before_action_completion(self, monkeypatch, caplog, tmp_
clean_yum_metadata_mock = mock.Mock()
run_pre_actions_mock = mock.Mock(side_effect=Exception("Action Framework Crashed"))
clear_versionlock_mock = mock.Mock()
ask_to_continue_mock = mock.Mock(return_value=True)
summary_as_txt_mock = mock.Mock()

# Mock the rollback calls
Expand All @@ -391,6 +397,7 @@ def test_main_traceback_before_action_completion(self, monkeypatch, caplog, tmp_
monkeypatch.setattr(system_info, "print_system_information", print_system_information_mock)
monkeypatch.setattr(breadcrumbs, "collect_early_data", collect_early_data_mock)
monkeypatch.setattr(pkghandler, "clear_versionlock", clear_versionlock_mock)
monkeypatch.setattr(utils, "ask_to_continue", ask_to_continue_mock)
monkeypatch.setattr(pkgmanager, "clean_yum_metadata", clean_yum_metadata_mock)
monkeypatch.setattr(actions, "run_pre_actions", run_pre_actions_mock)
monkeypatch.setattr(breadcrumbs, "finish_collection", finish_collection_mock)
Expand All @@ -411,6 +418,7 @@ def test_main_traceback_before_action_completion(self, monkeypatch, caplog, tmp_
assert clean_yum_metadata_mock.call_count == 1
assert run_pre_actions_mock.call_count == 1
assert clear_versionlock_mock.call_count == 1
assert ask_to_continue_mock.call_count == 1
assert finish_collection_mock.call_count == 1
assert should_subscribe_mock.call_count == 1
assert update_rhsm_custom_facts_mock.call_count == 1
Expand All @@ -436,6 +444,7 @@ def test_main_rollback_pre_ponr_changes_phase(self, monkeypatch, tmp_path, globa
run_pre_actions_mock = mock.Mock()
report_summary_mock = mock.Mock()
clear_versionlock_mock = mock.Mock()
ask_to_continue_mock = mock.Mock(return_value=True)
find_actions_of_severity_mock = mock.Mock()
summary_as_txt_mock = mock.Mock()

Expand All @@ -456,6 +465,7 @@ def test_main_rollback_pre_ponr_changes_phase(self, monkeypatch, tmp_path, globa
monkeypatch.setattr(system_info, "print_system_information", print_system_information_mock)
monkeypatch.setattr(breadcrumbs, "collect_early_data", collect_early_data_mock)
monkeypatch.setattr(pkghandler, "clear_versionlock", clear_versionlock_mock)
monkeypatch.setattr(utils, "ask_to_continue", ask_to_continue_mock)
monkeypatch.setattr(pkgmanager, "clean_yum_metadata", clean_yum_metadata_mock)
monkeypatch.setattr(actions, "run_pre_actions", run_pre_actions_mock)
monkeypatch.setattr(report, "_summary", report_summary_mock)
Expand All @@ -480,6 +490,7 @@ def test_main_rollback_pre_ponr_changes_phase(self, monkeypatch, tmp_path, globa
assert report_summary_mock.call_count == 1
assert find_actions_of_severity_mock.call_count == 1
assert clear_versionlock_mock.call_count == 1
assert ask_to_continue_mock.call_count == 1
assert finish_collection_mock.call_count == 1
assert should_subscribe_mock.call_count == 1
assert update_rhsm_custom_facts_mock.call_count == 1
Expand Down Expand Up @@ -507,6 +518,7 @@ def test_main_rollback_analyze_exit_phase_without_subman(self, global_tool_opts,
(system_info, "print_system_information", mock.Mock()),
(breadcrumbs, "collect_early_data", mock.Mock()),
(pkghandler, "clear_versionlock", mock.Mock()),
(utils, "ask_to_continue", mock.Mock(return_value=True)),
(pkgmanager, "clean_yum_metadata", mock.Mock()),
(actions, "run_pre_actions", mock.Mock()),
(report, "_summary", mock.Mock()),
Expand All @@ -530,6 +542,7 @@ def test_main_rollback_analyze_exit_phase_without_subman(self, global_tool_opts,
assert system_info.print_system_information.call_count == 1
assert breadcrumbs.collect_early_data.call_count == 1
assert pkghandler.clear_versionlock.call_count == 1
assert utils.ask_to_continue.call_count == 1
assert pkgmanager.clean_yum_metadata.call_count == 1
assert actions.run_pre_actions.call_count == 1
assert report._summary.call_count == 1
Expand All @@ -553,6 +566,7 @@ def test_main_rollback_analyze_exit_phase(self, global_tool_opts, monkeypatch, t
run_pre_actions_mock = mock.Mock()
report_summary_mock = mock.Mock()
clear_versionlock_mock = mock.Mock()
ask_to_continue_mock = mock.Mock(return_value=True)
summary_as_json_mock = mock.Mock()
summary_as_txt_mock = mock.Mock()

Expand All @@ -572,6 +586,7 @@ def test_main_rollback_analyze_exit_phase(self, global_tool_opts, monkeypatch, t
monkeypatch.setattr(system_info, "print_system_information", print_system_information_mock)
monkeypatch.setattr(breadcrumbs, "collect_early_data", collect_early_data_mock)
monkeypatch.setattr(pkghandler, "clear_versionlock", clear_versionlock_mock)
monkeypatch.setattr(utils, "ask_to_continue", ask_to_continue_mock)
monkeypatch.setattr(pkgmanager, "clean_yum_metadata", clean_yum_metadata_mock)
monkeypatch.setattr(actions, "run_pre_actions", run_pre_actions_mock)
monkeypatch.setattr(report, "_summary", report_summary_mock)
Expand All @@ -595,6 +610,7 @@ def test_main_rollback_analyze_exit_phase(self, global_tool_opts, monkeypatch, t
assert run_pre_actions_mock.call_count == 1
assert report_summary_mock.call_count == 1
assert clear_versionlock_mock.call_count == 1
assert ask_to_continue_mock.call_count == 1
assert finish_collection_mock.call_count == 1
assert should_subscribe_mock.call_count == 1
assert update_rhsm_custom_facts_mock.call_count == 1
Expand Down Expand Up @@ -661,7 +677,7 @@ def test_main_rollback_post_ponr_changes_phase(self, monkeypatch, caplog, tmp_pa
assert find_actions_of_severity_mock.call_count == 1
assert clear_versionlock_mock.call_count == 1
assert report_summary_mock.call_count == 2
assert ask_to_continue_mock.call_count == 1
assert ask_to_continue_mock.call_count == 2
assert finish_collection_mock.call_count == 1
assert summary_as_json_mock.call_count == 1
assert summary_as_txt_mock.call_count == 1
Expand Down Expand Up @@ -768,3 +784,22 @@ def test_handle_inhibitors_found_exception(monkeypatch, rollback_failures, retur
ret = main._handle_inhibitors_found_exception()

assert ret == return_code


def test_confirm_user_backup(monkeypatch, caplog):
ask_to_continue_mock = mock.Mock(return_value=True)

# Mock the ask_to_continue function
monkeypatch.setattr(utils, "ask_to_continue", ask_to_continue_mock)

main.confirm_user_backup()

message = (
Fixed Show fixed Hide fixed
"Convert2RHEL modifies the systems during the analysis and then rolls back these "
"changes when the analysis is complete. In rare cases, this rollback can fail. "
"By continuing, you confirm that you have made a system backup and verified that "
"you can restore from the backup."
)

assert message in caplog.records[-1].message
assert ask_to_continue_mock.call_count == 1
r0x0d marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ def test_failures_and_skips_in_report(convert2rhel):
c2r.expect("Continue with the system conversion?")
c2r.sendline("y")

c2r.expect("Continue with the system conversion?")
c2r.sendline("y")

# Assert that we start rollback first
c2r.expect_exact("TASK - [Rollback:")

Expand Down Expand Up @@ -105,6 +108,9 @@ def test_successful_report(convert2rhel):
c2r.expect("Continue with the system conversion?")
c2r.sendline("y")

c2r.expect("Continue with the system conversion?")
c2r.sendline("y")

# Assert that we start rollback first
c2r.expect("Rollback: RHSM-related actions")

Expand Down Expand Up @@ -147,6 +153,9 @@ def test_convert_method_successful_report(convert2rhel):
c2r.expect("Continue with the system conversion?")
c2r.sendline("y")

c2r.expect("Continue with the system conversion?")
c2r.sendline("y")

# Refuse the full conversion at PONR
c2r.expect("Continue with the system conversion?")
c2r.sendline("n")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ def test_c2r_version_latest_with_mocked_newer_version(convert2rhel, c2r_version,
c2r.expect("Continue with the system conversion?")
c2r.sendline("y")

c2r.expect("Continue with the system conversion?")
c2r.sendline("y")

assert c2r.expect("Latest available convert2rhel version is installed.", timeout=300) == 0

c2r.sendcontrol("c")
Expand All @@ -125,6 +128,9 @@ def test_c2r_version_latest_inhibitor(convert2rhel, c2r_version, version):
c2r.expect("Continue with the system conversion?")
c2r.sendline("y")

c2r.expect("Continue with the system conversion?")
c2r.sendline("y")

assert (
c2r.expect_exact(
"(OVERRIDABLE) CONVERT2RHEL_LATEST_VERSION::OUT_OF_DATE - Outdated convert2rhel version detected",
Expand Down Expand Up @@ -153,6 +159,9 @@ def test_c2r_version_latest_override_inhibitor(convert2rhel, c2r_version, versio
c2r.expect("Continue with the system conversion?")
c2r.sendline("y")

c2r.expect("Continue with the system conversion?")
c2r.sendline("y")

assert c2r.expect("You are currently running 0.01.0", timeout=300) == 0
assert (
c2r.expect(
Expand All @@ -176,6 +185,9 @@ def test_clean_cache(convert2rhel):
c2r.expect("Continue with the system conversion?")
c2r.sendline("y")

c2r.expect("Continue with the system conversion?")
c2r.sendline("y")

assert c2r.expect("Prepare: Clean yum cache metadata", timeout=300) == 0
assert c2r.expect("Cached repositories metadata cleaned successfully.", timeout=300) == 0

Expand All @@ -196,6 +208,9 @@ def test_rhsm_error_logged(convert2rhel):
c2r.expect("Continue with the system conversion?")
c2r.sendline("y")

c2r.expect("Continue with the system conversion?")
c2r.sendline("y")

# Wait until we reach the point where the RHEL certificate has been
# installed otherwise we won't attempt to remove it.
assert c2r.expect("PRE_SUBSCRIPTION has succeeded") == 0
Expand Down Expand Up @@ -260,6 +275,7 @@ def test_analyze_incomplete_rollback(remove_repositories, convert2rhel):
with convert2rhel("analyze --debug") as c2r:
# We need to get past the data collection acknowledgement
c2r.sendline("y")
c2r.sendline("y")
# Verify the user is informed to not use the envar during the analysis
assert (
c2r.expect(
Expand All @@ -276,6 +292,7 @@ def test_analyze_incomplete_rollback(remove_repositories, convert2rhel):
with convert2rhel("--debug") as c2r:
# We need to get past the data collection acknowledgement
c2r.sendline("y")
c2r.sendline("y")
assert (
c2r.expect(
"'CONVERT2RHEL_INCOMPLETE_ROLLBACK' environment variable detected, continuing conversion.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ def test_override_inhibitor_with_unavailable_kmod_loaded(
c2r.expect("Continue with the system conversion?")
c2r.sendline("y")

c2r.expect("Continue with the system conversion?")
c2r.sendline("y")

c2r.expect("Detected 'CONVERT2RHEL_ALLOW_UNAVAILABLE_KMODS' environment variable")
c2r.expect("We will continue the conversion with the following kernel modules")

Expand Down Expand Up @@ -101,6 +104,9 @@ def test_inhibitor_with_force_loaded_tainted_kmod(shell, convert2rhel, forced_km
c2r.expect("Continue with the system conversion?")
c2r.sendline("y")

c2r.expect("Continue with the system conversion?")
c2r.sendline("y")

assert c2r.expect("TAINTED_KMODS::TAINTED_KMODS_DETECTED - Tainted kernel modules detected") == 0
c2r.sendcontrol("c")

Expand All @@ -127,6 +133,8 @@ def test_override_inhibitor_with_tainted_kmod(shell, convert2rhel, forced_kmods,
# We need to get past the data collection acknowledgement.
c2r.expect("Continue with the system conversion?")
c2r.sendline("y")
c2r.expect("Continue with the system conversion?")
c2r.sendline("y")
# Validate that with the envar the conversion is not inhibited with an error,
# but just a warning is displayed and the user is allowed to proceed with a full conversion
c2r.expect_exact("(WARNING) TAINTED_KMODS::SKIP_TAINTED_KERNEL_MODULE_CHECK")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ def test_custom_kernel(convert2rhel, shell, custom_kernel):
c2r.expect("Continue with the system conversion?")
c2r.sendline("y")

c2r.expect("Continue with the system conversion?")
c2r.sendline("y")

c2r.expect(
"WARNING - Custom kernel detected. The booted kernel needs to be signed by {}".format(os_vendor)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ def test_verify_latest_kernel_check_passes_with_failed_repoquery(convert2rhel, t
c2r.expect("Continue with the system conversion?")
c2r.sendline("y")

c2r.expect("Continue with the system conversion?")
c2r.sendline("y")

c2r.expect(
"Couldn't fetch the list of the most recent kernels available in the repositories. Did not perform the loaded kernel check.",
timeout=300,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ def test_logfile_starts_with_command(convert2rhel):
c2r.expect("Continue with the system conversion?")
c2r.sendline("y")

c2r.expect("Continue with the system conversion?")
c2r.sendline("y")

# After that we can stop the execution.
c2r.expect("Prepare: Clear YUM/DNF version locks")
c2r.sendcontrol("c")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ def test_proper_rhsm_clean_up(shell, convert2rhel):
c2r.expect("Continue with the system conversion?")
c2r.sendline("y")

c2r.expect("Continue with the system conversion?")
c2r.sendline("y")

# Wait till the system is properly registered and subscribed, then
# send the interrupt signal to the c2r process.
c2r.expect("Prepare: Get RHEL repository IDs")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@ def test_packages_with_in_name_period(shell, convert2rhel, packages_with_period)
c2r.expect("Continue with the system conversion", timeout=300)
c2r.sendline("y")

c2r.expect("Continue with the system conversion", timeout=300)
c2r.sendline("y")

c2r.expect("VALIDATE_PACKAGE_MANAGER_TRANSACTION has succeeded")

assert c2r.exitstatus == 0
Expand Down
Loading
Loading