heat tests : separate Autoscaling and CW alarm tests
Currently the AutoScaling test also tests the CloudWatch Alarm resource, so separate out the CW Alarm test to simplify things Change-Id: Ia346ee49f3a363e2d63e801c74265545d7af1acf
This commit is contained in:
parent
6e9a0e4683
commit
d03d56f3bf
@ -22,12 +22,9 @@ from heat.common import template_format
|
|||||||
from heat.engine.resources import autoscaling as asc
|
from heat.engine.resources import autoscaling as asc
|
||||||
from heat.engine.resources import loadbalancer
|
from heat.engine.resources import loadbalancer
|
||||||
from heat.engine.resources import instance
|
from heat.engine.resources import instance
|
||||||
from heat.engine.resources import cloud_watch
|
|
||||||
from heat.engine import clients
|
|
||||||
from heat.engine import scheduler
|
from heat.engine import scheduler
|
||||||
from heat.engine.resource import Metadata
|
from heat.engine.resource import Metadata
|
||||||
from heat.openstack.common import timeutils
|
from heat.openstack.common import timeutils
|
||||||
from heat.tests.v1_1 import fakes
|
|
||||||
from heat.tests.common import HeatTestCase
|
from heat.tests.common import HeatTestCase
|
||||||
from heat.tests.utils import setup_dummy_db
|
from heat.tests.utils import setup_dummy_db
|
||||||
from heat.tests.utils import parse_stack
|
from heat.tests.utils import parse_stack
|
||||||
@ -80,38 +77,11 @@ as_template = '''
|
|||||||
}
|
}
|
||||||
'''
|
'''
|
||||||
|
|
||||||
alarm_template = '''
|
|
||||||
{
|
|
||||||
"AWSTemplateFormatVersion" : "2010-09-09",
|
|
||||||
"Description" : "Alarm Test",
|
|
||||||
"Parameters" : {},
|
|
||||||
"Resources" : {
|
|
||||||
"MEMAlarmHigh": {
|
|
||||||
"Type": "AWS::CloudWatch::Alarm",
|
|
||||||
"Properties": {
|
|
||||||
"AlarmDescription": "Scale-up if MEM > 50% for 1 minute",
|
|
||||||
"MetricName": "MemoryUtilization",
|
|
||||||
"Namespace": "system/linux",
|
|
||||||
"Statistic": "Average",
|
|
||||||
"Period": "60",
|
|
||||||
"EvaluationPeriods": "1",
|
|
||||||
"Threshold": "50",
|
|
||||||
"AlarmActions": [],
|
|
||||||
"Dimensions": [],
|
|
||||||
"ComparisonOperator": "GreaterThanThreshold"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
'''
|
|
||||||
|
|
||||||
|
|
||||||
class AutoScalingTest(HeatTestCase):
|
class AutoScalingTest(HeatTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(AutoScalingTest, self).setUp()
|
super(AutoScalingTest, self).setUp()
|
||||||
setup_dummy_db()
|
setup_dummy_db()
|
||||||
self.fc = fakes.FakeClient()
|
|
||||||
self.m.StubOutWithMock(clients.OpenStackClients, 'nova')
|
|
||||||
|
|
||||||
def create_scaling_group(self, t, stack, resource_name):
|
def create_scaling_group(self, t, stack, resource_name):
|
||||||
resource = asc.AutoScalingGroup(resource_name,
|
resource = asc.AutoScalingGroup(resource_name,
|
||||||
@ -133,16 +103,6 @@ class AutoScalingTest(HeatTestCase):
|
|||||||
resource.state)
|
resource.state)
|
||||||
return resource
|
return resource
|
||||||
|
|
||||||
def create_alarm(self, t, stack, resource_name):
|
|
||||||
resource = cloud_watch.CloudWatchAlarm(resource_name,
|
|
||||||
t['Resources'][resource_name],
|
|
||||||
stack)
|
|
||||||
self.assertEqual(None, resource.validate())
|
|
||||||
scheduler.TaskRunner(resource.create)()
|
|
||||||
self.assertEqual(cloud_watch.CloudWatchAlarm.CREATE_COMPLETE,
|
|
||||||
resource.state)
|
|
||||||
return resource
|
|
||||||
|
|
||||||
def _stub_create(self, num):
|
def _stub_create(self, num):
|
||||||
self.m.StubOutWithMock(eventlet, 'sleep')
|
self.m.StubOutWithMock(eventlet, 'sleep')
|
||||||
|
|
||||||
@ -332,65 +292,6 @@ class AutoScalingTest(HeatTestCase):
|
|||||||
resource.delete()
|
resource.delete()
|
||||||
self.m.VerifyAll()
|
self.m.VerifyAll()
|
||||||
|
|
||||||
def test_mem_alarm_high_update_no_replace(self):
|
|
||||||
'''
|
|
||||||
Make sure that we can change the update-able properties
|
|
||||||
without replacing the Alarm resource.
|
|
||||||
'''
|
|
||||||
t = template_format.parse(alarm_template)
|
|
||||||
|
|
||||||
#short circuit the alarm's references
|
|
||||||
properties = t['Resources']['MEMAlarmHigh']['Properties']
|
|
||||||
properties['AlarmActions'] = ['a']
|
|
||||||
properties['Dimensions'] = [{'a': 'v'}]
|
|
||||||
|
|
||||||
stack = parse_stack(t)
|
|
||||||
# the watch rule needs a valid stack_id
|
|
||||||
stack.store()
|
|
||||||
|
|
||||||
self.m.ReplayAll()
|
|
||||||
resource = self.create_alarm(t, stack, 'MEMAlarmHigh')
|
|
||||||
snippet = copy.deepcopy(resource.parsed_template())
|
|
||||||
snippet['Properties']['ComparisonOperator'] = 'LessThanThreshold'
|
|
||||||
snippet['Properties']['AlarmDescription'] = 'fruity'
|
|
||||||
snippet['Properties']['EvaluationPeriods'] = '2'
|
|
||||||
snippet['Properties']['Period'] = '90'
|
|
||||||
snippet['Properties']['Statistic'] = 'Maximum'
|
|
||||||
snippet['Properties']['Threshold'] = '39'
|
|
||||||
|
|
||||||
self.assertEqual(cloud_watch.CloudWatchAlarm.UPDATE_COMPLETE,
|
|
||||||
resource.handle_update(snippet))
|
|
||||||
|
|
||||||
resource.delete()
|
|
||||||
self.m.VerifyAll()
|
|
||||||
|
|
||||||
def test_mem_alarm_high_update_replace(self):
|
|
||||||
'''
|
|
||||||
Make sure that the Alarm resource IS replaced when non-update-able
|
|
||||||
properties are changed.
|
|
||||||
'''
|
|
||||||
t = template_format.parse(alarm_template)
|
|
||||||
|
|
||||||
#short circuit the alarm's references
|
|
||||||
properties = t['Resources']['MEMAlarmHigh']['Properties']
|
|
||||||
properties['AlarmActions'] = ['a']
|
|
||||||
properties['Dimensions'] = [{'a': 'v'}]
|
|
||||||
|
|
||||||
stack = parse_stack(t)
|
|
||||||
# the watch rule needs a valid stack_id
|
|
||||||
stack.store()
|
|
||||||
|
|
||||||
self.m.ReplayAll()
|
|
||||||
resource = self.create_alarm(t, stack, 'MEMAlarmHigh')
|
|
||||||
snippet = copy.deepcopy(resource.parsed_template())
|
|
||||||
snippet['Properties']['MetricName'] = 'temp'
|
|
||||||
|
|
||||||
self.assertEqual(cloud_watch.CloudWatchAlarm.UPDATE_REPLACE,
|
|
||||||
resource.handle_update(snippet))
|
|
||||||
|
|
||||||
resource.delete()
|
|
||||||
self.m.VerifyAll()
|
|
||||||
|
|
||||||
def test_scaling_group_adjust(self):
|
def test_scaling_group_adjust(self):
|
||||||
t = template_format.parse(as_template)
|
t = template_format.parse(as_template)
|
||||||
stack = parse_stack(t)
|
stack = parse_stack(t)
|
||||||
|
124
heat/tests/test_cw_alarm.py
Normal file
124
heat/tests/test_cw_alarm.py
Normal file
@ -0,0 +1,124 @@
|
|||||||
|
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||||
|
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
# not use this file except in compliance with the License. You may obtain
|
||||||
|
# a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
# License for the specific language governing permissions and limitations
|
||||||
|
# under the License.
|
||||||
|
|
||||||
|
|
||||||
|
import copy
|
||||||
|
|
||||||
|
from heat.common import template_format
|
||||||
|
from heat.engine.resources import cloud_watch
|
||||||
|
from heat.engine import scheduler
|
||||||
|
from heat.tests.common import HeatTestCase
|
||||||
|
from heat.tests.utils import setup_dummy_db
|
||||||
|
from heat.tests.utils import parse_stack
|
||||||
|
|
||||||
|
|
||||||
|
alarm_template = '''
|
||||||
|
{
|
||||||
|
"AWSTemplateFormatVersion" : "2010-09-09",
|
||||||
|
"Description" : "Alarm Test",
|
||||||
|
"Parameters" : {},
|
||||||
|
"Resources" : {
|
||||||
|
"MEMAlarmHigh": {
|
||||||
|
"Type": "AWS::CloudWatch::Alarm",
|
||||||
|
"Properties": {
|
||||||
|
"AlarmDescription": "Scale-up if MEM > 50% for 1 minute",
|
||||||
|
"MetricName": "MemoryUtilization",
|
||||||
|
"Namespace": "system/linux",
|
||||||
|
"Statistic": "Average",
|
||||||
|
"Period": "60",
|
||||||
|
"EvaluationPeriods": "1",
|
||||||
|
"Threshold": "50",
|
||||||
|
"AlarmActions": [],
|
||||||
|
"Dimensions": [],
|
||||||
|
"ComparisonOperator": "GreaterThanThreshold"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
'''
|
||||||
|
|
||||||
|
|
||||||
|
class CloudWatchAlarmTest(HeatTestCase):
|
||||||
|
def setUp(self):
|
||||||
|
super(CloudWatchAlarmTest, self).setUp()
|
||||||
|
setup_dummy_db()
|
||||||
|
|
||||||
|
def create_alarm(self, t, stack, resource_name):
|
||||||
|
resource = cloud_watch.CloudWatchAlarm(resource_name,
|
||||||
|
t['Resources'][resource_name],
|
||||||
|
stack)
|
||||||
|
self.assertEqual(None, resource.validate())
|
||||||
|
scheduler.TaskRunner(resource.create)()
|
||||||
|
self.assertEqual(cloud_watch.CloudWatchAlarm.CREATE_COMPLETE,
|
||||||
|
resource.state)
|
||||||
|
return resource
|
||||||
|
|
||||||
|
def test_mem_alarm_high_update_no_replace(self):
|
||||||
|
'''
|
||||||
|
Make sure that we can change the update-able properties
|
||||||
|
without replacing the Alarm resource.
|
||||||
|
'''
|
||||||
|
t = template_format.parse(alarm_template)
|
||||||
|
|
||||||
|
#short circuit the alarm's references
|
||||||
|
properties = t['Resources']['MEMAlarmHigh']['Properties']
|
||||||
|
properties['AlarmActions'] = ['a']
|
||||||
|
properties['Dimensions'] = [{'a': 'v'}]
|
||||||
|
|
||||||
|
stack = parse_stack(t)
|
||||||
|
# the watch rule needs a valid stack_id
|
||||||
|
stack.store()
|
||||||
|
|
||||||
|
self.m.ReplayAll()
|
||||||
|
resource = self.create_alarm(t, stack, 'MEMAlarmHigh')
|
||||||
|
snippet = copy.deepcopy(resource.parsed_template())
|
||||||
|
snippet['Properties']['ComparisonOperator'] = 'LessThanThreshold'
|
||||||
|
snippet['Properties']['AlarmDescription'] = 'fruity'
|
||||||
|
snippet['Properties']['EvaluationPeriods'] = '2'
|
||||||
|
snippet['Properties']['Period'] = '90'
|
||||||
|
snippet['Properties']['Statistic'] = 'Maximum'
|
||||||
|
snippet['Properties']['Threshold'] = '39'
|
||||||
|
|
||||||
|
self.assertEqual(cloud_watch.CloudWatchAlarm.UPDATE_COMPLETE,
|
||||||
|
resource.handle_update(snippet))
|
||||||
|
|
||||||
|
resource.delete()
|
||||||
|
self.m.VerifyAll()
|
||||||
|
|
||||||
|
def test_mem_alarm_high_update_replace(self):
|
||||||
|
'''
|
||||||
|
Make sure that the Alarm resource IS replaced when non-update-able
|
||||||
|
properties are changed.
|
||||||
|
'''
|
||||||
|
t = template_format.parse(alarm_template)
|
||||||
|
|
||||||
|
#short circuit the alarm's references
|
||||||
|
properties = t['Resources']['MEMAlarmHigh']['Properties']
|
||||||
|
properties['AlarmActions'] = ['a']
|
||||||
|
properties['Dimensions'] = [{'a': 'v'}]
|
||||||
|
|
||||||
|
stack = parse_stack(t)
|
||||||
|
# the watch rule needs a valid stack_id
|
||||||
|
stack.store()
|
||||||
|
|
||||||
|
self.m.ReplayAll()
|
||||||
|
resource = self.create_alarm(t, stack, 'MEMAlarmHigh')
|
||||||
|
snippet = copy.deepcopy(resource.parsed_template())
|
||||||
|
snippet['Properties']['MetricName'] = 'temp'
|
||||||
|
|
||||||
|
self.assertEqual(cloud_watch.CloudWatchAlarm.UPDATE_REPLACE,
|
||||||
|
resource.handle_update(snippet))
|
||||||
|
|
||||||
|
resource.delete()
|
||||||
|
self.m.VerifyAll()
|
Loading…
Reference in New Issue
Block a user