]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Fixes issues found in /os-hosts API
authorFei Long Wang <flwang@cn.ibm.com>
Sun, 3 Mar 2013 08:48:22 +0000 (16:48 +0800)
committerFei Long Wang <flwang@cn.ibm.com>
Tue, 5 Mar 2013 14:10:57 +0000 (22:10 +0800)
There are some issues found in Cinder /os-hosts API:

1) Bracket in the wrong spot in Cinder HostController show method
There is an erroneous bracket on the following line in the show method
that should be at the end of the response:
   'total_volume_gb': str(sum)},

2) XML Attributes Missing for List/Index method in Cinder HostController
The HostIndexTemplate class specifies mapping for "host" and "topic"
attributes rather than any of the ones that are actually returned from
the index method.

3) XML Serialization is commented for Cinder HostController show method

Fixes Bug: 1139984

Change-Id: I881e80b5e109ed6ddcc4f7c4bf5749ab6dca563d

cinder/api/contrib/hosts.py
cinder/tests/api/contrib/test_hosts.py

index 2c68c71c9efd1ab9d8fac06bb80eb169be49f1ff..0fc85481d6e96f69dcfcd382e6e3ee660de9b3a2 100644 (file)
@@ -36,14 +36,14 @@ authorize = extensions.extension_authorizer('volume', 'hosts')
 
 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)
 
@@ -183,7 +183,7 @@ class HostController(object):
             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.
 
@@ -219,9 +219,9 @@ class HostController(object):
         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))
index ff8f9bed029bcd0c058a7d9034df962abb3dbea3..525f96305133a720f89058524341aca8b56ba459 100644 (file)
@@ -161,18 +161,26 @@ class HostSerializerTest(test.TestCase):
 
     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')