From 3abd54b30a164415912532175a2145310bb83933 Mon Sep 17 00:00:00 2001 From: Tom Patzig Date: Fri, 4 Dec 2015 20:19:20 +0100 Subject: [PATCH] Additional argument support for CinderVolumes This patch adds support for providing additional arguments to create_volume in the rally task CinderVolumes.create_and_attach_volume. Currently only the size of the volume to be created can be given. Change-Id: I9c7ca61629c817ad44d2421a1fe988c75140c6e5 Closes-Bug: #1522935 --- .../openstack/scenarios/cinder/volumes.py | 24 +++++++++++++++---- .../cinder/create-and-attach-volume.json | 7 ++++++ .../cinder/create-and-attach-volume.yaml | 5 ++++ .../scenarios/cinder/test_volumes.py | 7 +++++- 4 files changed, 38 insertions(+), 5 deletions(-) diff --git a/rally/plugins/openstack/scenarios/cinder/volumes.py b/rally/plugins/openstack/scenarios/cinder/volumes.py index 0c1d7b18f5..4bc2152061 100644 --- a/rally/plugins/openstack/scenarios/cinder/volumes.py +++ b/rally/plugins/openstack/scenarios/cinder/volumes.py @@ -278,7 +278,12 @@ class CinderVolumes(cinder_utils.CinderScenario, @validation.required_services(consts.Service.NOVA, consts.Service.CINDER) @validation.required_openstack(users=True) @scenario.configure(context={"cleanup": ["cinder", "nova"]}) - def create_and_attach_volume(self, size, image, flavor, **kwargs): + @logging.log_deprecated_args( + "Use 'create_vm_params' for additional instance parameters.", + "0.2.0", ["kwargs"], once=True) + def create_and_attach_volume(self, size, image, flavor, + create_volume_params=None, + create_vm_params=None, **kwargs): """Create a VM and attach a volume to it. Simple test to create a VM and attach a volume, then @@ -290,11 +295,22 @@ class CinderVolumes(cinder_utils.CinderScenario, max - maximum size volumes will be created as. :param image: Glance image name to use for the VM :param flavor: VM flavor name - :param kwargs: optional arguments for VM creation + :param create_volume_params: optional arguments for volume creation + :param create_vm_params: optional arguments for VM creation + :param kwargs: (deprecated) optional arguments for VM creation """ - server = self._boot_server(image, flavor, **kwargs) - volume = self._create_volume(size) + create_volume_params = create_volume_params or {} + + if kwargs and create_vm_params: + raise ValueError("You can not set both 'kwargs'" + "and 'create_vm_params' attributes." + "Please use 'create_vm_params'.") + + create_vm_params = create_vm_params or kwargs or {} + + server = self._boot_server(image, flavor, **create_vm_params) + volume = self._create_volume(size, **create_volume_params) self._attach_volume(server, volume) self._detach_volume(server, volume) diff --git a/samples/tasks/scenarios/cinder/create-and-attach-volume.json b/samples/tasks/scenarios/cinder/create-and-attach-volume.json index faf1cbaa17..c3a2ff5f5d 100644 --- a/samples/tasks/scenarios/cinder/create-and-attach-volume.json +++ b/samples/tasks/scenarios/cinder/create-and-attach-volume.json @@ -1,4 +1,5 @@ {% set flavor_name = flavor_name or "m1.tiny" %} +{% set availability_zone = availability_zone or "nova" %} { "CinderVolumes.create_and_attach_volume": [ { @@ -9,6 +10,9 @@ }, "flavor": { "name": "{{flavor_name}}" + }, + "create_volume_params": { + "availability_zone": "{{availability_zone}}" } }, "runner": { @@ -34,6 +38,9 @@ }, "image": { "name": "^cirros.*uec$" + }, + "create_volume_params": { + "availability_zone": "{{availability_zone}}" } }, "runner": { diff --git a/samples/tasks/scenarios/cinder/create-and-attach-volume.yaml b/samples/tasks/scenarios/cinder/create-and-attach-volume.yaml index 18de5fecd6..0fd4ab6795 100644 --- a/samples/tasks/scenarios/cinder/create-and-attach-volume.yaml +++ b/samples/tasks/scenarios/cinder/create-and-attach-volume.yaml @@ -1,4 +1,5 @@ {% set flavor_name = flavor_name or "m1.tiny" %} +{% set availability_zone = availability_zone or "nova" %} --- CinderVolumes.create_and_attach_volume: - @@ -8,6 +9,8 @@ name: "^cirros.*uec$" flavor: name: "{{flavor_name}}" + create_volume_params: + availability_zone: "{{availability_zone}}" runner: type: "constant" times: 5 @@ -25,6 +28,8 @@ name: "{{flavor_name}}" image: name: "^cirros.*uec$" + create_volume_params: + availability_zone: "{{availability_zone}}" runner: type: "constant" times: 5 diff --git a/tests/unit/plugins/openstack/scenarios/cinder/test_volumes.py b/tests/unit/plugins/openstack/scenarios/cinder/test_volumes.py index 0fe53bbaf9..e524927e7e 100644 --- a/tests/unit/plugins/openstack/scenarios/cinder/test_volumes.py +++ b/tests/unit/plugins/openstack/scenarios/cinder/test_volumes.py @@ -196,7 +196,12 @@ class CinderServersTestCase(test.ScenarioTestCase): scenario._create_volume = mock.MagicMock(return_value=fake_volume) scenario._delete_volume = mock.MagicMock() - scenario.create_and_attach_volume(10, "img", "0") + volume_args = {"some_key": "some_val"} + vm_args = {"some_key": "some_val"} + + scenario.create_and_attach_volume(10, "img", "0", + create_volume_params=volume_args, + create_vm_params=vm_args) scenario._attach_volume.assert_called_once_with(fake_server, fake_volume) scenario._detach_volume.assert_called_once_with(fake_server,