From 666055844e13b556ded97f4c92f3089e272507e8 Mon Sep 17 00:00:00 2001 From: Felipe Reyes Date: Thu, 10 Oct 2019 18:24:53 -0300 Subject: [PATCH] Stop resource before deleting it. Pacemaker will refuse to delete a resource that it's running, so it needs to be stopped always before deleting it. Change-Id: I3c6acdef401e9ec18fedc65e9c77db4719fe60ec Closes-Bug: #1838528 --- hooks/hooks.py | 5 +++++ unit_tests/test_hacluster_hooks.py | 12 ++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/hooks/hooks.py b/hooks/hooks.py index bc0a053..5f5ef6d 100755 --- a/hooks/hooks.py +++ b/hooks/hooks.py @@ -354,6 +354,11 @@ def ha_relation_changed(): pcmk.commit('crm resource cleanup %s' % res_name) # Daemon process may still be running after the upgrade. kill_legacy_ocf_daemon_process(res_name) + + # Stop the resource before the deletion (LP: #1838528) + log('Stopping %s' % res_name, level=INFO) + pcmk.commit('crm -w -F resource stop %s' % res_name) + log('Deleting %s' % res_name, level=INFO) pcmk.commit('crm -w -F configure delete %s' % res_name) log('Configuring Resources: %s' % (resources), level=DEBUG) diff --git a/unit_tests/test_hacluster_hooks.py b/unit_tests/test_hacluster_hooks.py index a2d08be..986e9e7 100644 --- a/unit_tests/test_hacluster_hooks.py +++ b/unit_tests/test_hacluster_hooks.py @@ -75,7 +75,8 @@ class TestCorosyncConf(unittest.TestCase): def fake_crm_opt_exists(res_name): # res_ubuntu will take the "update resource" route - return res_name == "res_ubuntu" + # res_nova_eth0_vip will take the delete resource route + return res_name in ["res_ubuntu", "res_nova_eth0_vip"] crm_opt_exists.side_effect = fake_crm_opt_exists commit.return_value = 0 @@ -105,7 +106,8 @@ class TestCorosyncConf(unittest.TestCase): 'resource_params': {'res_foo': 'params bar', 'res_ubuntu': 'params ubuntu=42'}, 'ms': {'ms_foo': 'res_foo meta notify=true'}, - 'orders': {'foo_after': 'inf: res_foo ms_foo'}} + 'orders': {'foo_after': 'inf: res_foo ms_foo'}, + 'delete_resources': ['res_nova_eth0_vip']} def fake_parse_data(relid, unit, key): return rel_get_data.get(key, {}) @@ -125,6 +127,12 @@ class TestCorosyncConf(unittest.TestCase): configure_pacemaker_remote_resources.assert_called_with() write_maas_dns_address.assert_not_called() + # verify deletion of resources. + crm_opt_exists.assert_any_call('res_nova_eth0_vip') + commit.assert_any_call('crm resource cleanup res_nova_eth0_vip') + commit.assert_any_call('crm -w -F resource stop res_nova_eth0_vip') + commit.assert_any_call('crm -w -F configure delete res_nova_eth0_vip') + for kw, key in [('location', 'locations'), ('clone', 'clones'), ('group', 'groups'),