From eacf26da3f56549bba7d2afc6861034a39bd57f8 Mon Sep 17 00:00:00 2001 From: chen-li Date: Tue, 25 Mar 2014 14:38:22 +0800 Subject: [PATCH] add create_and_list_volume benchmark Added create_and_list_volume benchmark. Config example is below. { "CinderVolumes.create_and_list_volume": [ { "args": { "size": 1, "detailed": True }, "runner": { "type": "continuous", "times": 3, "active_users": 1 }, "context": { "users": { "tenants": 1, "users_per_tenant": 1 } } } ] } Change-Id: I8b56a6e9e12cc2801332ba9760a2bc2892112d99 --- .../tasks/cinder/create-and-list-volume.json | 21 ++++++++++ .../tasks/cinder/create-and-list-volume.yaml | 14 +++++++ rally/benchmark/scenarios/cinder/utils.py | 6 +++ rally/benchmark/scenarios/cinder/volumes.py | 16 ++++++++ .../benchmark/scenarios/cinder/test_utils.py | 41 +++++++++++++++++++ .../scenarios/cinder/test_volumes.py | 8 ++++ 6 files changed, 106 insertions(+) create mode 100644 doc/samples/tasks/cinder/create-and-list-volume.json create mode 100644 doc/samples/tasks/cinder/create-and-list-volume.yaml create mode 100644 tests/benchmark/scenarios/cinder/test_utils.py diff --git a/doc/samples/tasks/cinder/create-and-list-volume.json b/doc/samples/tasks/cinder/create-and-list-volume.json new file mode 100644 index 0000000000..a066a00b5b --- /dev/null +++ b/doc/samples/tasks/cinder/create-and-list-volume.json @@ -0,0 +1,21 @@ +{ + "CinderVolumes.create_and_list_volume": [ + { + "args": { + "size": 1, + "detailed": True + }, + "runner": { + "type": "continuous", + "times": 3, + "active_users": 1 + }, + "context": { + "users": { + "tenants": 1, + "users_per_tenant": 1 + } + } + } + ] +} diff --git a/doc/samples/tasks/cinder/create-and-list-volume.yaml b/doc/samples/tasks/cinder/create-and-list-volume.yaml new file mode 100644 index 0000000000..d9667b1762 --- /dev/null +++ b/doc/samples/tasks/cinder/create-and-list-volume.yaml @@ -0,0 +1,14 @@ +--- + CinderVolumes.create_and_list_volume: + - + args: + size: 1 + detailed: True + runner: + type: "continuous" + times: 3 + active_users: 1 + context: + users: + tenants: 1 + users_per_tenant: 1 diff --git a/rally/benchmark/scenarios/cinder/utils.py b/rally/benchmark/scenarios/cinder/utils.py index 874b33dacb..b79653244a 100644 --- a/rally/benchmark/scenarios/cinder/utils.py +++ b/rally/benchmark/scenarios/cinder/utils.py @@ -64,6 +64,12 @@ def generate_volume_name(length=10): class CinderScenario(base.Scenario): + @scenario_utils.atomic_action_timer('cinder.list_volumes') + def _list_volumes(self, detailed=True): + """Returns user volumes list.""" + + return self.clients("cinder").volumes.list(detailed) + @scenario_utils.atomic_action_timer('cinder.create_volume') def _create_volume(self, size, **kwargs): """create one volume. diff --git a/rally/benchmark/scenarios/cinder/volumes.py b/rally/benchmark/scenarios/cinder/volumes.py index 7b280fe737..fa7bfd464a 100644 --- a/rally/benchmark/scenarios/cinder/volumes.py +++ b/rally/benchmark/scenarios/cinder/volumes.py @@ -18,6 +18,22 @@ from rally.benchmark.scenarios.cinder import utils class CinderVolumes(utils.CinderScenario): + def create_and_list_volume(self, size, detailed=True, **kwargs): + """Tests creating a volume and listing volumes. + + This scenario is a very useful tool to measure + the "cinder volume-list" command performance. + + If you have only 1 user in your context, you will + add 1 volume on every iteration. So you will have more + and more volumes and will be able to measure the + performance of the "cinder volume-list" command depending on + the number of images owned by users. + """ + + self._create_volume(size, **kwargs) + self._list_volumes(detailed) + def create_and_delete_volume(self, size, min_sleep=0, max_sleep=0, **kwargs): """Tests creating and then deleting a volume. diff --git a/tests/benchmark/scenarios/cinder/test_utils.py b/tests/benchmark/scenarios/cinder/test_utils.py new file mode 100644 index 0000000000..a97135e2ca --- /dev/null +++ b/tests/benchmark/scenarios/cinder/test_utils.py @@ -0,0 +1,41 @@ +# Copyright 2013: Mirantis Inc. +# 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 mock + +from rally.benchmark.scenarios.cinder import utils +from tests.benchmark.scenarios import test_utils +from tests import test + +CINDER_UTILS = "rally.benchmark.scenarios.cinder.utils" + + +class CinderScenarioTestCase(test.TestCase): + + def _test_atomic_action_timer(self, atomic_actions_time, name): + action_duration = test_utils.get_atomic_action_timer_value_by_name( + atomic_actions_time, name) + self.assertIsNotNone(action_duration) + self.assertIsInstance(action_duration, float) + + @mock.patch(CINDER_UTILS + '.CinderScenario.clients') + def test__list_volumes(self, mock_clients): + volumes_list = mock.Mock() + mock_clients("cinder").volumes.list.return_value = volumes_list + scenario = utils.CinderScenario() + return_volumes_list = scenario._list_volumes() + self.assertEqual(volumes_list, return_volumes_list) + self._test_atomic_action_timer(scenario.atomic_actions_time(), + 'cinder.list_volumes') diff --git a/tests/benchmark/scenarios/cinder/test_volumes.py b/tests/benchmark/scenarios/cinder/test_volumes.py index fa57f13830..88d111e3ac 100644 --- a/tests/benchmark/scenarios/cinder/test_volumes.py +++ b/tests/benchmark/scenarios/cinder/test_volumes.py @@ -24,6 +24,14 @@ CINDER_VOLUMES = "rally.benchmark.scenarios.cinder.volumes.CinderVolumes" class CinderServersTestCase(test.TestCase): + def test_create_and_list_volume(self): + scenario = volumes.CinderVolumes() + scenario._create_volume = mock.MagicMock() + scenario._list_volumes = mock.MagicMock() + scenario.create_and_list_volume(1, True, fakearg="f") + scenario._create_volume.assert_called_once_with(1, fakearg="f") + scenario._list_volumes.assert_called_once_with(True) + def test_create_and_delete_volume(self): fake_volume = mock.MagicMock()