summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2016-05-30 06:12:00 +0000
committerGerrit Code Review <review@openstack.org>2016-05-30 06:12:00 +0000
commit734d315a4f5c5e7598666e9dfc18397f4e7fb1fc (patch)
treeff55b1a77408e483a78a0d394b83d60d4b65099e
parent089acb164a1213cfd97d44dc86cf7673594f99ef (diff)
parent579fea6bcdd9d602e290ae88c9613515f1b1976e (diff)
downloadheat-734d315a4f5c5e7598666e9dfc18397f4e7fb1fc.tar.gz
Merge "Fixes cooldown logic throws ValueError" into stable/mitaka
-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 56c67ff0b..fd6142e7b 100644
--- a/heat/tests/autoscaling/test_heat_scaling_policy.py
+++ b/heat/tests/autoscaling/test_heat_scaling_policy.py
@@ -217,6 +217,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)