Skip to content

Commit

Permalink
Merge pull request #19 from plesk/fix-galera-reinstallation
Browse files Browse the repository at this point in the history
Avoid galera package reinstallation if mariadb provided by governor
  • Loading branch information
SandakovMM authored Sep 10, 2024
2 parents c7b1272 + 5b41f8e commit 912e6aa
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 1 deletion.
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

0 comments on commit 912e6aa

Please sign in to comment.