class HostIndexTemplate(xmlutil.TemplateBuilder):
def construct(self):
- def shimmer(obj, do_raise=False):
- # A bare list is passed in; we need to wrap it in a dict
- return dict(hosts=obj)
-
- root = xmlutil.TemplateElement('hosts', selector=shimmer)
+ root = xmlutil.TemplateElement('hosts')
elem = xmlutil.SubTemplateElement(root, 'host', selector='hosts')
- elem.set('host')
- elem.set('topic')
+ elem.set('service-status')
+ elem.set('service')
+ elem.set('zone')
+ elem.set('service-state')
+ elem.set('host_name')
+ elem.set('last-update')
return xmlutil.MasterTemplate(root, 1)
raise webob.exc.HTTPBadRequest(explanation=result)
return {"host": host, "status": result}
- #@wsgi.serializers(xml=HostShowTemplate)
+ @wsgi.serializers(xml=HostShowTemplate)
def show(self, req, id):
"""Shows the volume usage info given by hosts.
snap_sum_total = 0
resources = [{'resource': {'host': host, 'project': '(total)',
'volume_count': str(count),
- 'total_volume_gb': str(sum)},
+ 'total_volume_gb': str(sum),
'snapshot_count': str(snap_count_total),
- 'total_snapshot_gb': str(snap_sum_total)}]
+ 'total_snapshot_gb': str(snap_sum_total)}}]
project_ids = [v['project_id'] for v in volume_refs]
project_ids = list(set(project_ids))
def test_index_serializer(self):
serializer = os_hosts.HostIndexTemplate()
- text = serializer.serialize(SERVICE_LIST)
+ text = serializer.serialize({"hosts": LIST_RESPONSE})
tree = etree.fromstring(text)
self.assertEqual('hosts', tree.tag)
- self.assertEqual(len(SERVICE_LIST), len(tree))
- for i in range(len(SERVICE_LIST)):
+ self.assertEqual(len(LIST_RESPONSE), len(tree))
+ for i in range(len(LIST_RESPONSE)):
self.assertEqual('host', tree[i].tag)
- self.assertEqual(SERVICE_LIST[i]['host'],
- tree[i].get('host'))
- self.assertEqual(SERVICE_LIST[i]['topic'],
- tree[i].get('topic'))
+ self.assertEqual(LIST_RESPONSE[i]['service-status'],
+ tree[i].get('service-status'))
+ self.assertEqual(LIST_RESPONSE[i]['service'],
+ tree[i].get('service'))
+ self.assertEqual(LIST_RESPONSE[i]['zone'],
+ tree[i].get('zone'))
+ self.assertEqual(LIST_RESPONSE[i]['service-state'],
+ tree[i].get('service-state'))
+ self.assertEqual(LIST_RESPONSE[i]['host_name'],
+ tree[i].get('host_name'))
+ self.assertEqual(str(LIST_RESPONSE[i]['last-update']),
+ tree[i].get('last-update'))
def test_update_serializer_with_status(self):
exemplar = dict(host='test.host.1', status='enabled')