Skip to content

Commit

Permalink
Dev: add pre-migration checks for pacemaker version (jsc#PED-11808)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholasyang2022 committed Jan 2, 2025
1 parent 76036c0 commit a338bc6
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 11 deletions.
48 changes: 37 additions & 11 deletions crmsh/migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,21 +226,47 @@ def check_dependency_version(handler: CheckResultHandler):
handler.log_info('Checking dependency version...')
shell = sh.LocalShell()
out = shell.get_stdout_or_raise_error(None, 'corosync -v')
match = re.search(r"version\s+'(\d+(?:\.\d+)*)'", out)
corosync_supported = True
_check_version_range(

Check warning on line 229 in crmsh/migration.py

View check run for this annotation

Codecov / codecov/patch

crmsh/migration.py#L226-L229

Added lines #L226 - L229 were not covered by tests
handler,
'Corosync', (2, 4, 6), (3,),
re.compile(r"version\s+'(\d+(?:\.\d+)*)'"),
shell.get_stdout_or_raise_error(None, 'corosync -v'),
)
_check_version_range(

Check warning on line 235 in crmsh/migration.py

View check run for this annotation

Codecov / codecov/patch

crmsh/migration.py#L235

Added line #L235 was not covered by tests
handler,
'Pacemaker', (2, 1, 7), (3,),
re.compile(r"^Pacemaker\s+(\d+(?:\.\d+)*)"),
shell.get_stdout_or_raise_error(None, 'pacemakerd --version'),
)


def _check_version_range(
handler: CheckResultHandler, component_name: str,
minimum: tuple, maximum: tuple,
pattern,
text: str,
):
match = pattern.search(text)
if not match:
corosync_supported = False
else:
version = tuple(int(x) for x in match.group(1).split('.'))
if not (2, 4, 6) <= version < (3,):
corosync_supported = False
if not corosync_supported:
handler.handle_problem(

Check warning on line 251 in crmsh/migration.py

View check run for this annotation

Codecov / codecov/patch

crmsh/migration.py#L251

Added line #L251 was not covered by tests
False, 'Corosync version not supported', [
'Supported version: 2.4.6 <= corosync < 3',
f'Actual version: corosync == {match.group(1)}',
False, f'{component_name} version not supported', [
'Unknown version:',
text,
],
)
else:
version = tuple(int(x) for x in match.group(1).split('.'))
if not minimum <= version < maximum:
handler.handle_problem(
False, f'{component_name} version not supported', [
'Supported version: {} <= {} < {}'.format(
'.'.join(str(x) for x in minimum),
component_name,
'.'.join(str(x) for x in maximum)
),
f'Actual version: {component_name} == {match.group(1)}',
],
)


def check_service_status(handler: CheckResultHandler):
Expand Down
28 changes: 28 additions & 0 deletions test/unittests/test_migration.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
import unittest
from unittest import mock

Expand All @@ -13,3 +14,30 @@ def test_load_supported_resource_agents(self):
self.assertIn(cibquery.ResourceAgent('ocf', 'heartbeat', 'IPaddr2'), s)
self.assertIn(cibquery.ResourceAgent('stonith', None, 'fence_sbd'), s)
self.assertNotIn(cibquery.ResourceAgent('foo', None, 'bar'), s)

def test_check_version_range(self):
def check_fn(x):
migration._check_version_range(
self._handler,
'foo',
(0, 2,),
(1,),
re.compile(r'^foo\s+(\d+(?:.\d+)*)'),
x,
)
check_fn('foo 0.2')
self._handler.handle_problem.assert_not_called()
check_fn('foo 0.2.1')
self._handler.handle_problem.assert_not_called()
check_fn('foo 0.9')
self._handler.handle_problem.assert_not_called()
check_fn('foo 0.9.99')
self._handler.handle_problem.assert_not_called()
check_fn('foo 1')
self._handler.handle_problem.assert_called()
self._handler.handle_problem.reset_mock()
check_fn('foo 1.0')
self._handler.handle_problem.assert_called()
self._handler.handle_problem.reset_mock()
check_fn('foo 1.0.0')
self._handler.handle_problem.assert_called()

0 comments on commit a338bc6

Please sign in to comment.