Fixes AttributeError of FloatingIPPollster

Currently FloatingIPPollster is using Nova client to get floating
IP metrics instead of accessing OpenStack DB directly. So there are
some attributes can't be accessed from Nova /os-floating-ips REST API.
In this fix, those attributes usage will be removed temporarily.
And they will be back after fix the Nova bug 1174802.

Fixes bug 1173845

Change-Id: I61572c50db6f90c26bbdb7da5f0e9a249b405e58
This commit is contained in:
Fei Long Wang 2013-05-01 16:14:06 -05:00
parent cb7362ed04
commit 39d9ca7b33
2 changed files with 30 additions and 15 deletions

View File

@ -2,6 +2,9 @@
# #
# Copyright © 2012 eNovance <licensing@enovance.com> # Copyright © 2012 eNovance <licensing@enovance.com>
# #
# Copyright 2013 IBM Corp
# All Rights Reserved.
#
# Author: Julien Danjou <julien@danjou.info> # Author: Julien Danjou <julien@danjou.info>
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may # Licensed under the Apache License, Version 2.0 (the "License"); you may
@ -35,20 +38,21 @@ class FloatingIPPollster(plugin.CentralPollster):
def get_counters(self, manager): def get_counters(self, manager):
nv = nova_client.Client() nv = nova_client.Client()
for ip in nv.floating_ip_get_all(): for ip in nv.floating_ip_get_all():
self.LOG.info("FLOATING IP USAGE: %s" % ip.address) self.LOG.info("FLOATING IP USAGE: %s" % ip.ip)
# FIXME (flwang) Now Nova API /os-floating-ips can't provide those
# attributes were used by Ceilometer, such as project id, host.
# In this fix, those attributes usage will be removed temporarily.
# And they will be back after fix the Nova bug 1174802.
yield counter.Counter( yield counter.Counter(
name='ip.floating', name='ip.floating',
type=counter.TYPE_GAUGE, type=counter.TYPE_GAUGE,
unit='ip', unit='ip',
volume=1, volume=1,
user_id=None, user_id=None,
project_id=ip.project_id, project_id=None,
resource_id=ip.id, resource_id=ip.id,
timestamp=timeutils.utcnow().isoformat(), timestamp=timeutils.utcnow().isoformat(),
resource_metadata={ resource_metadata={
'address': ip.address, 'address': ip.ip,
'fixed_ip_id': ip.fixed_ip_id, 'pool': ip.pool
'host': ip.host,
'pool': ip.pool,
'auto_assigned': ip.auto_assigned
}) })

View File

@ -3,6 +3,9 @@
# #
# Copyright © 2012 eNovance <licensing@enovance.com> # Copyright © 2012 eNovance <licensing@enovance.com>
# #
# Copyright 2013 IBM Corp
# All Rights Reserved.
#
# Author: Julien Danjou <julien@danjou.info> # Author: Julien Danjou <julien@danjou.info>
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may # Licensed under the Apache License, Version 2.0 (the "License"); you may
@ -42,7 +45,9 @@ class TestFloatingIPPollster(base.TestCase):
ips = [] ips = []
for i in range(1, 4): for i in range(1, 4):
ip = mock.MagicMock() ip = mock.MagicMock()
ip.address = '1.1.1.%d' % i ip.id = i
ip.ip = '1.1.1.%d' % i
ip.pool = 'public'
ips.append(ip) ips.append(ip)
return ips return ips
@ -62,13 +67,19 @@ class TestFloatingIPPollster(base.TestCase):
def test_get_counters_not_empty(self): def test_get_counters_not_empty(self):
counters = list(self.pollster.get_counters(self.manager)) counters = list(self.pollster.get_counters(self.manager))
self.assertEqual(len(counters), 3) self.assertEqual(len(counters), 3)
addresses = [c.resource_metadata['address'] # It's necessary to verify all the attributes extracted by Nova
for c in counters # API /os-floating-ips to make sure they're available and correct.
] self.assertEqual(counters[0].resource_id, 1)
self.assertEqual(addresses, ['1.1.1.1', self.assertEqual(counters[0].resource_metadata["address"], "1.1.1.1")
'1.1.1.2', self.assertEqual(counters[0].resource_metadata["pool"], "public")
'1.1.1.3',
]) self.assertEqual(counters[1].resource_id, 2)
self.assertEqual(counters[1].resource_metadata["address"], "1.1.1.2")
self.assertEqual(counters[1].resource_metadata["pool"], "public")
self.assertEqual(counters[2].resource_id, 3)
self.assertEqual(counters[2].resource_metadata["address"], "1.1.1.3")
self.assertEqual(counters[2].resource_metadata["pool"], "public")
def test_get_counter_names(self): def test_get_counter_names(self):
counters = list(self.pollster.get_counters(self.manager)) counters = list(self.pollster.get_counters(self.manager))