def test_stats_hover_hints(self): class Struct(object): def __init__(self, d): self.__dict__.update(d) def _get_link(meter): link = ('http://localhost:8777/v2/meters/%s?' 'q.field=resource_id&q.value=ignored') return dict(href=link % meter, rel=meter) flavors = ['m1.tiny', 'm1.massive', 'm1.secret'] resources = [ Struct( dict(resource_id=uuid.uuid4(), project_id='fake_project_id', user_id='fake_user_id', timestamp='2013-10-22T12:42:37', metadata=dict(ramdisk_id='fake_image_id'), links=[ _get_link('instance:%s' % f), _get_link('instance'), _get_link('cpu') ])) for f in flavors ] request = self.mox.CreateMock(http.HttpRequest) api.nova.flavor_list(request, None).AndReturn(self.flavors.list()) ceilometerclient = self.stub_ceilometerclient() meters = [] for r in resources: for link in r.links: meters.append( Struct( dict(resource_id=r.resource_id, project_id=r.project_id, user_id=r.user_id, timestamp=r.timestamp, name=link['rel']))) ceilometerclient.meters = self.mox.CreateMockAnything() ceilometerclient.meters.list(None).AndReturn(meters) self.mox.ReplayAll() tab = tabs.GlobalStatsTab(None) context_data = tab.get_context_data(request) self.assertTrue('nova_meters' in context_data) meter_hints = {} for d in context_data['nova_meters']: meter_hints[d.name] = d.description expected_meters = ['instance:%s' % f for f in flavors] expected_meters.extend(['instance', 'cpu']) for meter in expected_meters: self.assertTrue(meter in meter_hints) self.assertNotEqual(meter_hints[meter], '')
def test_stats_hover_hints(self): class Struct(object): def __init__(self, d): self.__dict__.update(d) def _get_link(meter): link = ('http://localhost:8777/v2/meters/%s?' 'q.field=resource_id&q.value=fake_resource_id') return dict(href=link % meter, rel=meter) resources = [ Struct( dict(resource_id='fake_resource_id', project_id='fake_project_id', user_id='fake_user_id', timestamp='2013-10-22T12:42:37', metadata=dict(ramdisk_id='fake_image_id'), links=[ _get_link('instance:m1.massive'), _get_link('instance'), _get_link('cpu') ])), ] request = self.mox.CreateMock(http.HttpRequest) api.nova.flavor_list(request, None).AndReturn(self.flavors.list()) ceilometerclient = self.stub_ceilometerclient() ceilometerclient.resources = self.mox.CreateMockAnything() ceilometerclient.resources.list(q=IsA(list)).AndReturn(resources) self.mox.ReplayAll() tab = tabs.GlobalStatsTab(None) context_data = tab.get_context_data(request) self.assertTrue('meters' in context_data) meter_hints = {} for d in context_data['meters']: meter_hints[d.name] = d.title for meter in ['instance:m1.massive', 'instance', 'cpu']: self.assertTrue(meter in meter_hints) self.assertNotEqual(meter_hints[meter], '')