Merge "Add CinderVolumes.create_volume_and_update_readonly_flag"

This commit is contained in:
Jenkins 2016-10-31 13:27:49 +00:00 committed by Gerrit Code Review
commit 94d160f62b
7 changed files with 133 additions and 0 deletions

View File

@ -166,6 +166,40 @@
failure_rate:
max: 0
CinderVolumes.create_volume_and_update_readonly_flag:
-
args:
size: 1
read_only: true
runner:
type: "constant"
times: 3
concurrency: 2
context:
users:
tenants: 2
users_per_tenant: 2
sla:
failure_rate:
max: 0
-
args:
size: 1
read_only: false
image:
name: {{image_name}}
runner:
type: "constant"
times: 3
concurrency: 2
context:
users:
tenants: 2
users_per_tenant: 2
sla:
failure_rate:
max: 0
CinderVolumes.create_and_list_volume:
-
args:

View File

@ -175,6 +175,18 @@ class CinderScenario(scenario.OpenStackScenario):
client = cinder_wrapper.wrap(self._clients.cinder, self)
client.update_volume(volume, **update_volume_args)
@atomic.action_timer("cinder.update_readonly_flag")
def _update_readonly_flag(self, volume, read_only):
"""Update the read-only access mode flag of the specified volume.
:param volume: The UUID of the volume to update.
:param read_only: The value to indicate whether to update volume to
read-only access mode.
:returns: A tuple of http Response and body
"""
return self.clients("cinder").volumes.update_readonly_flag(
volume, read_only)
@atomic.action_timer("cinder.delete_volume")
def _delete_volume(self, volume):
"""Delete the given volume.

View File

@ -719,3 +719,28 @@ class CreateVolumeFromSnapshot(cinder_utils.CinderScenario,
if do_delete:
self._delete_snapshot(snapshot)
self._delete_volume(volume)
@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"]},
name="CinderVolumes.create_volume_"
"and_update_readonly_flag")
class CreateVolumeAndUpdateReadonlyFlag(cinder_utils.CinderScenario,
glance_utils.GlanceScenario):
def run(self, size, image=None, read_only=True, **kwargs):
"""Create a volume and then update its readonly flag.
:param size: volume size (integer, in GB)
:param image: image to be used to create volume
:param read_only:The value to indicate whether to update volume to
read-only access mode
:param kwargs: optional args to create a volume
"""
if image:
kwargs["imageRef"] = image
volume = self._create_volume(size, **kwargs)
self._update_readonly_flag(volume.id, read_only)

View File

@ -0,0 +1,26 @@
{
"CinderVolumes.create_volume_and_update_readonly_flag": [
{
"args": {
"size": 1,
"read_only": true
},
"runner": {
"type": "constant",
"times": 3,
"concurrency": 2
},
"context": {
"users": {
"tenants": 2,
"users_per_tenant": 2
}
},
"sla": {
"failure_rate": {
"max": 0
}
}
}
]
}

View File

@ -0,0 +1,17 @@
---
CinderVolumes.create_volume_and_update_readonly_flag:
-
args:
size: 1
read_only: true
runner:
type: "constant"
times: 3
concurrency: 2
context:
users:
tenants: 2
users_per_tenant: 2
sla:
failure_rate:
max: 0

View File

@ -152,6 +152,15 @@ class CinderScenarioTestCase(test.ScenarioTestCase):
self._test_atomic_action_timer(self.scenario.atomic_actions(),
"cinder.update_volume")
def test__update_readonly_flag(self):
fake_volume = mock.MagicMock()
self.scenario._update_readonly_flag(fake_volume, "fake_flag")
self.clients(
"cinder").volumes.update_readonly_flag.assert_called_once_with(
fake_volume, "fake_flag")
self._test_atomic_action_timer(self.scenario.atomic_actions(),
"cinder.update_readonly_flag")
def test__delete_volume(self):
cinder = mock.Mock()
self.scenario._delete_volume(cinder)

View File

@ -71,6 +71,16 @@ class CinderServersTestCase(test.ScenarioTestCase):
scenario._update_volume.assert_called_once_with(fake_volume,
**volume_update_args)
def test_create_volume_and_update_readonly_flag(self):
scenario = volumes.CreateVolumeAndUpdateReadonlyFlag(self.context)
fake_volume = mock.MagicMock()
scenario._create_volume = mock.MagicMock(return_value=fake_volume)
scenario._update_readonly_flag = mock.MagicMock()
scenario.run(1, None, True, fakearg="f")
scenario._create_volume.assert_called_once_with(1, fakearg="f")
scenario._update_readonly_flag.assert_called_once_with(
fake_volume.id, True)
def test_create_and_delete_volume(self):
fake_volume = mock.MagicMock()