Skip to content

Commit

Permalink
Dev: adds a new command $ crm check migration
Browse files Browse the repository at this point in the history
This new command checks if the migration from sle15 to sle16 is safe.
(ref: PED-8270)
  • Loading branch information
Aleksei Burlakov committed May 6, 2024
1 parent 73eaf02 commit 21b734b
Show file tree
Hide file tree
Showing 3 changed files with 65 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
52 changes: 52 additions & 0 deletions crmsh/ui_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# 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

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_SAPHanaSR(self) -> Tuple[int, str]:
pkg = report_utils.Package('SAPHanaSR')
SAPHanaSR_current_version = pkg.pkg_ver_rpm('%{VERSION}')
SAPHanaSR_minimum_version = '0.162.2'
if SAPHanaSR_current_version == '':
return -1, 'SAPHanaSR is not installed'

Check warning on line 31 in crmsh/ui_check.py

View check run for this annotation

Codecov / codecov/patch

crmsh/ui_check.py#L27-L31

Added lines #L27 - L31 were not covered by tests

if not just_utils.is_larger_than_min_version(SAPHanaSR_current_version, SAPHanaSR_minimum_version):
return -1, f'SAPHanaSR is too old. Minimum required version {SAPHanaSR_minimum_version}'

Check warning on line 34 in crmsh/ui_check.py

View check run for this annotation

Codecov / codecov/patch

crmsh/ui_check.py#L33-L34

Added lines #L33 - L34 were not covered by tests

return 0, ''

Check warning on line 36 in crmsh/ui_check.py

View check run for this annotation

Codecov / codecov/patch

crmsh/ui_check.py#L36

Added line #L36 was not covered by tests

def check_version_FOOPackage(self) -> Tuple[int, str]:
if False:
return -1, 'Check has failed'
return 0, ''

Check warning on line 41 in crmsh/ui_check.py

View check run for this annotation

Codecov / codecov/patch

crmsh/ui_check.py#L41

Added line #L41 was not covered by tests

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

rc, errmsg = self.check_version_SAPHanaSR()

Check warning on line 47 in crmsh/ui_check.py

View check run for this annotation

Codecov / codecov/patch

crmsh/ui_check.py#L47

Added line #L47 was not covered by tests

if rc == 0:
print(f'OK: SAPHanaSR')

Check warning on line 50 in crmsh/ui_check.py

View check run for this annotation

Codecov / codecov/patch

crmsh/ui_check.py#L49-L50

Added lines #L49 - L50 were not covered by tests
else:
print(f'FAIL: SAPHanaSR: {errmsg}')

Check warning on line 52 in crmsh/ui_check.py

View check run for this annotation

Codecov / codecov/patch

crmsh/ui_check.py#L52

Added line #L52 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 21b734b

Please sign in to comment.