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

Changes related to cloudlinux7to8 #51

Merged
merged 9 commits into from
Jul 12, 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
44 changes: 25 additions & 19 deletions pleskdistup/actions/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@


class MoveOldBindConfigToNamed(action.ActiveAction):
def __init__(self):
old_bind_config_path: str
dst_config_path: str

def __init__(self) -> None:
self.name = "move old BIND configuration to named"
self.old_bind_config_path = "/etc/default/bind9"
self.dst_config_path = "/etc/default/named"
Expand Down Expand Up @@ -39,7 +42,7 @@ class AddFinishSshLoginMessage(action.ActiveAction):
"""
finish_message: str

def __init__(self, new_os: str):
def __init__(self, new_os: str) -> None:
self.name = "add finish SSH login message"
self.finish_message = f"""The server has been upgraded to {new_os}.\n"""

Expand All @@ -57,7 +60,9 @@ def _revert_action(self) -> action.ActionResult:


class AddInProgressSshLoginMessage(action.ActiveAction):
def __init__(self, new_os: str):
in_progress_message: str

def __init__(self, new_os: str) -> None:
self.name = "add in progress SSH login message"
path_to_util = os.path.abspath(sys.argv[0])
self.in_progress_message = f"""
Expand Down Expand Up @@ -85,7 +90,9 @@ def _revert_action(self) -> action.ActionResult:


class DisablePleskSshBanner(action.ActiveAction):
def __init__(self):
banner_command_path: str

def __init__(self) -> None:
self.name = "disable Plesk SSH banner"
self.banner_command_path = "/root/.plesk_banner"

Expand All @@ -106,15 +113,14 @@ def _revert_action(self) -> action.ActionResult:


class HandleConversionStatus(action.ActiveAction):
name: str
status_flag_path: str
completion_flag_path: str

def __init__(
self,
status_flag_path: str,
completion_flag_path: str,
):
) -> None:
self.name = "prepare and send conversion status"
self.status_flag_path = status_flag_path
self.completion_flag_path = completion_flag_path
Expand All @@ -141,7 +147,9 @@ def _revert_action(self) -> action.ActionResult:


class CleanApparmorCacheConfig(action.ActiveAction):
def __init__(self):
possible_locations: typing.List[str]

def __init__(self) -> None:
self.name = "clean AppArmor cache configuration"
self.possible_locations = ["/etc/apparmor/cache", "/etc/apparmor.d/cache"]

Expand Down Expand Up @@ -170,13 +178,13 @@ def _revert_action(self) -> action.ActionResult:
shutil.move(location + ".backup", location)
return action.ActionResult()

def estimate_prepare_time(self):
def estimate_prepare_time(self) -> int:
return 1

def estimate_post_time(self):
def estimate_post_time(self) -> int:
return 1

def estimate_revert_time(self):
def estimate_revert_time(self) -> int:
return 1


Expand All @@ -186,7 +194,6 @@ class Reboot(action.ActiveAction):
prepare_next_phase: typing.Optional[Phase]
post_reboot: typing.Optional[action.RebootType]
post_next_phase: typing.Optional[Phase]
name: str

def __init__(
self,
Expand All @@ -195,7 +202,7 @@ def __init__(
post_reboot: typing.Optional[action.RebootType] = None,
post_next_phase: typing.Optional[Phase] = None,
name: str = "reboot the system",
):
) -> None:
self.prepare_reboot = prepare_reboot
self.prepare_next_phase = prepare_next_phase
self.post_reboot = post_reboot
Expand All @@ -219,21 +226,21 @@ def _post_action(self) -> action.ActionResult:
def _revert_action(self) -> action.ActionResult:
return action.ActionResult()

def estimate_prepare_time(self):
def estimate_prepare_time(self) -> int:
return 60 if self.prepare_reboot else 0

def estimate_post_time(self):
def estimate_post_time(self) -> int:
return 60 if self.post_reboot else 0

def estimate_revert_time(self):
def estimate_revert_time(self) -> int:
return 0


class DisableSelinuxDuringUpgrade(action.ActiveAction):
selinux_config: str
getenforce_cmd: str

def __init__(self):
def __init__(self) -> None:
self.name = "rule selinux status"
self.selinux_config = "/etc/selinux/config"
self.getenforce_cmd = "/usr/sbin/getenforce"
Expand All @@ -258,11 +265,10 @@ def _revert_action(self) -> action.ActionResult:


class PreRebootPause(action.ActiveAction):
name: str
pause_time: int
message: str

def __init__(self, reboot_message: str, pause_time: int = 45):
def __init__(self, reboot_message: str, pause_time: int = 45) -> None:
self.name = "pause before reboot"
self.pause_time = pause_time
self.message = reboot_message
Expand All @@ -282,7 +288,7 @@ def _revert_action(self) -> action.ActionResult:
class RevertChangesInGrub(action.ActiveAction):
grub_configs_paths: typing.List[str]

def __init__(self):
def __init__(self) -> None:
self.name = "revert changes in GRUB made by ELevate"
self.grub_configs_paths = [
"/boot/grub2/grub.cfg",
Expand Down
15 changes: 14 additions & 1 deletion pleskdistup/actions/common_checks.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright 2023-2024. WebPros International GmbH. All rights reserved.

import configparser
import json
import os
import subprocess
Expand Down Expand Up @@ -466,8 +467,20 @@ def _is_docker(self) -> bool:
def _is_podman(self) -> bool:
return os.path.exists("/run/.containerenv")

def _is_cloudlinux(self) -> bool:
try:
os_release_filename = '/etc/os-release'
section_name = 'top'
config = configparser.ConfigParser()
with open(os_release_filename, encoding='utf-8') as stream:
config.read_string(f"[{section_name}]\n" + stream.read())
os_name = config.get(section_name, 'ID').strip('"')
return os_name == "cloudlinux"
except (OSError, IOError, configparser.Error):
return False

def _is_vz_like(self) -> bool:
return os.path.exists("/proc/vz")
return os.path.exists("/proc/vz") and not self._is_cloudlinux()

def _do_check(self) -> bool:
log.debug("Checking if running in a container")
Expand Down
2 changes: 1 addition & 1 deletion pleskdistup/actions/extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def estimate_revert_time(self) -> int:
class RebundleRubyApplications(action.ActiveAction):
plesk_apache_configs_path: str

def __init__(self):
def __init__(self) -> None:
self.name = "rebundling ruby applications"
self.description = "rebundling ruby applications"

Expand Down
10 changes: 6 additions & 4 deletions pleskdistup/actions/spamassassin.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
# Copyright 2023-2024. WebPros International GmbH. All rights reserved.
import os
import shutil
import typing

from pleskdistup.common import action, dist, packages, motd, rpm, util

SPAMASSASIN_CONFIG_PATH = "/etc/mail/spamassassin/init.pre"


class RestoreCurrentSpamassasinConfiguration(action.ActiveAction):
name: str
state_dir: str
spamassasin_config_path: str
spamassasin_backup_path: str

def __init__(self, state_dir: str):
def __init__(self, state_dir: str) -> None:
self.state_dir = state_dir
self.name = "restore current spamassassin configuration after conversion"
self.spamassasin_config_path = "/etc/spamassassin/local.cf"
Expand All @@ -38,7 +38,7 @@ def _revert_action(self) -> action.ActionResult:
class HandleUpdatedSpamassassinConfig(action.ActiveAction):
# Make sure the trick is preformed before any call of 'systemctl daemon-reload'
# because we change spamassassin.service configuration in scope of this action.
def __init__(self):
def __init__(self) -> None:
self.name = "handle spamassassin configuration update"

def _is_required(self) -> bool:
Expand Down Expand Up @@ -75,7 +75,9 @@ def _revert_action(self) -> action.ActionResult:


class AssertSpamassassinAdditionalPluginsDisabled(action.CheckAction):
def __init__(self):
supported_plugins: typing.List[str]

def __init__(self) -> None:
self.name = "check spamassassin additional plugins are disabled"
self.description = """There are additional plugins enabled in spamassassin configuration:
\t- {}
Expand Down
13 changes: 7 additions & 6 deletions pleskdistup/actions/systemd.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def __init__(
options: typing.Any,
name: str = "add the service {self.service_name!r} to resume Plesk dist-upgrade after reboot",
service_name: str = "plesk-dist-upgrade-resume.service",
):
) -> None:
self.util_path = util_path
self.options = options
self.service_name = service_name
Expand Down Expand Up @@ -81,7 +81,7 @@ class DisablePleskRelatedServicesDuringUpgrade(action.ActiveAction):
plesk_systemd_services: typing.List[str]
oneshot_services: typing.List[str]

def __init__(self):
def __init__(self) -> None:
self.name = "disable plesk related services"
plesk_known_systemd_services = [
"crond.service",
Expand Down Expand Up @@ -133,19 +133,20 @@ def _revert_action(self) -> action.ActionResult:
util.logged_check_call(["/usr/bin/systemctl", "start"] + self.plesk_systemd_services)
return action.ActionResult()

def estimate_prepare_time(self):
def estimate_prepare_time(self) -> int:
return 10

def estimate_post_time(self):
def estimate_post_time(self) -> int:
return 5

def estimate_revert_time(self):
def estimate_revert_time(self) -> int:
return 10


class StartPleskBasicServices(action.ActiveAction):
plesk_basic_services: typing.List[str]

def __init__(self):
def __init__(self) -> None:
self.name = "starting plesk services"
self.plesk_basic_services = [
"mariadb.service",
Expand Down
8 changes: 8 additions & 0 deletions pleskdistup/common/src/dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,17 @@ def name(self) -> str:
return "CentOS"


class CloudLinux(StoredVersionMixin, RhelBasedDistro):
@property
def name(self) -> str:
return "CloudLinux"


_distro_mapping = {
("CentOS Linux", "7"): CentOs("7"),
("AlmaLinux", "8"): AlmaLinux("8"),
("CloudLinux", "7"): CloudLinux("7"),
("CloudLinux", "8"): CloudLinux("8"),
("Debian GNU/Linux", "10"): Debian("10"),
("Debian GNU/Linux", "11"): Debian("11"),
("Debian GNU/Linux", "12"): Debian("12"),
Expand Down
4 changes: 2 additions & 2 deletions pleskdistup/common/src/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def __get_files_recursive(path: str) -> typing.Iterator[str]:
yield os.path.relpath(os.path.join(root, file), path)


def find_files_case_insensitive(path: str, regexps_strings: typing.Union[typing.List, str], recursive: bool = False):
def find_files_case_insensitive(path: str, regexps_strings: typing.Union[typing.List, str], recursive: bool = False) -> typing.List[str]:
# Todo. We should add typing for our functions
if not isinstance(regexps_strings, list) and not isinstance(regexps_strings, str):
raise TypeError("find_files_case_insensitive argument regexps_strings must be a list")
Expand All @@ -105,7 +105,7 @@ def find_files_case_insensitive(path: str, regexps_strings: typing.Union[typing.
return result


def is_directory_empty(path: str):
def is_directory_empty(path: str) -> bool:
return not os.path.exists(path) or len(os.listdir(path)) == 0


Expand Down
3 changes: 2 additions & 1 deletion pleskdistup/common/src/leapp_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ def _do_url_replacement(url: typing.Optional[str]) -> typing.Optional[str]:
_fix_mariadb_repository,
_fix_postgresql_official_repository,
lambda to_change: to_change.replace("rpm-CentOS-7", "rpm-RedHat-el8"),
lambda to_change: to_change.replace("CloudLinux-7", "CloudLinux-8"),
lambda to_change: to_change.replace("epel-7", "epel-8"),
lambda to_change: to_change.replace("epel-debug-7", "epel-debug-8"),
lambda to_change: to_change.replace("epel-source-7", "epel-source-8"),
Expand Down Expand Up @@ -163,7 +164,7 @@ def adopt_repositories(repofile: str, ignore: typing.Optional[typing.List[str]]
if ignore is None:
ignore = []

log.debug("Adopt repofile '{filename}' for AlmaLinux 8".format(filename=repofile))
log.debug(f"Adopt repofile '{repofile}'")

if not os.path.exists(repofile):
log.warn("The repository adapter has tried to open an unexistent file: {filename}".format(filename=repofile))
Expand Down
8 changes: 4 additions & 4 deletions pleskdistup/common/src/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@


def is_postgres_installed() -> bool:
return os.path.exists(get_phsql_root_path()) and os.path.exists(_PATH_TO_PSQL_UTIL)
return os.path.exists(get_pgsql_root_path()) and os.path.exists(_PATH_TO_PSQL_UTIL)


def get_postgres_major_version() -> int:
version_out = subprocess.check_output([_PATH_TO_PSQL_UTIL, '--version'], universal_newlines=True)
return int(version_out.split(' ')[2].split('.')[0])


def get_phsql_root_path() -> str:
def get_pgsql_root_path() -> str:
return '/var/lib/pgsql'


def get_data_path() -> str:
return os.path.join(get_phsql_root_path(), 'data')
return os.path.join(get_pgsql_root_path(), 'data')


def get_saved_data_path() -> str:
return os.path.join(get_phsql_root_path(), 'data-old')
return os.path.join(get_pgsql_root_path(), 'data-old')


def is_database_initialized() -> bool:
Expand Down
Loading