summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2012-05-08 19:34:54 +0000
committerGerrit Code Review <review@openstack.org>2012-05-08 19:34:54 +0000
commitd64e93967c8271d1d85e44f4c21aefdbb1b0461c (patch)
treeb718a86603d2eab754f5fb966e757cf6aeff0490
parent45b4955b4663e67c5fb3dd0bdd2ffcbe00881f18 (diff)
parentb7e894b1962d272dfebc42427f7b7ce0f737d065 (diff)
downloadnova-d64e93967c8271d1d85e44f4c21aefdbb1b0461c.tar.gz
nova-d64e93967c8271d1d85e44f4c21aefdbb1b0461c.tar.xz
nova-d64e93967c8271d1d85e44f4c21aefdbb1b0461c.zip
Merge "Do not fail on notify when quantum and melange are out of sync."
-rwxr-xr-xbin/instance-usage-audit3
-rw-r--r--nova/compute/utils.py26
2 files changed, 22 insertions, 7 deletions
diff --git a/bin/instance-usage-audit b/bin/instance-usage-audit
index 48ded73cf..5b30c3586 100755
--- a/bin/instance-usage-audit
+++ b/bin/instance-usage-audit
@@ -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"
diff --git a/nova/compute/utils.py b/nova/compute/utils.py
index 2415abf7c..5da501c8a 100644
--- a/nova/compute/utils.py
+++ b/nova/compute/utils.py
@@ -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]