From 54bf3d9137aa3d13e728040991a29f82dab4a56a Mon Sep 17 00:00:00 2001 From: nicholasyang Date: Thu, 26 Dec 2024 15:58:22 +0800 Subject: [PATCH] Dev: pre-migration: check removed resource agents (jsc#PED-11808) --- crmsh/migration-supported-resource-agents.txt | 88 +++++++++++++++++++ crmsh/migration.py | 12 +++ test/unittests/test_migration.py | 17 ++++ 3 files changed, 117 insertions(+) create mode 100644 crmsh/migration-supported-resource-agents.txt create mode 100644 test/unittests/test_migration.py diff --git a/crmsh/migration-supported-resource-agents.txt b/crmsh/migration-supported-resource-agents.txt new file mode 100644 index 000000000..572da3fe3 --- /dev/null +++ b/crmsh/migration-supported-resource-agents.txt @@ -0,0 +1,88 @@ +ocf::heartbeat:CTDB +ocf::heartbeat:ClusterMon +ocf::heartbeat:Delay +ocf::heartbeat:Dummy +ocf::heartbeat:Filesystem +ocf::heartbeat:IPaddr2 +ocf::heartbeat:IPsrcaddr +ocf::heartbeat:IPv6addr +ocf::heartbeat:LVM-activate +ocf::heartbeat:MailTo +ocf::heartbeat:NodeUtilization +ocf::heartbeat:Raid1 +ocf::heartbeat:Route +ocf::heartbeat:SAPDatabase +ocf::heartbeat:SAPInstance +ocf::heartbeat:SendArp +ocf::heartbeat:Squid +ocf::heartbeat:Stateful +ocf::heartbeat:VirtualDomain +ocf::heartbeat:WAS +ocf::heartbeat:WAS6 +ocf::heartbeat:Xinetd +ocf::heartbeat:aliyun-vpc-move-ip +ocf::heartbeat:apache +ocf::heartbeat:aws-vpc-move-ip +ocf::heartbeat:aws-vpc-route53 +ocf::heartbeat:awseip +ocf::heartbeat:awsvip +ocf::heartbeat:azure-events +ocf::heartbeat:azure-events-az +ocf::heartbeat:azure-lb +ocf::heartbeat:conntrackd +ocf::heartbeat:corosync-qnetd +ocf::heartbeat:crypt +ocf::heartbeat:db2 +ocf::heartbeat:dhcpd +ocf::heartbeat:docker +ocf::heartbeat:docker-compose +ocf::heartbeat:dummypy +ocf::heartbeat:ethmonitor +ocf::heartbeat:exportfs +ocf::heartbeat:galera +ocf::heartbeat:garbd +ocf::heartbeat:gcp-ilb +ocf::heartbeat:gcp-pd-move +ocf::heartbeat:gcp-vpc-move-ip +ocf::heartbeat:gcp-vpc-move-vip +ocf::heartbeat:iSCSILogicalUnit +ocf::heartbeat:iSCSITarget +ocf::heartbeat:iface-bridge +ocf::heartbeat:iface-macvlan +ocf::heartbeat:iface-vlan +ocf::heartbeat:ldirectord +ocf::heartbeat:lvmlockd +ocf::heartbeat:mariadb +ocf::heartbeat:mdraid +ocf::heartbeat:mpathpersist +ocf::heartbeat:mysql +ocf::heartbeat:mysql-proxy +ocf::heartbeat:named +ocf::heartbeat:nfsnotify +ocf::heartbeat:nfsserver +ocf::heartbeat:nginx +ocf::heartbeat:nvmet-namespace +ocf::heartbeat:nvmet-port +ocf::heartbeat:nvmet-subsystem +ocf::heartbeat:oraasm +ocf::heartbeat:oracle +ocf::heartbeat:oralsnr +ocf::heartbeat:osceip +ocf::heartbeat:ovsmonitor +ocf::heartbeat:pgagent +ocf::heartbeat:pgsql +ocf::heartbeat:podman +ocf::heartbeat:portblock +ocf::heartbeat:postfix +ocf::heartbeat:powervs-subnet +ocf::heartbeat:rabbitmq-cluster +ocf::heartbeat:rabbitmq-server-ha +ocf::heartbeat:redis +ocf::heartbeat:rsyncd +ocf::heartbeat:sfex +ocf::heartbeat:sg_persist +ocf::heartbeat:slapd +ocf::heartbeat:storage-mon +ocf::heartbeat:symlink +ocf::heartbeat:tomcat +ocf::suse:aws-vpc-move-ip diff --git a/crmsh/migration.py b/crmsh/migration.py index d0d90d980..f7d3fc39e 100644 --- a/crmsh/migration.py +++ b/crmsh/migration.py @@ -1,6 +1,7 @@ import argparse import json import logging +import pkgutil import re import subprocess import sys @@ -264,6 +265,7 @@ def check_unsupported_resource_agents(handler: CheckResultHandler): 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]): @@ -283,3 +285,13 @@ def _check_saphana_resource_agent(handler: CheckResultHandler, resource_agents: handler.handle_problem(False, 'SAPHanaSR Classic will be removed in SLES 16.', [ '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( + 'crmsh', 'migration-supported-resource-agents.txt' + ).decode('ascii').splitlines()) + 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.', [ + f'* {x}' for x in unsupported_resource_agents + ]) diff --git a/test/unittests/test_migration.py b/test/unittests/test_migration.py new file mode 100644 index 000000000..38dda5ec8 --- /dev/null +++ b/test/unittests/test_migration.py @@ -0,0 +1,17 @@ +import unittest +from unittest import mock + +from crmsh import migration + + +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()