Do not fail on notify when quantum and melange are out of sync.

This patch adds the `ignore_missing_network_data` flag which will log
exceptions rather than raising them when generating usage exists
notifications.

Change-Id: Ie11bc9028790c2d1b3de1f4709a9e17a67e06f26
This commit is contained in:
Jason Kölker 2012-03-22 17:41:58 -05:00 committed by Rick Harris
parent 7ad7e9049c
commit b7e894b196
2 changed files with 22 additions and 7 deletions

View File

@ -78,7 +78,8 @@ if __name__ == '__main__':
for instance_ref in instances:
try:
nova.compute.utils.notify_usage_exists(
admin_context, instance_ref, safe=False)
admin_context, instance_ref,
ignore_missing_network_data=False)
except Exception, e:
print traceback.format_exc(e)
print "Instance usage audit completed"

View File

@ -22,6 +22,7 @@ import nova.context
from nova import db
from nova import exception
from nova import flags
from nova import log
from nova import network
from nova.network import model as network_model
from nova.notifier import api as notifier_api
@ -29,14 +30,21 @@ from nova import utils
FLAGS = flags.FLAGS
LOG = log.getLogger(__name__)
def notify_usage_exists(context, instance_ref, current_period=False):
""" Generates 'exists' notification for an instance for usage auditing
purposes.
def notify_usage_exists(context, instance_ref, current_period=False,
ignore_missing_network_data=True):
"""Generates 'exists' notification for an instance for usage auditing
purposes.
Generates usage for last completed period, unless 'current_period'
is True."""
:param current_period: if True, this will generate a usage for the
current usage period; if False, this will generate a usage for the
previous audit period.
:param ignore_missing_network_data: if True, log any exceptions generated
while getting network info; if False, raise the exception.
"""
admin_context = nova.context.get_admin_context(read_deleted='yes')
begin, end = utils.last_completed_audit_period()
bw = {}
@ -53,8 +61,14 @@ def notify_usage_exists(context, instance_ref, current_period=False):
cached_info = instance_ref['info_cache']['network_info']
nw_info = network_model.NetworkInfo.hydrate(cached_info)
else:
nw_info = network.API().get_instance_nw_info(admin_context,
try:
nw_info = network.API().get_instance_nw_info(admin_context,
instance_ref)
except Exception:
LOG.exception('Failed to get nw_info', instance=instance_ref)
if ignore_missing_network_data:
return
raise
macs = [vif['address'] for vif in nw_info]
uuids = [instance_ref.uuid]