Add NoverServers.boot_server_from_volume_snapshot

The scenario first creates a volume and creates a
snapshot from this volume, then boots a server from
the created snapshot.

Change-Id: Ib2a320ab097ac05c104729223cc4ae1e53365144
This commit is contained in:
chenhb-zte 2016-06-14 19:23:19 -04:00
parent c11108a6e3
commit d201049cfb
5 changed files with 113 additions and 0 deletions
rally-jobs
rally/plugins/openstack/scenarios/nova
samples/tasks/scenarios/nova
tests/unit/plugins/openstack/scenarios/nova

@ -1098,3 +1098,23 @@
sla:
failure_rate:
max: 0
NovaServers.boot_server_from_volume_snapshot:
-
args:
flavor:
name: {{flavor_name}}
image:
name: {{image_name}}
volume_size: 1
runner:
type: "constant"
times: 2
concurrency: 2
context:
users:
tenants: 2
users_per_tenant: 2
sla:
failure_rate:
max: 0

@ -881,3 +881,31 @@ class NovaServers(utils.NovaScenario,
"""
server = self._boot_server(image, flavor, **kwargs)
self._update_server(server, description)
@types.convert(image={"type": "glance_image"},
flavor={"type": "nova_flavor"})
@validation.image_valid_on_flavor("flavor", "image")
@validation.required_services(consts.Service.NOVA, consts.Service.CINDER)
@validation.required_openstack(users=True)
@scenario.configure(context={"cleanup": ["nova", "cinder"]})
def boot_server_from_volume_snapshot(self, image, flavor, volume_size,
auto_assign_nic=False, **kwargs):
"""Boot a server from a snapshot.
The scenario first creates a volume and creates a
snapshot from this volume, then boots a server from
the created snapshot.
Assumes that cleanup is done elsewhere.
:param image: image to be used to boot an instance
:param flavor: flavor to be used to boot an instance
:param volume_size: volume size (in GB)
:param auto_assign_nic: True if NICs should be assigned
:param kwargs: Optional additional arguments for server creation
"""
volume = self._create_volume(volume_size, imageRef=image)
snapshot = self._create_snapshot(volume.id, False)
block_device_mapping = {"vda": "%s:snap::1" % snapshot.id}
self._boot_server(None, flavor, auto_assign_nic=auto_assign_nic,
block_device_mapping=block_device_mapping,
**kwargs)

@ -0,0 +1,27 @@
{% set flavor_name = flavor_name or "m1.tiny" %}
{
"NovaServers.boot_server_from_volume_snapshot": [
{
"args": {
"flavor": {
"name": "{{flavor_name}}"
},
"image": {
"name": "^cirros.*uec$"
},
"volume_size": 10
},
"runner": {
"type": "constant",
"times": 10,
"concurrency": 2
},
"context": {
"users": {
"tenants": 3,
"users_per_tenant": 2
}
}
}
]
}

@ -0,0 +1,18 @@
{% set flavor_name = flavor_name or "m1.tiny" %}
---
NovaServers.boot_server_from_volume_snapshot:
-
args:
flavor:
name: "{{flavor_name}}"
image:
name: "^cirros.*uec$"
volume_size: 10
runner:
type: "constant"
times: 10
concurrency: 2
context:
users:
tenants: 3
users_per_tenant: 2

@ -769,3 +769,23 @@ class NovaServersTestCase(test.ScenarioTestCase):
fakearg="fakearg")
scenario._update_server.assert_called_once_with(
scenario._boot_server.return_value, "desp")
def test_boot_server_from_volume_snapshot(self):
fake_volume = mock.MagicMock(id="volume_id")
fake_snapshot = mock.MagicMock(id="snapshot_id")
scenario = servers.NovaServers(self.context)
scenario._boot_server = mock.MagicMock()
scenario._create_volume = mock.MagicMock(return_value=fake_volume)
scenario._create_snapshot = mock.MagicMock(return_value=fake_snapshot)
scenario.boot_server_from_volume_snapshot("img", "flavor", 1,
auto_assign_nic=False,
fakearg="f")
scenario._create_volume.assert_called_once_with(1, imageRef="img")
scenario._create_snapshot.assert_called_once_with("volume_id", False)
scenario._boot_server.assert_called_once_with(
None, "flavor", auto_assign_nic=False,
block_device_mapping={"vda": "snapshot_id:snap::1"},
fakearg="f")