From e4b418f263ebf5db2e0aaaedd7665a8ced37a436 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Ho=C5=A1ek?= Date: Mon, 19 Aug 2024 17:37:44 +0200 Subject: [PATCH] Port breadcrumbs.finish_collection to action (#1305) Port one of the final steps of conversion to be called by action framework. --- .../breadcrumbs_finish_collection.py | 37 +++++++++++++++++ convert2rhel/main.py | 3 -- .../breadcrumbs_finish_collection_test.py | 40 +++++++++++++++++++ convert2rhel/unit_tests/main_test.py | 3 -- 4 files changed, 77 insertions(+), 6 deletions(-) create mode 100644 convert2rhel/actions/post_conversion/breadcrumbs_finish_collection.py create mode 100644 convert2rhel/unit_tests/actions/post_conversion/breadcrumbs_finish_collection_test.py diff --git a/convert2rhel/actions/post_conversion/breadcrumbs_finish_collection.py b/convert2rhel/actions/post_conversion/breadcrumbs_finish_collection.py new file mode 100644 index 0000000000..0c78c4bac3 --- /dev/null +++ b/convert2rhel/actions/post_conversion/breadcrumbs_finish_collection.py @@ -0,0 +1,37 @@ +# Copyright(C) 2024 Red Hat, Inc. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +__metaclass__ = type + +import logging + +from convert2rhel import actions, breadcrumbs + + +logger = logging.getLogger(__name__) + + +class BreadcumbsFinishCollection(actions.Action): + id = "BREADCRUMBS_FINISH_COLLECTION" + dependencies = ( + "KERNEL_BOOT_FILES", + "UPDATE_GRUB", + ) + + def run(self): + super(BreadcumbsFinishCollection, self).run() + + logger.task("Final: Update breadcrumbs") + breadcrumbs.breadcrumbs.finish_collection(success=True) diff --git a/convert2rhel/main.py b/convert2rhel/main.py index c94cadd8f6..a1d86d1ba1 100644 --- a/convert2rhel/main.py +++ b/convert2rhel/main.py @@ -372,9 +372,6 @@ def prepare_system(): def post_ponr_changes(): """Start the conversion itself""" - loggerinst.task("Final: Update breadcrumbs") - breadcrumbs.breadcrumbs.finish_collection(success=True) - loggerinst.task("Final: Update RHSM custom facts") subscription.update_rhsm_custom_facts() diff --git a/convert2rhel/unit_tests/actions/post_conversion/breadcrumbs_finish_collection_test.py b/convert2rhel/unit_tests/actions/post_conversion/breadcrumbs_finish_collection_test.py new file mode 100644 index 0000000000..7d354ff0a8 --- /dev/null +++ b/convert2rhel/unit_tests/actions/post_conversion/breadcrumbs_finish_collection_test.py @@ -0,0 +1,40 @@ +# Copyright(C) 2024 Red Hat, Inc. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +__metaclass__ = type + +import pytest +import six + +from convert2rhel.actions.post_conversion import breadcrumbs_finish_collection + + +six.add_move(six.MovedModule("mock", "mock", "unittest.mock")) +from six.moves import mock + + +@pytest.fixture +def breadcrumbs_finish_collection_instance(): + return breadcrumbs_finish_collection.BreadcumbsFinishCollection() + + +def test_breadcrumbs_finish_collection(monkeypatch, caplog, breadcrumbs_finish_collection_instance): + finish_collection = mock.Mock() + monkeypatch.setattr(breadcrumbs_finish_collection.breadcrumbs.breadcrumbs, "finish_collection", finish_collection) + + breadcrumbs_finish_collection_instance.run() + + assert "Final: Update breadcrumbs" in caplog.records[-1].message + assert finish_collection.call_count == 1 diff --git a/convert2rhel/unit_tests/main_test.py b/convert2rhel/unit_tests/main_test.py index b3d0b4156b..9e0cefa78f 100644 --- a/convert2rhel/unit_tests/main_test.py +++ b/convert2rhel/unit_tests/main_test.py @@ -242,7 +242,6 @@ def test_main(monkeypatch, tmp_path): clear_versionlock_mock = mock.Mock() ask_to_continue_mock = mock.Mock() restart_system_mock = mock.Mock() - finish_collection_mock = mock.Mock() update_rhsm_custom_facts_mock = mock.Mock() summary_as_json_mock = mock.Mock() summary_as_txt_mock = mock.Mock() @@ -264,7 +263,6 @@ def test_main(monkeypatch, tmp_path): monkeypatch.setattr(report, "_summary", report_summary_mock) monkeypatch.setattr(utils, "ask_to_continue", ask_to_continue_mock) monkeypatch.setattr(utils, "restart_system", restart_system_mock) - monkeypatch.setattr(breadcrumbs, "finish_collection", finish_collection_mock) monkeypatch.setattr(subscription, "update_rhsm_custom_facts", update_rhsm_custom_facts_mock) monkeypatch.setattr(report, "summary_as_json", summary_as_json_mock) monkeypatch.setattr(report, "summary_as_txt", summary_as_txt_mock) @@ -285,7 +283,6 @@ def test_main(monkeypatch, tmp_path): assert clear_versionlock_mock.call_count == 1 assert ask_to_continue_mock.call_count == 1 assert restart_system_mock.call_count == 1 - assert finish_collection_mock.call_count == 1 assert update_rhsm_custom_facts_mock.call_count == 1 assert summary_as_json_mock.call_count == 1 assert summary_as_txt_mock.call_count == 1