Angus Salkeld | 406bbd5 | 2015-05-13 14:24:04 +1000 | [diff] [blame] | 1 | # 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 | |
| 13 | from oslo_log import log as logging |
| 14 | |
| 15 | from heat_integrationtests.common import test |
Rabi Mishra | 477efc9 | 2015-07-31 13:01:45 +0530 | [diff] [blame] | 16 | from heat_integrationtests.scenario import scenario_base |
Angus Salkeld | 406bbd5 | 2015-05-13 14:24:04 +1000 | [diff] [blame] | 17 | |
| 18 | LOG = logging.getLogger(__name__) |
| 19 | |
| 20 | |
Rabi Mishra | 477efc9 | 2015-07-31 13:01:45 +0530 | [diff] [blame] | 21 | class CeilometerAlarmTest(scenario_base.ScenarioTestsBase): |
Angus Salkeld | 406bbd5 | 2015-05-13 14:24:04 +1000 | [diff] [blame] | 22 | """Class is responsible for testing of ceilometer usage.""" |
| 23 | def setUp(self): |
| 24 | super(CeilometerAlarmTest, self).setUp() |
Angus Salkeld | 406bbd5 | 2015-05-13 14:24:04 +1000 | [diff] [blame] | 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: |
LiuNanke | c7e36ed | 2015-12-29 12:54:49 +0800 | [diff] [blame] | 33 | LOG.warning('check_instance_count exp:%d, act:%s' % (expected, |
| 34 | actual)) |
Angus Salkeld | 406bbd5 | 2015-05-13 14:24:04 +1000 | [diff] [blame] | 35 | return actual == expected |
| 36 | |
| 37 | def test_alarm(self): |
| 38 | """Confirm we can create an alarm and trigger it.""" |
Angus Salkeld | 406bbd5 | 2015-05-13 14:24:04 +1000 | [diff] [blame] | 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)) |