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:
parent
041b1987fc
commit
7a82ac4a32
@ -302,6 +302,8 @@ class PowerVCCloudManager(manager.Manager):
|
||||
base_options['display_name'] = local_instance.get('display_name')
|
||||
|
||||
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,
|
||||
pvc_instance['id'],
|
||||
local_instance)
|
||||
@ -461,7 +463,7 @@ class PowerVCCloudManager(manager.Manager):
|
||||
"associated host or hypervisor. Skip to sync" %
|
||||
pvc_instance['id']))
|
||||
return
|
||||
|
||||
LOG.debug('entering to insert local instance for: %s' % pvc_instance)
|
||||
ins, image, flavor = self._translate_pvc_instance(ctx, pvc_instance)
|
||||
security_group_map = self.\
|
||||
_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'],
|
||||
vm_state=pvc_instance['OS-EXT-STS:vm_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,
|
||||
ins['metadata'][constants.PVC_ID],
|
||||
db_instance)
|
||||
@ -504,6 +507,7 @@ class PowerVCCloudManager(manager.Manager):
|
||||
compute.utils.notify_about_instance_usage(
|
||||
self.notifier, ctx, db_instance, 'create.sync', network_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.
|
||||
# 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: 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.
|
||||
instance = None
|
||||
@ -1114,7 +1118,7 @@ class PowerVCCloudManager(manager.Manager):
|
||||
:param: event_type message event type
|
||||
: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
|
||||
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 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
|
||||
|
||||
# Get the newly added PowerVC instance and add it to the local OS
|
||||
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
|
||||
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
|
||||
in utills.get_utils().get_our_scg_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:
|
||||
self._add_local_instance(context, instance)
|
||||
except Exception as e:
|
||||
LOG.warning(_("Failed to insert instance due to: %s ")
|
||||
% str(e))
|
||||
else:
|
||||
LOG.debug(_('Tried to add newly created instance but it could not '
|
||||
'be found in PowerVC'))
|
||||
try:
|
||||
self._add_local_instance(context, instance)
|
||||
except Exception:
|
||||
LOG.exception('Failed to insert instance')
|
||||
|
||||
def _handle_powervc_instance_delete(self,
|
||||
context=None,
|
||||
@ -1157,7 +1163,7 @@ class PowerVCCloudManager(manager.Manager):
|
||||
:param: event_type message event type
|
||||
: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
|
||||
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 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
|
||||
|
||||
# Remove the instance from the local OS
|
||||
@ -1185,12 +1192,14 @@ class PowerVCCloudManager(manager.Manager):
|
||||
:param: event_type message event type
|
||||
: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.\
|
||||
_get_matched_instance_by_pvc_id(context, powervc_instance_id)
|
||||
|
||||
if not local_instance:
|
||||
LOG.debug('PVC Instance %s does not exist locally for '
|
||||
'instance update event' % powervc_instance_id)
|
||||
return
|
||||
|
||||
powervc_instance = self.driver.get_instance(powervc_instance_id)
|
||||
@ -1210,11 +1219,13 @@ class PowerVCCloudManager(manager.Manager):
|
||||
:param: event_type message event type
|
||||
: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.\
|
||||
_get_matched_instance_by_pvc_id(context, powervc_instance_id)
|
||||
if not local_instance:
|
||||
LOG.debug('PVC Instance %s does not exist locally for '
|
||||
'volume attach/detach event' % powervc_instance_id)
|
||||
return
|
||||
|
||||
powervc_volume_id = payload.get('volume_id')
|
||||
@ -1241,7 +1252,7 @@ class PowerVCCloudManager(manager.Manager):
|
||||
self.sync_volume_attachment(context, powervc_instance_id,
|
||||
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
|
||||
instance in the event
|
||||
|
||||
@ -1249,6 +1260,8 @@ class PowerVCCloudManager(manager.Manager):
|
||||
:returns instance id triggering the event
|
||||
"""
|
||||
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
|
||||
|
||||
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
|
||||
instance_ref = self.compute_api.update(context, local_instance,
|
||||
**updated_instance)
|
||||
|
||||
LOG.debug('update state for local db instance: %s with '
|
||||
'data: %s' % (local_instance, updated_instance))
|
||||
# Send sync notification
|
||||
self._send_instance_sync_notification(context, event_type,
|
||||
instance_ref)
|
||||
|
@ -1,4 +1,4 @@
|
||||
# Copyright 2013 IBM Corp.
|
||||
# Copyright 2013, 2014 IBM Corp.
|
||||
|
||||
"""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
|
||||
"""
|
||||
if pvc_instance is None or not isinstance(pvc_instance, dict):
|
||||
LOG.warning('pvc instance is not a dict: %s' % pvc_instance)
|
||||
return {}
|
||||
if metadata is None:
|
||||
metadata = {}
|
||||
|
Loading…
Reference in New Issue
Block a user