From ed9c3a3d96c6d387550ca1a1e84aa21acd83f822 Mon Sep 17 00:00:00 2001 From: maxinjian Date: Wed, 26 Oct 2016 03:23:34 -0400 Subject: [PATCH] Add CeilometerAlarms.create_and_get_alarm Create and get the newly created alarm. These scenarios test GET /v2/alarms/(alarm_id) Initially alarm is created and then its detailed information is fetched using its alarm_id. Change-Id: I3320df227bd963890e4be8765569dbd82329ff4d --- rally-jobs/unstable-neutron.yaml | 22 +++++++++++++ .../openstack/scenarios/ceilometer/alarms.py | 24 ++++++++++++++ .../openstack/scenarios/ceilometer/utils.py | 10 ++++++ .../ceilometer/create-and-get-alarm.json | 31 +++++++++++++++++++ .../ceilometer/create-and-get-alarm.yaml | 22 +++++++++++++ .../scenarios/ceilometer/test_alarms.py | 12 +++++++ .../scenarios/ceilometer/test_utils.py | 8 +++++ 7 files changed, 129 insertions(+) create mode 100644 samples/tasks/scenarios/ceilometer/create-and-get-alarm.json create mode 100644 samples/tasks/scenarios/ceilometer/create-and-get-alarm.yaml diff --git a/rally-jobs/unstable-neutron.yaml b/rally-jobs/unstable-neutron.yaml index 8e251ca445..ff461fa197 100644 --- a/rally-jobs/unstable-neutron.yaml +++ b/rally-jobs/unstable-neutron.yaml @@ -156,6 +156,28 @@ failure_rate: max: 0 + 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 + CeilometerAlarms.create_and_update_alarm: - args: diff --git a/rally/plugins/openstack/scenarios/ceilometer/alarms.py b/rally/plugins/openstack/scenarios/ceilometer/alarms.py index 5c0d053c80..966dbdc246 100644 --- a/rally/plugins/openstack/scenarios/ceilometer/alarms.py +++ b/rally/plugins/openstack/scenarios/ceilometer/alarms.py @@ -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"]}, diff --git a/rally/plugins/openstack/scenarios/ceilometer/utils.py b/rally/plugins/openstack/scenarios/ceilometer/utils.py index 6f4f5876d1..a8f2636e93 100644 --- a/rally/plugins/openstack/scenarios/ceilometer/utils.py +++ b/rally/plugins/openstack/scenarios/ceilometer/utils.py @@ -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. diff --git a/samples/tasks/scenarios/ceilometer/create-and-get-alarm.json b/samples/tasks/scenarios/ceilometer/create-and-get-alarm.json new file mode 100644 index 0000000000..002789e7ed --- /dev/null +++ b/samples/tasks/scenarios/ceilometer/create-and-get-alarm.json @@ -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 + } + } + } + ] +} diff --git a/samples/tasks/scenarios/ceilometer/create-and-get-alarm.yaml b/samples/tasks/scenarios/ceilometer/create-and-get-alarm.yaml new file mode 100644 index 0000000000..5ad7c024a6 --- /dev/null +++ b/samples/tasks/scenarios/ceilometer/create-and-get-alarm.yaml @@ -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 diff --git a/tests/unit/plugins/openstack/scenarios/ceilometer/test_alarms.py b/tests/unit/plugins/openstack/scenarios/ceilometer/test_alarms.py index b12f249911..81d8c3aa1e 100644 --- a/tests/unit/plugins/openstack/scenarios/ceilometer/test_alarms.py +++ b/tests/unit/plugins/openstack/scenarios/ceilometer/test_alarms.py @@ -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() diff --git a/tests/unit/plugins/openstack/scenarios/ceilometer/test_utils.py b/tests/unit/plugins/openstack/scenarios/ceilometer/test_utils.py index 928155a545..4ee611bf9e 100644 --- a/tests/unit/plugins/openstack/scenarios/ceilometer/test_utils.py +++ b/tests/unit/plugins/openstack/scenarios/ceilometer/test_utils.py @@ -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)