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_services(consts.Service.NOVA, consts.Service.CINDER)
@validation.required_openstack(users=True) @validation.required_openstack(users=True)
@scenario.configure(context={"cleanup": ["cinder", "nova"]}) @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. """Create a VM and attach a volume to it.
Simple test to create a VM and attach a volume, then 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. max - maximum size volumes will be created as.
:param image: Glance image name to use for the VM :param image: Glance image name to use for the VM
:param flavor: VM flavor name :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) create_volume_params = create_volume_params or {}
volume = self._create_volume(size)
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._attach_volume(server, volume)
self._detach_volume(server, volume) self._detach_volume(server, volume)

View File

@ -1,4 +1,5 @@
{% set flavor_name = flavor_name or "m1.tiny" %} {% set flavor_name = flavor_name or "m1.tiny" %}
{% set availability_zone = availability_zone or "nova" %}
{ {
"CinderVolumes.create_and_attach_volume": [ "CinderVolumes.create_and_attach_volume": [
{ {
@ -9,6 +10,9 @@
}, },
"flavor": { "flavor": {
"name": "{{flavor_name}}" "name": "{{flavor_name}}"
},
"create_volume_params": {
"availability_zone": "{{availability_zone}}"
} }
}, },
"runner": { "runner": {
@ -34,6 +38,9 @@
}, },
"image": { "image": {
"name": "^cirros.*uec$" "name": "^cirros.*uec$"
},
"create_volume_params": {
"availability_zone": "{{availability_zone}}"
} }
}, },
"runner": { "runner": {

View File

@ -1,4 +1,5 @@
{% set flavor_name = flavor_name or "m1.tiny" %} {% set flavor_name = flavor_name or "m1.tiny" %}
{% set availability_zone = availability_zone or "nova" %}
--- ---
CinderVolumes.create_and_attach_volume: CinderVolumes.create_and_attach_volume:
- -
@ -8,6 +9,8 @@
name: "^cirros.*uec$" name: "^cirros.*uec$"
flavor: flavor:
name: "{{flavor_name}}" name: "{{flavor_name}}"
create_volume_params:
availability_zone: "{{availability_zone}}"
runner: runner:
type: "constant" type: "constant"
times: 5 times: 5
@ -25,6 +28,8 @@
name: "{{flavor_name}}" name: "{{flavor_name}}"
image: image:
name: "^cirros.*uec$" name: "^cirros.*uec$"
create_volume_params:
availability_zone: "{{availability_zone}}"
runner: runner:
type: "constant" type: "constant"
times: 5 times: 5

View File

@ -196,7 +196,12 @@ class CinderServersTestCase(test.ScenarioTestCase):
scenario._create_volume = mock.MagicMock(return_value=fake_volume) scenario._create_volume = mock.MagicMock(return_value=fake_volume)
scenario._delete_volume = mock.MagicMock() 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, scenario._attach_volume.assert_called_once_with(fake_server,
fake_volume) fake_volume)
scenario._detach_volume.assert_called_once_with(fake_server, scenario._detach_volume.assert_called_once_with(fake_server,