From 960b004c3c281d56d22c87a1f59dfa4fb4ae3b08 Mon Sep 17 00:00:00 2001 From: nayna-patel Date: Tue, 4 Aug 2015 11:07:55 +0000 Subject: [PATCH] Add Cinder create_and_update_volume scenario Implement create_and_update_volume scenario for cinder. Adds supporting method '_update_volume' to "rally/plugins/openstack/scenarios/cinder/utils.py". Change-Id: I275be08eae74886694286af903acb075b3e82d0c --- rally-jobs/cinder.yaml | 38 +++++++++++++++++++ .../openstack/scenarios/cinder/utils.py | 16 ++++++++ .../openstack/scenarios/cinder/volumes.py | 22 +++++++++++ .../cinder/create-and-update-volume.json | 24 ++++++++++++ .../cinder/create-and-update-volume.yaml | 16 ++++++++ .../openstack/scenarios/cinder/test_utils.py | 11 ++++++ .../scenarios/cinder/test_volumes.py | 12 ++++++ 7 files changed, 139 insertions(+) create mode 100644 samples/tasks/scenarios/cinder/create-and-update-volume.json create mode 100644 samples/tasks/scenarios/cinder/create-and-update-volume.yaml diff --git a/rally-jobs/cinder.yaml b/rally-jobs/cinder.yaml index 5e3a6a44..eac9bfed 100644 --- a/rally-jobs/cinder.yaml +++ b/rally-jobs/cinder.yaml @@ -96,6 +96,44 @@ failure_rate: max: 0 + CinderVolumes.create_and_update_volume: + - + args: + update_volume_kwargs: + display_name: "name_updated" + display_description: "desc_updated" + size: 1 + runner: + type: "constant" + times: 2 + concurrency: 2 + context: + users: + tenants: 2 + users_per_tenant: 2 + sla: + failure_rate: + max: 0 + - + args: + update_volume_kwargs: + display_name: "name_updated" + display_description: "desc_updated" + size: 1 + image: + name: {{image_name}} + runner: + type: "constant" + times: 2 + concurrency: 2 + context: + users: + tenants: 2 + users_per_tenant: 2 + sla: + failure_rate: + max: 0 + CinderVolumes.create_and_list_volume: - args: diff --git a/rally/plugins/openstack/scenarios/cinder/utils.py b/rally/plugins/openstack/scenarios/cinder/utils.py index c1cbd8ca..46f9ec3b 100644 --- a/rally/plugins/openstack/scenarios/cinder/utils.py +++ b/rally/plugins/openstack/scenarios/cinder/utils.py @@ -148,6 +148,22 @@ class CinderScenario(scenario.OpenStackScenario): ) return volume + @atomic.action_timer("cinder.update_volume") + def _update_volume(self, volume, **update_volume_args): + """Update name and description for this volume + + This atomic function updates volume display name and description + + :param volume: volume object + :param update_volume_args: dict, contains values to be updated. + """ + kwargs = {} + kwargs["display_name"] = update_volume_args.get( + "display_name", self._generate_random_name("_")) + kwargs["display_description"] = update_volume_args.get( + "display_description", self._generate_random_name("_")) + self.clients("cinder").volumes.update(volume, **kwargs) + @atomic.action_timer("cinder.delete_volume") def _delete_volume(self, volume): """Delete the given volume. diff --git a/rally/plugins/openstack/scenarios/cinder/volumes.py b/rally/plugins/openstack/scenarios/cinder/volumes.py index 4b7f70f0..9e6e2130 100644 --- a/rally/plugins/openstack/scenarios/cinder/volumes.py +++ b/rally/plugins/openstack/scenarios/cinder/volumes.py @@ -80,6 +80,28 @@ class CinderVolumes(utils.CinderScenario, self._list_volumes(detailed) + @types.set(image=types.ImageResourceType) + @validation.image_exists("image", nullable=True) + @validation.required_services(consts.Service.CINDER) + @validation.required_openstack(users=True) + @scenario.configure(context={"cleanup": ["cinder"]}) + def create_and_update_volume(self, size, image=None, + create_volume_kwargs=None, + update_volume_kwargs=None): + """Create a volume and update its name and description. + + :param size: volume size (integer, in GB) + :param image: image to be used to create volume + :param create_volume_kwargs: dict, to be used to create volume + :param update_volume_kwargs: dict, to be used to update volume + """ + create_volume_kwargs = create_volume_kwargs or {} + update_volume_kwargs = update_volume_kwargs or {} + if image: + create_volume_kwargs["imageRef"] = image + volume = self._create_volume(size, **create_volume_kwargs) + self._update_volume(volume, **update_volume_kwargs) + @types.set(image=types.ImageResourceType) @validation.image_exists("image", nullable=True) @validation.required_services(consts.Service.CINDER) diff --git a/samples/tasks/scenarios/cinder/create-and-update-volume.json b/samples/tasks/scenarios/cinder/create-and-update-volume.json new file mode 100644 index 00000000..215ec44e --- /dev/null +++ b/samples/tasks/scenarios/cinder/create-and-update-volume.json @@ -0,0 +1,24 @@ +{ + "CinderVolumes.create_and_update_volume": [ + { + "args": { + "update_volume_kwargs": { + "display_name": "name_updated", + "display_description": "desc_updated" + }, + "size": 1 + }, + "runner": { + "type": "constant", + "times": 3, + "concurrency": 1 + }, + "context": { + "users": { + "tenants": 1, + "users_per_tenant": 1 + } + } + } + ] +} diff --git a/samples/tasks/scenarios/cinder/create-and-update-volume.yaml b/samples/tasks/scenarios/cinder/create-and-update-volume.yaml new file mode 100644 index 00000000..bce928f1 --- /dev/null +++ b/samples/tasks/scenarios/cinder/create-and-update-volume.yaml @@ -0,0 +1,16 @@ +--- + CinderVolumes.create_and_update_volume: + - + args: + update_volume_kwargs: + display_name: "name_updated" + display_description: "desc_updated" + size: 1 + runner: + type: "constant" + times: 3 + concurrency: 1 + context: + users: + tenants: 1 + users_per_tenant: 1 diff --git a/tests/unit/plugins/openstack/scenarios/cinder/test_utils.py b/tests/unit/plugins/openstack/scenarios/cinder/test_utils.py index 1b3b3fb7..3c46739a 100644 --- a/tests/unit/plugins/openstack/scenarios/cinder/test_utils.py +++ b/tests/unit/plugins/openstack/scenarios/cinder/test_utils.py @@ -127,6 +127,17 @@ class CinderScenarioTestCase(test.ScenarioTestCase): self._test_atomic_action_timer(self.scenario.atomic_actions(), "cinder.create_volume") + def test__update_volume(self): + fake_volume = mock.MagicMock() + volume_update_args = {"display_name": "_updated", + "display_description": "_updated"} + self.scenario._update_volume(fake_volume, **volume_update_args) + self.clients("cinder").volumes.update.assert_called_once_with( + fake_volume, display_name="_updated", + display_description="_updated") + self._test_atomic_action_timer(self.scenario.atomic_actions(), + "cinder.update_volume") + def test__delete_volume(self): cinder = mock.Mock() self.scenario._delete_volume(cinder) diff --git a/tests/unit/plugins/openstack/scenarios/cinder/test_volumes.py b/tests/unit/plugins/openstack/scenarios/cinder/test_volumes.py index e99225e1..6aa9db82 100644 --- a/tests/unit/plugins/openstack/scenarios/cinder/test_volumes.py +++ b/tests/unit/plugins/openstack/scenarios/cinder/test_volumes.py @@ -49,6 +49,18 @@ class CinderServersTestCase(test.ScenarioTestCase): scenario.list_volumes(True) scenario._list_volumes.assert_called_once_with(True) + def test_create_and_update_volume(self): + volume_update_args = {"dispaly_name": "_updated"} + scenario = volumes.CinderVolumes() + fake_volume = mock.MagicMock() + scenario._create_volume = mock.MagicMock(return_value=fake_volume) + scenario._update_volume = mock.MagicMock() + scenario.create_and_update_volume( + 1, update_volume_kwargs=volume_update_args) + scenario._create_volume.assert_called_once_with(1) + scenario._update_volume.assert_called_once_with(fake_volume, + **volume_update_args) + def test_create_and_delete_volume(self): fake_volume = mock.MagicMock()