blob: 90288a27abade601d6328e3724c3bfe9c33f87fa [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
Rabi Mishra477efc92015-07-31 13:01:45 +053016from heat_integrationtests.scenario import scenario_base
Angus Salkeld406bbd52015-05-13 14:24:04 +100017
18LOG = logging.getLogger(__name__)
19
20
huangtianhua422c1ba2016-06-08 15:50:39 +080021class AodhAlarmTest(scenario_base.ScenarioTestsBase):
22 """Class is responsible for testing of aodh usage."""
Angus Salkeld406bbd52015-05-13 14:24:04 +100023 def setUp(self):
huangtianhua422c1ba2016-06-08 15:50:39 +080024 super(AodhAlarmTest, self).setUp()
Angus Salkeld406bbd52015-05-13 14:24:04 +100025 self.template = self._load_template(__file__,
huangtianhua422c1ba2016-06-08 15:50:39 +080026 'test_aodh_alarm.yaml',
Angus Salkeld406bbd52015-05-13 14:24:04 +100027 '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:
LiuNankec7e36ed2015-12-29 12:54:49 +080033 LOG.warning('check_instance_count exp:%d, act:%s' % (expected,
34 actual))
Angus Salkeld406bbd52015-05-13 14:24:04 +100035 return actual == expected
36
37 def test_alarm(self):
38 """Confirm we can create an alarm and trigger it."""
Angus Salkeld406bbd52015-05-13 14:24:04 +100039
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))