Fix bug on image_valid_on_flavor

Whether validates flavor's disk or not depends on
booting type of the instance.
If the instance is booted from an image, should validate.
If the instance is booted from a volume, should not validate.

Change-Id: If1f364717cbfc9259808076006c5f6240055f0f0
Closes-Bug: #1596756
This commit is contained in:
Lv Fumei 2016-06-28 10:49:54 +08:00
parent 14bb2716dc
commit 2ea5f31afa
3 changed files with 26 additions and 8 deletions

View File

@ -129,7 +129,7 @@ class NovaServers(utils.NovaScenario,
@types.convert(image={"type": "glance_image"},
flavor={"type": "nova_flavor"})
@validation.image_valid_on_flavor("flavor", "image")
@validation.image_valid_on_flavor("flavor", "image", validate_disk=False)
@validation.required_services(consts.Service.NOVA, consts.Service.CINDER)
@validation.required_openstack(users=True)
@scenario.configure(context={"cleanup": ["nova", "cinder"]})
@ -273,7 +273,7 @@ class NovaServers(utils.NovaScenario,
@types.convert(image={"type": "glance_image"},
flavor={"type": "nova_flavor"})
@validation.image_valid_on_flavor("flavor", "image")
@validation.image_valid_on_flavor("flavor", "image", validate_disk=False)
@validation.required_services(consts.Service.NOVA, consts.Service.CINDER)
@validation.required_openstack(users=True)
@scenario.configure(context={"cleanup": ["nova", "cinder"]})
@ -489,7 +489,7 @@ class NovaServers(utils.NovaScenario,
@types.convert(image={"type": "glance_image"},
flavor={"type": "nova_flavor"},
to_flavor={"type": "nova_flavor"})
@validation.image_valid_on_flavor("flavor", "image")
@validation.image_valid_on_flavor("flavor", "image", validate_disk=False)
@validation.required_services(consts.Service.NOVA, consts.Service.CINDER)
@validation.required_openstack(users=True)
@scenario.configure(context={"cleanup": ["nova", "cinder"]})
@ -643,7 +643,7 @@ class NovaServers(utils.NovaScenario,
@types.convert(image={"type": "glance_image"},
flavor={"type": "nova_flavor"})
@validation.image_valid_on_flavor("flavor", "image")
@validation.image_valid_on_flavor("flavor", "image", validate_disk=False)
@validation.required_services(consts.Service.NOVA, consts.Service.CINDER)
@validation.required_openstack(admin=True, users=True)
@scenario.configure(context={"cleanup": ["nova", "cinder"]})

8
rally/task/validation.py Normal file → Executable file
View File

@ -339,13 +339,17 @@ def flavor_exists(config, clients, deployment, param_name):
@validator
def image_valid_on_flavor(config, clients, deployment, flavor_name,
image_name):
image_name, validate_disk=True):
"""Returns validator for image could be used for current flavor
:param flavor_name: defines which variable should be used
to get flavor id value.
:param image_name: defines which variable should be used
to get image id value.
:param validate_disk: flag to indicate whether to validate flavor's disk.
Should be True if instance is booted from image.
Should be False if instance is booted from volume.
Default value is True.
"""
valid_result, flavor = _get_validated_flavor(config, clients, flavor_name)
@ -361,7 +365,7 @@ def image_valid_on_flavor(config, clients, deployment, flavor_name,
"for requested image '%s'") % (flavor.id, image["id"])
return ValidationResult(False, message)
if flavor.disk:
if flavor.disk and validate_disk:
if image["size"] > flavor.disk * (1024 ** 3):
message = _("The disk size for flavor '%s' is too small "
"for requested image '%s'") % (flavor.id, image["id"])

18
tests/unit/task/test_validation.py Normal file → Executable file
View File

@ -423,9 +423,9 @@ class ValidatorsTestCase(test.TestCase):
mock__get_validated_flavor.return_value = (success, flavor)
mock__get_validated_image.return_value = (success, image)
# test flavor.disk None
validator = self._unwrap_validator(validation.image_valid_on_flavor,
"flavor", "image")
# test ram
flavor.disk = None
flavor.ram = 2
image["min_ram"] = 4
@ -435,7 +435,21 @@ class ValidatorsTestCase(test.TestCase):
result = validator(None, None, None)
self.assertTrue(result.is_valid, result.msg)
# test disk (flavor.disk not None)
# test validate_disk false
validator = self._unwrap_validator(validation.image_valid_on_flavor,
"flavor", "image", False)
flavor.disk = 1
flavor.ram = 2
image["min_ram"] = 4
result = validator(None, None, None)
self.assertFalse(result.is_valid, result.msg)
image["min_ram"] = 1
result = validator(None, None, None)
self.assertTrue(result.is_valid, result.msg)
# test validate_disk true and flavor.disk not None
validator = self._unwrap_validator(validation.image_valid_on_flavor,
"flavor", "image")
image["size"] = 2
image["min_disk"] = 0
flavor.disk = 5.0 / (1024 ** 3)