Merge "Add CeilometerAlarms.create_and_get_alarm"
This commit is contained in:
commit
a47ff0da96
@ -79,6 +79,30 @@ class CreateAndListAlarm(ceiloutils.CeilometerScenario):
|
||||
self._list_alarms(alarm.alarm_id)
|
||||
|
||||
|
||||
@validation.required_services(consts.Service.CEILOMETER)
|
||||
@validation.required_openstack(users=True)
|
||||
@scenario.configure(context={"cleanup": ["ceilometer"]},
|
||||
name="CeilometerAlarms.create_and_get_alarm")
|
||||
class CreateAndGetAlarm(ceiloutils.CeilometerScenario):
|
||||
|
||||
def run(self, meter_name, threshold, **kwargs):
|
||||
"""Create and get the newly created alarm.
|
||||
|
||||
These scenarios test GET /v2/alarms/(alarm_id)
|
||||
Initially an alarm is created and then its detailed information is
|
||||
fetched using its alarm_id. meter_name and threshold are required
|
||||
parameters for alarm creation. kwargs stores other optional parameters
|
||||
like 'ok_actions', 'project_id' etc. that may be passed while creating
|
||||
an alarm.
|
||||
|
||||
:param meter_name: specifies meter name of the alarm
|
||||
:param threshold: specifies alarm threshold
|
||||
:param kwargs: specifies optional arguments for alarm creation.
|
||||
"""
|
||||
alarm = self._create_alarm(meter_name, threshold, kwargs)
|
||||
self._get_alarm(alarm.alarm_id)
|
||||
|
||||
|
||||
@validation.required_services(consts.Service.CEILOMETER)
|
||||
@validation.required_openstack(users=True)
|
||||
@scenario.configure(context={"cleanup": ["ceilometer"]},
|
||||
|
@ -187,6 +187,16 @@ class CeilometerScenario(scenario.OpenStackScenario):
|
||||
else:
|
||||
return self.clients("ceilometer").alarms.list()
|
||||
|
||||
@atomic.action_timer("ceilometer.get_alarm")
|
||||
def _get_alarm(self, alarm_id):
|
||||
"""Get detailed information of an alarm.
|
||||
|
||||
:param alarm_id: Specifies id of the alarm
|
||||
:returns: If alarm_id is existed and correct, returns
|
||||
detailed information of an alarm, else returns None
|
||||
"""
|
||||
return self.clients("ceilometer").alarms.get(alarm_id)
|
||||
|
||||
@atomic.action_timer("ceilometer.create_alarm")
|
||||
def _create_alarm(self, meter_name, threshold, kwargs):
|
||||
"""Create an alarm.
|
||||
|
31
samples/tasks/scenarios/ceilometer/create-and-get-alarm.json
Normal file
31
samples/tasks/scenarios/ceilometer/create-and-get-alarm.json
Normal file
@ -0,0 +1,31 @@
|
||||
{
|
||||
"CeilometerAlarms.create_and_get_alarm": [
|
||||
{
|
||||
"args": {
|
||||
"meter_name": "ram_util",
|
||||
"threshold": 10.0,
|
||||
"type": "threshold",
|
||||
"statistic": "avg",
|
||||
"alarm_actions": ["http://localhost:8776/alarm"],
|
||||
"ok_actions": ["http://localhost:8776/ok"],
|
||||
"insufficient_data_actions": ["http://localhost:8776/notok"]
|
||||
},
|
||||
"runner": {
|
||||
"type": "constant",
|
||||
"times": 10,
|
||||
"concurrency": 2
|
||||
},
|
||||
"context": {
|
||||
"users": {
|
||||
"tenants": 2,
|
||||
"users_per_tenant": 2
|
||||
}
|
||||
},
|
||||
"sla": {
|
||||
"failure_rate": {
|
||||
"max": 0
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
22
samples/tasks/scenarios/ceilometer/create-and-get-alarm.yaml
Normal file
22
samples/tasks/scenarios/ceilometer/create-and-get-alarm.yaml
Normal file
@ -0,0 +1,22 @@
|
||||
---
|
||||
CeilometerAlarms.create_and_get_alarm:
|
||||
-
|
||||
args:
|
||||
meter_name: "ram_util"
|
||||
threshold: 10.0
|
||||
type: "threshold"
|
||||
statistic: "avg"
|
||||
alarm_actions: ["http://localhost:8776/alarm"]
|
||||
ok_actions: ["http://localhost:8776/ok"]
|
||||
insufficient_data_actions: ["http://localhost:8776/notok"]
|
||||
runner:
|
||||
type: "constant"
|
||||
times: 10
|
||||
concurrency: 2
|
||||
context:
|
||||
users:
|
||||
tenants: 2
|
||||
users_per_tenant: 2
|
||||
sla:
|
||||
failure_rate:
|
||||
max: 0
|
@ -47,6 +47,18 @@ class CeilometerAlarmsTestCase(test.ScenarioTestCase):
|
||||
{"fakearg": "f"})
|
||||
scenario._list_alarms.assert_called_once_with(fake_alarm.alarm_id)
|
||||
|
||||
def test_create_and_get_alarm(self):
|
||||
fake_alarm = mock.MagicMock()
|
||||
scenario = alarms.CreateAndGetAlarm(self.context)
|
||||
|
||||
scenario._create_alarm = mock.MagicMock(return_value=fake_alarm)
|
||||
scenario._get_alarm = mock.MagicMock()
|
||||
scenario.run("fake_meter_name", "fake_threshold", fakearg="f")
|
||||
scenario._create_alarm.assert_called_once_with("fake_meter_name",
|
||||
"fake_threshold",
|
||||
{"fakearg": "f"})
|
||||
scenario._get_alarm.assert_called_once_with(fake_alarm.alarm_id)
|
||||
|
||||
def test_create_and_update_alarm(self):
|
||||
fake_alram_dict_diff = {"description": "Changed Test Description"}
|
||||
fake_alarm = mock.MagicMock()
|
||||
|
@ -107,6 +107,14 @@ class CeilometerScenarioTestCase(test.ScenarioTestCase):
|
||||
self._test_atomic_action_timer(self.scenario.atomic_actions(),
|
||||
"ceilometer.list_alarms")
|
||||
|
||||
def test__get_alarm(self):
|
||||
self.assertEqual(self.clients("ceilometer").alarms.get.return_value,
|
||||
self.scenario._get_alarm("alarm-id"))
|
||||
self.clients("ceilometer").alarms.get.assert_called_once_with(
|
||||
"alarm-id")
|
||||
self._test_atomic_action_timer(self.scenario.atomic_actions(),
|
||||
"ceilometer.get_alarm")
|
||||
|
||||
def test__create_alarm(self):
|
||||
alarm_dict = {"alarm_id": "fake-alarm-id"}
|
||||
orig_alarm_dict = copy.copy(alarm_dict)
|
||||
|
Loading…
Reference in New Issue
Block a user