From 9d1d4a8369fe36cc7eccd61eac5f95b0a1be7ab0 Mon Sep 17 00:00:00 2001 From: zhangzhang Date: Thu, 29 Dec 2016 10:18:55 -0500 Subject: [PATCH] Add cinder.CreateAndSetVolumeType scenario Create and set a volume type's extra specs. Change-Id: Idb13f2e119a3798149f6fd268bad4822a45c737e --- rally-jobs/cinder.yaml | 17 ++++++++++++ .../openstack/scenarios/cinder/utils.py | 10 +++++++ .../scenarios/cinder/volume_types.py | 18 +++++++++++++ .../create-and-set-volume-type-keys.json | 27 +++++++++++++++++++ .../create-and-set-volume-type-keys.yaml | 17 ++++++++++++ .../openstack/scenarios/cinder/test_utils.py | 11 ++++++++ .../scenarios/cinder/test_volume_types.py | 16 +++++++++++ 7 files changed, 116 insertions(+) create mode 100644 samples/tasks/scenarios/cinder/create-and-set-volume-type-keys.json create mode 100644 samples/tasks/scenarios/cinder/create-and-set-volume-type-keys.yaml diff --git a/rally-jobs/cinder.yaml b/rally-jobs/cinder.yaml index fb2358d0..ec088b53 100755 --- a/rally-jobs/cinder.yaml +++ b/rally-jobs/cinder.yaml @@ -907,6 +907,23 @@ failure_rate: max: 0 + CinderVolumeTypes.create_and_set_volume_type_keys: + - + args: + volume_type_key: + volume_backend_name: "LVM_iSCSI" + runner: + type: "constant" + times: 5 + concurrency: 2 + context: + users: + tenants: 2 + users_per_tenant: 2 + sla: + failure_rate: + max: 0 + CinderVolumes.list_transfers: - args: diff --git a/rally/plugins/openstack/scenarios/cinder/utils.py b/rally/plugins/openstack/scenarios/cinder/utils.py index e543ec14..3a74865f 100644 --- a/rally/plugins/openstack/scenarios/cinder/utils.py +++ b/rally/plugins/openstack/scenarios/cinder/utils.py @@ -423,6 +423,16 @@ class CinderScenario(scenario.OpenStackScenario): volume_type) return (tuple_res[0].status_code == 202) + @atomic.action_timer("cinder.set_volume_type_keys") + def _set_volume_type_keys(self, volume_type, metadata): + """Set extra specs on a volume type. + + :param volume_type: The :class:`VolumeType` to set extra spec on + :param metadata: A dict of key/value pairs to be set + :returns: extra_specs if the request has been accepted + """ + return volume_type.set_keys(metadata) + @atomic.action_timer("cinder.transfer_create") def _transfer_create(self, volume_id): """Create a volume transfer. diff --git a/rally/plugins/openstack/scenarios/cinder/volume_types.py b/rally/plugins/openstack/scenarios/cinder/volume_types.py index 23175915..ef80670e 100644 --- a/rally/plugins/openstack/scenarios/cinder/volume_types.py +++ b/rally/plugins/openstack/scenarios/cinder/volume_types.py @@ -80,3 +80,21 @@ class CreateAndListEncryptionType(cinder_utils.CinderScenario): volume_type = self._create_volume_type(**kwargs) self._create_encryption_type(volume_type, specs) self._list_encryption_type(search_opts) + + +@validation.required_services(consts.Service.CINDER) +@validation.required_openstack(admin=True) +@scenario.configure(context={"admin_cleanup": ["cinder"]}, + name="CinderVolumeTypes.create_and_set_volume_type_keys") +class CreateAndSetVolumeTypeKeys(cinder_utils.CinderScenario): + + def run(self, volume_type_key, **kwargs): + """Create and set a volume type's extra specs. + + :param volume_type_key: A dict of key/value pairs to be set + :param kwargs: Optional parameters used during volume + type creation. + """ + volume_type = self._create_volume_type(**kwargs) + + self._set_volume_type_keys(volume_type, volume_type_key) diff --git a/samples/tasks/scenarios/cinder/create-and-set-volume-type-keys.json b/samples/tasks/scenarios/cinder/create-and-set-volume-type-keys.json new file mode 100644 index 00000000..a7ae21c9 --- /dev/null +++ b/samples/tasks/scenarios/cinder/create-and-set-volume-type-keys.json @@ -0,0 +1,27 @@ +{ + "CinderVolumeTypes.create_and_set_volume_type_keys": [ + { + "args": { + "volume_type_key": { + "volume_backend_name": "LVM_iSCSI" + } + }, + "runner": { + "type": "constant", + "times": 5, + "concurrency": 2 + }, + "context": { + "users": { + "tenants": 2, + "users_per_tenant": 2 + } + }, + "sla": { + "failure_rate": { + "max": 0 + } + } + } + ] +} diff --git a/samples/tasks/scenarios/cinder/create-and-set-volume-type-keys.yaml b/samples/tasks/scenarios/cinder/create-and-set-volume-type-keys.yaml new file mode 100644 index 00000000..4a9d2ed7 --- /dev/null +++ b/samples/tasks/scenarios/cinder/create-and-set-volume-type-keys.yaml @@ -0,0 +1,17 @@ +--- + CinderVolumeTypes.create_and_set_volume_type_keys: + - + args: + volume_type_key: + volume_backend_name: "LVM_iSCSI" + runner: + type: "constant" + times: 5 + concurrency: 2 + context: + users: + tenants: 2 + users_per_tenant: 2 + 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 2c558889..bc3616d5 100644 --- a/tests/unit/plugins/openstack/scenarios/cinder/test_utils.py +++ b/tests/unit/plugins/openstack/scenarios/cinder/test_utils.py @@ -441,3 +441,14 @@ class CinderScenarioTestCase(test.ScenarioTestCase): fake_transfer.id, "fake_key") self._test_atomic_action_timer(self.scenario.atomic_actions(), "cinder.transfer_accept") + + def test__set_volume_type_keys(self): + volume_type = mock.MagicMock() + volume_type.set_keys = mock.MagicMock() + volume_type_key = {"volume_backend_name": "LVM_iSCSI"} + result = self.scenario._set_volume_type_keys(volume_type, + volume_type_key) + self.assertEqual(volume_type.set_keys.return_value, result) + volume_type.set_keys.assert_called_once_with(volume_type_key) + self._test_atomic_action_timer(self.scenario.atomic_actions(), + "cinder.set_volume_type_keys") diff --git a/tests/unit/plugins/openstack/scenarios/cinder/test_volume_types.py b/tests/unit/plugins/openstack/scenarios/cinder/test_volume_types.py index 3cef8758..00d7e096 100644 --- a/tests/unit/plugins/openstack/scenarios/cinder/test_volume_types.py +++ b/tests/unit/plugins/openstack/scenarios/cinder/test_volume_types.py @@ -57,3 +57,19 @@ class CinderVolumeTypesTestCase(test.ScenarioTestCase): scenario._create_volume_type.return_value, "fakespecs") scenario._list_encryption_type.assert_called_once_with( "fakeopts") + + def test_create_and_set_volume_type_keys(self): + scenario = volume_types.CreateAndSetVolumeTypeKeys(self.context) + + volume_type = mock.MagicMock() + volume_type_key = {"volume_backend_name": "LVM_iSCSI"} + scenario._create_volume_type = mock.MagicMock() + scenario._set_volume_type_keys = mock.MagicMock() + + scenario._create_volume_type.return_value = volume_type + scenario.run(volume_type_key, fakeargs="fakeargs") + + scenario._create_volume_type.assert_called_once_with( + fakeargs="fakeargs") + scenario._set_volume_type_keys.assert_called_once_with(volume_type, + volume_type_key)