]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
add GET /{tenant_id}/stacks/detail to Heat API
authorLiang Chen <cbjchen@cn.ibm.com>
Fri, 28 Jun 2013 14:27:59 +0000 (22:27 +0800)
committerLiang Chen <cbjchen@cn.ibm.com>
Fri, 28 Jun 2013 14:31:51 +0000 (22:31 +0800)
Enables the building of a useful dashboard interface for Heat stacks
without looping through stacks returned from "/{tenant_id}/stacks/"
to fetch the detailed data.

Fixes bug #1191117

Change-Id: I06b1100873de462c69302e43259df13104cad79f

heat/api/openstack/v1/__init__.py
heat/api/openstack/v1/stacks.py
heat/tests/test_api_openstack_v1.py

index 2f65ad8189c7ef514fbabe218249ac6ef75fb466..7fdc86ccd593dd802361ac9e4361ce080661844f 100644 (file)
@@ -62,6 +62,10 @@ class API(wsgi.Router):
                                  "/stacks",
                                  action="create",
                                  conditions={'method': 'POST'})
+            stack_mapper.connect("stack_detail",
+                                 "/stacks/detail",
+                                 action="detail",
+                                 conditions={'method': 'GET'})
 
             # Stack data
             stack_mapper.connect("stack_lookup",
index 450be99097ad5e85350283864f44890448ef5415..44473e13e2362413f79bdfb5242e5cc1980cda4f 100644 (file)
@@ -205,6 +205,18 @@ class StackController(object):
 
         return {'stacks': [format_stack(req, s, summary_keys) for s in stacks]}
 
+    @util.tenant_local
+    def detail(self, req):
+        """
+        Lists detailed information for all stacks
+        """
+        try:
+            stacks = self.engine.list_stacks(req.context)
+        except rpc_common.RemoteError as ex:
+            return util.remote_error(ex)
+
+        return {'stacks': [format_stack(req, s) for s in stacks]}
+
     @util.tenant_local
     def create(self, req, body):
         """
index 7783a712ee9278476b42e72f542b4fdd674413fd..64ff64847450162f6cc28ad175c27b735807bef9 100644 (file)
@@ -307,6 +307,67 @@ class StackControllerTest(ControllerTest, HeatTestCase):
         self.assertEqual(result, expected)
         self.m.VerifyAll()
 
+    def test_detail(self):
+        req = self._get('/stacks/detail')
+
+        identity = identifier.HeatIdentifier(self.tenant, 'wordpress', '1')
+
+        engine_resp = [
+            {
+                u'stack_identity': dict(identity),
+                u'updated_time': u'2012-07-09T09:13:11Z',
+                u'template_description': u'blah',
+                u'description': u'blah',
+                u'stack_status_reason': u'Stack successfully created',
+                u'creation_time': u'2012-07-09T09:12:45Z',
+                u'stack_name': identity.stack_name,
+                u'stack_action': u'CREATE',
+                u'stack_status': u'COMPLETE',
+                u'parameters': {'foo': 'bar'},
+                u'outputs': ['key', 'value'],
+                u'notification_topics': [],
+                u'capabilities': [],
+                u'disable_rollback': True,
+                u'timeout_mins': 60,
+            }
+        ]
+        self.m.StubOutWithMock(rpc, 'call')
+        rpc.call(req.context, self.topic,
+                 {'namespace': None,
+                  'method': 'list_stacks',
+                  'args': {},
+                  'version': self.api_version},
+                 None).AndReturn(engine_resp)
+        self.m.ReplayAll()
+
+        result = self.controller.detail(req, tenant_id=identity.tenant)
+
+        expected = {
+            'stacks': [
+                {
+                    'links': [{"href": self._url(identity),
+                               "rel": "self"}],
+                    'id': '1',
+                    u'updated_time': u'2012-07-09T09:13:11Z',
+                    u'template_description': u'blah',
+                    u'description': u'blah',
+                    u'stack_status_reason': u'Stack successfully created',
+                    u'creation_time': u'2012-07-09T09:12:45Z',
+                    u'stack_name': identity.stack_name,
+                    u'stack_status': u'CREATE_COMPLETE',
+                    u'parameters': {'foo': 'bar'},
+                    u'outputs': ['key', 'value'],
+                    u'notification_topics': [],
+                    u'capabilities': [],
+                    u'disable_rollback': True,
+                    u'timeout_mins': 60,
+                }
+            ]
+        }
+
+        self.assertEqual(result, expected)
+        self.m.VerifyAll()
+
     def test_index_rmt_aterr(self):
         req = self._get('/stacks')
 
@@ -1819,6 +1880,15 @@ class RoutesTest(HeatTestCase):
             {
                 'tenant_id': 'aaaa'
             })
+        self.assertRoute(
+            self.m,
+            '/aaaa/stacks/detail',
+            'GET',
+            'detail',
+            'StackController',
+            {
+                'tenant_id': 'aaaa'
+            })
 
     def test_stack_data(self):
         self.assertRoute(