Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View abadger's full-sized avatar

Toshio Kuratomi abadger

View GitHub Profile
@abadger
abadger / gist:2f04378c477dc3af20c47f4f3bbe5a31
Last active November 6, 2023 12:58
Early code for Actor-side implementation of configs
diff --git a/repos/system_upgrade/common/actors/rpmtransactionconfigtaskscollector/actor.py b/repos/system_upgrade/common/actors/rpmtransactionconfigtaskscollector/actor.py
index 4ef726f5..e85240be 100644
--- a/repos/system_upgrade/common/actors/rpmtransactionconfigtaskscollector/actor.py
+++ b/repos/system_upgrade/common/actors/rpmtransactionconfigtaskscollector/actor.py
@@ -6,6 +6,94 @@ from leapp.tags import FactsPhaseTag, IPUWorkflowTag
CONFIGURATION_BASE_PATH = '/etc/leapp/transaction'
+import abc
+import six
@pytest.mark.parametrize(
("bad_output_from_extract",),
(
[
[
"convert2rhel-0:0.18.0-1.el7.noarch",
"Not a NEVRA that we was not filtered due to a bug",
"convert2rhel-0:0.20.0-1.el7.noarch",
],
],
@abadger
abadger / gist:68e4ed8d44494df9ed9a2473d5f77da2
Created September 6, 2023 18:41
Front end format for MVP (script
The problem (as you pointed out earlier) is that you really want to apply one or more
transformations to the raw data to make it easier for the front end to work with it. I knew that
we would need to transform the results but there was a miscommunication about where that
transformation would occur. We thought it would be done somewhere after the data was passed back
from the client and the front end folks thought it would occur somewhere before they got it and no
one checked with the folks in the middle to make sure they understood that the only place left for
the transformation was in their code. Transformations that I know are needed:
* For each message, our unique key is a combination of the action's id (an action is one discrete
test or action that we can verify works prior to committing to going through with a conversion)
Some thoughts on the design of the framework:
We need to have separate returns for final results (SUCCESS, FAILURE, and SKIP) because there must be one and only one of those after run() finishes.
final result messages should be a list so that adding multiple messages to SUCCESS can be nicely formatted.
WARNING, and other things messages that can have multiple should be stored in a new list attribute on the Action class.
When evaluating logger.warning and logger.info, decide whether to set it as a SUCCESS messages or WARNING message. success messages will not be shown in convresion, only in analyze. warning messages will be shown in both.
add_result() should be renamed since we want results to be final results only. Maybe add_message()?
diff --git a/convert2rhel/actions/pre_ponr_changes/handle_packages.py b/convert2rhel/actions/pre_ponr_changes/handle_packages.py
index ad4ce58..a46b93f 100644
--- a/convert2rhel/actions/pre_ponr_changes/handle_packages.py
+++ b/convert2rhel/actions/pre_ponr_changes/handle_packages.py
@@ -17,7 +17,7 @@ __metaclass__ = type
import logging
-from convert2rhel import actions, pkghandler
+from convert2rhel import actions, pkghandler, utils
[03/31/2023 18:17:22] TASK - [Conversion analysis report] ***************************************
(ERROR) RHEL_COMPATIBLE_KERNEL.BOOTED_KERNEL_INCOMPATIBLE: The booted kernel version is incompatible with the standard RHEL kernel. To proceed with the conversion, boot into a kernel that is available in the Oracle Linux Server 8 base repository by executing the following steps:
1. Ensure that the Oracle Linux Server 8 base repository is enabled
2. Run: yum install kernel
3. (optional) Run: grubby --set-default /boot/vmlinuz-`rpm -q --qf "%{BUILDTIME}\t%{EVR}.%{ARCH}\n" kernel | sort -nr | head -1 | cut -f2`
4. Reboot the machine and if step 3 was not applied choose the kernel installed in step 2 manually
(ERROR) PRE_SUBSCRIPTION.UNKNOWN_ERROR: Failed to install subscription-manager packages. See the above yum output for details.
(SKIP) SUBSCRIBE_SYSTEM.SKIP: Skipped because PRE_SUBSCRIPTION was not successful
(SKIP) ENSURE_KERNEL_MODULES_COMPATIBILITY.SKIP: Skipped because SUBSCRIBE_SYSTEM was not successful
@abadger
abadger / subcommand.py
Created March 22, 2023 17:24
pseudo-python code to add a default subcommand
--#!/usr/bin/python -tt # W: Missing module docstring
import argparse
import sys
global_options = argparse.ArgumentParser()
global_options.add_argument('--debug', action='store_true')
global_option_names = frozenset(('--debug', '-d', 'convert', 'analyze'))
@abadger
abadger / catchall.py
Last active March 15, 2023 18:34
Have catchalls reraise KeyboardInterrupt
try:
subscription_manager_stuff()
# Not needed as long as we do not catch BaseException later on
# except KeyboardInterrupt:
# raise
except KnownError:
self.set_result("NICE_ERROR_CODE", "ERROR", "Nice error message")
except (Exception, SystemExit) as e:
self.set_result("UNKNOWN_ERROR", "ERROR", "Unknown Error was returned: %s" % e)
@abadger
abadger / gist:238eca60f1664e4fbf91f6285d54f6a5
Created March 14, 2023 20:12
How to write a unittest fixture
diff --git a/convert2rhel/unit_tests/actions/actions_test.py b/convert2rhel/unit_tests/actions/actions_test.py
index 8dbac8a..0716164 100644
--- a/convert2rhel/unit_tests/actions/actions_test.py
+++ b/convert2rhel/unit_tests/actions/actions_test.py
@@ -584,6 +584,9 @@ def _gen_version(major, minor):
class TestEFIChecks(unittest.TestCase):
+ def setUp(self):
+ self.efi_check = actions.efi_check.EfiCheck()
@abadger
abadger / decorate.py
Last active March 6, 2023 18:22
How to write a unittest that ignores a decorator
# let's say we have a function "testing" which is decorated by "my_decorator"
import functools
def my_decorator(func):
@functools.wraps(func)
def wrapped(*args, **kwargs):
print("In real decorator")
print(func.__name__)
print(args)
print(kwargs)