Broken charting for non compute resources

- Code for resource charts contained query that
  filtered only nova instances. That condition
  is removed. Now it filters resources by the
  meter name.

Fixes bug 1243796

Conflicts:
	openstack_dashboard/dashboards/admin/metering/tests.py

Change-Id: I7debb2b457ede83b726934c082f22307ddc0c630
(cherry picked from commit 1e1da618bb)
This commit is contained in:
Julie Pichon 2013-12-05 19:10:45 +00:00
parent 5d9684d8c2
commit 1912cc6a88
3 changed files with 28 additions and 6 deletions

View File

@ -130,7 +130,7 @@ class MeteringViewTests(test.APITestCase, test.BaseAdminViewTests):
ceilometerclient = self.stub_ceilometerclient()
ceilometerclient.resources = self.mox.CreateMockAnything()
ceilometerclient.resources.list(q=IsA(list)).AndReturn(resources)
ceilometerclient.resources.list(q=[]).AndReturn(resources)
ceilometerclient.statistics = self.mox.CreateMockAnything()
ceilometerclient.statistics.list(meter_name="storage.objects",

View File

@ -121,10 +121,6 @@ class SamplesView(TemplateView):
# If some date is missing, just set static window to one day.
period = 3600 * 24
query = [{"field": "metadata.OS-EXT-AZ:availability_zone",
"op": "eq",
"value": "nova"}]
additional_query = []
if date_from:
additional_query += [{'field': 'timestamp',
@ -175,11 +171,26 @@ class SamplesView(TemplateView):
stats_attr,
unit)
else:
query = []
def filter_by_meter_name(resource):
""" Function for filtering of the list of resources.
Will pick the right resources according to currently selected
meter.
"""
for link in resource.links:
if link['rel'] == meter:
# If resource has the currently chosen meter.
return True
return False
ceilometer_usage = ceilometer.CeilometerUsage(request)
try:
resources = ceilometer_usage.resources_with_statistics(
query, [meter], period=period, stats_attr=None,
additional_query=additional_query)
additional_query=additional_query,
filter_func=filter_by_meter_name)
except Exception:
resources = []
exceptions.handle(request,

View File

@ -104,12 +104,23 @@ def data(TEST):
metadata={'tag': 'self.counter3', 'display_name': 'test-server'},
links=[{'url': 'test_url', 'rel': 'storage.objects'}],
)
resource_dict_3 = dict(
resource_id='fake_resource_id3',
project_id='fake_project_id',
user_id="fake_user_id",
timestamp='2012-07-02T10:42:00.000000',
metadata={'tag': 'self.counter3', 'display_name': 'test-server'},
links=[{'url': 'test_url', 'rel': 'intance'}],
)
resource_1 = resources.Resource(resources.ResourceManager(None),
resource_dict_1)
resource_2 = resources.Resource(resources.ResourceManager(None),
resource_dict_2)
resource_3 = resources.Resource(resources.ResourceManager(None),
resource_dict_3)
TEST.resources.add(resource_1)
TEST.resources.add(resource_2)
TEST.resources.add(resource_3)
# samples
sample_dict_1 = {'resource_id': 'fake_resource_id',