From 39d9ca7b330e15eed5200bad4943818c353332ed Mon Sep 17 00:00:00 2001 From: Fei Long Wang Date: Wed, 1 May 2013 16:14:06 -0500 Subject: [PATCH] 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 --- ceilometer/network/floatingip.py | 18 +++++++++++------- tests/network/test_floatingip.py | 27 +++++++++++++++++++-------- 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/ceilometer/network/floatingip.py b/ceilometer/network/floatingip.py index ae07aa6b1..530333ca1 100644 --- a/ceilometer/network/floatingip.py +++ b/ceilometer/network/floatingip.py @@ -2,6 +2,9 @@ # # Copyright © 2012 eNovance # +# Copyright 2013 IBM Corp +# All Rights Reserved. +# # Author: Julien Danjou # # 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): nv = nova_client.Client() 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( name='ip.floating', type=counter.TYPE_GAUGE, unit='ip', volume=1, user_id=None, - project_id=ip.project_id, + project_id=None, resource_id=ip.id, timestamp=timeutils.utcnow().isoformat(), resource_metadata={ - 'address': ip.address, - 'fixed_ip_id': ip.fixed_ip_id, - 'host': ip.host, - 'pool': ip.pool, - 'auto_assigned': ip.auto_assigned + 'address': ip.ip, + 'pool': ip.pool }) diff --git a/tests/network/test_floatingip.py b/tests/network/test_floatingip.py index 9e6e7308e..3c1f5098c 100644 --- a/tests/network/test_floatingip.py +++ b/tests/network/test_floatingip.py @@ -3,6 +3,9 @@ # # Copyright © 2012 eNovance # +# Copyright 2013 IBM Corp +# All Rights Reserved. +# # Author: Julien Danjou # # Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -42,7 +45,9 @@ class TestFloatingIPPollster(base.TestCase): ips = [] for i in range(1, 4): 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) return ips @@ -62,13 +67,19 @@ class TestFloatingIPPollster(base.TestCase): def test_get_counters_not_empty(self): counters = list(self.pollster.get_counters(self.manager)) self.assertEqual(len(counters), 3) - addresses = [c.resource_metadata['address'] - for c in counters - ] - self.assertEqual(addresses, ['1.1.1.1', - '1.1.1.2', - '1.1.1.3', - ]) + # It's necessary to verify all the attributes extracted by Nova + # API /os-floating-ips to make sure they're available and correct. + self.assertEqual(counters[0].resource_id, 1) + self.assertEqual(counters[0].resource_metadata["address"], "1.1.1.1") + self.assertEqual(counters[0].resource_metadata["pool"], "public") + + 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): counters = list(self.pollster.get_counters(self.manager))