summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKanagaraj Manickam <mkr1481@gmail.com>2016-04-12 16:50:40 +0530
committerOleksii Chuprykov <ochuprykov@mirantis.com>2016-05-24 15:29:40 +0000
commitb740ea2d8dceb11a12d4cf46c613be30248b69af (patch)
tree1f71ec7c9d969d0d0301774f445496fdcb40962f
parent93c5a3a68a0c0da6c703f72940db7516fb34d619 (diff)
downloadheat-b740ea2d8dceb11a12d4cf46c613be30248b69af.tar.gz
Fixes cooldown logic throws ValueError
Change-Id: I2835e8b2b570a82625761aa55ec34e0df4d6ecd5 Closes-bug: #1569273 (cherry picked from commit 080ace0054682494134a5bca5921fe937abdbe99)
-rw-r--r--heat/scaling/cooldown.py26
-rw-r--r--heat/tests/autoscaling/test_heat_scaling_policy.py10
2 files changed, 26 insertions, 10 deletions
diff --git a/heat/scaling/cooldown.py b/heat/scaling/cooldown.py
index effa4e6b3..fd874badb 100644
--- a/heat/scaling/cooldown.py
+++ b/heat/scaling/cooldown.py
@@ -33,16 +33,22 @@ class CooldownMixin(object):
# If not specified, it will be None, same as cooldown == 0
cooldown = 0
- if 'cooldown' not in metadata:
- # Note: this is for supporting old version cooldown checking
- if metadata and cooldown != 0:
- last_adjust = next(six.iterkeys(metadata))
- if not timeutils.is_older_than(last_adjust, cooldown):
- return False
- elif cooldown != 0:
- last_adjust = next(six.iterkeys(metadata['cooldown']))
- if not timeutils.is_older_than(last_adjust, cooldown):
- return False
+ if cooldown != 0:
+ try:
+ if 'cooldown' not in metadata:
+ # 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
+ 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
diff --git a/heat/tests/autoscaling/test_heat_scaling_policy.py b/heat/tests/autoscaling/test_heat_scaling_policy.py
index ae5020c1e..bbaf46bb0 100644
--- a/heat/tests/autoscaling/test_heat_scaling_policy.py
+++ b/heat/tests/autoscaling/test_heat_scaling_policy.py
@@ -197,6 +197,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)