Fix check_snapshot_complete for nova server

Now that we're making glance client api calls to get the image
after the snapshot is created, the image status is returned
in lower case.

This also fixes handle_delete_snapshot to make the correct
client api call.

Change-Id: I60c84d4bc3ba75604b0c5bd6c4819cd0504f1cc8
Closes-Bug: #1691939
This commit is contained in:
rabi 2017-05-19 11:39:48 +05:30
parent 7e8c9a9c26
commit 660d8d517d
1 changed files with 11 additions and 9 deletions

View File

@ -143,8 +143,9 @@ class Server(server_base.BaseServer, sh.SchedulerHintsMixin,
'instance_name', 'accessIPv4', 'accessIPv6', 'console_urls', 'tags'
)
# valid image Status
IMAGE_STATUS_ACTIVE = 'active'
# Image Statuses
IMAGE_STATUSES = (IMAGE_ACTIVE, IMAGE_ERROR,
IMAGE_DELETED) = ('active', 'error', 'deleted')
properties_schema = {
NAME: properties.Schema(
@ -1336,10 +1337,10 @@ class Server(server_base.BaseServer, sh.SchedulerHintsMixin,
return
raise
else:
if image_obj.status.lower() != self.IMAGE_STATUS_ACTIVE:
if image_obj.status.lower() != self.IMAGE_ACTIVE:
msg = _('Image status is required to be %(cstatus)s not '
'%(wstatus)s.') % {
'cstatus': self.IMAGE_STATUS_ACTIVE,
'cstatus': self.IMAGE_ACTIVE,
'wstatus': image_obj.status}
raise exception.StackValidationFailed(message=msg)
@ -1499,9 +1500,10 @@ class Server(server_base.BaseServer, sh.SchedulerHintsMixin,
return True
if not prg.image_complete:
image = self.client_plugin('glance').get_image(prg.image_id)
if image.status in ('DELETED', 'ERROR'):
if image.status.lower() in (self.IMAGE_ERROR,
self.IMAGE_DELETED):
raise exception.Error(image.status)
elif image.status == 'ACTIVE':
elif image.status.lower() == self.IMAGE_ACTIVE:
prg.image_complete = True
if not self._delete():
return True
@ -1591,9 +1593,9 @@ class Server(server_base.BaseServer, sh.SchedulerHintsMixin,
def check_snapshot_complete(self, image_id):
image = self.client_plugin('glance').get_image(image_id)
if image.status == 'ACTIVE':
if image.status.lower() == self.IMAGE_ACTIVE:
return True
elif image.status == 'ERROR' or image.status == 'DELETED':
elif image.status.lower() in (self.IMAGE_ERROR, self.IMAGE_DELETED):
raise exception.Error(image.status)
return False
@ -1601,7 +1603,7 @@ class Server(server_base.BaseServer, sh.SchedulerHintsMixin,
def handle_delete_snapshot(self, snapshot):
image_id = snapshot['resource_data'].get('snapshot_image_id')
with self.client_plugin().ignore_not_found:
self.client_plugin('glance').images.delete(image_id)
self.client('glance').images.delete(image_id)
def handle_restore(self, defn, restore_data):
image_id = restore_data['resource_data']['snapshot_image_id']