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:
parent
7ad7e9049c
commit
b7e894b196
|
@ -78,7 +78,8 @@ if __name__ == '__main__':
|
||||||
for instance_ref in instances:
|
for instance_ref in instances:
|
||||||
try:
|
try:
|
||||||
nova.compute.utils.notify_usage_exists(
|
nova.compute.utils.notify_usage_exists(
|
||||||
admin_context, instance_ref, safe=False)
|
admin_context, instance_ref,
|
||||||
|
ignore_missing_network_data=False)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
print traceback.format_exc(e)
|
print traceback.format_exc(e)
|
||||||
print "Instance usage audit completed"
|
print "Instance usage audit completed"
|
||||||
|
|
|
@ -22,6 +22,7 @@ import nova.context
|
||||||
from nova import db
|
from nova import db
|
||||||
from nova import exception
|
from nova import exception
|
||||||
from nova import flags
|
from nova import flags
|
||||||
|
from nova import log
|
||||||
from nova import network
|
from nova import network
|
||||||
from nova.network import model as network_model
|
from nova.network import model as network_model
|
||||||
from nova.notifier import api as notifier_api
|
from nova.notifier import api as notifier_api
|
||||||
|
@ -29,14 +30,21 @@ from nova import utils
|
||||||
|
|
||||||
|
|
||||||
FLAGS = flags.FLAGS
|
FLAGS = flags.FLAGS
|
||||||
|
LOG = log.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def notify_usage_exists(context, instance_ref, current_period=False):
|
def notify_usage_exists(context, instance_ref, current_period=False,
|
||||||
|
ignore_missing_network_data=True):
|
||||||
"""Generates 'exists' notification for an instance for usage auditing
|
"""Generates 'exists' notification for an instance for usage auditing
|
||||||
purposes.
|
purposes.
|
||||||
|
|
||||||
Generates usage for last completed period, unless 'current_period'
|
:param current_period: if True, this will generate a usage for the
|
||||||
is True."""
|
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')
|
admin_context = nova.context.get_admin_context(read_deleted='yes')
|
||||||
begin, end = utils.last_completed_audit_period()
|
begin, end = utils.last_completed_audit_period()
|
||||||
bw = {}
|
bw = {}
|
||||||
|
@ -53,8 +61,14 @@ def notify_usage_exists(context, instance_ref, current_period=False):
|
||||||
cached_info = instance_ref['info_cache']['network_info']
|
cached_info = instance_ref['info_cache']['network_info']
|
||||||
nw_info = network_model.NetworkInfo.hydrate(cached_info)
|
nw_info = network_model.NetworkInfo.hydrate(cached_info)
|
||||||
else:
|
else:
|
||||||
|
try:
|
||||||
nw_info = network.API().get_instance_nw_info(admin_context,
|
nw_info = network.API().get_instance_nw_info(admin_context,
|
||||||
instance_ref)
|
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]
|
macs = [vif['address'] for vif in nw_info]
|
||||||
uuids = [instance_ref.uuid]
|
uuids = [instance_ref.uuid]
|
||||||
|
|
Loading…
Reference in New Issue