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:
parent
5a255d5d95
commit
e506e9a9b4
@ -293,15 +293,10 @@ class PowerVCDriver(driver.ComputeDriver):
|
|||||||
"""
|
"""
|
||||||
This method does the following things when exception thrown in spawn:
|
This method does the following things when exception thrown in spawn:
|
||||||
1. log powervc side error message to hosting os fault property
|
1. log powervc side error message to hosting os fault property
|
||||||
2. remove pvc_id from local vm
|
2. destroy vm in powerVC with pvc_id set in instance
|
||||||
3. destroy vm in powerVC with pvc_id set in instance
|
3. remove pvc_id from local vm
|
||||||
"""
|
"""
|
||||||
LOG.warning("Created instance failed: %s" % message)
|
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,
|
# To log powervc side error message to hosting os fault property,
|
||||||
# raise an InstanceDeployFailure with powervc error message set
|
# 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
|
# 1. Set scheduler_max_attempts=1 in /etc/nova/nova.conf
|
||||||
# 2. Restart openstack-nova-scheduler service
|
# 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
|
# destory vm in pvc side
|
||||||
instance['metadata'] = {constants.PVC_ID: pvc_id}
|
|
||||||
try:
|
try:
|
||||||
self.destroy(None, instance, None)
|
self.destroy(None, instance, None)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
# Ignore the exception in destroy()
|
# Ignore the exception in destroy()
|
||||||
LOG.warning("Destroy instance throw exception: %s" % e.message)
|
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,
|
def destroy(self, context, instance, network_info, block_device_info=None,
|
||||||
destroy_disks=True):
|
destroy_disks=True):
|
||||||
|
@ -621,23 +621,26 @@ class PowerVCService(object):
|
|||||||
"""
|
"""
|
||||||
created_instance = created_server.__dict__
|
created_instance = created_server.__dict__
|
||||||
# get original metadata from DB and insert the pvc_id
|
# get original metadata from DB and insert the pvc_id
|
||||||
meta = db.instance_metadata_get(context, orig_instance['uuid'])
|
meta = orig_instance.get('metadata')
|
||||||
meta.update(pvc_id=created_instance['id'])
|
|
||||||
# update powervc specified metadata to hosting os vm instance
|
# update powervc specified metadata to hosting os vm instance
|
||||||
powervc_meta = created_instance.get('metadata')
|
powervc_meta = created_instance.get('metadata')
|
||||||
if powervc_meta:
|
if powervc_meta:
|
||||||
meta.update(powervc_meta)
|
meta.update(powervc_meta)
|
||||||
update_properties = {
|
# Always override pvc_id with created_server id regardless even if
|
||||||
'node': created_instance.get(
|
# PowerVC instance has such pvc_id in metadata
|
||||||
'OS-EXT-SRV-ATTR:hypervisor_hostname', None),
|
meta.update(pvc_id=created_instance['id'])
|
||||||
'host': created_instance.get('OS-EXT-SRV-ATTR:host', None),
|
node = created_instance.get('OS-EXT-SRV-ATTR:hypervisor_hostname',
|
||||||
'metadata': meta,
|
None)
|
||||||
'architecture': constants.PPC64,
|
host = created_instance.get('OS-EXT-SRV-ATTR:host', None)
|
||||||
'power_state': created_instance['OS-EXT-STS:power_state']}
|
powerstate = created_instance['OS-EXT-STS:power_state']
|
||||||
orig_instance['node'] = update_properties['node']
|
orig_instance['node'] = node
|
||||||
orig_instance['host'] = update_properties['host']
|
orig_instance['host'] = host
|
||||||
db.instance_update(context, orig_instance['uuid'],
|
orig_instance['architecture'] = constants.PPC64
|
||||||
update_properties)
|
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,
|
def spawn(self, context, instance, injected_files, name, imageUUID,
|
||||||
flavorDict, nics, hypervisorID, availability_zone, isDefer):
|
flavorDict, nics, hypervisorID, availability_zone, isDefer):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user