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
This commit is contained in:
Tom Patzig 2015-12-04 20:19:20 +01:00
parent e8ba46705b
commit 3abd54b30a
4 changed files with 38 additions and 5 deletions

View File

@ -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)

View File

@ -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": {

View File

@ -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

View File

@ -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,