Fix the issue for two instances sometimes after booting vm

1. Add debug logs to sync code
2. fix an issue found the new added instance scg_id is None, there will
be an AttributeError thrown. 

Closes-Bug: #1391875
Change-Id: Idaa6ec9982e915d8fec0e2e6d32d5bb5e49a674f
This commit is contained in:
terryyao 2014-11-13 13:33:32 +08:00
parent 041b1987fc
commit 7a82ac4a32
2 changed files with 39 additions and 24 deletions

View File

@ -302,6 +302,8 @@ class PowerVCCloudManager(manager.Manager):
base_options['display_name'] = local_instance.get('display_name') base_options['display_name'] = local_instance.get('display_name')
self.compute_api.update(context, local_instance, **base_options) self.compute_api.update(context, local_instance, **base_options)
LOG.debug('update local db instance: %s with '
'data: %s' % (local_instance, base_options))
self.sync_volume_attachment(context, self.sync_volume_attachment(context,
pvc_instance['id'], pvc_instance['id'],
local_instance) local_instance)
@ -461,7 +463,7 @@ class PowerVCCloudManager(manager.Manager):
"associated host or hypervisor. Skip to sync" % "associated host or hypervisor. Skip to sync" %
pvc_instance['id'])) pvc_instance['id']))
return return
LOG.debug('entering to insert local instance for: %s' % pvc_instance)
ins, image, flavor = self._translate_pvc_instance(ctx, pvc_instance) ins, image, flavor = self._translate_pvc_instance(ctx, pvc_instance)
security_group_map = self.\ security_group_map = self.\
_get_security_group_for_instance(ctx, pvc_instance) _get_security_group_for_instance(ctx, pvc_instance)
@ -485,7 +487,8 @@ class PowerVCCloudManager(manager.Manager):
power_state=pvc_instance['OS-EXT-STS:power_state'], power_state=pvc_instance['OS-EXT-STS:power_state'],
vm_state=pvc_instance['OS-EXT-STS:vm_state'], vm_state=pvc_instance['OS-EXT-STS:vm_state'],
task_state=pvc_instance['OS-EXT-STS:task_state']) task_state=pvc_instance['OS-EXT-STS:task_state'])
LOG.debug('created local db instance: %s for '
'powervc instance: %s' % (db_instance, pvc_instance))
self.sync_volume_attachment(ctx, self.sync_volume_attachment(ctx,
ins['metadata'][constants.PVC_ID], ins['metadata'][constants.PVC_ID],
db_instance) db_instance)
@ -504,6 +507,7 @@ class PowerVCCloudManager(manager.Manager):
compute.utils.notify_about_instance_usage( compute.utils.notify_about_instance_usage(
self.notifier, ctx, db_instance, 'create.sync', network_info={}, self.notifier, ctx, db_instance, 'create.sync', network_info={},
system_metadata={}, extra_usage_info={}) system_metadata={}, extra_usage_info={})
LOG.debug('exiting to insert local instance for: %s' % pvc_instance)
# Remove an instance that is not in pvc anymore from local DB. # Remove an instance that is not in pvc anymore from local DB.
# TODO: This is not being used. Do we need to worry about deleting metadata # TODO: This is not being used. Do we need to worry about deleting metadata
@ -1069,7 +1073,7 @@ class PowerVCCloudManager(manager.Manager):
:param: event_type message event type :param: event_type message event type
:param: payload The AMQP message sent from OpenStack (dictionary) :param: payload The AMQP message sent from OpenStack (dictionary)
""" """
hosting_id = self._pre_process_message(payload) hosting_id = self._pre_process_message(payload, event_type, True)
# Attempt to get the local instance. # Attempt to get the local instance.
instance = None instance = None
@ -1114,7 +1118,7 @@ class PowerVCCloudManager(manager.Manager):
:param: event_type message event type :param: event_type message event type
:param: payload The AMQP message sent from OpenStack (dictionary) :param: payload The AMQP message sent from OpenStack (dictionary)
""" """
powervc_instance_id = self._pre_process_message(payload) powervc_instance_id = self._pre_process_message(payload, event_type)
# Check for matching local instance # Check for matching local instance
matched_instances = self._get_local_instance_by_pvc_id( matched_instances = self._get_local_instance_by_pvc_id(
@ -1122,28 +1126,30 @@ class PowerVCCloudManager(manager.Manager):
# If the instance already exists locally then ignore # If the instance already exists locally then ignore
if len(matched_instances) > 0: if len(matched_instances) > 0:
LOG.debug(_('Instance already exists locally')) LOG.debug('PVC instance %s already exists locally,'
' skip to insert' % powervc_instance_id)
return return
# Get the newly added PowerVC instance and add it to the local OS # Get the newly added PowerVC instance and add it to the local OS
instance = self.driver.get_instance(powervc_instance_id) instance = self.driver.get_instance(powervc_instance_id)
if not instance:
LOG.debug('instance %s does not exist in powervc '
'side while gets creation event' % powervc_instance_id)
return
instance = instance.__dict__
# Filter out the instance in scg that is not specified in conf # Filter out the instance in scg that is not specified in conf
instance_scg_id = instance.storage_connectivity_group_id instance_scg_id = instance.get('storage_connectivity_group_id')
our_scg_id_list = [scg.id for scg our_scg_id_list = [scg.id for scg
in utills.get_utils().get_our_scg_list()] in utills.get_utils().get_our_scg_list()]
if instance_scg_id and instance_scg_id not in our_scg_id_list: if instance_scg_id and instance_scg_id not in our_scg_id_list:
instance = None LOG.debug('instance %s does not in accessible '
'scg list' % instance)
return
if instance:
instance = instance.__dict__
try: try:
self._add_local_instance(context, instance) self._add_local_instance(context, instance)
except Exception as e: except Exception:
LOG.warning(_("Failed to insert instance due to: %s ") LOG.exception('Failed to insert instance')
% str(e))
else:
LOG.debug(_('Tried to add newly created instance but it could not '
'be found in PowerVC'))
def _handle_powervc_instance_delete(self, def _handle_powervc_instance_delete(self,
context=None, context=None,
@ -1157,7 +1163,7 @@ class PowerVCCloudManager(manager.Manager):
:param: event_type message event type :param: event_type message event type
:param: payload The AMQP message sent from OpenStack (dictionary) :param: payload The AMQP message sent from OpenStack (dictionary)
""" """
powervc_instance_id = self._pre_process_message(payload) powervc_instance_id = self._pre_process_message(payload, event_type)
# Check for matching local instance # Check for matching local instance
matched_instances = self._get_local_instance_by_pvc_id( matched_instances = self._get_local_instance_by_pvc_id(
@ -1165,7 +1171,8 @@ class PowerVCCloudManager(manager.Manager):
# If the instance does not exist then ignore # If the instance does not exist then ignore
if len(matched_instances) == 0: if len(matched_instances) == 0:
LOG.debug(_('Instance does not exist locally')) LOG.debug('PVC Instance %s does not exist locally for '
'instance delete event' % powervc_instance_id)
return return
# Remove the instance from the local OS # Remove the instance from the local OS
@ -1185,12 +1192,14 @@ class PowerVCCloudManager(manager.Manager):
:param: event_type message event type :param: event_type message event type
:param: payload The AMQP message sent from OpenStack (dictionary) :param: payload The AMQP message sent from OpenStack (dictionary)
""" """
powervc_instance_id = self._pre_process_message(payload) powervc_instance_id = self._pre_process_message(payload, event_type)
local_instance = self.\ local_instance = self.\
_get_matched_instance_by_pvc_id(context, powervc_instance_id) _get_matched_instance_by_pvc_id(context, powervc_instance_id)
if not local_instance: if not local_instance:
LOG.debug('PVC Instance %s does not exist locally for '
'instance update event' % powervc_instance_id)
return return
powervc_instance = self.driver.get_instance(powervc_instance_id) powervc_instance = self.driver.get_instance(powervc_instance_id)
@ -1210,11 +1219,13 @@ class PowerVCCloudManager(manager.Manager):
:param: event_type message event type :param: event_type message event type
:param: payload The AMQP message sent from OpenStack (dictionary) :param: payload The AMQP message sent from OpenStack (dictionary)
""" """
powervc_instance_id = self._pre_process_message(payload) powervc_instance_id = self._pre_process_message(payload, event_type)
local_instance = self.\ local_instance = self.\
_get_matched_instance_by_pvc_id(context, powervc_instance_id) _get_matched_instance_by_pvc_id(context, powervc_instance_id)
if not local_instance: if not local_instance:
LOG.debug('PVC Instance %s does not exist locally for '
'volume attach/detach event' % powervc_instance_id)
return return
powervc_volume_id = payload.get('volume_id') powervc_volume_id = payload.get('volume_id')
@ -1241,7 +1252,7 @@ class PowerVCCloudManager(manager.Manager):
self.sync_volume_attachment(context, powervc_instance_id, self.sync_volume_attachment(context, powervc_instance_id,
local_instance) local_instance)
def _pre_process_message(self, payload): def _pre_process_message(self, payload, eventtype=None, local=False):
"""Logging the event type and return the instance id of the nova server """Logging the event type and return the instance id of the nova server
instance in the event instance in the event
@ -1249,6 +1260,8 @@ class PowerVCCloudManager(manager.Manager):
:returns instance id triggering the event :returns instance id triggering the event
""" """
instance_id = payload.get('instance_id') instance_id = payload.get('instance_id')
LOG.debug('Handling %s notification type %s for instance: '
'%s' % ('local' if local else '', eventtype, instance_id))
return instance_id return instance_id
def _get_matched_instance_by_pvc_id(self, context, pvc_id): def _get_matched_instance_by_pvc_id(self, context, pvc_id):
@ -1345,7 +1358,8 @@ class PowerVCCloudManager(manager.Manager):
# Call the compute API to update the local instance # Call the compute API to update the local instance
instance_ref = self.compute_api.update(context, local_instance, instance_ref = self.compute_api.update(context, local_instance,
**updated_instance) **updated_instance)
LOG.debug('update state for local db instance: %s with '
'data: %s' % (local_instance, updated_instance))
# Send sync notification # Send sync notification
self._send_instance_sync_notification(context, event_type, self._send_instance_sync_notification(context, event_type,
instance_ref) instance_ref)

View File

@ -1,4 +1,4 @@
# Copyright 2013 IBM Corp. # Copyright 2013, 2014 IBM Corp.
"""PowerVC Driver related Utilities""" """PowerVC Driver related Utilities"""
@ -83,6 +83,7 @@ def fill_metadata_dict_by_pvc_instance(metadata, pvc_instance):
This common method help to get PowerVC unique property into metadata This common method help to get PowerVC unique property into metadata
""" """
if pvc_instance is None or not isinstance(pvc_instance, dict): if pvc_instance is None or not isinstance(pvc_instance, dict):
LOG.warning('pvc instance is not a dict: %s' % pvc_instance)
return {} return {}
if metadata is None: if metadata is None:
metadata = {} metadata = {}