Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid galera package reinstallation if mariadb provided by governor #19

Merged
merged 1 commit into from
Sep 10, 2024
Merged
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
77 changes: 77 additions & 0 deletions cloudlinux7to8/actions/mariadb.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,3 +286,80 @@ def _post_action(self) -> action.ActionResult:

def _revert_action(self) -> action.ActionResult:
return action.ActionResult()


class ReinstallMariadbConflictPackages(action.ActiveAction):
"""
ReinstallMariadbConflictPackages is an action class that handles the removal and reinstallation
of conflicting MariaDB packages during a system upgrade.

Some packages are unavailable from the Cloudlinux mariadb repository, so we must remove them before conversion.
However, we also need to avoid installing their analogues at the finishing stage.
This is why we have separated this action from the ReinstallConflictPackages.

Attributes:
removed_packages_file (str): Path to the file where removed packages are logged.

Methods:
__init__(temp_directory: str) -> None:
Initializes the action with a temporary directory for logging removed packages.

_prepare_action() -> action.ActionResult:
Preparation conversion by removing conflicting packages if MariaDB Governor is not installed.
Logs the removed packages to a file.

_post_action() -> action.ActionResult:
Reinstalls the previously removed packages after the conversion is completed.
Removes the log file after reinstallation.

_revert_action() -> action.ActionResult:
Reinstalls the previously removed packages if the action needs to be reverted.
Removes the log file after reinstallation.
"""

removed_packages_file: str

def __init__(self, temp_directory: str) -> None:
self.name = "reinstall mariadb conflict packages"
self.removed_packages_file = temp_directory + "/cloudlinux7to8_removed_mariadb_packages.txt"
self.conflict_pkgs_map = {
"galera": "galera",
}

def _prepare_action(self) -> action.ActionResult:
packages_to_remove = rpm.filter_installed_packages(["galera"])
rpm.remove_packages(packages_to_remove)

# Avoid reinstallation if mariadb installed by governor
if _is_governor_mariadb_installed():
return action.ActionResult()

with open(self.removed_packages_file, "a") as f:
f.write("\n".join(packages_to_remove) + "\n")

return action.ActionResult()

def _post_action(self) -> action.ActionResult:
if not os.path.exists(self.removed_packages_file):
return action.ActionResult()

with open(self.removed_packages_file, "r") as f:
packages_to_install = [self.conflict_pkgs_map[pkg] for pkg in set(f.read().splitlines())]
rpm.install_packages(packages_to_install)

os.unlink(self.removed_packages_file)
return action.ActionResult()

def _revert_action(self) -> action.ActionResult:
if not os.path.exists(self.removed_packages_file):
return action.ActionResult()

with open(self.removed_packages_file, "r") as f:
packages_to_install = list(set(f.read().splitlines()))
rpm.install_packages(packages_to_install)

os.unlink(self.removed_packages_file)
return action.ActionResult()

def estimate_prepare_time(self) -> int:
return 5
1 change: 0 additions & 1 deletion cloudlinux7to8/actions/packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ def __init__(self, temp_directory: str):
self.name = "re-installing common conflict packages"
self.removed_packages_file = temp_directory + "/cloudlinux7to8_removed_packages.txt"
self.conflict_pkgs_map = {
"galera": "galera",
"python36-argcomplete": "python3-argcomplete",
"python36-cffi": "python3-cffi",
"python36-chardet": "python3-chardet",
Expand Down
1 change: 1 addition & 0 deletions cloudlinux7to8/upgrader.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ def construct_actions(
custom_actions.RemovingPleskConflictPackages(),
custom_actions.ReinstallPleskComponents(),
custom_actions.ReinstallConflictPackages(options.state_dir),
custom_actions.ReinstallMariadbConflictPackages(options.state_dir),
custom_actions.ReinstallPerlCpanModules(options.state_dir),
custom_actions.DisableSuspiciousKernelModules(),
common_actions.HandleUpdatedSpamassassinConfig(),
Expand Down
Loading