Fixes cooldown logic throws ValueError
Change-Id: I2835e8b2b570a82625761aa55ec34e0df4d6ecd5 Closes-bug: #1569273
This commit is contained in:
parent
e7ae7c3531
commit
080ace0054
@ -33,16 +33,22 @@ class CooldownMixin(object):
|
||||
# If not specified, it will be None, same as cooldown == 0
|
||||
cooldown = 0
|
||||
|
||||
if cooldown != 0:
|
||||
try:
|
||||
if 'cooldown' not in metadata:
|
||||
# Note: this is for supporting old version cooldown checking
|
||||
if metadata and cooldown != 0:
|
||||
# Note: this is for supporting old version cooldown logic
|
||||
if metadata:
|
||||
last_adjust = next(six.iterkeys(metadata))
|
||||
if not timeutils.is_older_than(last_adjust, cooldown):
|
||||
return False
|
||||
elif cooldown != 0:
|
||||
else:
|
||||
last_adjust = next(six.iterkeys(metadata['cooldown']))
|
||||
if not timeutils.is_older_than(last_adjust, cooldown):
|
||||
return False
|
||||
except ValueError:
|
||||
# occurs when metadata has only {scaling_in_progress: False}
|
||||
pass
|
||||
|
||||
# Assumes _finished_scaling is called
|
||||
# after the scaling operation completes
|
||||
metadata['scaling_in_progress'] = True
|
||||
|
@ -250,6 +250,16 @@ class TestCooldownMixin(common.HeatTestCase):
|
||||
self.patchobject(pol, 'metadata_get', return_value=previous_meta)
|
||||
self.assertTrue(pol._is_scaling_allowed())
|
||||
|
||||
def test_no_cooldown_no_scaling_in_progress(self):
|
||||
t = template_format.parse(as_template)
|
||||
stack = utils.parse_stack(t, params=as_params)
|
||||
pol = self.create_scaling_policy(t, stack, 'my-policy')
|
||||
|
||||
# no cooldown entry in the metadata
|
||||
previous_meta = {'scaling_in_progress': False}
|
||||
self.patchobject(pol, 'metadata_get', return_value=previous_meta)
|
||||
self.assertTrue(pol._is_scaling_allowed())
|
||||
|
||||
def test_metadata_is_written(self):
|
||||
t = template_format.parse(as_template)
|
||||
stack = utils.parse_stack(t, params=as_params)
|
||||
|
Loading…
Reference in New Issue
Block a user