Chandan Kumar | 6f97ca0 | 2017-12-07 12:50:34 +0530 | [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 tempest import config |
| 14 | from tempest.lib.common.utils import data_utils |
| 15 | from tempest.lib import exceptions as lib_exc |
| 16 | import tempest.test |
| 17 | |
Chandan Kumar | b30a192 | 2017-12-09 20:24:46 +0530 | [diff] [blame] | 18 | from telemetry_tempest_plugin.aodh.service import client |
Chandan Kumar | 6f97ca0 | 2017-12-07 12:50:34 +0530 | [diff] [blame] | 19 | |
| 20 | CONF = config.CONF |
| 21 | |
| 22 | |
| 23 | class BaseAlarmingTest(tempest.test.BaseTestCase): |
| 24 | """Base test case class for all Alarming API tests.""" |
| 25 | |
| 26 | credentials = ['primary'] |
| 27 | client_manager = client.Manager |
| 28 | |
| 29 | @classmethod |
| 30 | def skip_checks(cls): |
| 31 | super(BaseAlarmingTest, cls).skip_checks() |
Takashi Kajinami | c606168 | 2023-03-22 00:05:08 +0900 | [diff] [blame] | 32 | if not CONF.service_available.aodh: |
Chandan Kumar | 6f97ca0 | 2017-12-07 12:50:34 +0530 | [diff] [blame] | 33 | raise cls.skipException("Aodh support is required") |
Jaromir Wysoglad | 3dd1d0d | 2023-11-22 05:17:28 -0500 | [diff] [blame^] | 34 | if not CONF.service_available.gnocchi: |
| 35 | raise cls.skipException("Gnocchi support is required") |
Chandan Kumar | 6f97ca0 | 2017-12-07 12:50:34 +0530 | [diff] [blame] | 36 | |
| 37 | @classmethod |
| 38 | def setup_clients(cls): |
| 39 | super(BaseAlarmingTest, cls).setup_clients() |
| 40 | cls.alarming_client = cls.os_primary.alarming_client |
| 41 | |
| 42 | @classmethod |
| 43 | def resource_setup(cls): |
| 44 | super(BaseAlarmingTest, cls).resource_setup() |
| 45 | cls.alarm_ids = [] |
| 46 | |
| 47 | @classmethod |
Lingxian Kong | d852577 | 2020-02-03 10:02:30 +1300 | [diff] [blame] | 48 | def create_alarm(cls, type='event', **kwargs): |
Chandan Kumar | 6f97ca0 | 2017-12-07 12:50:34 +0530 | [diff] [blame] | 49 | body = cls.alarming_client.create_alarm( |
| 50 | name=data_utils.rand_name('telemetry_alarm'), |
Lingxian Kong | d852577 | 2020-02-03 10:02:30 +1300 | [diff] [blame] | 51 | type=type, **kwargs) |
Chandan Kumar | 6f97ca0 | 2017-12-07 12:50:34 +0530 | [diff] [blame] | 52 | cls.alarm_ids.append(body['alarm_id']) |
| 53 | return body |
| 54 | |
| 55 | @staticmethod |
| 56 | def cleanup_resources(method, list_of_ids): |
| 57 | for resource_id in list_of_ids: |
| 58 | try: |
| 59 | method(resource_id) |
| 60 | except lib_exc.NotFound: |
| 61 | pass |
| 62 | |
| 63 | @classmethod |
| 64 | def resource_cleanup(cls): |
| 65 | cls.cleanup_resources(cls.alarming_client.delete_alarm, cls.alarm_ids) |
| 66 | super(BaseAlarmingTest, cls).resource_cleanup() |