Skip to content

Commit

Permalink
Dev: pre-migration: check SAPHanaSR Classic resource agents (jsc#PED-…
Browse files Browse the repository at this point in the history
…11808)
  • Loading branch information
nicholasyang2022 committed Dec 24, 2024
1 parent 156fdf2 commit a2518dd
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 9 deletions.
56 changes: 47 additions & 9 deletions crmsh/migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import json
import logging
import re
import subprocess
import sys
import typing

Expand All @@ -10,6 +11,7 @@
from crmsh import service_manager
from crmsh import sh
from crmsh import utils
from crmsh import xmlutil
from crmsh.prun import prun

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -103,7 +105,9 @@ def write_in_color(f, color: str, text: str):
f.write(text)

Check warning on line 105 in crmsh/migration.py

View check run for this annotation

Codecov / codecov/patch

crmsh/migration.py#L105

Added line #L105 was not covered by tests

def end(self):
if not self.has_problems:
if self.has_problems:
self.write_in_color(sys.stdout, constants.RED, '[FAIL]\n\n')

Check warning on line 109 in crmsh/migration.py

View check run for this annotation

Codecov / codecov/patch

crmsh/migration.py#L108-L109

Added lines #L108 - L109 were not covered by tests
else:
self.write_in_color(sys.stdout, constants.GREEN, '[PASS]\n\n')

Check warning on line 111 in crmsh/migration.py

View check run for this annotation

Codecov / codecov/patch

crmsh/migration.py#L111

Added line #L111 was not covered by tests


Expand All @@ -112,19 +116,24 @@ def check(args: typing.Sequence[str]) -> int:
parser.add_argument('--json', nargs='?', const='pretty', choices=['oneline', 'pretty'])
parser.add_argument('--local', action='store_true')
parsed_args = parser.parse_args(args)

Check warning on line 118 in crmsh/migration.py

View check run for this annotation

Codecov / codecov/patch

crmsh/migration.py#L115-L118

Added lines #L115 - L118 were not covered by tests

if 'oneline' == parsed_args.json:
handler = CheckResultJsonHandler()
elif 'pretty' == parsed_args.json:
handler = CheckResultJsonHandler(indent=2)

Check warning on line 123 in crmsh/migration.py

View check run for this annotation

Codecov / codecov/patch

crmsh/migration.py#L120-L123

Added lines #L120 - L123 were not covered by tests
else:
handler = CheckResultInteractiveHandler()

Check warning on line 125 in crmsh/migration.py

View check run for this annotation

Codecov / codecov/patch

crmsh/migration.py#L125

Added line #L125 was not covered by tests

ret = 0
if not parsed_args.local and not parsed_args.json:
remote_ret = check_remote()
print('------ localhost ------')
check_local(handler)
check_global(handler)

Check warning on line 132 in crmsh/migration.py

View check run for this annotation

Codecov / codecov/patch

crmsh/migration.py#L127-L132

Added lines #L127 - L132 were not covered by tests
else:
remote_ret = 0
if 'oneline' == parsed_args.json:
handler = CheckResultJsonHandler()
elif 'pretty' == parsed_args.json:
handler = CheckResultJsonHandler(indent=2)
else:
handler = CheckResultInteractiveHandler()
check_local(handler)
check_local(handler)
handler.end()
if isinstance(handler, CheckResultJsonHandler):
ret = 0 if handler.json_result["pass"] else 1
elif isinstance(handler, CheckResultInteractiveHandler):
Expand All @@ -139,7 +148,6 @@ def check_local(handler: CheckResultHandler):
check_dependency_version(handler)
check_service_status(handler)
check_unsupported_corosync_features(handler)

Check warning on line 150 in crmsh/migration.py

View check run for this annotation

Codecov / codecov/patch

crmsh/migration.py#L148-L150

Added lines #L148 - L150 were not covered by tests
handler.end()


def check_remote():
Expand Down Expand Up @@ -206,6 +214,10 @@ def check_remote():
return ret

Check warning on line 214 in crmsh/migration.py

View check run for this annotation

Codecov / codecov/patch

crmsh/migration.py#L206-L214

Added lines #L206 - L214 were not covered by tests


def check_global(handler: CheckResultHandler):
check_unsupported_resource_agents(handler)

Check warning on line 218 in crmsh/migration.py

View check run for this annotation

Codecov / codecov/patch

crmsh/migration.py#L218

Added line #L218 was not covered by tests


def check_dependency_version(handler: CheckResultHandler):
handler.log_info('Checking dependency version...')
shell = sh.LocalShell()
Expand Down Expand Up @@ -245,3 +257,29 @@ def check_unsupported_corosync_features(handler: CheckResultHandler):
handler.handle_tip(f'Corosync RRP will be deprecated in corosync 3.', [

Check warning on line 257 in crmsh/migration.py

View check run for this annotation

Codecov / codecov/patch

crmsh/migration.py#L256-L257

Added lines #L256 - L257 were not covered by tests
'After migrating to SLES 16, run "crm health sles16 --fix" to migrate it to knet multilink.',
])


def check_unsupported_resource_agents(handler: CheckResultHandler):
handler.log_info("Checking used resource agents...")
crm_mon = xmlutil.CrmMonXmlParser()
resource_agents = crm_mon.get_configured_resource_agents()
_check_saphana_resource_agent(handler, resource_agents)

Check warning on line 266 in crmsh/migration.py

View check run for this annotation

Codecov / codecov/patch

crmsh/migration.py#L263-L266

Added lines #L263 - L266 were not covered by tests


def _check_saphana_resource_agent(handler: CheckResultHandler, resource_agents: typing.Set[str]):
# "SAPHana" appears only in SAPHanaSR Classic
has_sap_hana_sr_resources = any(agent in resource_agents for agent in [

Check warning on line 271 in crmsh/migration.py

View check run for this annotation

Codecov / codecov/patch

crmsh/migration.py#L271

Added line #L271 was not covered by tests
'ocf::suse:SAPHana',
'ocf::suse:SAPHanaController',
'ocf::suse:SAPHanaTopology',
])
if has_sap_hana_sr_resources:
if 0 != subprocess.run(

Check warning on line 277 in crmsh/migration.py

View check run for this annotation

Codecov / codecov/patch

crmsh/migration.py#L276-L277

Added lines #L276 - L277 were not covered by tests
['rpm', '-q', 'SAPHanaSR-angi'],
stdin=subprocess.DEVNULL,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
).returncode:
handler.handle_problem(False, 'SAPHanaSR Classic will be removed in SLES 16.', [

Check warning on line 283 in crmsh/migration.py

View check run for this annotation

Codecov / codecov/patch

crmsh/migration.py#L283

Added line #L283 was not covered by tests
'Before migrating to SLES 16, replace it with SAPHanaSR-angi.',
])
6 changes: 6 additions & 0 deletions crmsh/xmlutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import os
import subprocess
import typing

from lxml import etree, doctestcompare
import copy
import bz2
Expand Down Expand Up @@ -1576,4 +1578,8 @@ def get_resource_id_list_via_type(self, ra_type):
"""
xpath = f'//resource[@resource_agent="{ra_type}"]'
return [elem.get('id') for elem in self.xml_elem.xpath(xpath)]

def get_configured_resource_agents(self) -> typing.Set[str]:
xpath = '/*/resources/resource/@resource_agent'
return set(self.xml_elem.xpath(xpath))

Check warning on line 1584 in crmsh/xmlutil.py

View check run for this annotation

Codecov / codecov/patch

crmsh/xmlutil.py#L1583-L1584

Added lines #L1583 - L1584 were not covered by tests
# vim:ts=4:sw=4:et:

0 comments on commit a2518dd

Please sign in to comment.