Merge "Add validation for glance image"
This commit is contained in:
commit
d360b2d419
heat
@ -11,6 +11,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from heat.common import exception
|
||||
from heat.common.i18n import _
|
||||
from heat.engine import constraints
|
||||
from heat.engine import properties
|
||||
@ -126,6 +127,17 @@ class GlanceImage(resource.Resource):
|
||||
image = self.glance().images.get(self.resource_id)
|
||||
return dict(image)
|
||||
|
||||
def validate(self):
|
||||
super(GlanceImage, self).validate()
|
||||
container_format = self.properties[self.CONTAINER_FORMAT]
|
||||
if (container_format in ['ami', 'ari', 'aki']
|
||||
and self.properties[self.DISK_FORMAT] != container_format):
|
||||
msg = _("Invalid mix of disk and container formats. When "
|
||||
"setting a disk or container format to one of 'aki', "
|
||||
"'ari', or 'ami', the container and disk formats must "
|
||||
"match.")
|
||||
raise exception.StackValidationFailed(message=msg)
|
||||
|
||||
|
||||
def resource_mapping():
|
||||
return {
|
||||
|
@ -177,6 +177,21 @@ class GlanceImageTest(common.HeatTestCase):
|
||||
error_msg = 'Property location not assigned'
|
||||
self._test_validate(image, error_msg)
|
||||
|
||||
def test_invalid_disk_container_mix(self):
|
||||
tpl = template_format.parse(image_template_validate)
|
||||
stack = parser.Stack(
|
||||
self.ctx, 'glance_image_stack_validate',
|
||||
template.Template(tpl)
|
||||
)
|
||||
image = stack['image']
|
||||
image.t['Properties']['disk_format'] = 'raw'
|
||||
image.t['Properties']['container_format'] = 'ari'
|
||||
error_msg = ("Invalid mix of disk and container formats. When "
|
||||
"setting a disk or container format to one of 'aki', "
|
||||
"'ari', or 'ami', the container and disk formats must "
|
||||
"match.")
|
||||
self._test_validate(image, error_msg)
|
||||
|
||||
def test_image_handle_create(self):
|
||||
value = mock.MagicMock()
|
||||
image_id = '41f0e60c-ebb4-4375-a2b4-845ae8b9c995'
|
||||
|
Loading…
x
Reference in New Issue
Block a user