Return complete response from compute/aggregates_client

Currently compute aggregates_client returns Response by removing
top key from Response.
For example- return service_client.ResponseBody(resp, body['aggregate'])

As service clients are in direction to move to Tempest-lib, all
service clients should return Response without any truncation.
One good example is Resource pagination links which are lost with current
way of return value. Resource pagination links are present in parallel
(not inside) to top key of Response.

This patch makes compute aggregates_client to return complete Response body.

Change-Id: Iac7e2e59b0a5b498fb5be5c7696ebe7bb15be8fe
Implements: blueprint method-return-value-and-move-service-clients-to-lib
diff --git a/tempest/api/compute/admin/test_aggregates.py b/tempest/api/compute/admin/test_aggregates.py
index 9334fb6..a8cfe93 100644
--- a/tempest/api/compute/admin/test_aggregates.py
+++ b/tempest/api/compute/admin/test_aggregates.py
@@ -57,7 +57,8 @@
     def test_aggregate_create_delete(self):
         # Create and delete an aggregate.
         aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
-        aggregate = self.client.create_aggregate(name=aggregate_name)
+        aggregate = (self.client.create_aggregate(name=aggregate_name)
+                     ['aggregate'])
         self.addCleanup(self._try_delete_aggregate, aggregate['id'])
         self.assertEqual(aggregate_name, aggregate['name'])
         self.assertIsNone(aggregate['availability_zone'])
@@ -71,7 +72,7 @@
         aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
         az_name = data_utils.rand_name(self.az_name_prefix)
         aggregate = self.client.create_aggregate(
-            name=aggregate_name, availability_zone=az_name)
+            name=aggregate_name, availability_zone=az_name)['aggregate']
         self.addCleanup(self._try_delete_aggregate, aggregate['id'])
         self.assertEqual(aggregate_name, aggregate['name'])
         self.assertEqual(az_name, aggregate['availability_zone'])
@@ -83,10 +84,11 @@
     def test_aggregate_create_verify_entry_in_list(self):
         # Create an aggregate and ensure it is listed.
         aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
-        aggregate = self.client.create_aggregate(name=aggregate_name)
+        aggregate = (self.client.create_aggregate(name=aggregate_name)
+                     ['aggregate'])
         self.addCleanup(self.client.delete_aggregate, aggregate['id'])
 
-        aggregates = self.client.list_aggregates()
+        aggregates = self.client.list_aggregates()['aggregates']
         self.assertIn((aggregate['id'], aggregate['availability_zone']),
                       map(lambda x: (x['id'], x['availability_zone']),
                           aggregates))
@@ -95,10 +97,11 @@
     def test_aggregate_create_update_metadata_get_details(self):
         # Create an aggregate and ensure its details are returned.
         aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
-        aggregate = self.client.create_aggregate(name=aggregate_name)
+        aggregate = (self.client.create_aggregate(name=aggregate_name)
+                     ['aggregate'])
         self.addCleanup(self.client.delete_aggregate, aggregate['id'])
 
-        body = self.client.show_aggregate(aggregate['id'])
+        body = self.client.show_aggregate(aggregate['id'])['aggregate']
         self.assertEqual(aggregate['name'], body['name'])
         self.assertEqual(aggregate['availability_zone'],
                          body['availability_zone'])
@@ -107,10 +110,10 @@
         # set the metadata of the aggregate
         meta = {"key": "value"}
         body = self.client.set_metadata(aggregate['id'], metadata=meta)
-        self.assertEqual(meta, body["metadata"])
+        self.assertEqual(meta, body['aggregate']["metadata"])
 
         # verify the metadata has been set
-        body = self.client.show_aggregate(aggregate['id'])
+        body = self.client.show_aggregate(aggregate['id'])['aggregate']
         self.assertEqual(meta, body["metadata"])
 
     @test.idempotent_id('4d2b2004-40fa-40a1-aab2-66f4dab81beb')
@@ -119,7 +122,7 @@
         aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
         az_name = data_utils.rand_name(self.az_name_prefix)
         aggregate = self.client.create_aggregate(
-            name=aggregate_name, availability_zone=az_name)
+            name=aggregate_name, availability_zone=az_name)['aggregate']
         self.addCleanup(self.client.delete_aggregate, aggregate['id'])
 
         self.assertEqual(aggregate_name, aggregate['name'])
@@ -133,11 +136,11 @@
         resp_aggregate = self.client.update_aggregate(
             aggregate_id,
             name=new_aggregate_name,
-            availability_zone=new_az_name)
+            availability_zone=new_az_name)['aggregate']
         self.assertEqual(new_aggregate_name, resp_aggregate['name'])
         self.assertEqual(new_az_name, resp_aggregate['availability_zone'])
 
-        aggregates = self.client.list_aggregates()
+        aggregates = self.client.list_aggregates()['aggregates']
         self.assertIn((aggregate_id, new_aggregate_name, new_az_name),
                       map(lambda x:
                           (x['id'], x['name'], x['availability_zone']),
@@ -148,16 +151,19 @@
         # Add an host to the given aggregate and remove.
         self.useFixture(fixtures.LockFixture('availability_zone'))
         aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
-        aggregate = self.client.create_aggregate(name=aggregate_name)
+        aggregate = (self.client.create_aggregate(name=aggregate_name)
+                     ['aggregate'])
         self.addCleanup(self.client.delete_aggregate, aggregate['id'])
 
-        body = self.client.add_host(aggregate['id'], host=self.host)
+        body = (self.client.add_host(aggregate['id'], host=self.host)
+                ['aggregate'])
         self.assertEqual(aggregate_name, body['name'])
         self.assertEqual(aggregate['availability_zone'],
                          body['availability_zone'])
         self.assertIn(self.host, body['hosts'])
 
-        body = self.client.remove_host(aggregate['id'], host=self.host)
+        body = (self.client.remove_host(aggregate['id'], host=self.host)
+                ['aggregate'])
         self.assertEqual(aggregate_name, body['name'])
         self.assertEqual(aggregate['availability_zone'],
                          body['availability_zone'])
@@ -168,13 +174,14 @@
         # Add an host to the given aggregate and list.
         self.useFixture(fixtures.LockFixture('availability_zone'))
         aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
-        aggregate = self.client.create_aggregate(name=aggregate_name)
+        aggregate = (self.client.create_aggregate(name=aggregate_name)
+                     ['aggregate'])
         self.addCleanup(self.client.delete_aggregate, aggregate['id'])
         self.client.add_host(aggregate['id'], host=self.host)
         self.addCleanup(self.client.remove_host, aggregate['id'],
                         host=self.host)
 
-        aggregates = self.client.list_aggregates()
+        aggregates = self.client.list_aggregates()['aggregates']
         aggs = filter(lambda x: x['id'] == aggregate['id'], aggregates)
         self.assertEqual(1, len(aggs))
         agg = aggs[0]
@@ -187,13 +194,14 @@
         # Add an host to the given aggregate and get details.
         self.useFixture(fixtures.LockFixture('availability_zone'))
         aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
-        aggregate = self.client.create_aggregate(name=aggregate_name)
+        aggregate = (self.client.create_aggregate(name=aggregate_name)
+                     ['aggregate'])
         self.addCleanup(self.client.delete_aggregate, aggregate['id'])
         self.client.add_host(aggregate['id'], host=self.host)
         self.addCleanup(self.client.remove_host, aggregate['id'],
                         host=self.host)
 
-        body = self.client.show_aggregate(aggregate['id'])
+        body = self.client.show_aggregate(aggregate['id'])['aggregate']
         self.assertEqual(aggregate_name, body['name'])
         self.assertIsNone(body['availability_zone'])
         self.assertIn(self.host, body['hosts'])
@@ -205,7 +213,7 @@
         aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
         az_name = data_utils.rand_name(self.az_name_prefix)
         aggregate = self.client.create_aggregate(
-            name=aggregate_name, availability_zone=az_name)
+            name=aggregate_name, availability_zone=az_name)['aggregate']
         self.addCleanup(self.client.delete_aggregate, aggregate['id'])
         self.client.add_host(aggregate['id'], host=self.host)
         self.addCleanup(self.client.remove_host, aggregate['id'],
diff --git a/tempest/api/compute/admin/test_aggregates_negative.py b/tempest/api/compute/admin/test_aggregates_negative.py
index 231c88f..5434b3f 100644
--- a/tempest/api/compute/admin/test_aggregates_negative.py
+++ b/tempest/api/compute/admin/test_aggregates_negative.py
@@ -76,7 +76,8 @@
         # creating an aggregate with existent aggregate name is forbidden
         aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
         aggregate = self.client.create_aggregate(name=aggregate_name)
-        self.addCleanup(self.client.delete_aggregate, aggregate['id'])
+        self.addCleanup(self.client.delete_aggregate,
+                        aggregate['aggregate']['id'])
 
         self.assertRaises(lib_exc.Conflict,
                           self.client.create_aggregate,
@@ -87,7 +88,8 @@
     def test_aggregate_delete_as_user(self):
         # Regular user is not allowed to delete an aggregate.
         aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
-        aggregate = self.client.create_aggregate(name=aggregate_name)
+        aggregate = (self.client.create_aggregate(name=aggregate_name)
+                     ['aggregate'])
         self.addCleanup(self.client.delete_aggregate, aggregate['id'])
 
         self.assertRaises(lib_exc.Forbidden,
@@ -106,7 +108,8 @@
     def test_aggregate_get_details_as_user(self):
         # Regular user is not allowed to get aggregate details.
         aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
-        aggregate = self.client.create_aggregate(name=aggregate_name)
+        aggregate = (self.client.create_aggregate(name=aggregate_name)
+                     ['aggregate'])
         self.addCleanup(self.client.delete_aggregate, aggregate['id'])
 
         self.assertRaises(lib_exc.Forbidden,
@@ -139,7 +142,8 @@
                 break
 
         aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
-        aggregate = self.client.create_aggregate(name=aggregate_name)
+        aggregate = (self.client.create_aggregate(name=aggregate_name)
+                     ['aggregate'])
         self.addCleanup(self.client.delete_aggregate, aggregate['id'])
 
         self.assertRaises(lib_exc.NotFound, self.client.add_host,
@@ -150,7 +154,8 @@
     def test_aggregate_add_host_as_user(self):
         # Regular user is not allowed to add a host to an aggregate.
         aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
-        aggregate = self.client.create_aggregate(name=aggregate_name)
+        aggregate = (self.client.create_aggregate(name=aggregate_name)
+                     ['aggregate'])
         self.addCleanup(self.client.delete_aggregate, aggregate['id'])
 
         self.assertRaises(lib_exc.Forbidden,
@@ -162,7 +167,8 @@
     def test_aggregate_add_existent_host(self):
         self.useFixture(fixtures.LockFixture('availability_zone'))
         aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
-        aggregate = self.client.create_aggregate(name=aggregate_name)
+        aggregate = (self.client.create_aggregate(name=aggregate_name)
+                     ['aggregate'])
         self.addCleanup(self.client.delete_aggregate, aggregate['id'])
 
         self.client.add_host(aggregate['id'], host=self.host)
@@ -178,7 +184,8 @@
         # Regular user is not allowed to remove a host from an aggregate.
         self.useFixture(fixtures.LockFixture('availability_zone'))
         aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
-        aggregate = self.client.create_aggregate(name=aggregate_name)
+        aggregate = (self.client.create_aggregate(name=aggregate_name)
+                     ['aggregate'])
         self.addCleanup(self.client.delete_aggregate, aggregate['id'])
         self.client.add_host(aggregate['id'], host=self.host)
         self.addCleanup(self.client.remove_host, aggregate['id'],
@@ -193,7 +200,8 @@
     def test_aggregate_remove_nonexistent_host(self):
         non_exist_host = data_utils.rand_name('nonexist_host')
         aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
-        aggregate = self.client.create_aggregate(name=aggregate_name)
+        aggregate = (self.client.create_aggregate(name=aggregate_name)
+                     ['aggregate'])
         self.addCleanup(self.client.delete_aggregate, aggregate['id'])
 
         self.assertRaises(lib_exc.NotFound, self.client.remove_host,
diff --git a/tempest/scenario/test_aggregates_basic_ops.py b/tempest/scenario/test_aggregates_basic_ops.py
index f5f4a61..f1c18e1 100644
--- a/tempest/scenario/test_aggregates_basic_ops.py
+++ b/tempest/scenario/test_aggregates_basic_ops.py
@@ -46,7 +46,8 @@
         cls.hosts_client = cls.manager.hosts_client
 
     def _create_aggregate(self, **kwargs):
-        aggregate = self.aggregates_client.create_aggregate(**kwargs)
+        aggregate = (self.aggregates_client.create_aggregate(**kwargs)
+                     ['aggregate'])
         self.addCleanup(self._delete_aggregate, aggregate)
         aggregate_name = kwargs['name']
         availability_zone = kwargs['availability_zone']
@@ -64,17 +65,19 @@
         return computes[0]['host_name']
 
     def _add_host(self, aggregate_id, host):
-        aggregate = self.aggregates_client.add_host(aggregate_id, host=host)
+        aggregate = (self.aggregates_client.add_host(aggregate_id, host=host)
+                     ['aggregate'])
         self.addCleanup(self._remove_host, aggregate['id'], host)
         self.assertIn(host, aggregate['hosts'])
 
     def _remove_host(self, aggregate_id, host):
         aggregate = self.aggregates_client.remove_host(aggregate_id, host=host)
-        self.assertNotIn(host, aggregate['hosts'])
+        self.assertNotIn(host, aggregate['aggregate']['hosts'])
 
     def _check_aggregate_details(self, aggregate, aggregate_name, azone,
                                  hosts, metadata):
-        aggregate = self.aggregates_client.show_aggregate(aggregate['id'])
+        aggregate = (self.aggregates_client.show_aggregate(aggregate['id'])
+                     ['aggregate'])
         self.assertEqual(aggregate_name, aggregate['name'])
         self.assertEqual(azone, aggregate['availability_zone'])
         self.assertEqual(hosts, aggregate['hosts'])
@@ -88,13 +91,14 @@
                                                         metadata=meta)
 
         for key, value in meta.items():
-            self.assertEqual(meta[key], aggregate['metadata'][key])
+            self.assertEqual(meta[key],
+                             aggregate['aggregate']['metadata'][key])
 
     def _update_aggregate(self, aggregate, aggregate_name,
                           availability_zone):
         aggregate = self.aggregates_client.update_aggregate(
             aggregate['id'], name=aggregate_name,
-            availability_zone=availability_zone)
+            availability_zone=availability_zone)['aggregate']
         self.assertEqual(aggregate['name'], aggregate_name)
         self.assertEqual(aggregate['availability_zone'], availability_zone)
         return aggregate
diff --git a/tempest/services/compute/json/aggregates_client.py b/tempest/services/compute/json/aggregates_client.py
index 4114b8b..c9895db 100644
--- a/tempest/services/compute/json/aggregates_client.py
+++ b/tempest/services/compute/json/aggregates_client.py
@@ -27,14 +27,14 @@
         resp, body = self.get("os-aggregates")
         body = json.loads(body)
         self.validate_response(schema.list_aggregates, resp, body)
-        return service_client.ResponseBodyList(resp, body['aggregates'])
+        return service_client.ResponseBody(resp, body)
 
     def show_aggregate(self, aggregate_id):
         """Get details of the given aggregate."""
         resp, body = self.get("os-aggregates/%s" % aggregate_id)
         body = json.loads(body)
         self.validate_response(schema.get_aggregate, resp, body)
-        return service_client.ResponseBody(resp, body['aggregate'])
+        return service_client.ResponseBody(resp, body)
 
     def create_aggregate(self, **kwargs):
         """Creates a new aggregate."""
@@ -43,7 +43,7 @@
 
         body = json.loads(body)
         self.validate_response(schema.create_aggregate, resp, body)
-        return service_client.ResponseBody(resp, body['aggregate'])
+        return service_client.ResponseBody(resp, body)
 
     def update_aggregate(self, aggregate_id, **kwargs):
         """Update a aggregate."""
@@ -52,7 +52,7 @@
 
         body = json.loads(body)
         self.validate_response(schema.update_aggregate, resp, body)
-        return service_client.ResponseBody(resp, body['aggregate'])
+        return service_client.ResponseBody(resp, body)
 
     def delete_aggregate(self, aggregate_id):
         """Deletes the given aggregate."""
@@ -79,7 +79,7 @@
                                post_body)
         body = json.loads(body)
         self.validate_response(schema.aggregate_add_remove_host, resp, body)
-        return service_client.ResponseBody(resp, body['aggregate'])
+        return service_client.ResponseBody(resp, body)
 
     def remove_host(self, aggregate_id, **kwargs):
         """Removes a host from the given aggregate."""
@@ -88,7 +88,7 @@
                                post_body)
         body = json.loads(body)
         self.validate_response(schema.aggregate_add_remove_host, resp, body)
-        return service_client.ResponseBody(resp, body['aggregate'])
+        return service_client.ResponseBody(resp, body)
 
     def set_metadata(self, aggregate_id, **kwargs):
         """Replaces the aggregate's existing metadata with new metadata."""
@@ -97,4 +97,4 @@
                                post_body)
         body = json.loads(body)
         self.validate_response(schema.aggregate_set_metadata, resp, body)
-        return service_client.ResponseBody(resp, body['aggregate'])
+        return service_client.ResponseBody(resp, body)
diff --git a/tempest/tests/services/compute/test_aggregates_client.py b/tempest/tests/services/compute/test_aggregates_client.py
index eacc251..14930a7 100644
--- a/tempest/tests/services/compute/test_aggregates_client.py
+++ b/tempest/tests/services/compute/test_aggregates_client.py
@@ -34,7 +34,7 @@
         body = '{"aggregates": []}'
         if bytes_body:
             body = body.encode('utf-8')
-        expected = []
+        expected = {"aggregates": []}
         response = (httplib2.Response({'status': 200}), body)
         self.useFixture(mockpatch.Patch(
             'tempest.common.service_client.ServiceClient.get',
@@ -48,17 +48,17 @@
         self._test_list_aggregates(bytes_body=True)
 
     def _test_show_aggregate(self, bytes_body=False):
-        expected = {"name": "hoge",
-                    "availability_zone": None,
-                    "deleted": False,
-                    "created_at":
-                    "2015-07-16T03:07:32.000000",
-                    "updated_at": None,
-                    "hosts": [],
-                    "deleted_at": None,
-                    "id": 1,
-                    "metadata": {}}
-        serialized_body = json.dumps({"aggregate": expected})
+        expected = {"aggregate": {"name": "hoge",
+                                  "availability_zone": None,
+                                  "deleted": False,
+                                  "created_at":
+                                  "2015-07-16T03:07:32.000000",
+                                  "updated_at": None,
+                                  "hosts": [],
+                                  "deleted_at": None,
+                                  "id": 1,
+                                  "metadata": {}}}
+        serialized_body = json.dumps(expected)
         if bytes_body:
             serialized_body = serialized_body.encode('utf-8')
 
@@ -76,14 +76,14 @@
         self._test_show_aggregate(bytes_body=True)
 
     def _test_create_aggregate(self, bytes_body=False):
-        expected = {"name": u'\xf4',
-                    "availability_zone": None,
-                    "deleted": False,
-                    "created_at": "2015-07-21T04:11:18.000000",
-                    "updated_at": None,
-                    "deleted_at": None,
-                    "id": 1}
-        serialized_body = json.dumps({"aggregate": expected})
+        expected = {"aggregate": {"name": u'\xf4',
+                                  "availability_zone": None,
+                                  "deleted": False,
+                                  "created_at": "2015-07-21T04:11:18.000000",
+                                  "updated_at": None,
+                                  "deleted_at": None,
+                                  "id": 1}}
+        serialized_body = json.dumps(expected)
         if bytes_body:
             serialized_body = serialized_body.encode('utf-8')
 
@@ -110,16 +110,16 @@
         self.assertEqual(expected, resp)
 
     def _test_update_aggregate(self, bytes_body=False):
-        expected = {"name": u'\xe9',
-                    "availability_zone": None,
-                    "deleted": False,
-                    "created_at": "2015-07-16T03:07:32.000000",
-                    "updated_at": "2015-07-23T05:16:29.000000",
-                    "hosts": [],
-                    "deleted_at": None,
-                    "id": 1,
-                    "metadata": {}}
-        serialized_body = json.dumps({"aggregate": expected})
+        expected = {"aggregate": {"name": u'\xe9',
+                                  "availability_zone": None,
+                                  "deleted": False,
+                                  "created_at": "2015-07-16T03:07:32.000000",
+                                  "updated_at": "2015-07-23T05:16:29.000000",
+                                  "hosts": [],
+                                  "deleted_at": None,
+                                  "id": 1,
+                                  "metadata": {}}}
+        serialized_body = json.dumps(expected)
         if bytes_body:
             serialized_body = serialized_body.encode('utf-8')