blob: 7298170f9ea8b63152d564b45322290c56883eb7 [file] [log] [blame]
Chandan Kumar6f97ca02017-12-07 12:50:34 +05301# 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 tempest import config
14from tempest.lib.common.utils import data_utils
15from tempest.lib import exceptions as lib_exc
16import tempest.test
17
Chandan Kumarb30a1922017-12-09 20:24:46 +053018from telemetry_tempest_plugin.aodh.service import client
Chandan Kumar6f97ca02017-12-07 12:50:34 +053019
20CONF = config.CONF
21
22
23class 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 Kajinamic6061682023-03-22 00:05:08 +090032 if not CONF.service_available.aodh:
Chandan Kumar6f97ca02017-12-07 12:50:34 +053033 raise cls.skipException("Aodh support is required")
Jaromir Wysoglad3dd1d0d2023-11-22 05:17:28 -050034 if not CONF.service_available.gnocchi:
35 raise cls.skipException("Gnocchi support is required")
Chandan Kumar6f97ca02017-12-07 12:50:34 +053036
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 Kongd8525772020-02-03 10:02:30 +130048 def create_alarm(cls, type='event', **kwargs):
Chandan Kumar6f97ca02017-12-07 12:50:34 +053049 body = cls.alarming_client.create_alarm(
50 name=data_utils.rand_name('telemetry_alarm'),
Lingxian Kongd8525772020-02-03 10:02:30 +130051 type=type, **kwargs)
Chandan Kumar6f97ca02017-12-07 12:50:34 +053052 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()