Get capacity when notification send if resize failed
If the autoscaling group resize failed, the capacity may be changed, so need to get capacity of group again when sending notification. Change-Id: Ied3a9ddf9255429f33aecf9e32db782d2d557902 Closes-Bug: #1466283
This commit is contained in:
parent
fd75324f44
commit
8c7a53c13f
|
@ -341,6 +341,7 @@ class AutoScalingGroup(instgrp.InstanceGroup, cooldown.CooldownMixin):
|
|||
try:
|
||||
notif.update({'suffix': 'error',
|
||||
'message': six.text_type(resize_ex),
|
||||
'capacity': grouputils.get_size(self),
|
||||
})
|
||||
notification.send(**notif)
|
||||
except Exception:
|
||||
|
|
|
@ -266,7 +266,40 @@ class TestGroupAdjust(common.HeatTestCase):
|
|||
stack=self.group.stack)]
|
||||
|
||||
self.assertEqual(expected_notifies, notify.call_args_list)
|
||||
grouputils.get_size.assert_called_once_with(self.group)
|
||||
grouputils.get_size.assert_called_with(self.group)
|
||||
|
||||
def test_notification_send_if_resize_failed(self):
|
||||
"""If resize failed, the capacity of group might have been changed"""
|
||||
self.patchobject(grouputils, 'get_size', side_effect=[3, 4])
|
||||
self.patchobject(self.group, 'resize',
|
||||
side_effect=ValueError('test error'))
|
||||
notify = self.patch('heat.engine.notification.autoscaling.send')
|
||||
self.patchobject(self.group, '_cooldown_inprogress',
|
||||
return_value=False)
|
||||
|
||||
self.assertRaises(ValueError, self.group.adjust,
|
||||
5, adjustment_type='ExactCapacity')
|
||||
|
||||
expected_notifies = [
|
||||
mock.call(
|
||||
capacity=3, suffix='start',
|
||||
adjustment_type='ExactCapacity',
|
||||
groupname='my-group',
|
||||
message='Start resizing the group my-group',
|
||||
adjustment=5,
|
||||
stack=self.group.stack),
|
||||
mock.call(
|
||||
capacity=4, suffix='error',
|
||||
adjustment_type='ExactCapacity',
|
||||
groupname='my-group',
|
||||
message=u'test error',
|
||||
adjustment=5,
|
||||
stack=self.group.stack)]
|
||||
|
||||
self.assertEqual(expected_notifies, notify.call_args_list)
|
||||
self.group.resize.assert_called_once_with(5)
|
||||
grouputils.get_size.assert_has_calls([mock.call(self.group),
|
||||
mock.call(self.group)])
|
||||
|
||||
|
||||
class TestGroupCrud(common.HeatTestCase):
|
||||
|
|
|
@ -453,7 +453,40 @@ class TestGroupAdjust(common.HeatTestCase):
|
|||
stack=self.group.stack)]
|
||||
|
||||
self.assertEqual(expected_notifies, notify.call_args_list)
|
||||
grouputils.get_size.assert_called_once_with(self.group)
|
||||
grouputils.get_size.assert_called_with(self.group)
|
||||
|
||||
def test_notification_send_if_resize_failed(self):
|
||||
"""If resize failed, the capacity of group might have been changed"""
|
||||
self.patchobject(grouputils, 'get_size', side_effect=[3, 4])
|
||||
self.patchobject(self.group, 'resize',
|
||||
side_effect=ValueError('test error'))
|
||||
notify = self.patch('heat.engine.notification.autoscaling.send')
|
||||
self.patchobject(self.group, '_cooldown_inprogress',
|
||||
return_value=False)
|
||||
|
||||
self.assertRaises(ValueError, self.group.adjust,
|
||||
5, adjustment_type='ExactCapacity')
|
||||
|
||||
expected_notifies = [
|
||||
mock.call(
|
||||
capacity=3, suffix='start',
|
||||
adjustment_type='ExactCapacity',
|
||||
groupname=u'WebServerGroup',
|
||||
message=u'Start resizing the group WebServerGroup',
|
||||
adjustment=5,
|
||||
stack=self.group.stack),
|
||||
mock.call(
|
||||
capacity=4, suffix='error',
|
||||
adjustment_type='ExactCapacity',
|
||||
groupname=u'WebServerGroup',
|
||||
message=u'test error',
|
||||
adjustment=5,
|
||||
stack=self.group.stack)]
|
||||
|
||||
self.assertEqual(expected_notifies, notify.call_args_list)
|
||||
self.group.resize.assert_called_once_with(5)
|
||||
grouputils.get_size.assert_has_calls([mock.call(self.group),
|
||||
mock.call(self.group)])
|
||||
|
||||
|
||||
class TestGroupCrud(common.HeatTestCase):
|
||||
|
|
Loading…
Reference in New Issue