From 724a1db8b9bf8fa9000612c6953a0dbe5d0d19fc Mon Sep 17 00:00:00 2001 From: maxinjian Date: Sun, 16 Oct 2016 23:05:21 -0400 Subject: [PATCH] Add CinderVolumes.list_types This simple scenario tests the cinder type-list command by listing all the volume types. Change-Id: I33c0a4eef8cc21bb848050d23e0d207653efca23 --- rally-jobs/cinder.yaml | 18 +++++++++++++ .../openstack/scenarios/cinder/utils.py | 11 ++++++++ .../openstack/scenarios/cinder/volumes.py | 20 ++++++++++++++- .../tasks/scenarios/cinder/list-types.json | 25 +++++++++++++++++++ .../tasks/scenarios/cinder/list-types.yaml | 16 ++++++++++++ .../openstack/scenarios/cinder/test_utils.py | 7 ++++++ .../scenarios/cinder/test_volumes.py | 6 +++++ 7 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 samples/tasks/scenarios/cinder/list-types.json create mode 100644 samples/tasks/scenarios/cinder/list-types.yaml diff --git a/rally-jobs/cinder.yaml b/rally-jobs/cinder.yaml index 2c0bb07f5c..b6ca3df2e9 100755 --- a/rally-jobs/cinder.yaml +++ b/rally-jobs/cinder.yaml @@ -236,6 +236,24 @@ failure_rate: max: 0 + CinderVolumes.list_types: + {% for s in ("true", "false") %} + - + args: + is_public: {{s}} + runner: + type: "constant" + times: 10 + concurrency: 2 + context: + users: + tenants: 2 + users_per_tenant: 3 + sla: + failure_rate: + max: 0 + {% endfor %} + CinderVolumes.create_volume: - args: diff --git a/rally/plugins/openstack/scenarios/cinder/utils.py b/rally/plugins/openstack/scenarios/cinder/utils.py index 6ebe27c694..3a042196ff 100644 --- a/rally/plugins/openstack/scenarios/cinder/utils.py +++ b/rally/plugins/openstack/scenarios/cinder/utils.py @@ -65,6 +65,17 @@ class CinderScenario(scenario.OpenStackScenario): return self.clients("cinder").volume_snapshots.list(detailed) + @atomic.action_timer("cinder.list_types") + def _list_types(self, search_opts=None, is_public=None): + """Lists all volume types. + + :param search_opts: Options used when search for volume types + :param is_public: If query public volume type + :returns: A list of volume types + """ + return self.clients("cinder").volume_types.list(search_opts, + is_public) + def _set_metadata(self, volume, sets=10, set_size=3): """Set volume metadata. diff --git a/rally/plugins/openstack/scenarios/cinder/volumes.py b/rally/plugins/openstack/scenarios/cinder/volumes.py index dc0dc4a21b..7a8e650cad 100755 --- a/rally/plugins/openstack/scenarios/cinder/volumes.py +++ b/rally/plugins/openstack/scenarios/cinder/volumes.py @@ -88,6 +88,24 @@ class ListVolumes(cinder_utils.CinderScenario, self._list_volumes(detailed) +@validation.required_services(consts.Service.CINDER) +@validation.required_openstack(users=True) +@scenario.configure(name="CinderVolumes.list_types") +class ListTypes(cinder_utils.CinderScenario): + + def run(self, search_opts=None, is_public=None): + """List all volume types. + + This simple scenario tests the cinder type-list command by listing + all the volume types. + + :param search_opts: Options used when search for volume types + :param is_public: If query public volume type + """ + + self._list_types(search_opts, is_public) + + @types.convert(image={"type": "glance_image"}) @validation.image_exists("image", nullable=True) @validation.required_services(consts.Service.CINDER) @@ -702,4 +720,4 @@ class CreateVolumeFromSnapshot(cinder_utils.CinderScenario, if do_delete: self._delete_snapshot(snapshot) - self._delete_volume(volume) \ No newline at end of file + self._delete_volume(volume) diff --git a/samples/tasks/scenarios/cinder/list-types.json b/samples/tasks/scenarios/cinder/list-types.json new file mode 100644 index 0000000000..f108862e8a --- /dev/null +++ b/samples/tasks/scenarios/cinder/list-types.json @@ -0,0 +1,25 @@ +{ + "CinderVolumes.list_types": [ + { + "args": { + "is_public": true + }, + "runner": { + "type": "constant", + "times": 10, + "concurrency": 2 + }, + "context": { + "users": { + "tenants": 2, + "users_per_tenant": 3 + } + }, + "sla": { + "failure_rate": { + "max": 0 + } + } + } + ] +} diff --git a/samples/tasks/scenarios/cinder/list-types.yaml b/samples/tasks/scenarios/cinder/list-types.yaml new file mode 100644 index 0000000000..939c634649 --- /dev/null +++ b/samples/tasks/scenarios/cinder/list-types.yaml @@ -0,0 +1,16 @@ +--- + CinderVolumes.list_types: + - + args: + is_public: true + runner: + type: "constant" + times: 10 + concurrency: 2 + context: + users: + tenants: 2 + users_per_tenant: 3 + sla: + failure_rate: + max: 0 diff --git a/tests/unit/plugins/openstack/scenarios/cinder/test_utils.py b/tests/unit/plugins/openstack/scenarios/cinder/test_utils.py index 550c57afdb..012f41669f 100644 --- a/tests/unit/plugins/openstack/scenarios/cinder/test_utils.py +++ b/tests/unit/plugins/openstack/scenarios/cinder/test_utils.py @@ -45,6 +45,13 @@ class CinderScenarioTestCase(test.ScenarioTestCase): self._test_atomic_action_timer(self.scenario.atomic_actions(), "cinder.list_volumes") + def test__list_types(self): + return_types_list = self.scenario._list_types() + self.assertEqual(self.clients("cinder").volume_types.list.return_value, + return_types_list) + self._test_atomic_action_timer(self.scenario.atomic_actions(), + "cinder.list_types") + def test__list_snapshots(self): return_snapshots_list = self.scenario._list_snapshots() self.assertEqual( diff --git a/tests/unit/plugins/openstack/scenarios/cinder/test_volumes.py b/tests/unit/plugins/openstack/scenarios/cinder/test_volumes.py index 42d6dd44ab..8e1f55e47f 100755 --- a/tests/unit/plugins/openstack/scenarios/cinder/test_volumes.py +++ b/tests/unit/plugins/openstack/scenarios/cinder/test_volumes.py @@ -54,6 +54,12 @@ class CinderServersTestCase(test.ScenarioTestCase): scenario.run(True) scenario._list_volumes.assert_called_once_with(True) + def test_list_types(self): + scenario = volumes.ListTypes(self.context) + scenario._list_types = mock.MagicMock() + scenario.run(None, None) + scenario._list_types.assert_called_once_with(None, None) + def test_create_and_update_volume(self): volume_update_args = {"dispaly_name": "_updated"} scenario = volumes.CreateAndUpdateVolume(self.context)