Clear pvc_id during instance spawn failing

1. In powevc nova driver, it's better to use instance.save() instead of
db call

2. clear pvc_id after destory the powervc instance.

3. override pvc_id regardless powervc instance's metadata pvc_id.

Closes-Bug: #1395731
Change-Id: I2bb2494a8a2976064494101af811f6be22379472
This commit is contained in:
terryyao 2014-11-24 23:02:33 +08:00
parent 5a255d5d95
commit e506e9a9b4
2 changed files with 29 additions and 27 deletions

View File

@ -293,15 +293,10 @@ class PowerVCDriver(driver.ComputeDriver):
"""
This method does the following things when exception thrown in spawn:
1. log powervc side error message to hosting os fault property
2. remove pvc_id from local vm
3. destroy vm in powerVC with pvc_id set in instance
2. destroy vm in powerVC with pvc_id set in instance
3. remove pvc_id from local vm
"""
LOG.warning("Created instance failed: %s" % message)
# In this time, powervc uuid is not saved in instance metadata, get
# it from db then update the instance and call destroy()
# remove pvc_id before destroy to avoid instance synchronization
meta = db.instance_metadata_get(context, instance['uuid'])
pvc_id = meta.get(constants.PVC_ID, '')
# To log powervc side error message to hosting os fault property,
# raise an InstanceDeployFailure with powervc error message set
@ -314,19 +309,23 @@ class PowerVCDriver(driver.ComputeDriver):
# 1. Set scheduler_max_attempts=1 in /etc/nova/nova.conf
# 2. Restart openstack-nova-scheduler service
# remove pvc_id
if constants.PVC_ID in meta.keys():
del(meta[constants.PVC_ID])
update_properties = {'metadata': meta}
db.instance_update(context, instance['uuid'], update_properties)
# destory vm in pvc side
instance['metadata'] = {constants.PVC_ID: pvc_id}
try:
self.destroy(None, instance, None)
except Exception as e:
# Ignore the exception in destroy()
LOG.warning("Destroy instance throw exception: %s" % e.message)
meta = instance.get('metadata')
if not meta:
LOG.warning("No metadata for instance: %s", instance)
return
# remove pvc_id
if constants.PVC_ID in meta.keys():
del(meta[constants.PVC_ID])
instance['metadata'] = meta
instance.save()
LOG.debug('Saved instance with clearing pvc_id in metadata during'
'spawn failure: %s', instance)
def destroy(self, context, instance, network_info, block_device_info=None,
destroy_disks=True):

View File

@ -621,23 +621,26 @@ class PowerVCService(object):
"""
created_instance = created_server.__dict__
# get original metadata from DB and insert the pvc_id
meta = db.instance_metadata_get(context, orig_instance['uuid'])
meta.update(pvc_id=created_instance['id'])
meta = orig_instance.get('metadata')
# update powervc specified metadata to hosting os vm instance
powervc_meta = created_instance.get('metadata')
if powervc_meta:
meta.update(powervc_meta)
update_properties = {
'node': created_instance.get(
'OS-EXT-SRV-ATTR:hypervisor_hostname', None),
'host': created_instance.get('OS-EXT-SRV-ATTR:host', None),
'metadata': meta,
'architecture': constants.PPC64,
'power_state': created_instance['OS-EXT-STS:power_state']}
orig_instance['node'] = update_properties['node']
orig_instance['host'] = update_properties['host']
db.instance_update(context, orig_instance['uuid'],
update_properties)
# Always override pvc_id with created_server id regardless even if
# PowerVC instance has such pvc_id in metadata
meta.update(pvc_id=created_instance['id'])
node = created_instance.get('OS-EXT-SRV-ATTR:hypervisor_hostname',
None)
host = created_instance.get('OS-EXT-SRV-ATTR:host', None)
powerstate = created_instance['OS-EXT-STS:power_state']
orig_instance['node'] = node
orig_instance['host'] = host
orig_instance['architecture'] = constants.PPC64
orig_instance['power_state'] = powerstate
orig_instance['metadata'] = meta
orig_instance.save()
LOG.debug('Saved instance after created PowerVC instance: %s',
orig_instance)
def spawn(self, context, instance, injected_files, name, imageUUID,
flavorDict, nics, hypervisorID, availability_zone, isDefer):