~ubuntu-branches/ubuntu/vivid/heat/vivid-proposed

« back to all changes in this revision

Viewing changes to heat/tests/autoscaling/test_scaling_policy.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, Chuck Short, Corey Byrant
  • Date: 2015-10-15 08:50:03 UTC
  • mfrom: (1.1.27)
  • Revision ID: package-import@ubuntu.com-20151015085003-4xp9fdix1m3ocf4t
Tags: 2015.1.2-0ubuntu1
[ Chuck Short ]
* Resynchronize with stable/kilo (a4aafba) (LP: #1506058):
  - [a4aafba] Only write to template files if template data changes
  - [9e6d7c2] Make ResourceDefinition round-trip stable to avoid extra writes
  - [2f14f1f] Set resource status to FAILED when engine is down
  - [3ab316b] Include nested stacks in reset_stack_status
  - [2bffb12] Don't metadata_update all resources for deployment signals
  - [0fa81c2] Don't create events when signals don't perform an action
  - [382d038] Stack updated error if creation fails
  - [d8bdac7] Copy resource data in _delete_backup_stack
  - [8a2dcfa] Signal SoftwareDeployment resource
  - [22a404d] Allow empty/None output values
  - [9258321] Unlimited option max_resources_per_stack
  - [0d95270] Try to get the version of cloud init via popen
  - [05b2cc4] To use id instead of name when making credentials from context
  - [aeba790] Inherit files when restore
  - [ebc7994] Set correct tenant id when python-client init
  - [5d084a2] Make sure UpdatePolicy is unset for Heat scaling group
  - [d76094c] Refactor and correct purge_deleted
  - [5f86d05] Eventlet green threads not released back to pool
  - [edd2f8f] Work around problems storing huge properties in events
  - [92d2ac9] Fix RouterInterface properties validation
  - [88a216c] Adds resource uuid, volume support to lifecycle scheduler hints
  - [e889d66] Don't raise exception when get nested stack
  - [7248ec4] The cirros image is now cirros-0.3.4
  - [e9e2f50] Fix validation failure for TemplateResource
  - [be01cf1] Use atomic_key for deployment metadata updates
  - [21331a5] Always commit after deployment db operations
  - [7454b7b] Revert failing tests and use v3 for ec2 tokens
  - [cb3734b] Fix stack-list after failed update
  - [2d5f981] Fix server creation with block_device_mapping_v2
  - [274f96b] Support time-delays in server.resize
  - [034c582] ASG scaling account for cooldown timestamp & in-progress
  - [4a8282c] Correct stack identity when delete nested
  - [03ac6b1] Do not specify version for contrib plugins
  - [a748424] Switch total_resources to use stack_count_total_resources
  - [7e73da5] Don't copy exception classes
  - [8f43aee] Not all exceptions from remote stacks are internal exceptions
  - [f34a474] Fix unsupported format character error for multipart mime
* debian/patches/fix-requirements.patch: Refreshed

[ Corey Byrant ]
* d/rules: Prevent dh_python2 from guessing dependencies.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
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)
68
70
 
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)
83
86
 
109
112
        self.assertEqual((rsrc.CREATE, rsrc.COMPLETE), rsrc.state)
110
113
        return rsrc
111
114
 
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')
116
119
 
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())
121
 
 
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())
 
125
 
 
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')
 
130
 
 
131
        previous_meta = {'scaling_in_progress': True}
 
132
        self.patchobject(pol, 'metadata_get', return_value=previous_meta)
 
133
        self.assertTrue(pol._cooldown_inprogress())
 
134
 
 
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')
126
139
 
127
140
        awhile_ago = timeutils.utcnow() - datetime.timedelta(seconds=100)
128
 
        previous_meta = {timeutils.strtime(awhile_ago): 'ChangeInCapacity : 1'}
 
141
 
 
142
        previous_meta = {
 
143
            'cooldown': {
 
144
                awhile_ago.isoformat(): 'ChangeInCapacity : 1'
 
145
            },
 
146
            'scaling_in_progress': False
 
147
        }
129
148
        self.patchobject(pol, 'metadata_get', return_value=previous_meta)
130
149
        self.assertFalse(pol._cooldown_inprogress())
131
150
 
165
184
        stack = utils.parse_stack(t, params=as_params)
166
185
        pol = self.create_scaling_policy(t, stack, 'WebServerScaleUpPolicy')
167
186
 
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})
174
195
 
175
196
 
176
197
class ScalingPolicyAttrTest(common.HeatTestCase):