From 02559f1373b01cdcf77be1c119ef982aa322555a Mon Sep 17 00:00:00 2001 From: zhangzhang Date: Tue, 17 Jan 2017 11:31:34 -0500 Subject: [PATCH] Add cinder.CreateAndGetVolumeType scenario Create a volume Type, then get the details of the type Change-Id: I1e4468008e00d4ca5efaf6838e8b0eed56c807e7 --- rally-jobs/cinder.yaml | 15 ++++++++++++ .../openstack/scenarios/cinder/utils.py | 9 ++++++++ .../scenarios/cinder/volume_types.py | 16 +++++++++++++ .../cinder/create-and-get-volume-type.json | 23 +++++++++++++++++++ .../cinder/create-and-get-volume-type.yaml | 15 ++++++++++++ .../openstack/scenarios/cinder/test_utils.py | 12 ++++++++++ .../scenarios/cinder/test_volume_types.py | 9 ++++++++ 7 files changed, 99 insertions(+) create mode 100644 samples/tasks/scenarios/cinder/create-and-get-volume-type.json create mode 100644 samples/tasks/scenarios/cinder/create-and-get-volume-type.yaml diff --git a/rally-jobs/cinder.yaml b/rally-jobs/cinder.yaml index 2deb5b54..e091fdcf 100755 --- a/rally-jobs/cinder.yaml +++ b/rally-jobs/cinder.yaml @@ -852,6 +852,21 @@ failure_rate: max: 0 + CinderVolumeTypes.create_and_get_volume_type: + - + args: {} + runner: + type: "constant" + times: 5 + concurrency: 2 + context: + users: + tenants: 2 + users_per_tenant: 2 + sla: + failure_rate: + max: 0 + CinderVolumeTypes.create_and_delete_volume_type: - args: {} diff --git a/rally/plugins/openstack/scenarios/cinder/utils.py b/rally/plugins/openstack/scenarios/cinder/utils.py index fe2db2bc..12bef746 100644 --- a/rally/plugins/openstack/scenarios/cinder/utils.py +++ b/rally/plugins/openstack/scenarios/cinder/utils.py @@ -448,6 +448,15 @@ class CinderScenario(scenario.OpenStackScenario): """ return volume_type.set_keys(metadata) + @atomic.action_timer("cinder.get_volume_type") + def _get_volume_type(self, volume_type): + """get details of volume_type. + + :param volume_type: The ID of the :class:`VolumeType` to get + :rtype: :class:`VolumeType` + """ + return self.admin_clients("cinder").volume_types.get(volume_type) + @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 9cfbd9f6..caeffcce 100644 --- a/rally/plugins/openstack/scenarios/cinder/volume_types.py +++ b/rally/plugins/openstack/scenarios/cinder/volume_types.py @@ -39,6 +39,22 @@ class CreateAndDeleteVolumeType(cinder_utils.CinderScenario): self._delete_volume_type(volume_type) +@validation.required_services(consts.Service.CINDER) +@validation.required_openstack(admin=True) +@scenario.configure(context={"admin_cleanup": ["cinder"]}, + name="CinderVolumeTypes.create_and_get_volume_type") +class CreateAndGetVolumeType(cinder_utils.CinderScenario): + + def run(self, **kwargs): + """Create a volume Type, then get the details of the type. + + :param kwargs: Optional parameters used during volume + type creation. + """ + volume_type = self._create_volume_type(**kwargs) + self._get_volume_type(volume_type) + + @validation.required_services(consts.Service.CINDER) @validation.required_openstack(admin=True) @scenario.configure(context={"admin_cleanup": ["cinder"]}, diff --git a/samples/tasks/scenarios/cinder/create-and-get-volume-type.json b/samples/tasks/scenarios/cinder/create-and-get-volume-type.json new file mode 100644 index 00000000..6ce2599e --- /dev/null +++ b/samples/tasks/scenarios/cinder/create-and-get-volume-type.json @@ -0,0 +1,23 @@ +{ + "CinderVolumeTypes.create_and_get_volume_type": [ + { + "args": {}, + "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-get-volume-type.yaml b/samples/tasks/scenarios/cinder/create-and-get-volume-type.yaml new file mode 100644 index 00000000..a940d49e --- /dev/null +++ b/samples/tasks/scenarios/cinder/create-and-get-volume-type.yaml @@ -0,0 +1,15 @@ +--- + CinderVolumeTypes.create_and_get_volume_type: + - + args: {} + 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 2d1078dd..7770a45c 100644 --- a/tests/unit/plugins/openstack/scenarios/cinder/test_utils.py +++ b/tests/unit/plugins/openstack/scenarios/cinder/test_utils.py @@ -427,6 +427,18 @@ class CinderScenarioTestCase(test.ScenarioTestCase): self._test_atomic_action_timer(self.scenario.atomic_actions(), "cinder.list_encryption_type") + def test__get_volume_type(self): + volume_type = mock.Mock() + result = self.scenario._get_volume_type(volume_type) + self.assertEqual( + self.admin_clients("cinder").volume_types.get.return_value, + result) + + self.admin_clients("cinder").volume_types.get.assert_called_once_with( + volume_type) + self._test_atomic_action_timer(self.scenario.atomic_actions(), + "cinder.get_volume_type") + def test__delete_volume_type(self): volume_type = mock.Mock() self.scenario._delete_volume_type(volume_type) 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 af93e05b..dd8bb128 100644 --- a/tests/unit/plugins/openstack/scenarios/cinder/test_volume_types.py +++ b/tests/unit/plugins/openstack/scenarios/cinder/test_volume_types.py @@ -31,6 +31,15 @@ class CinderVolumeTypesTestCase(test.ScenarioTestCase): "name": "fake_name"}]}) return context + def test_create_and_get_volume_type(self): + scenario = volume_types.CreateAndGetVolumeType(self.context) + scenario._create_volume_type = mock.Mock() + scenario._get_volume_type = mock.Mock() + scenario.run(fakeargs="f") + scenario._create_volume_type.assert_called_once_with(fakeargs="f") + scenario._get_volume_type.assert_called_once_with( + scenario._create_volume_type.return_value) + def test_create_and_delete_volume_type(self): scenario = volume_types.CreateAndDeleteVolumeType(self.context) scenario._create_volume_type = mock.Mock()