Merge "Add CRUD tests for telemetry alarming"
This commit is contained in:
commit
209827826b
4 files changed
+74
-7
No files matched your search
@@ -10,7 +10,9 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from tempest.common.utils import data_utils
|
||||
from tempest import config
|
||||
from tempest import exceptions
|
||||
import tempest.test
|
||||
|
||||
CONF = config.CONF
|
||||
@@ -22,6 +24,28 @@ class BaseTelemetryTest(tempest.test.BaseTestCase):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super(BaseTelemetryTest, cls).setUpClass()
|
||||
if not CONF.service_available.ceilometer:
|
||||
raise cls.skipException("Ceilometer support is required")
|
||||
super(BaseTelemetryTest, cls).setUpClass()
|
||||
os = cls.get_client_manager()
|
||||
cls.telemetry_client = os.telemetry_client
|
||||
cls.alarm_ids = []
|
||||
|
||||
@classmethod
|
||||
def create_alarm(cls, **kwargs):
|
||||
resp, body = cls.telemetry_client.create_alarm(
|
||||
name=data_utils.rand_name('telemetry_alarm'),
|
||||
type='threshold', **kwargs)
|
||||
if resp['status'] == '201':
|
||||
cls.alarm_ids.append(body['alarm_id'])
|
||||
return resp, body
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
for alarm_id in cls.alarm_ids:
|
||||
try:
|
||||
cls.telemetry_client.delete_alarm(alarm_id)
|
||||
except exceptions.NotFound:
|
||||
pass
|
||||
cls.clear_isolated_creds()
|
||||
super(BaseTelemetryTest, cls).tearDownClass()
|
||||
@@ -0,0 +1,43 @@
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from tempest.api.telemetry import base
|
||||
from tempest import exceptions
|
||||
from tempest.test import attr
|
||||
|
||||
|
||||
class TelemetryAlarmingAPITestJSON(base.BaseTelemetryTest):
|
||||
_interface = 'json'
|
||||
|
||||
@attr(type="gate")
|
||||
def test_alarm_list(self):
|
||||
resp, _ = self.telemetry_client.list_alarms()
|
||||
self.assertEqual(int(resp['status']), 200)
|
||||
|
||||
@attr(type="gate")
|
||||
def test_create_alarm(self):
|
||||
rules = {'meter_name': 'cpu_util',
|
||||
'comparison_operator': 'gt',
|
||||
'threshold': 80.0,
|
||||
'period': 70}
|
||||
resp, body = self.create_alarm(threshold_rule=rules)
|
||||
self.alarm_id = body['alarm_id']
|
||||
self.assertEqual(int(resp['status']), 201)
|
||||
self.assertDictContainsSubset(rules, body['threshold_rule'])
|
||||
resp, body = self.telemetry_client.get_alarm(self.alarm_id)
|
||||
self.assertEqual(int(resp['status']), 200)
|
||||
self.assertDictContainsSubset(rules, body['threshold_rule'])
|
||||
resp, _ = self.telemetry_client.delete_alarm(self.alarm_id)
|
||||
self.assertEqual(int(resp['status']), 204)
|
||||
self.assertRaises(exceptions.NotFound,
|
||||
self.telemetry_client.get_alarm,
|
||||
self.alarm_id)
|
||||
@@ -29,10 +29,6 @@ class TelemetryClientJSON(client.TelemetryClientBase):
|
||||
def serialize(self, body):
|
||||
return json.dumps(body)
|
||||
|
||||
def create_alarm(self, **kwargs):
|
||||
uri = "%s/alarms" % self.uri_prefix
|
||||
return self.post(uri, kwargs)
|
||||
|
||||
def add_sample(self, sample_list, meter_name, meter_unit, volume,
|
||||
sample_type, resource_id, **kwargs):
|
||||
sample = {"counter_name": meter_name, "counter_unit": meter_unit,
|
||||
|
||||
@@ -77,7 +77,7 @@ class TelemetryClientBase(object):
|
||||
return self.rest_client.put(uri, body, self.headers)
|
||||
|
||||
def get(self, uri):
|
||||
resp, body = self.rest_client.get(uri)
|
||||
resp, body = self.rest_client.get(uri, self.headers)
|
||||
body = self.deserialize(body)
|
||||
return resp, body
|
||||
|
||||
@@ -124,9 +124,13 @@ class TelemetryClientBase(object):
|
||||
return self.get(uri)
|
||||
|
||||
def get_alarm(self, alarm_id):
|
||||
uri = '%s/meter/%s' % (self.uri_prefix, alarm_id)
|
||||
uri = '%s/alarms/%s' % (self.uri_prefix, alarm_id)
|
||||
return self.get(uri)
|
||||
|
||||
def delete_alarm(self, alarm_id):
|
||||
uri = "%s/alarms/%s" % (self.uri_prefix, alarm_id)
|
||||
return self.delete(uri)
|
||||
|
||||
def create_alarm(self, **kwargs):
|
||||
uri = "%s/alarms" % self.uri_prefix
|
||||
return self.post(uri, kwargs)
|
||||
Reference in new issue
Block a user