Add glance.DownloadImageData scenario

Create an image, then download data of the image

Change-Id: I4e1de26f3e8cd883b5cf881c76cfd29d7d65ee62
This commit is contained in:
zhangzhang 2017-02-15 04:29:51 -05:00 committed by Andrey Kurilin
parent 783199468c
commit 04e50d71ab
9 changed files with 175 additions and 0 deletions

View File

@ -474,6 +474,24 @@
failure_rate:
max: 100
GlanceImages.create_and_download_image:
-
args:
image_location: "{{ cirros_image_url }}"
container_format: "bare"
disk_format: "qcow2"
runner:
type: "constant"
times: 4
concurrency: 2
context:
users:
tenants: 2
users_per_tenant: 2
sla:
failure_rate:
max: 0
GlanceImages.create_and_delete_image:
# -
# args:

View File

@ -334,3 +334,44 @@ class CreateAndDeactivateImage(GlanceBasic):
min_disk=min_disk,
min_ram=min_ram)
service.deactivate_image(image.id)
@validation.add("enum", param_name="container_format",
values=["ami", "ari", "aki", "bare", "ovf"])
@validation.add("enum", param_name="disk_format",
values=["ami", "ari", "aki", "vhd", "vmdk", "raw",
"qcow2", "vdi", "iso"])
@types.convert(image_location={"type": "path_or_url"},
kwargs={"type": "glance_image_args"})
@validation.add("required_services", services=[consts.Service.GLANCE])
@validation.add("required_platform", platform="openstack", users=True)
@scenario.configure(context={"cleanup": ["glance"]},
name="GlanceImages.create_and_download_image",
platform="openstack")
class CreateAndDownloadImage(GlanceBasic):
def run(self, container_format, image_location, disk_format,
visibility="private", min_disk=0, min_ram=0, properties=None):
"""Create an image, then download data of the image.
:param container_format: container format of image. Acceptable
formats: ami, ari, aki, bare, and ovf
:param image_location: image file location
:param disk_format: disk format of image. Acceptable formats:
ami, ari, aki, vhd, vmdk, raw, qcow2, vdi, and iso
:param visibility: The access permission for the created image
:param min_disk: The min disk of created images
:param min_ram: The min ram of created images
:param properties: A dict of image metadata properties to set
on the image
"""
image = self.glance.create_image(
container_format=container_format,
image_location=image_location,
disk_format=disk_format,
visibility=visibility,
min_disk=min_disk,
min_ram=min_ram,
properties=properties)
self.glance.download_image(image.id)

View File

@ -43,6 +43,18 @@ class GlanceMixin(object):
with atomic.ActionTimer(self, aname):
self._get_client().images.delete(image_id)
def download_image(self, image_id, do_checksum=True):
"""Retrieve data of an image.
:param image_id: ID of the image to download.
:param do_checksum: Enable/disable checksum validation.
:returns: An iterable body or None
"""
aname = "glance_v%s.download_image" % self.version
with atomic.ActionTimer(self, aname):
return self._get_client().images.data(image_id,
do_checksum=do_checksum)
class UnifiedGlanceMixin(object):
@ -69,3 +81,12 @@ class UnifiedGlanceMixin(object):
def delete_image(self, image_id):
"""Delete image."""
self._impl.delete_image(image_id=image_id)
def download_image(self, image_id, do_checksum=True):
"""Download data for an image.
:param image_id: image id to look up
:param do_checksum: Enable/disable checksum validation
:rtype: iterable containing image data or None
"""
return self._impl.download_image(image_id, do_checksum=do_checksum)

View File

@ -121,3 +121,13 @@ class Image(service.UnifiedService):
def delete_image(self, image_id):
"""delete image."""
self._impl.delete_image(image_id)
@service.should_be_overridden
def download_image(self, image, do_checksum=True):
"""Download data for an image.
:param image: image object or id to look up
:param do_checksum: Enable/disable checksum validation
:rtype: iterable containing image data or None
"""
return self._impl.download_image(image, do_checksum=do_checksum)

View File

@ -0,0 +1,28 @@
{
"GlanceImages.create_and_download_image": [
{
"args": {
"image_location": "http://download.cirros-cloud.net/0.3.4/cirros-0.3.4-x86_64-disk.img",
"container_format": "bare",
"disk_format": "qcow2"
},
"runner": {
"type": "constant",
"times": 10,
"concurrency": 2
},
"context": {
"users": {
"tenants": 2,
"users_per_tenant": 3
}
},
"sla": {
"failure_rate": {
"max": 0
}
}
}
]
}

View File

@ -0,0 +1,18 @@
---
GlanceImages.create_and_download_image:
-
args:
image_location: "http://download.cirros-cloud.net/0.3.4/cirros-0.3.4-x86_64-disk.img"
container_format: "bare"
disk_format: "qcow2"
runner:
type: "constant"
times: 10
concurrency: 2
context:
users:
tenants: 2
users_per_tenant: 3
sla:
failure_rate:
max: 0

View File

@ -156,6 +156,26 @@ class GlanceBasicTestCase(test.ScenarioTestCase):
image_service.get_image.assert_called_with(
image_service.create_image.return_value)
def test_create_and_download_image(self):
image_service = self.mock_image.return_value
fake_image = fakes.FakeImage()
image_service.create_image.return_value = fake_image
properties = {"fakeprop": "fake"}
call_args = {"container_format": "cf",
"image_location": "url",
"disk_format": "df",
"visibility": "vs",
"min_disk": 0,
"min_ram": 0,
"properties": properties}
images.CreateAndDownloadImage(self.context).run(
"cf", "url", "df", "vs", 0, 0, properties=properties)
image_service.create_image.assert_called_once_with(**call_args)
image_service.download_image.assert_called_once_with(fake_image.id)
@mock.patch("%s.CreateImageAndBootInstances._boot_servers" % BASE)
def test_create_image_and_boot_instances(self, mock_boot_servers):
image_service = self.mock_image.return_value

View File

@ -62,6 +62,12 @@ class GlanceMixinTestCase(test.TestCase):
self.service.delete_image(image)
self.glance.images.delete.assert_called_once_with(image)
def test_download_image(self):
image_id = "image_id"
self.service.download_image(image_id)
self.glance.images.data.assert_called_once_with(image_id,
do_checksum=True)
class FullUnifiedGlance(glance_common.UnifiedGlanceMixin,
service.Service):
@ -113,3 +119,9 @@ class UnifiedGlanceMixinTestCase(test.TestCase):
self.service.delete_image(image_id)
self.service._impl.delete_image.assert_called_once_with(
image_id=image_id)
def test_download_image(self):
image_id = "image_id"
self.service.download_image(image_id)
self.service._impl.download_image.assert_called_once_with(
image_id, do_checksum=True)

View File

@ -101,6 +101,13 @@ class ImageTestCase(test.TestCase):
service.delete_image(image_id=image_id)
service._impl.delete_image.assert_called_once_with(image_id)
def test_download_image(self):
image_id = "image_id"
service = self.get_service_with_fake_impl()
service.download_image(image=image_id, do_checksum=True)
service._impl.download_image.assert_called_once_with(image_id,
do_checksum=True)
def test_is_applicable(self):
clients = mock.Mock()