Merge "Fixes AttributeError of FloatingIPPollster"
This commit is contained in:
@@ -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
|
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -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))
|
||||||
|
|||||||
Reference in New Issue
Block a user