Browse Source

Merge "Fix health policy attach/detach action when messaging.MessagingTimeout occurred"

changes/97/783897/1
Zuul 3 months ago
committed by Gerrit Code Review
parent
commit
7ecb5b8819
2 changed files with 27 additions and 3 deletions
  1. +8
    -1
      senlin/policies/health_policy.py
  2. +19
    -2
      senlin/tests/unit/policies/test_health_policy.py

+ 8
- 1
senlin/policies/health_policy.py View File

@ -391,7 +391,12 @@ class HealthPolicy(base.Policy):
detection_mode = {'detection_modes': converted_detection_modes}
kwargs['params'].update(detection_mode)
health_manager.register(cluster.id, engine_id=None, **kwargs)
ret = health_manager.register(cluster.id, engine_id=None, **kwargs)
if not ret:
LOG.warning('Registering health manager for cluster %s '
'timed out.', cluster.id)
err_msg = _("Registering health manager for cluster timed out.")
return False, err_msg
data = {
'interval': self.interval,
@ -415,6 +420,8 @@ class HealthPolicy(base.Policy):
if not ret:
LOG.warning('Unregistering health manager for cluster %s '
'timed out.', cluster.id)
err_msg = _("Unregistering health manager for cluster timed out.")
return False, err_msg
return True, ''
def pre_op(self, cluster_id, action, **args):


+ 19
- 2
senlin/tests/unit/policies/test_health_policy.py View File

@ -281,12 +281,29 @@ class TestHealthPolicy(base.SenlinTestCase):
self.assertEqual("Recovery action REBOOT is only applicable to "
"os.nova.server clusters.", data)
@mock.patch.object(health_manager, 'register')
def test_attach_failed_with_notify_timeout(self, mock_hm_reg):
mock_hm_reg.return_value = False
res, data = self.hp.attach(self.cluster)
self.assertFalse(res)
self.assertEqual("Registering health manager for cluster timed "
"out.", data)
@mock.patch.object(health_manager, 'unregister')
def test_detach(self, mock_hm_reg):
def test_detach(self, mock_hm_unreg):
res, data = self.hp.detach(self.cluster)
self.assertTrue(res)
self.assertEqual('', data)
mock_hm_reg.assert_called_once_with('CLUSTER_ID')
mock_hm_unreg.assert_called_once_with('CLUSTER_ID')
@mock.patch.object(health_manager, 'unregister')
def test_detach_failed_with_notify_timeout(self, mock_hm_unreg):
mock_hm_unreg.return_value = False
res, data = self.hp.detach(self.cluster)
self.assertFalse(res)
self.assertEqual("Unregistering health manager for cluster timed "
"out.", data)
mock_hm_unreg.assert_called_once_with('CLUSTER_ID')
def test_pre_op_default(self):
action = mock.Mock(context='action_context', data={},


Loading…
Cancel
Save