Merge "Add CinderVolumes.create_volume_and_clone"

This commit is contained in:
Jenkins 2016-05-12 13:34:23 +00:00 committed by Gerrit Code Review
commit dd83ba9758
6 changed files with 139 additions and 1 deletions

View File

@ -629,3 +629,19 @@
sla:
failure_rate:
max: 0
CinderVolumes.create_volume_and_clone:
-
args:
size: 1
runner:
type: "constant"
times: 3
concurrency: 2
context:
users:
tenants: 2
users_per_tenant: 2
sla:
failure_rate:
max: 0

View File

@ -115,7 +115,7 @@ class CinderScenario(scenario.OpenStackScenario):
to_del = keys[i * delete_size:(i + 1) * delete_size]
self.clients("cinder").volumes.delete_metadata(volume, to_del)
@atomic.action_timer("cinder.create_volume")
@atomic.optional_action_timer("cinder.create_volume")
def _create_volume(self, size, **kwargs):
"""Create one volume.
@ -126,6 +126,9 @@ class CinderScenario(scenario.OpenStackScenario):
dictionary, must contain two values:
min - minimum size volumes will be created as;
max - maximum size volumes will be created as.
:param atomic_action: True if this is an atomic action. added
and handled by the
optional_action_timer() decorator
:param kwargs: Other optional parameters to initialize the volume
:returns: Created volume object
"""

View File

@ -22,6 +22,7 @@ from rally.plugins.openstack import scenario
from rally.plugins.openstack.scenarios.cinder import utils as cinder_utils
from rally.plugins.openstack.scenarios.glance import utils as glance_utils
from rally.plugins.openstack.scenarios.nova import utils as nova_utils
from rally.task import atomic
from rally.task import types
from rally.task import validation
@ -540,3 +541,28 @@ class CinderVolumes(cinder_utils.CinderScenario,
if do_delete:
self._delete_volume(volume)
self._delete_backup(backup)
@types.convert(image={"type": "glance_image"})
@validation.image_exists("image", nullable=True)
@validation.required_services(consts.Service.CINDER)
@validation.required_openstack(users=True)
@scenario.configure(context={"cleanup": ["cinder"]})
def create_volume_and_clone(self, size, image=None, **kwargs):
"""Create a volume, then clone it to another volume.
:param size: volume size (integer, in GB) or
dictionary, must contain two values:
min - minimum size volumes will be created as;
max - maximum size volumes will be created as.
:param image: image to be used to create initial volume
:param kwargs: optional args to create volumes
"""
if image:
kwargs["imageRef"] = image
vol1 = self._create_volume(size, **kwargs)
kwargs.pop("imageRef", None)
with atomic.ActionTimer(self, "cinder.clone_volume"):
self._create_volume(size, source_volid=vol1.id,
atomic_action=False, **kwargs)

View File

@ -0,0 +1,39 @@
{
"CinderVolumes.create_volume_and_clone": [
{
"args": {
"size": 1
},
"runner": {
"type": "constant",
"times": 3,
"concurrency": 2
},
"context": {
"users": {
"tenants": 2,
"users_per_tenant": 2
}
}
},
{
"args": {
"size": {
"min": 1,
"max": 5
}
},
"runner": {
"type": "constant",
"times": 3,
"concurrency": 2
},
"context": {
"users": {
"tenants": 2,
"users_per_tenant": 2
}
}
}
]
}

View File

@ -0,0 +1,26 @@
---
CinderVolumes.create_volume_and_clone:
-
args:
size: 1
runner:
type: "constant"
times: 3
concurrency: 2
context:
users:
tenants: 2
users_per_tenant: 2
-
args:
size:
min: 1
max: 5
runner:
type: "constant"
times: 3
concurrency: 2
context:
users:
tenants: 2
users_per_tenant: 2

View File

@ -490,3 +490,31 @@ class CinderServersTestCase(test.ScenarioTestCase):
scenario._list_backups.assert_called_once_with(True)
self.assertFalse(scenario._delete_volume.called)
self.assertFalse(scenario._delete_backup.called)
def test_create_volume_and_clone(self):
fake_volumes = [mock.Mock(), mock.Mock()]
scenario = volumes.CinderVolumes(self.context)
scenario._create_volume = mock.MagicMock(side_effect=fake_volumes)
scenario.create_volume_and_clone(1, fakearg="fake")
scenario._create_volume.assert_has_calls([
mock.call(1, fakearg="fake"),
mock.call(1, source_volid=fake_volumes[0].id, atomic_action=False,
fakearg="fake")])
self._test_atomic_action_timer(scenario.atomic_actions(),
"cinder.clone_volume")
def test_create_volume_and_clone_from_image(self):
fake_volumes = [mock.Mock(), mock.Mock()]
scenario = volumes.CinderVolumes(self.context)
scenario._create_volume = mock.MagicMock(side_effect=fake_volumes)
scenario.create_volume_and_clone(1, image="image_id", fakearg="fake")
scenario._create_volume.assert_has_calls([
mock.call(1, fakearg="fake", imageRef="image_id"),
mock.call(1, source_volid=fake_volumes[0].id, atomic_action=False,
fakearg="fake")])
self._test_atomic_action_timer(scenario.atomic_actions(),
"cinder.clone_volume")