[glance]delete redundant validation

such as create_and_list_images scenario, I have specifed all available
variables explicitly, so kwargs will not be used at all, and now we can delete
validation.restricted_parameters(["image_name", "name"])

Change-Id: I0b0f522ec6b450cce334f6129a2959699eba4212
This commit is contained in:
zhangzhang 2017-05-19 07:48:41 -04:00
parent 6fe3134545
commit 41e33c027c
2 changed files with 63 additions and 24 deletions

View File

@ -39,7 +39,11 @@ class GlanceBasic(scenario.OpenStackScenario):
atomic_inst=self.atomic_actions())
@validation.restricted_parameters(["image_name", "name"])
@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])
@ -48,7 +52,8 @@ class GlanceBasic(scenario.OpenStackScenario):
name="GlanceImages.create_and_list_image")
class CreateAndListImage(GlanceBasic):
def run(self, container_format, image_location, disk_format, **kwargs):
def run(self, container_format, image_location, disk_format,
visibility="private", min_disk=0, min_ram=0):
"""Create an image and then list all images.
Measure the "glance image-list" command performance.
@ -64,18 +69,27 @@ class CreateAndListImage(GlanceBasic):
: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 kwargs: optional parameters to create image
: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
"""
image = self.glance.create_image(
container_format=container_format,
image_location=image_location,
disk_format=disk_format,
**kwargs)
visibility=visibility,
min_disk=min_disk,
min_ram=min_ram)
self.assertTrue(image)
image_list = self.glance.list_images()
self.assertIn(image.id, [i.id for i in image_list])
@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])
@ -128,7 +142,11 @@ class ListImages(GlanceBasic):
self.glance.list_images()
@validation.restricted_parameters(["image_name", "name"])
@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])
@ -137,7 +155,8 @@ class ListImages(GlanceBasic):
name="GlanceImages.create_and_delete_image")
class CreateAndDeleteImage(GlanceBasic):
def run(self, container_format, image_location, disk_format, **kwargs):
def run(self, container_format, image_location, disk_format,
visibility="private", min_disk=0, min_ram=0):
"""Create and then delete an image.
:param container_format: container format of image. Acceptable
@ -145,17 +164,25 @@ class CreateAndDeleteImage(GlanceBasic):
: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 kwargs: optional parameters to create image
: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
"""
image = self.glance.create_image(
container_format=container_format,
image_location=image_location,
disk_format=disk_format,
**kwargs)
visibility=visibility,
min_disk=min_disk,
min_ram=min_ram)
self.glance.delete_image(image.id)
@validation.restricted_parameters(["image_name", "name"])
@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(flavor={"type": "nova_flavor"},
image_location={"type": "path_or_url"},
kwargs={"type": "glance_image_args"})
@ -168,8 +195,8 @@ class CreateAndDeleteImage(GlanceBasic):
class CreateImageAndBootInstances(GlanceBasic, nova_utils.NovaScenario):
def run(self, container_format, image_location, disk_format,
flavor, number_instances, create_image_kwargs=None,
boot_server_kwargs=None, **kwargs):
flavor, number_instances, visibility="private", min_disk=0,
min_ram=0, boot_server_kwargs=None, **kwargs):
"""Create an image and boot several instances from it.
:param container_format: container format of image. Acceptable
@ -177,13 +204,15 @@ class CreateImageAndBootInstances(GlanceBasic, nova_utils.NovaScenario):
: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 flavor: Nova flavor to be used to launch an instance
:param number_instances: number of Nova servers to boot
:param create_image_kwargs: optional parameters to create image
:param boot_server_kwargs: optional parameters to boot server
:param kwargs: optional parameters to create server (deprecated)
"""
create_image_kwargs = create_image_kwargs or {}
boot_server_kwargs = boot_server_kwargs or kwargs or {}
if kwargs:
@ -195,12 +224,19 @@ class CreateImageAndBootInstances(GlanceBasic, nova_utils.NovaScenario):
container_format=container_format,
image_location=image_location,
disk_format=disk_format,
**create_image_kwargs)
visibility=visibility,
min_disk=min_disk,
min_ram=min_ram)
self._boot_servers(image.id, flavor, number_instances,
**boot_server_kwargs)
@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])

View File

@ -59,18 +59,19 @@ class GlanceBasicTestCase(test.ScenarioTestCase):
call_args = {"container_format": "cf",
"image_location": "url",
"disk_format": "df",
"fakearg": "f"}
"visibility": "vs",
"min_disk": 0,
"min_ram": 0}
# Positive case
images.CreateAndListImage(self.context).run(
"cf", "url", "df", fakearg="f")
"cf", "url", "df", "vs", 0, 0)
image_service.create_image.assert_called_once_with(**call_args)
# Negative case: image isn't created
image_service.create_image.return_value = None
self.assertRaises(exceptions.RallyAssertionError,
images.CreateAndListImage(self.context).run,
"cf", "url", "df", fakearg="f")
"cf", "url", "df", "vs", 0, 0)
image_service.create_image.assert_called_with(**call_args)
# Negative case: created image n ot in the list of available images
@ -78,7 +79,7 @@ class GlanceBasicTestCase(test.ScenarioTestCase):
id=12, name="img_nameN")
self.assertRaises(exceptions.RallyAssertionError,
images.CreateAndListImage(self.context).run,
"cf", "url", "df", fakearg="f")
"cf", "url", "df", "vs", 0, 0)
image_service.create_image.assert_called_with(**call_args)
image_service.list_images.assert_called_with()
@ -96,10 +97,12 @@ class GlanceBasicTestCase(test.ScenarioTestCase):
call_args = {"container_format": "cf",
"image_location": "url",
"disk_format": "df",
"fakearg": "f"}
"visibility": "vs",
"min_disk": 0,
"min_ram": 0}
images.CreateAndDeleteImage(self.context).run(
"cf", "url", "df", fakearg="f")
"cf", "url", "df", "vs", 0, 0)
image_service.create_image.assert_called_once_with(**call_args)
image_service.delete_image.assert_called_once_with(fake_image.id)
@ -153,16 +156,16 @@ class GlanceBasicTestCase(test.ScenarioTestCase):
fake_servers = [mock.Mock() for i in range(5)]
image_service.create_image.return_value = fake_image
mock_boot_servers.return_value = fake_servers
create_image_kwargs = {"fakeimagearg": "f"}
boot_server_kwargs = {"fakeserverarg": "f"}
call_args = {"container_format": "cf",
"image_location": "url",
"disk_format": "df",
"fakeimagearg": "f"}
"visibility": "vs",
"min_disk": 0,
"min_ram": 0}
images.CreateImageAndBootInstances(self.context).run(
"cf", "url", "df", "fid", 5,
create_image_kwargs=create_image_kwargs,
"cf", "url", "df", "fid", 5, "vs", 0, 0,
boot_server_kwargs=boot_server_kwargs)
image_service.create_image.assert_called_once_with(**call_args)
mock_boot_servers.assert_called_once_with("image-id-0", "fid",