Merge "Add benchmark scenarios for ceilometer queries API"
This commit is contained in:
commit
b40b67037c
@ -0,0 +1,22 @@
|
||||
{
|
||||
"CeilometerQueries.create_and_query_alarm_history": [
|
||||
{
|
||||
"args": {
|
||||
"orderby": null,
|
||||
"limit": null,
|
||||
"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": 100,
|
||||
"concurrency": 10
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
---
|
||||
CeilometerQueries.create_and_query_alarm_history:
|
||||
-
|
||||
args:
|
||||
orderby: !!null
|
||||
limit: !!null
|
||||
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: 100
|
||||
concurrency: 10
|
23
doc/samples/tasks/ceilometer/create-and-query-alarms.json
Normal file
23
doc/samples/tasks/ceilometer/create-and-query-alarms.json
Normal file
@ -0,0 +1,23 @@
|
||||
{
|
||||
"CeilometerQueries.create_and_query_alarms": [
|
||||
{
|
||||
"args": {
|
||||
"filter": {"and": [{"!=": {"state": "dummy_state"}},{"=": {"type": "threshold"}}]},
|
||||
"orderby": null,
|
||||
"limit": 10,
|
||||
"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": 100,
|
||||
"concurrency": 10
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
18
doc/samples/tasks/ceilometer/create-and-query-alarms.yaml
Normal file
18
doc/samples/tasks/ceilometer/create-and-query-alarms.yaml
Normal file
@ -0,0 +1,18 @@
|
||||
---
|
||||
CeilometerQueries.create_and_query_alarms:
|
||||
-
|
||||
args:
|
||||
filter: {"and": [{"!=": {"state": "dummy_state"}},{"=": {"type": "threshold"}}]}
|
||||
orderby: !!null
|
||||
limit: 10
|
||||
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: 100
|
||||
concurrency: 10
|
21
doc/samples/tasks/ceilometer/create-and-query-samples.json
Normal file
21
doc/samples/tasks/ceilometer/create-and-query-samples.json
Normal file
@ -0,0 +1,21 @@
|
||||
{
|
||||
"CeilometerQueries.create_and_query_samples": [
|
||||
{
|
||||
"args": {
|
||||
"filter": {"=": {"counter_unit": "instance"}},
|
||||
"orderby": null,
|
||||
"limit": 10,
|
||||
"counter_name": "cpu_util",
|
||||
"counter_type": "gauge",
|
||||
"counter_unit": "instance",
|
||||
"counter_volume": 1.0,
|
||||
"resource_id": "resource_id",
|
||||
},
|
||||
"runner": {
|
||||
"type": "constant",
|
||||
"times": 100,
|
||||
"concurrency": 10
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
16
doc/samples/tasks/ceilometer/create-and-query-samples.yaml
Normal file
16
doc/samples/tasks/ceilometer/create-and-query-samples.yaml
Normal file
@ -0,0 +1,16 @@
|
||||
---
|
||||
CeilometerQueries.create_and_query_samples:
|
||||
-
|
||||
args:
|
||||
filter: {"=": {"counter_unit": "instance"}}
|
||||
orderby: !!null
|
||||
limit: 10
|
||||
counter_name: "cpu_util"
|
||||
counter_type: "gauge"
|
||||
counter_unit: "instance"
|
||||
counter_volume: 1.0
|
||||
resource_id: "resource_id"
|
||||
runner:
|
||||
type: "constant"
|
||||
times: 100
|
||||
concurrency: 10
|
@ -156,3 +156,54 @@
|
||||
type: "constant"
|
||||
times: 200
|
||||
concurrency: 5
|
||||
|
||||
CeilometerQueries.create_and_query_alarms:
|
||||
-
|
||||
args:
|
||||
filter: {"and": [{"!=": {"state": "dummy_state"}},{"=": {"type": "threshold"}}]}
|
||||
orderby: !!null
|
||||
limit: 10
|
||||
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: 10
|
||||
|
||||
CeilometerQueries.create_and_query_alarm_history:
|
||||
-
|
||||
args:
|
||||
orderby: !!null
|
||||
limit: !!null
|
||||
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: 10
|
||||
|
||||
CeilometerQueries.create_and_query_samples:
|
||||
-
|
||||
args:
|
||||
filter: {"=": {"counter_unit": "instance"}}
|
||||
orderby: !!null
|
||||
limit: 10
|
||||
counter_name: "cpu_util"
|
||||
counter_type: "gauge"
|
||||
counter_unit: "instance"
|
||||
counter_volume: 1.0
|
||||
resource_id: "resource_id"
|
||||
runner:
|
||||
type: "constant"
|
||||
times: 10
|
||||
concurrency: 10
|
||||
|
84
rally/benchmark/scenarios/ceilometer/queries.py
Normal file
84
rally/benchmark/scenarios/ceilometer/queries.py
Normal file
@ -0,0 +1,84 @@
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# 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.
|
||||
|
||||
import json
|
||||
|
||||
from rally.benchmark.scenarios import base
|
||||
from rally.benchmark.scenarios.ceilometer import utils as ceilometerutils
|
||||
|
||||
|
||||
class CeilometerQueries(ceilometerutils.CeilometerScenario):
|
||||
@base.scenario(context={"cleanup": ["ceilometer"]})
|
||||
def create_and_query_alarms(self, meter_name, threshold, filter=None,
|
||||
orderby=None, limit=None, **kwargs):
|
||||
"""Creates an alarm and then queries it with specific parameters.
|
||||
|
||||
This scenario tests POST /v2/query/alarms
|
||||
An alarm is first created and then fetched using the input query
|
||||
:param meter_name: specifies meter name of alarm
|
||||
:param threshold: specifies alarm threshold
|
||||
:param filter: optional filter query dictionary
|
||||
:param orderby: optional param for specifying ordering of results
|
||||
:param limit: optional param for maximum number of results returned
|
||||
:param kwargs: optional parameters for alarm creation
|
||||
"""
|
||||
if filter:
|
||||
filter = json.dumps(filter)
|
||||
|
||||
self._create_alarm(meter_name, threshold, kwargs)
|
||||
self._query_alarms(filter, orderby, limit)
|
||||
|
||||
@base.scenario(context={"cleanup": ["ceilometer"]})
|
||||
def create_and_query_alarm_history(self, meter_name, threshold,
|
||||
orderby=None, limit=None, **kwargs):
|
||||
"""Creates an alarm and then queries for its history
|
||||
|
||||
This scenario tests POST /v2/query/alarms/history
|
||||
An alarm is first created and then its alarm_id is used to fetch the
|
||||
history of that specific alarm
|
||||
:param meter_name: specifies meter name of alarm
|
||||
:param threshold: specifies alarm threshold
|
||||
:param orderby: optional param for specifying ordering of results
|
||||
:param limit: optional param for maximum number of results returned
|
||||
:param kwargs: optional parameters for alarm creation
|
||||
"""
|
||||
alarm = self._create_alarm(meter_name, threshold, kwargs)
|
||||
alarm_filter = json.dumps({"=": {"alarm_id": alarm.alarm_id}})
|
||||
self._query_alarm_history(alarm_filter, orderby, limit)
|
||||
|
||||
@base.scenario()
|
||||
def create_and_query_samples(self, counter_name, counter_type,
|
||||
counter_unit, counter_volume, resource_id,
|
||||
filter=None, orderby=None, limit=None,
|
||||
**kwargs):
|
||||
"""Creates a sample and then queries it with specific parameters
|
||||
|
||||
This scenario tests POST /v2/query/samples
|
||||
A sample is first created and then fetched using the input query
|
||||
:param counter_name: specifies name of the counter
|
||||
:param counter_type: specifies type of the counter
|
||||
:param counter_unit: specifies name of the counter
|
||||
:param counter_volume: specifies name of the counter
|
||||
:param resource_id: specifies resource id for the sample created
|
||||
:param filter: optional filter query dictionary
|
||||
:param orderby: optional param for specifying ordering of results
|
||||
:param limit: optional param for maximum number of results returned
|
||||
:param kwargs: parameters for sample creation
|
||||
"""
|
||||
self._create_sample(counter_name, counter_type, counter_unit,
|
||||
counter_volume, resource_id, **kwargs)
|
||||
|
||||
if filter:
|
||||
filter = json.dumps(filter)
|
||||
self._query_samples(filter, orderby, limit)
|
@ -119,3 +119,62 @@ class CeilometerScenario(base.Scenario):
|
||||
samples = self.clients("ceilometer").samples.create(
|
||||
counter_name=name, **kwargs)
|
||||
return samples[0]
|
||||
|
||||
@scenario_utils.atomic_action_timer('ceilometer.query_alarms')
|
||||
def _query_alarms(self, filter, orderby, limit):
|
||||
"""Query alarms with specific parameters.
|
||||
|
||||
If no input params are provided, it returns all the results in database
|
||||
:param limit: optional param for maximum number of results returned
|
||||
:param orderby: optional param for specifying ordering of results
|
||||
:param filter: optional filter query
|
||||
:returns: queried alarms
|
||||
"""
|
||||
return self.clients("ceilometer").query_alarms.query(
|
||||
filter, orderby, limit)
|
||||
|
||||
@scenario_utils.atomic_action_timer('ceilometer.query_alarm_history')
|
||||
def _query_alarm_history(self, filter, orderby, limit):
|
||||
"""Query history of an alarm.
|
||||
|
||||
If no input params are provided, it returns all the results in database
|
||||
:param limit: optional param for maximum number of results returned
|
||||
:param orderby: optional param for specifying ordering of results
|
||||
:param filter: optional filter query
|
||||
:returns: alarm history
|
||||
"""
|
||||
return self.clients("ceilometer").query_alarm_history.query(
|
||||
filter, orderby, limit)
|
||||
|
||||
@scenario_utils.atomic_action_timer('ceilometer.create_sample')
|
||||
def _create_sample(self, counter_name, counter_type, counter_unit,
|
||||
counter_volume, resource_id, **kwargs):
|
||||
"""Creates a Sample with specified parameters.
|
||||
|
||||
:param counter_name: specifies name of the counter
|
||||
:param counter_type: specifies type of the counter
|
||||
:param counter_unit: specifies name of the counter
|
||||
:param counter_volume: specifies name of the counter
|
||||
:param resource_id: specifies resource id for the sample created
|
||||
:param kwargs: contains optional parameters for creating a sample
|
||||
:returns: created sample
|
||||
"""
|
||||
kwargs.update({"counter_name": counter_name,
|
||||
"counter_type": counter_type,
|
||||
"counter_unit": counter_unit,
|
||||
"counter_volume": counter_volume,
|
||||
"resource_id": resource_id})
|
||||
return self.clients("ceilometer").samples.create(**kwargs)
|
||||
|
||||
@scenario_utils.atomic_action_timer('ceilometer.query_samples')
|
||||
def _query_samples(self, filter, orderby, limit):
|
||||
"""Query samples with specified parameters.
|
||||
|
||||
If no input params are provided, it returns all the results in database
|
||||
:param limit: optional param for maximum number of results returned
|
||||
:param orderby: optional param for specifying ordering of results
|
||||
:param filter: optional filter query
|
||||
:returns: queried samples
|
||||
"""
|
||||
return self.clients("ceilometer").query_samples.query(
|
||||
filter, orderby, limit)
|
||||
|
74
tests/benchmark/scenarios/ceilometer/test_queries.py
Normal file
74
tests/benchmark/scenarios/ceilometer/test_queries.py
Normal file
@ -0,0 +1,74 @@
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# 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.
|
||||
|
||||
import json
|
||||
import mock
|
||||
|
||||
from rally.benchmark.scenarios.ceilometer import queries
|
||||
from tests import test
|
||||
|
||||
|
||||
class CeilometerQueriesTestCase(test.TestCase):
|
||||
def test_create_and_query_alarms(self):
|
||||
scenario = queries.CeilometerQueries()
|
||||
scenario._create_alarm = mock.MagicMock()
|
||||
scenario._query_alarms = mock.MagicMock()
|
||||
|
||||
scenario.create_and_query_alarms("fake_meter_name",
|
||||
100, "fake_filter",
|
||||
"fake_orderby_attribute", 10,
|
||||
fakearg="f")
|
||||
scenario._create_alarm.assert_called_once_with("fake_meter_name",
|
||||
100, {'fakearg': 'f'})
|
||||
scenario._query_alarms.assert_called_once_with(
|
||||
json.dumps("fake_filter"), "fake_orderby_attribute", 10)
|
||||
|
||||
def test_create_and_query_alarm_history(self):
|
||||
fake_alarm = mock.MagicMock()
|
||||
fake_alarm.alarm_id = 'fake_alarm_id'
|
||||
scenario = queries.CeilometerQueries()
|
||||
scenario._create_alarm = mock.MagicMock(return_value=fake_alarm)
|
||||
scenario._query_alarm_history = mock.MagicMock()
|
||||
|
||||
fake_filter = json.dumps({"=": {"alarm_id": fake_alarm.alarm_id}})
|
||||
scenario.create_and_query_alarm_history("fake_meter_name", 100,
|
||||
"fake_orderby_attribute", 10,
|
||||
fakearg="f")
|
||||
scenario._create_alarm.assert_called_once_with("fake_meter_name", 100,
|
||||
{'fakearg': 'f'})
|
||||
scenario._query_alarm_history.assert_called_once_with(
|
||||
fake_filter, "fake_orderby_attribute", 10)
|
||||
|
||||
def test_create_and_query_samples(self):
|
||||
scenario = queries.CeilometerQueries()
|
||||
scenario._create_sample = mock.MagicMock()
|
||||
scenario._query_samples = mock.MagicMock()
|
||||
|
||||
scenario.create_and_query_samples("fake_counter_name",
|
||||
"fake_counter_type",
|
||||
"fake_counter_unit",
|
||||
"fake_counter_volume",
|
||||
"fake_resource_id",
|
||||
"fake_filter",
|
||||
"fake_orderby_attribute",
|
||||
10,
|
||||
fakearg="f")
|
||||
scenario._create_sample.assert_called_once_with("fake_counter_name",
|
||||
"fake_counter_type",
|
||||
"fake_counter_unit",
|
||||
"fake_counter_volume",
|
||||
"fake_resource_id",
|
||||
fakearg="f")
|
||||
scenario._query_samples.assert_called_once_with(
|
||||
json.dumps("fake_filter"), "fake_orderby_attribute", 10)
|
@ -111,3 +111,46 @@ class CeilometerScenarioTestCase(test.TestCase):
|
||||
scenario = utils.CeilometerScenario()
|
||||
created_meter = scenario._create_meter(**kwargs)
|
||||
self.assertEqual(fake_meter, created_meter)
|
||||
|
||||
@mock.patch(UTILS + '.CeilometerScenario.clients')
|
||||
def test__query_alarms(self, mock_clients):
|
||||
mock_client = mock_clients("ceilometer")
|
||||
mock_client.query_alarms.query = mock.MagicMock()
|
||||
scenario = utils.CeilometerScenario()
|
||||
scenario._query_alarms("fake_filter", "fake_orderby_attribute", 10)
|
||||
mock_client.query_alarms.query.assert_called_once_with(
|
||||
"fake_filter", "fake_orderby_attribute", 10)
|
||||
|
||||
@mock.patch(UTILS + '.CeilometerScenario.clients')
|
||||
def test__query_alarm_history(self, mock_clients):
|
||||
mock_client = mock_clients("ceilometer")
|
||||
mock_client.query_alarm_history.query = mock.MagicMock()
|
||||
scenario = utils.CeilometerScenario()
|
||||
scenario._query_alarm_history("fake_filter",
|
||||
"fake_orderby_attribute", 10)
|
||||
mock_client.query_alarm_history.query.assert_called_once_with(
|
||||
"fake_filter", "fake_orderby_attribute", 10)
|
||||
|
||||
@mock.patch(UTILS + '.CeilometerScenario.clients')
|
||||
def test__query_samples(self, mock_clients):
|
||||
mock_client = mock_clients("ceilometer")
|
||||
mock_client.query_samples.query = mock.MagicMock()
|
||||
scenario = utils.CeilometerScenario()
|
||||
scenario._query_samples("fake_filter", "fake_orderby_attribute", 10)
|
||||
mock_client.query_samples.query.assert_called_once_with(
|
||||
"fake_filter", "fake_orderby_attribute", 10)
|
||||
|
||||
@mock.patch(UTILS + '.CeilometerScenario.clients')
|
||||
def test__create_sample(self, mock_clients):
|
||||
"""Test _create_sample returns sample."""
|
||||
fake_sample = mock.MagicMock()
|
||||
fake_sample_dict = dict()
|
||||
mock_clients("ceilometer").samples.create.return_value = fake_sample
|
||||
scenario = utils.CeilometerScenario()
|
||||
created_sample = scenario._create_sample("fake_counter_name",
|
||||
"fake_counter_type",
|
||||
"fake_counter_unit",
|
||||
"fake_counter_volume",
|
||||
"fake_resource_id",
|
||||
**fake_sample_dict)
|
||||
self.assertEqual(fake_sample, created_sample)
|
||||
|
Loading…
x
Reference in New Issue
Block a user