blob: 29b1d613cf20df619e765f37bf82a84d5fef86e2 [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()
32 if not CONF.service_available.aodh_plugin:
33 raise cls.skipException("Aodh support is required")
34
35 @classmethod
36 def setup_clients(cls):
37 super(BaseAlarmingTest, cls).setup_clients()
38 cls.alarming_client = cls.os_primary.alarming_client
39
40 @classmethod
41 def resource_setup(cls):
42 super(BaseAlarmingTest, cls).resource_setup()
43 cls.alarm_ids = []
44
45 @classmethod
Lingxian Kongd8525772020-02-03 10:02:30 +130046 def create_alarm(cls, type='event', **kwargs):
Chandan Kumar6f97ca02017-12-07 12:50:34 +053047 body = cls.alarming_client.create_alarm(
48 name=data_utils.rand_name('telemetry_alarm'),
Lingxian Kongd8525772020-02-03 10:02:30 +130049 type=type, **kwargs)
Chandan Kumar6f97ca02017-12-07 12:50:34 +053050 cls.alarm_ids.append(body['alarm_id'])
51 return body
52
53 @staticmethod
54 def cleanup_resources(method, list_of_ids):
55 for resource_id in list_of_ids:
56 try:
57 method(resource_id)
58 except lib_exc.NotFound:
59 pass
60
61 @classmethod
62 def resource_cleanup(cls):
63 cls.cleanup_resources(cls.alarming_client.delete_alarm, cls.alarm_ids)
64 super(BaseAlarmingTest, cls).resource_cleanup()