Skip to content

Commit ec46647

Browse files
author
Aleksei Burlakov
committed
Dev: PED-8270
This commit adds a new command $ crm check migration Which checks if the migration from sle15 to sle16 is safe.
1 parent 73eaf02 commit ec46647

File tree

3 files changed

+69
-2
lines changed

3 files changed

+69
-2
lines changed

crmsh/report/utils.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -638,8 +638,11 @@ def pkg_ver_deb(self) -> str:
638638
_, out, _ = ShellUtils().get_stdout_stderr(cmd)
639639
return '\n'.join([line for line in out.splitlines() if "no packages found" not in line])
640640

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

645648
def version(self) -> str:

crmsh/ui_check.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Copyright (C) 2024 Aleksei Burlakov <aburlakov@suse.com>
2+
# See COPYING for license information.
3+
from . import command
4+
from . import log
5+
from typing import Tuple
6+
from crmsh.report import utils as report_utils
7+
from crmsh import utils as just_utils, constants
8+
9+
logger = log.setup_logger(__name__)
10+
11+
class Check(command.UI):
12+
'''
13+
Check that migration to sle16 is safe
14+
15+
- Packages installed correctly
16+
- T.B.A.
17+
'''
18+
name = "check"
19+
20+
def requires(self):
21+
return True
22+
23+
def __init__(self):
24+
command.UI.__init__(self)
25+
26+
27+
def check_version(self, package_name, minimum_version) -> Tuple[int, str]:
28+
pkg = report_utils.Package(package_name)
29+
current_version = pkg.pkg_ver_rpm('%{VERSION}')
30+
if current_version == '':
31+
return -1, ''
32+
if not just_utils.is_larger_than_min_version(current_version, minimum_version):
33+
return -2, current_version
34+
return 0, current_version
35+
36+
def check_versions(self):
37+
print('Package versions')
38+
for package_name, minimum_version in [
39+
['SAPHanaSR', '0.162.2'], # all sle15 have the same SAPHanaSR
40+
['libknet1', '1.21'], # sle154 and older have no libknet
41+
['libqb100','2.0.4'], # minimum (sle154). 2.0.2 (15.3) is too old
42+
['systemd','249.11'] # not sure, possibly older
43+
]:
44+
rc, current_version = self.check_version(package_name, minimum_version)
45+
if rc == 0:
46+
print(f' {constants.GREEN}OK{constants.END}: {package_name}-{current_version}')
47+
elif rc == -1:
48+
print(f' {constants.RED}FAIL{constants.END}: {package_name} is not installed')
49+
elif rc == -2:
50+
print(f' {constants.RED}FAIL{constants.END}: {package_name}-{current_version} is too old. \
51+
Minimum required version {minimum_version}')
52+
53+
@command.skill_level('administrator')
54+
def do_migration(self, context, *args):
55+
'usage: migration'
56+
self.check_versions()

crmsh/ui_root.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from . import cmd_status
2323
from . import ui_cib
2424
from . import ui_cibstatus
25+
from . import ui_check
2526
from . import ui_cluster
2627
from . import ui_configure
2728
from . import ui_corosync
@@ -68,6 +69,13 @@ def do_cibstatus(self):
6869
def do_cluster(self):
6970
pass
7071

72+
@command.level(ui_check.Check)
73+
@command.help('''Query the checks from the trento landscape:
74+
List, execute, show details.
75+
''')
76+
def do_check(self):
77+
pass
78+
7179
@command.level(ui_configure.CibConfig)
7280
@command.help('''CRM cluster configuration
7381
The configuration level.

0 commit comments

Comments
 (0)