Added properties to config and added new method to behavior

* Updated config and refernce config with new properties
* Added wait_for_image_status() method to Images behavior
* Fixed rebase issues and corrected imports

Change-Id: I31ee4ba653a66932d3e0cf3ea7c27662069401bd
This commit is contained in:
Nandhini Devi Kaliaperumal 2013-12-04 21:08:02 -06:00
parent e57dd5552d
commit 1fcaccbf14
3 changed files with 77 additions and 1 deletions

View File

@ -61,6 +61,26 @@ class ImagesConfig(ConfigSectionInterface):
def region(self):
return self.get('region')
@property
def primary_image(self):
"""Default image to be used when building servers in glance test"""
return self.get("primary_image")
@property
def secondary_image(self):
"""Alternate image to be used in glance test"""
return self.get("secondary_image")
@property
def image_status_interval(self):
"""Amount of time to wait between polling the status of an image"""
return int(self.get("image_status_interval"))
@property
def snapshot_timeout(self):
"""Length of time to wait before giving up on reaching a status"""
return int(self.get("snapshot_timeout"))
@property
def min_disk(self):
return int(self.get('min_disk'))

View File

@ -14,11 +14,14 @@ See the License for the specific language governing permissions and
limitations under the License.
"""
import time
from cafe.engine.behaviors import BaseBehavior
from cloudcafe.common.exceptions import BuildErrorException, TimeoutException
from cloudcafe.common.resources import ResourcePool
from cloudcafe.common.tools.datagen import rand_name
from cloudcafe.images.common.types import ImageContainerFormat, \
ImageDiskFormat, Schemas
ImageDiskFormat, ImageStatus, Schemas
class ImagesBehaviors(BaseBehavior):
@ -161,3 +164,46 @@ class ImagesBehaviors(BaseBehavior):
if image_member.updated_at is None:
errors.append(self.error_msg.format('updated_at', not None, None))
return errors
def wait_for_image_status(self, image_id, desired_status,
interval_time=None, timeout=None):
"""
@summary: Waits for a image to reach a desired status
@param image_id: The uuid of the image
@type image_id: String
@param desired_status: The desired final status of the image
@type desired_status: String
@param interval_time: The amount of time in seconds to wait
between polling
@type interval_time: Integer
@param timeout: The amount of time in seconds to wait
before aborting
@type timeout: Integer
@return: Response object containing response and the image
domain object
@rtype: requests.Response
"""
interval_time = interval_time or self.config.image_status_interval
timeout = timeout or self.config.snapshot_timeout
end_time = time.time() + timeout
while time.time() < end_time:
resp = self.client.get_image(image_id)
image = resp.entity
if image.status.lower() == ImageStatus.ERROR.lower():
raise BuildErrorException(
"Build failed. Image with uuid {0} "
"entered ERROR status.".format(image.id))
if image.status == desired_status:
break
time.sleep(interval_time)
else:
raise TimeoutException(
"wait_for_image_status ran for {0} seconds and did not "
"observe image {1} reach the {2} status.".format(
timeout, image_id, desired_status))
return resp

View File

@ -32,8 +32,18 @@ username=<username>
password=<password>
tenant_name=<tenant_name>
[compute_endpoint]
region=<region>
compute_endpoint_name=<compute_name>
[flavors]
primary_flavor=<flavor_id>
secondary_flavor=<different_flavor_id>
[images]
base_url=<http://x.x.x.x:9292>
primary_image=<image_id>
secondary_image=<different_image_id>
image_status_interval=15
snapshot_timeout=900
created_at_offset=300