Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 7 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ minimum_pre_commit_version: "2.9.0"
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.7.3
rev: v0.16.6
hooks:
# Run the linter.
- id: ruff
Expand All @@ -11,37 +11,37 @@ repos:
- id: ruff-format

- repo: "https://github.com/pre-commit/pre-commit-hooks"
rev: "v5.0.0"
rev: "v6.0.0"
hooks:
- id: "end-of-file-fixer"
- id: "trailing-whitespace"
- id: "check-toml"
- id: "check-yaml"
- id: "check-merge-conflict"
- repo: "https://gitlab.com/bmares/check-json5"
rev: "v1.0.0"
rev: "v1.0.1"
hooks:
- id: "check-json5"
- repo: "https://github.com/teemtee/tmt.git"
rev: "1.70.0"
rev: "1.78.0"
hooks:
- id: "tmt-tests-lint"
verbose: false
files: ^(tests/|plans/)

- repo: https://github.com/packit/pre-commit-hooks
rev: v1.2.0
rev: v1.3.0
hooks:
- id: check-rebase
args:
- https://github.com/oamg/convert2rhel.git
stages: [manual, pre-push]
- repo: https://github.com/gitleaks/gitleaks
rev: v8.21.2
rev: v8.30.0
hooks:
- id: gitleaks
stages: [manual, pre-push]
- repo: https://github.com/jendrikseipp/vulture
rev: v2.13
rev: v2.16
hooks:
- id: vulture
10 changes: 5 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -313,25 +313,25 @@ from rpmUtils.miscutils import checkSignals

yb = YumBase()
try:
#yb.doConfigSetup(init_plugins=False)
# yb.doConfigSetup(init_plugins=False)
yb.runTransaction(False)
except (BaseException, SystemExit, Exception) as e:
print('We were able to catch an exception from runTransaction!')
print("We were able to catch an exception from runTransaction!")
print(type(e))
print(e)
print('Sleeping')
print("Sleeping")
time.sleep(3)
# Hit Ctrl-C
# If KeyboardInterrupt is raised, chances are that this did not cause the
# problem
try:
checkSignals()
except (BaseException, SystemExit, Exception) as e:
print('We were able to catch an exception from checkSignals!')
print("We were able to catch an exception from checkSignals!")
print(type(e))
print(e)
finally:
print('In the finally block')
print("In the finally block")
# If the previous try: except exits immediately without message, then the
# issue occurred.
# If it raises a KeyboardInterrupt traceback then we're okay.
Expand Down
1 change: 0 additions & 1 deletion convert2rhel/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
__metaclass__ = type
__version__ = "2.3.1"
52 changes: 17 additions & 35 deletions convert2rhel/actions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,20 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

__metaclass__ = type


import abc
import collections
import importlib
import itertools
import pkgutil
import traceback

from functools import wraps

import six

from convert2rhel import utils
from convert2rhel.logger import root_logger


logger = root_logger.getChild(__name__)


Expand Down Expand Up @@ -135,7 +131,7 @@ class DependencyError(ActionError):
"""

def __init__(self, *args, **kwargs):
super(DependencyError, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
self.unresolved_actions = kwargs.pop("unresolved_actions", [])
self.resolved_actions = kwargs.pop("resolved_actions", [])

Expand Down Expand Up @@ -203,7 +199,7 @@ def run(self):
instead.
"""
if self._has_run:
raise ActionError("Action {} has already run".format(self.id))
raise ActionError(f"Action {self.id} has already run")

self._has_run = True

Expand Down Expand Up @@ -324,16 +320,7 @@ def __hash__(self):
return hash((self.level, self.id, self.title, self.description, self.diagnosis, self.remediations))

def __repr__(self):
return "{}(level={}, id={}, title={}, description={}, diagnosis={}, remediations={}, variables={})".format(
self.__class__.__name__,
_STATUS_NAME_FROM_CODE[self.level],
self.id,
self.title,
self.description,
self.diagnosis,
self.remediations,
self.variables,
)
return f"{self.__class__.__name__}(level={_STATUS_NAME_FROM_CODE[self.level]}, id={self.id}, title={self.title}, description={self.description}, diagnosis={self.diagnosis}, remediations={self.remediations}, variables={self.variables})"

def to_dict(self):
"""
Expand Down Expand Up @@ -364,9 +351,9 @@ def __init__(self, level="", id="", title="", description="", diagnosis="", reme
# None of the result status codes are legal as a message. So we error if any
# of them were given here.
if not (STATUS_CODE["SUCCESS"] < STATUS_CODE[level] < STATUS_CODE["SKIP"]):
raise InvalidMessageError("Invalid level '{}', set for a non-result message".format(level))
raise InvalidMessageError(f"Invalid level '{level}', set for a non-result message")

super(ActionMessage, self).__init__(level, id, title, description, diagnosis, remediations, variables)
super().__init__(level, id, title, description, diagnosis, remediations, variables)


class ActionResult(ActionMessageBase):
Expand All @@ -392,10 +379,10 @@ def __init__(

elif STATUS_CODE["SUCCESS"] < STATUS_CODE[level] < STATUS_CODE["SKIP"]:
raise InvalidMessageError(
"Invalid level '{}', the level for result must be SKIP or more fatal or SUCCESS.".format(level)
f"Invalid level '{level}', the level for result must be SKIP or more fatal or SUCCESS."
)

super(ActionResult, self).__init__(level, id, title, description, diagnosis, remediations, variables)
super().__init__(level, id, title, description, diagnosis, remediations, variables)


def get_actions(actions_path, prefix):
Expand Down Expand Up @@ -520,10 +507,10 @@ def run(self, successes=None, failures=None, skips=None):
running is WARNING or better (WARNING or SUCCESS) and
failure as worse than WARNING (OVERRIDABLE, ERROR)
"""
logger.task("{}".format(self.task_header))
logger.task(f"{self.task_header}")

if self._has_run:
raise ActionError("Stage {} has already run.".format(self.stage_name))
raise ActionError(f"Stage {self.stage_name} has already run.")
self._has_run = True

# Make a mutable copy of these parameters so we don't overwrite the caller's data.
Expand All @@ -548,24 +535,19 @@ def run(self, successes=None, failures=None, skips=None):
to_be = "was"
if len(failed_deps) > 1:
to_be = "were"
diagnosis = "Skipped because {} {} not successful".format(
utils.format_sequence_as_message(failed_deps),
to_be,
)
diagnosis = f"Skipped because {utils.format_sequence_as_message(failed_deps)} {to_be} not successful"

action.set_result(
level="SKIP",
id="SKIP",
title="Skipped action",
description="This action was skipped due to another action failing.",
diagnosis=diagnosis,
remediations="Please ensure that the {} check passes so that this Action can evaluate your system".format(
utils.format_sequence_as_message(failed_deps)
),
remediations=f"Please ensure that the {utils.format_sequence_as_message(failed_deps)} check passes so that this Action can evaluate your system",
)
skips.append(action)
failed_action_ids.add(action.id)
logger.error("Skipped {}. {}".format(action.id, diagnosis))
logger.error(f"Skipped {action.id}. {diagnosis}")
continue

# Run the Action
Expand All @@ -575,18 +557,18 @@ def run(self, successes=None, failures=None, skips=None):
# Uncaught exceptions are handled by constructing a generic
# failure message here that should be reported
description = (
"Unhandled exception was caught: {}\n"
f"Unhandled exception was caught: {e}\n"
"Please file a bug at https://issues.redhat.com/ to have this"
" fixed or a specific error message added.\n"
"Traceback: {}".format(e, traceback.format_exc())
f"Traceback: {traceback.format_exc()}"
)
action.set_result(
level="ERROR", id="UNEXPECTED_ERROR", title="Unhandled exception caught", description=description
)

# Categorize the results
if action.result.level <= STATUS_CODE["WARNING"]:
logger.info("{} has succeeded".format(action.id))
logger.info(f"{action.id} has succeeded")
successes.append(action)

if action.result.level > STATUS_CODE["WARNING"]:
Expand Down Expand Up @@ -752,7 +734,7 @@ def run_pre_actions():
except DependencyError as e:
# We want to fail early if dependencies are not properly set. This
# way we should fail in testing before release.
logger.critical("Some dependencies were set on Actions but not present in convert2rhel: {}".format(e))
logger.critical(f"Some dependencies were set on Actions but not present in convert2rhel: {e}")

# Run the Actions in system_checks and all subsequent Stages.
results = system_checks.run()
Expand Down Expand Up @@ -781,7 +763,7 @@ def run_post_actions():
except DependencyError as e:
# We want to fail early if dependencies are not properly set. This
# way we should fail in testing before release.
logger.critical("Some dependencies were set on Actions but not present in convert2rhel: {}".format(e))
logger.critical(f"Some dependencies were set on Actions but not present in convert2rhel: {e}")

# Run the Actions in conversion and all subsequent Stages.
results = conversion.run()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

__metaclass__ = type

from convert2rhel import actions, logger
from convert2rhel.pkghandler import get_installed_pkgs_w_different_key_id, print_pkg_info
from convert2rhel.systeminfo import system_info


loggerinst = logger.root_logger.getChild(__name__)


Expand All @@ -31,7 +29,7 @@ def run(self):
"""List all the packages that have not been replaced by the
Red Hat-signed ones during the conversion.
"""
super(ListNonRedHatPkgsLeft, self).run()
super().run()
loggerinst.task("List remaining non-Red Hat packages")

loggerinst.info("Listing packages not signed by Red Hat")
Expand Down
12 changes: 4 additions & 8 deletions convert2rhel/actions/conversion/lock_releasever.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

__metaclass__ = type

from convert2rhel import actions, logger, utils
from convert2rhel.systeminfo import system_info
from convert2rhel.toolopts import tool_opts


loggerinst = logger.root_logger.getChild(__name__)


Expand All @@ -38,7 +36,7 @@ def run(self):
keeps receiving updates for the specific EUS minor version instead of the latest minor version which is the
default.
"""
super(LockReleaseverInRHELRepositories, self).run()
super().run()
loggerinst.task("Lock releasever in RHEL repositories")

# We only lock the releasever on rhel repos if we detect that the running system is an EUS correspondent and if
Expand All @@ -51,17 +49,15 @@ def run(self):
)
return
loggerinst.info(
"Updating /etc/yum.repos.d/rehat.repo to point to RHEL {} instead of the default latest minor version.".format(
system_info.releasever
)
f"Updating /etc/yum.repos.d/rehat.repo to point to RHEL {system_info.releasever} instead of the default latest minor version."
)
cmd = [
"subscription-manager",
"release",
"--set={}".format(system_info.releasever),
f"--set={system_info.releasever}",
]
_, ret_code = utils.run_subprocess(cmd, print_output=False)
if ret_code != 0:
loggerinst.warning("Locking RHEL repositories failed.")
return
loggerinst.info("RHEL repositories locked to the {} minor version.".format(system_info.releasever))
loggerinst.info(f"RHEL repositories locked to the {system_info.releasever} minor version.")
4 changes: 1 addition & 3 deletions convert2rhel/actions/conversion/pkg_manager_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

__metaclass__ = type

from convert2rhel import actions, redhatrelease
from convert2rhel.logger import root_logger


logger = root_logger.getChild(__name__)


Expand All @@ -31,7 +29,7 @@ def run(self):
Check if the distroverpkg tag inside the package manager config has been modified before the conversion and if so
comment it out and write to the file.
"""
super(ConfigurePkgManager, self).run()
super().run()

logger.task("Patch package manager configuration file")

Expand Down
Loading
Loading