Add validate image member method to behaviors
*Added validate_image_member method to images behaviors *Added messages class to contansts *Added error_message to constants to be used with validate_image_member method *Updated error_message to ERROR_MSG for consistency in constants module *Removed constants module from the common package since images only uses it *Added validate_image method to images behaviors *Updated valid_image_member method to account for fixture and behavior changes *Fixed rebase issues Change-Id: Ieefde29c79c01dfa86295cd384d6f75e2412e82b
This commit is contained in:
parent
469b8cd7da
commit
6d4b426ada
@ -1,19 +0,0 @@
|
||||
"""
|
||||
Copyright 2013 Rackspace
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
"""
|
||||
|
||||
|
||||
class Messages:
|
||||
ASSERT_MSG = "Unexpected {0} value received. Expected: {1}, Received: {2}"
|
@ -23,3 +23,7 @@ class HTTPResponseCodes(object):
|
||||
class ImageProperties(object):
|
||||
ID_REGEX = ('^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-'
|
||||
'[0-9a-fA-F]{12}$')
|
||||
|
||||
|
||||
class Messages(object):
|
||||
ERROR_MSG = 'Unexpected {0} value received. Expected: {1}, Received: {2}'
|
||||
|
@ -17,8 +17,8 @@ limitations under the License.
|
||||
from cafe.engine.behaviors import BaseBehavior
|
||||
from cloudcafe.common.resources import ResourcePool
|
||||
from cloudcafe.common.tools.datagen import rand_name
|
||||
from cloudcafe.images.common.types import \
|
||||
ImageContainerFormat, ImageDiskFormat
|
||||
from cloudcafe.images.common.types import ImageContainerFormat, \
|
||||
ImageDiskFormat, Schemas
|
||||
|
||||
|
||||
class ImagesBehaviors(BaseBehavior):
|
||||
@ -107,3 +107,57 @@ class ImagesBehaviors(BaseBehavior):
|
||||
response = self.client.list_members(image_id)
|
||||
members = response.entity
|
||||
return [member.member_id for member in members]
|
||||
|
||||
def validate_image(self, image):
|
||||
"""@summary: Generically validate an image contains crucial expected
|
||||
data
|
||||
"""
|
||||
|
||||
errors = []
|
||||
if image.created_at is None:
|
||||
errors.append(self.error_msg.format('created_at', not None, None))
|
||||
if image.file_ != '/v2/images/{0}/file'.format(image.id_):
|
||||
errors.append(self.error_msg.format(
|
||||
'file_', '/v2/images/{0}/file'.format(image.id_), image.file_))
|
||||
if self.id_regex.match(image.id_) is None:
|
||||
errors.append(self.error_msg.format('id_', not None, None))
|
||||
if image.min_disk is None:
|
||||
errors.append(self.error_msg.format('min_disk', not None, None))
|
||||
if image.min_ram is None:
|
||||
errors.append(self.error_msg.format('min_ram', not None, None))
|
||||
if image.protected is None:
|
||||
errors.append(self.error_msg.format('protected', not None, None))
|
||||
if image.schema != Schemas.IMAGE_SCHEMA:
|
||||
errors.append(self.error_msg.format(
|
||||
'schema', Schemas.IMAGE_SCHEMA, image.schema))
|
||||
if image.self_ != '/v2/images/{0}'.format(image.id_):
|
||||
errors.append(self.error_msg.format(
|
||||
'schema', '/v2/images/{0}'.format(image.id_), image.self_))
|
||||
if image.status is None:
|
||||
errors.append(self.error_msg.format('status', not None, None))
|
||||
if image.updated_at is None:
|
||||
errors.append(self.error_msg.format('updated_at', not None, None))
|
||||
return errors
|
||||
|
||||
def validate_image_member(self, image_id, image_member, member_id):
|
||||
"""@summary: Generically validate an image member contains crucial
|
||||
expected data
|
||||
"""
|
||||
|
||||
errors = []
|
||||
if image_member.created_at is None:
|
||||
errors.append(self.error_msg.format('created_at', not None, None))
|
||||
if image_member.image_id != image_id:
|
||||
errors.append(self.error_msg.format(
|
||||
'image_id', image_id, image_member.image_id))
|
||||
if image_member.member_id != member_id:
|
||||
errors.append(self.error_msg.format(
|
||||
'member_id', member_id, image_member.member_id))
|
||||
if image_member.schema != Schemas.IMAGE_MEMBER_SCHEMA:
|
||||
errors.append(self.error_msg.format(
|
||||
'schema', Schemas.IMAGE_MEMBER_SCHEMA, image_member.schema))
|
||||
if image_member.status is None:
|
||||
errors.append(self.error_msg.format('status', not None, None))
|
||||
if image_member.updated_at is None:
|
||||
errors.append(self.error_msg.format('updated_at', not None, None))
|
||||
return errors
|
||||
|
Loading…
x
Reference in New Issue
Block a user