Skip to content

Commit

Permalink
[RHELC-1507] Port environment variables to config file (#1272)
Browse files Browse the repository at this point in the history
* Modify convert2rhel.ini with new fields and values

* Split toolopts from cli both in module as code

In the past, we used to have this portion of code all together inside
the toolopts module, making it very difficult to understand and improve
as the separation was not intuitive enough.

With this patch, we are splitting the cli related functions and classes
to its own module, making it an entrypoint for everything related to CLI
usage.

Toolopts also got its own module to further separate the logic between
cli stuff and options stuff. Historically we call all options from our
source code as "toolopts", so to preserve the naming convention and
minimize as much as possible the changes throughout the codebase, the
same name was preserved.

A new addition was also made which is the config module. This module is
responsible to gather all the configuration options we could ever define
for the tool. Currently, it only has CLIConfig and FileConfig, which are
the two supported options.

Toolopts, at this point, is our final class who will hold all the
options that are composed from the cli and config file (being able to be
extended in the future to other options).

* Move code to their related utils modules

A couple of functions and constants were moved to their related utils
modules to get them out of the way from circle dependency and make the
codebase a bit more clear

* Update code reference about toolopts and cli on codebase

This patch introduces the updated references to both toolopts and cli
throughout the codebase as some of the things we had before could be
changed to the new format, especially because no code get executed
before the CLI class parse all the options necessary.

We are not safe to call tool_opts even if nothing is populated inside
the class. Beware that it will still fail if we try to access any
attributes before they get created, but that should be a implementation
problem, not really a workflow one, since we expect that the CLI get
executed very early in the process.

* Update man script and vulture script

Add a couple of missing variables to the vulture whitelist script so the
hook can stop warning about unused variable.

* Update the unit_tests to reflect the changes in the refactor

* Integration tests fixup

* Fix convert2rhel.ini with defaults values and parsing

Parsing the values for inhibitor_overrides now convert it to a boolean
value by default.
  • Loading branch information
r0x0d authored Sep 19, 2024
1 parent 3ecb84a commit 0f8750e
Show file tree
Hide file tree
Showing 50 changed files with 2,560 additions and 1,577 deletions.
12 changes: 12 additions & 0 deletions config/convert2rhel.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,15 @@
# password = <insert_password>
# activation_key = <insert_activation_key>
# org = <insert_org>

[host_metering]
# Possible values here are "auto" or "force"
# configure_host_metering = "auto"

[inhibitor_overrides]
# incomplete_rollback = false
# tainted_kernel_module_check_skip = false
# outdated_package_check_skip = false
# allow_older_version = false
# allow_unavailable_kmods = false
# skip_kernel_currency_check = false
2 changes: 2 additions & 0 deletions convert2rhel/actions/post_conversion/kernel_boot_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ def run(self):
# from `uname -r`, as it requires a reboot in order to take place, we are
# detecting the latest kernel by using `rpm` and figuring out which was the
# latest kernel installed.

latest_installed_kernel = output.split("\n")[0].split(" ")[0]
latest_installed_kernel = latest_installed_kernel[len(kernel_name + "-") :]

grub2_config_file = grub.get_grub_config_file()
initramfs_file = INITRAMFS_FILEPATH % latest_installed_kernel
vmlinuz_file = VMLINUZ_FILEPATH % latest_installed_kernel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
from convert2rhel import actions, utils
from convert2rhel.logger import LOG_DIR, root_logger
from convert2rhel.systeminfo import system_info
from convert2rhel.toolopts import POST_RPM_VA_LOG_FILENAME, PRE_RPM_VA_LOG_FILENAME


logger = root_logger.getChild(__name__)
Expand All @@ -39,9 +38,9 @@ def run(self):

logger.task("Final: Show RPM files modified by the conversion")

system_info.generate_rpm_va(log_filename=POST_RPM_VA_LOG_FILENAME)
system_info.generate_rpm_va(log_filename=utils.rpm.POST_RPM_VA_LOG_FILENAME)

pre_rpm_va_log_path = os.path.join(LOG_DIR, PRE_RPM_VA_LOG_FILENAME)
pre_rpm_va_log_path = os.path.join(LOG_DIR, utils.rpm.PRE_RPM_VA_LOG_FILENAME)
if not os.path.exists(pre_rpm_va_log_path):
logger.info("Skipping comparison of the 'rpm -Va' output from before and after the conversion.")
self.add_message(
Expand All @@ -55,7 +54,7 @@ def run(self):
return

pre_rpm_va = utils.get_file_content(pre_rpm_va_log_path, True)
post_rpm_va_log_path = os.path.join(LOG_DIR, POST_RPM_VA_LOG_FILENAME)
post_rpm_va_log_path = os.path.join(LOG_DIR, utils.rpm.POST_RPM_VA_LOG_FILENAME)
post_rpm_va = utils.get_file_content(post_rpm_va_log_path, True)
modified_rpm_files_diff = "\n".join(
difflib.unified_diff(
Expand Down
2 changes: 1 addition & 1 deletion convert2rhel/actions/pre_ponr_changes/backup_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from convert2rhel.redhatrelease import os_release_file, system_release_file
from convert2rhel.repo import DEFAULT_DNF_VARS_DIR, DEFAULT_YUM_REPOFILE_DIR, DEFAULT_YUM_VARS_DIR
from convert2rhel.systeminfo import system_info
from convert2rhel.toolopts import PRE_RPM_VA_LOG_FILENAME
from convert2rhel.utils.rpm import PRE_RPM_VA_LOG_FILENAME


# Regex explanation:
Expand Down
5 changes: 3 additions & 2 deletions convert2rhel/breadcrumbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@

from datetime import datetime

from convert2rhel import pkghandler, toolopts, utils
from convert2rhel import pkghandler, utils
from convert2rhel.logger import root_logger
from convert2rhel.systeminfo import system_info
from convert2rhel.toolopts import tool_opts
from convert2rhel.utils import files


Expand Down Expand Up @@ -104,7 +105,7 @@ def finish_collection(self, success=False):

def _set_activity(self):
"""Set the activity that convert2rhel is going to perform"""
self.activity = toolopts.tool_opts.activity
self.activity = tool_opts.activity

def _set_pkg_object(self):
"""Set pkg_object which is used to get information about installed Convert2RHEL"""
Expand Down
Loading

0 comments on commit 0f8750e

Please sign in to comment.