Permalink
Browse files

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

  • Loading branch information...
2 parents 45b4955 + b7e894b commit d64e93967c8271d1d85e44f4c21aefdbb1b0461c Jenkins committed with openstack-gerrit May 8, 2012
Showing with 22 additions and 7 deletions.
  1. +2 −1 bin/instance-usage-audit
  2. +20 −6 nova/compute/utils.py
View
@@ -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
@@ -22,21 +22,29 @@
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
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]

0 comments on commit d64e939

Please sign in to comment.