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

[crmsh-4.6] Dev: adds a new command $ crm check migration #1398

Open
wants to merge 1 commit into
base: crmsh-4.6
Choose a base branch
from
Open
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
7 changes: 5 additions & 2 deletions crmsh/report/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -638,8 +638,11 @@ def pkg_ver_deb(self) -> str:
_, out, _ = ShellUtils().get_stdout_stderr(cmd)
return '\n'.join([line for line in out.splitlines() if "no packages found" not in line])

def pkg_ver_rpm(self) -> str:
_, out, _ = ShellUtils().get_stdout_stderr(f"rpm -q {self.packages}")
def pkg_ver_rpm(self, format='') -> str:
if format == '':
_, out, _ = ShellUtils().get_stdout_stderr(f"rpm -q {self.packages}")
else:
_, out, _ = ShellUtils().get_stdout_stderr(f'rpm -q {self.packages} --queryformat="{format}" ')
return '\n'.join([line for line in out.splitlines() if "not installed" not in line])

def version(self) -> str:
Expand Down
56 changes: 56 additions & 0 deletions crmsh/ui_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Copyright (C) 2024 Aleksei Burlakov <[email protected]>
# See COPYING for license information.
from . import command
from . import log
from typing import Tuple
from crmsh.report import utils as report_utils
from crmsh import utils as just_utils, constants

logger = log.setup_logger(__name__)

class Check(command.UI):
'''
Check that migration to sle16 is safe

- Packages installed correctly
- T.B.A.
'''
name = "check"

def requires(self):
return True

Check warning on line 21 in crmsh/ui_check.py

View check run for this annotation

Codecov / codecov/patch

crmsh/ui_check.py#L21

Added line #L21 was not covered by tests

def __init__(self):
command.UI.__init__(self)

Check warning on line 24 in crmsh/ui_check.py

View check run for this annotation

Codecov / codecov/patch

crmsh/ui_check.py#L24

Added line #L24 was not covered by tests


def check_version(self, package_name, minimum_version) -> Tuple[int, str]:
pkg = report_utils.Package(package_name)
current_version = pkg.pkg_ver_rpm('%{VERSION}')
if current_version == '':
return -1, ''
if not just_utils.is_larger_than_min_version(current_version, minimum_version):
return -2, current_version
return 0, current_version

Check warning on line 34 in crmsh/ui_check.py

View check run for this annotation

Codecov / codecov/patch

crmsh/ui_check.py#L28-L34

Added lines #L28 - L34 were not covered by tests

def check_versions(self):
print('Package versions')
for package_name, minimum_version in [

Check warning on line 38 in crmsh/ui_check.py

View check run for this annotation

Codecov / codecov/patch

crmsh/ui_check.py#L37-L38

Added lines #L37 - L38 were not covered by tests
['SAPHanaSR', '0.162.2'], # all sle15 have the same SAPHanaSR
['libknet1', '1.21'], # sle154 and older have no libknet
['libqb100','2.0.4'], # minimum (sle154). 2.0.2 (15.3) is too old
['systemd','249.11'] # not sure, possibly older
]:
rc, current_version = self.check_version(package_name, minimum_version)
if rc == 0:
print(f' {constants.GREEN}OK{constants.END}: {package_name}-{current_version}')
elif rc == -1:
print(f' {constants.RED}FAIL{constants.END}: {package_name} is not installed')
elif rc == -2:
print(f' {constants.RED}FAIL{constants.END}: {package_name}-{current_version} is too old. \

Check warning on line 50 in crmsh/ui_check.py

View check run for this annotation

Codecov / codecov/patch

crmsh/ui_check.py#L44-L50

Added lines #L44 - L50 were not covered by tests
Minimum required version {minimum_version}')

@command.skill_level('administrator')
def do_migration(self, context, *args):
'usage: migration'
self.check_versions()

Check warning on line 56 in crmsh/ui_check.py

View check run for this annotation

Codecov / codecov/patch

crmsh/ui_check.py#L56

Added line #L56 was not covered by tests
8 changes: 8 additions & 0 deletions crmsh/ui_root.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from . import cmd_status
from . import ui_cib
from . import ui_cibstatus
from . import ui_check
from . import ui_cluster
from . import ui_configure
from . import ui_corosync
Expand Down Expand Up @@ -68,6 +69,13 @@
def do_cluster(self):
pass

@command.level(ui_check.Check)
@command.help('''Query the checks from the trento landscape:
List, execute, show details.
''')
def do_check(self):
pass

Check warning on line 77 in crmsh/ui_root.py

View check run for this annotation

Codecov / codecov/patch

crmsh/ui_root.py#L77

Added line #L77 was not covered by tests

@command.level(ui_configure.CibConfig)
@command.help('''CRM cluster configuration
The configuration level.
Expand Down
Loading