Merge "Add test for volume snapshot in compute api"
diff --git a/tempest/api/compute/security_groups/test_security_group_rules.py b/tempest/api/compute/security_groups/test_security_group_rules.py
index 3c22d28..9aa59f7 100644
--- a/tempest/api/compute/security_groups/test_security_group_rules.py
+++ b/tempest/api/compute/security_groups/test_security_group_rules.py
@@ -161,8 +161,8 @@
         self.addCleanup(self.client.delete_security_group_rule, rule2_id)
 
         # Get rules of the created Security Group
-        rules = (self.client.list_security_group_rules(securitygroup_id)
-                 ['rules'])
+        rules = self.security_groups_client.show_security_group(
+            securitygroup_id)['security_group']['rules']
         self.assertTrue(any([i for i in rules if i['id'] == rule1_id]))
         self.assertTrue(any([i for i in rules if i['id'] == rule2_id]))
 
@@ -187,6 +187,7 @@
         # Delete group2
         self.security_groups_client.delete_security_group(sg2_id)
         # Get rules of the Group1
-        rules = self.client.list_security_group_rules(sg1_id)['rules']
+        rules = (self.security_groups_client.show_security_group(sg1_id)
+                 ['security_group']['rules'])
         # The group1 has no rules because group2 has deleted
         self.assertEqual(0, len(rules))
diff --git a/tempest/api/database/flavors/test_flavors.py b/tempest/api/database/flavors/test_flavors.py
index c97ddd7..62c1e05 100644
--- a/tempest/api/database/flavors/test_flavors.py
+++ b/tempest/api/database/flavors/test_flavors.py
@@ -28,7 +28,8 @@
     @test.idempotent_id('c94b825e-0132-4686-8049-8a4a2bc09525')
     def test_get_db_flavor(self):
         # The expected flavor details should be returned
-        flavor = self.client.get_db_flavor_details(self.db_flavor_ref)
+        flavor = (self.client.get_db_flavor_details(self.db_flavor_ref)
+                  ['flavor'])
         self.assertEqual(self.db_flavor_ref, str(flavor['id']))
         self.assertIn('ram', flavor)
         self.assertIn('links', flavor)
@@ -37,9 +38,10 @@
     @test.attr(type='smoke')
     @test.idempotent_id('685025d6-0cec-4673-8a8d-995cb8e0d3bb')
     def test_list_db_flavors(self):
-        flavor = self.client.get_db_flavor_details(self.db_flavor_ref)
+        flavor = (self.client.get_db_flavor_details(self.db_flavor_ref)
+                  ['flavor'])
         # List of all flavors should contain the expected flavor
-        flavors = self.client.list_db_flavors()
+        flavors = self.client.list_db_flavors()['flavors']
         self.assertIn(flavor, flavors)
 
     def _check_values(self, names, db_flavor, os_flavor, in_db=True):
@@ -57,7 +59,7 @@
     @test.idempotent_id('afb2667f-4ec2-4925-bcb7-313fdcffb80d')
     @test.services('compute')
     def test_compare_db_flavors_with_os(self):
-        db_flavors = self.client.list_db_flavors()
+        db_flavors = self.client.list_db_flavors()['flavors']
         os_flavors = (self.os_flavors_client.list_flavors(detail=True)
                       ['flavors'])
         self.assertEqual(len(os_flavors), len(db_flavors),
@@ -65,7 +67,7 @@
                          (os_flavors, db_flavors))
         for os_flavor in os_flavors:
             db_flavor =\
-                self.client.get_db_flavor_details(os_flavor['id'])
+                self.client.get_db_flavor_details(os_flavor['id'])['flavor']
             self._check_values(['id', 'name', 'ram'], db_flavor, os_flavor)
             self._check_values(['disk', 'vcpus', 'swap'], db_flavor, os_flavor,
                                in_db=False)
diff --git a/tempest/api/volume/admin/test_snapshots_actions.py b/tempest/api/volume/admin/test_snapshots_actions.py
index 784f1b6..aa6bfdf 100644
--- a/tempest/api/volume/admin/test_snapshots_actions.py
+++ b/tempest/api/volume/admin/test_snapshots_actions.py
@@ -15,10 +15,18 @@
 
 from tempest.api.volume import base
 from tempest.common.utils import data_utils
+from tempest import config
 from tempest import test
 
+CONF = config.CONF
+
 
 class SnapshotsActionsV2Test(base.BaseVolumeAdminTest):
+    @classmethod
+    def skip_checks(cls):
+        super(SnapshotsActionsV2Test, cls).skip_checks()
+        if not CONF.volume_feature_enabled.snapshot:
+            raise cls.skipException("Cinder snapshot feature disabled")
 
     @classmethod
     def setup_clients(cls):
diff --git a/tempest/api/volume/test_snapshot_metadata.py b/tempest/api/volume/test_snapshot_metadata.py
index ce6ba90..e50ca95 100644
--- a/tempest/api/volume/test_snapshot_metadata.py
+++ b/tempest/api/volume/test_snapshot_metadata.py
@@ -16,10 +16,18 @@
 from testtools import matchers
 
 from tempest.api.volume import base
+from tempest import config
 from tempest import test
 
+CONF = config.CONF
+
 
 class SnapshotV2MetadataTestJSON(base.BaseVolumeTest):
+    @classmethod
+    def skip_checks(cls):
+        super(SnapshotV2MetadataTestJSON, cls).skip_checks()
+        if not CONF.volume_feature_enabled.snapshot:
+            raise cls.skipException("Cinder snapshot feature disabled")
 
     @classmethod
     def setup_clients(cls):
diff --git a/tempest/config.py b/tempest/config.py
index 295b74d..ccfcd9c 100644
--- a/tempest/config.py
+++ b/tempest/config.py
@@ -1143,7 +1143,7 @@
                                title='Baremetal provisioning service options',
                                help='When enabling baremetal tests, Nova '
                                     'must be configured to use the Ironic '
-                                    'driver. The following paremeters for the '
+                                    'driver. The following parameters for the '
                                     '[compute] section must be disabled: '
                                     'console_output, interface_attach, '
                                     'live_migration, pause, rescue, resize '
diff --git a/tempest/services/compute/json/security_group_rules_client.py b/tempest/services/compute/json/security_group_rules_client.py
index c1c6b1a..9626f60 100644
--- a/tempest/services/compute/json/security_group_rules_client.py
+++ b/tempest/services/compute/json/security_group_rules_client.py
@@ -14,7 +14,6 @@
 #    under the License.
 
 from oslo_serialization import jsonutils as json
-from tempest_lib import exceptions as lib_exc
 
 from tempest.api_schema.response.compute.v2_1 import security_groups as schema
 from tempest.common import service_client
@@ -46,13 +45,3 @@
                                  group_rule_id)
         self.validate_response(schema.delete_security_group_rule, resp, body)
         return service_client.ResponseBody(resp, body)
-
-    def list_security_group_rules(self, security_group_id):
-        """List all rules for a security group."""
-        resp, body = self.get('os-security-groups')
-        body = json.loads(body)
-        self.validate_response(schema.list_security_groups, resp, body)
-        for sg in body['security_groups']:
-            if sg['id'] == security_group_id:
-                return service_client.ResponseBody(resp, sg)
-        raise lib_exc.NotFound('No such Security Group')
diff --git a/tempest/services/database/json/flavors_client.py b/tempest/services/database/json/flavors_client.py
index 4fe5a46..88feb17 100644
--- a/tempest/services/database/json/flavors_client.py
+++ b/tempest/services/database/json/flavors_client.py
@@ -13,6 +13,7 @@
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
+from oslo_serialization import jsonutils as json
 import urllib
 
 from tempest.common import service_client
@@ -27,9 +28,11 @@
 
         resp, body = self.get(url)
         self.expected_success(200, resp.status)
-        return service_client.ResponseBodyList(resp, self._parse_resp(body))
+        body = json.loads(body)
+        return service_client.ResponseBody(resp, body)
 
     def get_db_flavor_details(self, db_flavor_id):
         resp, body = self.get("flavors/%s" % str(db_flavor_id))
         self.expected_success(200, resp.status)
-        return service_client.ResponseBody(resp, self._parse_resp(body))
+        body = json.loads(body)
+        return service_client.ResponseBody(resp, body)
diff --git a/tempest/tests/services/compute/test_agents_client.py b/tempest/tests/services/compute/test_agents_client.py
index 9493a32..01035ab 100644
--- a/tempest/tests/services/compute/test_agents_client.py
+++ b/tempest/tests/services/compute/test_agents_client.py
@@ -56,6 +56,12 @@
             'tempest.common.service_client.ServiceClient.get',
             {"agents": []},
             bytes_body)
+        self.check_service_client_function(
+            self.client.list_agents,
+            'tempest.common.service_client.ServiceClient.get',
+            {"agents": []},
+            bytes_body,
+            hypervisor="kvm")
 
     def _test_create_agent(self, bytes_body=False):
         self.check_service_client_function(
diff --git a/tempest/tests/services/compute/test_server_groups_client.py b/tempest/tests/services/compute/test_server_groups_client.py
new file mode 100644
index 0000000..253dac1
--- /dev/null
+++ b/tempest/tests/services/compute/test_server_groups_client.py
@@ -0,0 +1,84 @@
+# Copyright 2015 IBM Corp.
+#
+#    Licensed under the Apache License, Version 2.0 (the "License"); you may
+#    not use this file except in compliance with the License. You may obtain
+#    a copy of the License at
+#
+#         http://www.apache.org/licenses/LICENSE-2.0
+#
+#    Unless required by applicable law or agreed to in writing, software
+#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+#    License for the specific language governing permissions and limitations
+#    under the License.
+
+import httplib2
+
+from oslotest import mockpatch
+
+from tempest.services.compute.json import server_groups_client
+from tempest.tests import fake_auth_provider
+from tempest.tests.services.compute import base
+
+
+class TestServerGroupsClient(base.BaseComputeServiceTest):
+
+    server_group = {
+        "id": "5bbcc3c4-1da2-4437-a48a-66f15b1b13f9",
+        "name": "test",
+        "policies": ["anti-affinity"],
+        "members": [],
+        "metadata": {}}
+
+    def setUp(self):
+        super(TestServerGroupsClient, self).setUp()
+        fake_auth = fake_auth_provider.FakeAuthProvider()
+        self.client = server_groups_client.ServerGroupsClient(
+            fake_auth, 'compute', 'regionOne')
+
+    def _test_create_server_group(self, bytes_body=False):
+        expected = {"server_group": TestServerGroupsClient.server_group}
+        self.check_service_client_function(
+            self.client.create_server_group,
+            'tempest.common.service_client.ServiceClient.post', expected,
+            bytes_body, name='fake-group', policies=['affinity'])
+
+    def test_create_server_group_str_body(self):
+        self._test_create_server_group(bytes_body=False)
+
+    def test_create_server_group_byte_body(self):
+        self._test_create_server_group(bytes_body=True)
+
+    def test_delete_server_group(self):
+        response = (httplib2.Response({'status': 204}), None)
+        self.useFixture(mockpatch.Patch(
+            'tempest.common.service_client.ServiceClient.delete',
+            return_value=response))
+        self.client.delete_server_group('fake-group')
+
+    def _test_list_server_groups(self, bytes_body=False):
+        expected = {"server_groups": [TestServerGroupsClient.server_group]}
+        self.check_service_client_function(
+            self.client.list_server_groups,
+            'tempest.common.service_client.ServiceClient.get',
+            expected, bytes_body)
+
+    def test_list_server_groups_str_body(self):
+        self._test_list_server_groups(bytes_body=False)
+
+    def test_list_server_groups_byte_body(self):
+        self._test_list_server_groups(bytes_body=True)
+
+    def _test_get_server_group(self, bytes_body=False):
+        expected = {"server_group": TestServerGroupsClient.server_group}
+        self.check_service_client_function(
+            self.client.get_server_group,
+            'tempest.common.service_client.ServiceClient.get',
+            expected, bytes_body,
+            server_group_id='5bbcc3c4-1da2-4437-a48a-66f15b1b13f9')
+
+    def test_get_server_group_str_body(self):
+        self._test_get_server_group(bytes_body=False)
+
+    def test_get_server_group_byte_body(self):
+        self._test_get_server_group(bytes_body=True)