21
21
from heat.common import exception
22
22
from heat.common import template_format
23
from heat.engine import resource
23
24
from heat.engine import scheduler
24
25
from heat.tests.autoscaling import inline_templates
25
26
from heat.tests import common
63
64
test = {'current': 'not_an_alarm'}
64
65
with mock.patch.object(pol, '_cooldown_inprogress',
65
66
side_effect=AssertionError()) as dont_call:
66
pol.handle_signal(details=test)
67
self.assertRaises(resource.NoActionRequired,
68
pol.handle_signal, details=test)
67
69
self.assertEqual([], dont_call.call_args_list)
69
71
def test_scaling_policy_cooldown_toosoon(self):
77
79
side_effect=AssertionError) as dont_call:
78
80
with mock.patch.object(pol, '_cooldown_inprogress',
79
81
return_value=True) as mock_cip:
80
pol.handle_signal(details=test)
82
self.assertRaises(resource.NoActionRequired,
83
pol.handle_signal, details=test)
81
84
mock_cip.assert_called_once_with()
82
85
self.assertEqual([], dont_call.call_args_list)
109
112
self.assertEqual((rsrc.CREATE, rsrc.COMPLETE), rsrc.state)
112
def test_is_in_progress(self):
115
def test_cooldown_is_in_progress_toosoon(self):
113
116
t = template_format.parse(as_template)
114
117
stack = utils.parse_stack(t, params=as_params)
115
118
pol = self.create_scaling_policy(t, stack, 'WebServerScaleUpPolicy')
117
120
now = timeutils.utcnow()
118
previous_meta = {timeutils.strtime(now): 'ChangeInCapacity : 1'}
119
self.patchobject(pol, 'metadata_get', return_value=previous_meta)
120
self.assertTrue(pol._cooldown_inprogress())
122
def test_not_in_progress(self):
121
previous_meta = {'cooldown': {
122
now.isoformat(): 'ChangeInCapacity : 1'}}
123
self.patchobject(pol, 'metadata_get', return_value=previous_meta)
124
self.assertTrue(pol._cooldown_inprogress())
126
def test_cooldown_is_in_progress_scaling_unfinished(self):
127
t = template_format.parse(as_template)
128
stack = utils.parse_stack(t, params=as_params)
129
pol = self.create_scaling_policy(t, stack, 'WebServerScaleUpPolicy')
131
previous_meta = {'scaling_in_progress': True}
132
self.patchobject(pol, 'metadata_get', return_value=previous_meta)
133
self.assertTrue(pol._cooldown_inprogress())
135
def test_cooldown_not_in_progress(self):
123
136
t = template_format.parse(as_template)
124
137
stack = utils.parse_stack(t, params=as_params)
125
138
pol = self.create_scaling_policy(t, stack, 'WebServerScaleUpPolicy')
127
140
awhile_ago = timeutils.utcnow() - datetime.timedelta(seconds=100)
128
previous_meta = {timeutils.strtime(awhile_ago): 'ChangeInCapacity : 1'}
144
awhile_ago.isoformat(): 'ChangeInCapacity : 1'
146
'scaling_in_progress': False
129
148
self.patchobject(pol, 'metadata_get', return_value=previous_meta)
130
149
self.assertFalse(pol._cooldown_inprogress())
165
184
stack = utils.parse_stack(t, params=as_params)
166
185
pol = self.create_scaling_policy(t, stack, 'WebServerScaleUpPolicy')
168
nowish = timeutils.strtime()
187
nowish = timeutils.utcnow()
169
188
reason = 'cool as'
170
189
meta_set = self.patchobject(pol, 'metadata_set')
171
self.patchobject(timeutils, 'strtime', return_value=nowish)
190
self.patchobject(timeutils, 'utcnow', return_value=nowish)
172
191
pol._cooldown_timestamp(reason)
173
meta_set.assert_called_once_with({nowish: reason})
192
meta_set.assert_called_once_with(
193
{'cooldown': {nowish.isoformat(): reason},
194
'scaling_in_progress': False})
176
197
class ScalingPolicyAttrTest(common.HeatTestCase):