blob: d8f21fd6202f1b36afea211581f19bf01583b30f [file] [log] [blame]
Angus Salkeld406bbd52015-05-13 14:24:04 +10001# Licensed under the Apache License, Version 2.0 (the "License"); you may
2# not use this file except in compliance with the License. You may obtain
3# a copy of the License at
4#
5# http://www.apache.org/licenses/LICENSE-2.0
6#
7# Unless required by applicable law or agreed to in writing, software
8# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10# License for the specific language governing permissions and limitations
11# under the License.
12
13from oslo_log import log as logging
14
15from heat_integrationtests.common import test
16
17LOG = logging.getLogger(__name__)
18
19
20class CeilometerAlarmTest(test.HeatIntegrationTest):
21 """Class is responsible for testing of ceilometer usage."""
22 def setUp(self):
23 super(CeilometerAlarmTest, self).setUp()
24 self.client = self.orchestration_client
25 self.template = self._load_template(__file__,
26 'test_ceilometer_alarm.yaml',
27 'templates')
28
29 def check_instance_count(self, stack_identifier, expected):
30 stack = self.client.stacks.get(stack_identifier)
31 actual = self._stack_output(stack, 'asg_size')
32 if actual != expected:
33 LOG.warn('check_instance_count exp:%d, act:%s' % (expected,
34 actual))
35 return actual == expected
36
37 def test_alarm(self):
38 """Confirm we can create an alarm and trigger it."""
39
40 # 1. create the stack
41 stack_identifier = self.stack_create(template=self.template)
42
43 # 2. send ceilometer a metric (should cause the alarm to fire)
44 sample = {}
45 sample['counter_type'] = 'gauge'
46 sample['counter_name'] = 'test_meter'
47 sample['counter_volume'] = 1
48 sample['counter_unit'] = 'count'
49 sample['resource_metadata'] = {'metering.stack_id':
50 stack_identifier.split('/')[-1]}
51 sample['resource_id'] = 'shouldnt_matter'
52 self.metering_client.samples.create(**sample)
53
54 # 3. confirm we get a scaleup.
55 # Note: there is little point waiting more than 60s+time to scale up.
56 self.assertTrue(test.call_until_true(
57 120, 2, self.check_instance_count, stack_identifier, 2))