Skip to content

Commit

Permalink
Add an option to keep leapp related logs after conversion finished
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikhail Sandakov committed Dec 31, 2024
1 parent 86d1b4d commit fba7329
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
9 changes: 7 additions & 2 deletions centos2almaconverter/actions/installation.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

class LeapInstallation(action.ActiveAction):

def __init__(self):
keep_logs_on_finish: bool

def __init__(self, keep_logs_on_finish: bool = False):
self.name = "installing leapp"
self.pkgs_to_install = [
"leapp-0.18.0-1.el7",
Expand All @@ -17,6 +19,7 @@ def __init__(self):
"leapp-upgrade-el7toel8-0.21.0-2.el7",
"leapp-upgrade-el7toel8-deps-0.21.0-2.el7",
]
self.keep_logs_on_finish = keep_logs_on_finish

def _remove_previous_installation(self) -> None:
# Remove previously installed leapp packages to make sure we will install the correct version
Expand Down Expand Up @@ -70,9 +73,11 @@ def _post_action(self) -> action.ActionResult:
leapp_related_directories = [
"/etc/leapp",
"/var/lib/leapp",
"/var/log/leapp",
"/usr/lib/python2.7/site-packages/leapp",
]
if not self.keep_logs_on_finish:
leapp_related_directories.append("/var/log/leapp")

for directory in leapp_related_directories:
if os.path.exists(directory):
shutil.rmtree(directory)
Expand Down
6 changes: 5 additions & 1 deletion centos2almaconverter/upgrader.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def __init__(self):
self.disable_spamassasin_plugins = False
self.amavis_upgrade_allowed = False
self.allow_raid_devices = False
self.keep_leapp_logs = False

def __repr__(self) -> str:
return f"{self.__class__.__name__}(From {self._distro_from}, To {self._distro_to})"
Expand Down Expand Up @@ -121,7 +122,7 @@ def construct_actions(
common_actions.AddInProgressSshLoginMessage(new_os),
],
"Leapp installation": [
centos2alma_actions.LeapInstallation(),
centos2alma_actions.LeapInstallation(keep_logs_on_finish=self.keep_leapp_logs),
],
"Prepare configurations": [
common_actions.RevertChangesInGrub(),
Expand Down Expand Up @@ -300,6 +301,8 @@ def parse_args(self, args: typing.Sequence[str]) -> None:
help="Allow to upgrade amavis antivirus even if there is not enough RAM available.")
parser.add_argument("--allow-raid-devices", action="store_true", dest="allow_raid_devices", default=False,
help="Allow to have direct RAID devices in /etc/fstab. This could lead to unbootable system after the conversion so use the option on your own risk.")
parser.add_argument("--keep-leapp-logs", action="store_true", dest="keep_leapp_logs", default=False,
help="Keep leapp logs after the conversion. By default, the logs are removed after the conversion.")
options = parser.parse_args(args)

self.upgrade_postgres_allowed = options.upgrade_postgres_allowed
Expand All @@ -308,6 +311,7 @@ def parse_args(self, args: typing.Sequence[str]) -> None:
self.amavis_upgrade_allowed = options.amavis_upgrade_allowed
self.leapp_ovl_size = options.leapp_ovl_size
self.allow_raid_devices = options.allow_raid_devices
self.keep_leapp_logs = options.keep_leapp_logs


class Centos2AlmaConverterFactory(DistUpgraderFactory):
Expand Down
2 changes: 1 addition & 1 deletion dist-upgrader

0 comments on commit fba7329

Please sign in to comment.