Skip to content

Commit

Permalink
Dev: PED-8270
Browse files Browse the repository at this point in the history
This commit adds a new command

$ crm check migration

Which checks if the migration from sle15 to sle16 is safe.
  • Loading branch information
Aleksei Burlakov committed May 12, 2024
1 parent 73eaf02 commit efc7460
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 2 deletions.
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
57 changes: 57 additions & 0 deletions crmsh/ui_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# 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'],
['libknet1', '1.28'],
['libqb100','2.0.8'],
['systemd','254.4']
]:
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_cibstatus(self):
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

0 comments on commit efc7460

Please sign in to comment.