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
(cherry picked from commit 3264f0d)
  • Loading branch information
nicholasyang2022 committed Jan 2, 2025
1 parent 0959961 commit 68bd445
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 5 deletions.
42 changes: 37 additions & 5 deletions crmsh/migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,14 +255,46 @@ 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)
if not match or match.group(2) != '3':
_check_version_range(

Check warning on line 258 in crmsh/migration.py

View check run for this annotation

Codecov / codecov/patch

crmsh/migration.py#L255-L258

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

Check warning on line 264 in crmsh/migration.py

View check run for this annotation

Codecov / codecov/patch

crmsh/migration.py#L264

Added line #L264 was not covered by tests
handler,
'Pacemaker', (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,
pattern,
text: str,
):
match = pattern.search(text)
if not match:
handler.handle_problem(

Check warning on line 280 in crmsh/migration.py

View check run for this annotation

Codecov / codecov/patch

crmsh/migration.py#L280

Added line #L280 was not covered by tests
False, 'Corosync version not supported', [
'Supported version: 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:
handler.handle_problem(
False, f'{component_name} version not supported', [
'Supported version: {} <= {}'.format(
'.'.join(str(x) for x in minimum),
component_name,
),
f'Actual version: {component_name} == {match.group(1)}',
],
)


def check_service_status(handler: CheckResultHandler):
Expand Down
35 changes: 35 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,37 @@ 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',
(1, 1,),
re.compile(r'^foo\s+(\d+(?:.\d+)*)'),
x,
)
check_fn('foo 0')
self._handler.handle_problem.assert_called()
self._handler.handle_problem.reset_mock()
check_fn('foo 0.9')
self._handler.handle_problem.assert_called()
self._handler.handle_problem.reset_mock()
check_fn('foo 0.9.99')
self._handler.handle_problem.assert_called()
self._handler.handle_problem.reset_mock()
check_fn('foo 1')
self._handler.handle_problem.assert_called()
self._handler.handle_problem.reset_mock()
check_fn('foo 1.1')
self._handler.handle_problem.assert_not_called()
check_fn('foo 1.1.0')
self._handler.handle_problem.assert_not_called()
check_fn('foo 1.1.1')
self._handler.handle_problem.assert_not_called()
check_fn('foo 1.2')
self._handler.handle_problem.assert_not_called()
check_fn('foo 2')
self._handler.handle_problem.assert_not_called()
check_fn('foo 2.0')
self._handler.handle_problem.assert_not_called()

0 comments on commit 68bd445

Please sign in to comment.