Skip to content

Commit

Permalink
Dev: pre-migration: check removed fence agents (jsc#PED-11808)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholasyang2022 committed Dec 30, 2024
1 parent a7b2e1d commit a740b3f
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 16 deletions.
56 changes: 56 additions & 0 deletions crmsh/migration-supported-resource-agents.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,59 @@ ocf::heartbeat:storage-mon
ocf::heartbeat:symlink
ocf::heartbeat:tomcat
ocf::suse:aws-vpc-move-ip
stonith:fence_aliyun
stonith:fence_alom
stonith:fence_apc
stonith:fence_apc-snmp
stonith:fence_aws
stonith:fence_azure-arm
stonith:fence_bladecenter
stonith:fence_brocade
stonith:fence_cisco-mds
stonith:fence_cisco-ucs
stonith:fence_compute
stonith:fence_docker
stonith:fence_drac5
stonith:fence_eaton-snmp
stonith:fence_eaton-ssh
stonith:fence_emerson
stonith:fence_eps
stonith:fence_gce
stonith:fence_hds-cb
stonith:fence_hpblade
stonith:fence_ibm-powervs
stonith:fence_ibm-vpc
stonith:fence_ibmblade
stonith:fence_ibmz
stonith:fence_ifmib
stonith:fence_ilo-moonshot
stonith:fence_ilo-mp
stonith:fence_ilo-ssh
stonith:fence_ilo2
stonith:fence_intelmodular
stonith:fence_ipdu
stonith:fence_ipmilan
stonith:fence_ironic
stonith:fence_kdump
stonith:fence_ldom
stonith:fence_lpar
stonith:fence_mpath
stonith:fence_netio
stonith:fence_openstack
stonith:fence_pve
stonith:fence_raritan
stonith:fence_rcd-serial
stonith:fence_redfish
stonith:fence_rhevm
stonith:fence_rsa
stonith:fence_rsb
stonith:fence_sanbox2
stonith:fence_sbd
stonith:fence_scsi
stonith:fence_vbox
stonith:fence_virsh
stonith:fence_vmware
stonith:fence_vmware-rest
stonith:fence_wti
stonith:fence_xenapi
stonith:fence_zvm
54 changes: 45 additions & 9 deletions crmsh/migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,12 +263,40 @@ def check_unsupported_corosync_features(handler: CheckResultHandler):
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_removed_resource_agents(handler, resource_agents)


def _check_saphana_resource_agent(handler: CheckResultHandler, resource_agents: typing.Set[str]):
ocf_resource_agents = list()
stonith_resource_agents = list()
for resource_agent in crm_mon.get_configured_resource_agents():
if resource_agent.startswith('ocf::'):
ocf_resource_agents.append(resource_agent)
elif resource_agent.startswith('stonith:'):
stonith_resource_agents.append(resource_agent)

Check warning on line 272 in crmsh/migration.py

View check run for this annotation

Codecov / codecov/patch

crmsh/migration.py#L264-L272

Added lines #L264 - L272 were not covered by tests
else:
raise ValueError(f'Unrecognized resource agent {resource_agent}')
_check_saphana_resource_agent(handler, ocf_resource_agents)
class TitledCheckResourceHandler(CheckResultHandler):
def __init__(self, parent: CheckResultHandler, title: str):
self._parent = parent
self._title= title
def log_info(self, fmt: str, *args):
return self._parent.log_info(fmt, *args)
def handle_problem(self, is_fatal: bool, title: str, detail: typing.Iterable[str]):
return self._parent.handle_problem(is_fatal, self._title, detail)
def handle_tip(self, title: str, details: typing.Iterable[str]):
return self._parent.handle_tip(self._title, details)
supported_resource_agents = _load_supported_resource_agents()
_check_removed_resource_agents(

Check warning on line 287 in crmsh/migration.py

View check run for this annotation

Codecov / codecov/patch

crmsh/migration.py#L274-L287

Added lines #L274 - L287 were not covered by tests
TitledCheckResourceHandler(handler, "The following resource agents will be removed in SLES 16."),
supported_resource_agents,
ocf_resource_agents,
)
_check_removed_resource_agents(

Check warning on line 292 in crmsh/migration.py

View check run for this annotation

Codecov / codecov/patch

crmsh/migration.py#L292

Added line #L292 was not covered by tests
TitledCheckResourceHandler(handler, "The following fence agents will be removed in SLES 16."),
supported_resource_agents,
stonith_resource_agents,
)


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

Check warning on line 301 in crmsh/migration.py

View check run for this annotation

Codecov / codecov/patch

crmsh/migration.py#L301

Added line #L301 was not covered by tests
'ocf::suse:SAPHana',
Expand All @@ -286,12 +314,20 @@ def _check_saphana_resource_agent(handler: CheckResultHandler, resource_agents:
'Before migrating to SLES 16, replace it with SAPHanaSR-angi.',
])

def _check_removed_resource_agents(handler: CheckResultHandler, resource_agents: typing.Set[str]):
supported_resource_agents = set(pkgutil.get_data(

def _load_supported_resource_agents() -> typing.Set[str]:
return set(pkgutil.get_data(
'crmsh', 'migration-supported-resource-agents.txt'
).decode('ascii').splitlines())


def _check_removed_resource_agents(
handler: CheckResultHandler,
supported_resource_agents: typing.Set[str],
resource_agents: typing.Iterable[str],
):
unsupported_resource_agents = [x for x in resource_agents if x not in supported_resource_agents]
if unsupported_resource_agents:
handler.handle_problem(False, 'The following resource agents will be removed in SLES 16.', [
handler.handle_problem(False, '', [

Check warning on line 331 in crmsh/migration.py

View check run for this annotation

Codecov / codecov/patch

crmsh/migration.py#L329-L331

Added lines #L329 - L331 were not covered by tests
f'* {x}' for x in unsupported_resource_agents
])
12 changes: 5 additions & 7 deletions test/unittests/test_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ class TestCheckRemovedResourceAgents(unittest.TestCase):
def setUp(self):
self._handler = mock.Mock(migration.CheckResultHandler)

def test_unsupported_resource_agent(self):
migration._check_removed_resource_agents(self._handler, {'foo::bar'})
self._handler.handle_problem.assert_called_once()

def test_supported_resource_agent(self):
migration._check_removed_resource_agents(self._handler, {'ocf::heartbeat:IPaddr2'})
self._handler.handle_problem.assert_not_called()
def test_load_supported_resource_agents(self):
s = migration._load_supported_resource_agents()
self.assertIn('ocf::heartbeat:IPaddr2', s)
self.assertIn('stonith:fence_sbd', s)
self.assertNotIn('foo::bar', s)

0 comments on commit a740b3f

Please sign in to comment.