port test_quotas into v3 part2

this ports test_quotas and corresponding clients into nova v3 api.
nova v3 api doesn't support security-groups. Due to the bug 1186354,
currently just remove some related tests, and these tests  will be
rework after that bug is fixed.
this removes the injected_files, injected_file_content_bytes and
injected_file_path_bytes in the v3 tests, because these have been
hidden in nova v3 api.

Partially implements blueprint nova-v3-api-tests

Change-Id: Ic60e33d798275c331e79a4600f1a52b27b79db2a
diff --git a/tempest/api/compute/base.py b/tempest/api/compute/base.py
index 1e5b6d2..80ac9fa 100644
--- a/tempest/api/compute/base.py
+++ b/tempest/api/compute/base.py
@@ -272,6 +272,7 @@
         cls.keypairs_client = cls.os.keypairs_v3_client
         cls.aggregates_client = cls.os.aggregates_v3_client
         cls.hosts_client = cls.os.hosts_v3_client
+        cls.quotas_client = cls.os.quotas_v3_client
 
     @classmethod
     def create_image_from_server(cls, server_id, **kwargs):
@@ -339,3 +340,4 @@
         cls.flavors_admin_client = cls.os_adm.flavors_v3_client
         cls.aggregates_admin_client = cls.os_adm.aggregates_v3_client
         cls.hosts_admin_client = cls.os_adm.hosts_v3_client
+        cls.quotas_admin_client = cls.os_adm.quotas_v3_client
diff --git a/tempest/api/compute/v3/admin/test_quotas.py b/tempest/api/compute/v3/admin/test_quotas.py
index 66d41b8..e67ed8f 100644
--- a/tempest/api/compute/v3/admin/test_quotas.py
+++ b/tempest/api/compute/v3/admin/test_quotas.py
@@ -1,6 +1,6 @@
 # vim: tabstop=4 shiftwidth=4 softtabstop=4
 
-# Copyright 2012 OpenStack Foundation
+# Copyright 2013 OpenStack Foundation
 # All Rights Reserved.
 #
 #    Licensed under the Apache License, Version 2.0 (the "License"); you may
@@ -17,41 +17,34 @@
 
 from tempest.api.compute import base
 from tempest.common.utils import data_utils
-from tempest import config
 from tempest import exceptions
-from tempest.test import attr
-from tempest.test import skip_because
-
-CONF = config.CONF
+from tempest import test
 
 
-class QuotasAdminTestJSON(base.BaseV2ComputeAdminTest):
+class QuotasAdminV3TestJSON(base.BaseV3ComputeAdminTest):
     _interface = 'json'
     force_tenant_isolation = True
 
     @classmethod
     def setUpClass(cls):
-        super(QuotasAdminTestJSON, cls).setUpClass()
+        super(QuotasAdminV3TestJSON, cls).setUpClass()
         cls.auth_url = cls.config.identity.uri
-        cls.client = cls.os.quotas_client
-        cls.adm_client = cls.os_adm.quotas_client
+        cls.client = cls.quotas_client
+        cls.adm_client = cls.quotas_admin_client
         cls.identity_admin_client = cls._get_identity_admin_client()
-        cls.sg_client = cls.security_groups_client
 
         # NOTE(afazekas): these test cases should always create and use a new
         # tenant most of them should be skipped if we can't do that
         cls.demo_tenant_id = cls.isolated_creds.get_primary_user().get(
             'tenantId')
 
-        cls.default_quota_set = set(('injected_file_content_bytes',
-                                     'metadata_items', 'injected_files',
+        cls.default_quota_set = set(('metadata_items',
                                      'ram', 'floating_ips',
                                      'fixed_ips', 'key_pairs',
-                                     'injected_file_path_bytes',
                                      'instances', 'security_group_rules',
                                      'cores', 'security_groups'))
 
-    @attr(type='smoke')
+    @test.attr(type='smoke')
     def test_get_default_quotas(self):
         # Admin can get the default resource quota set for a tenant
         expected_quota_set = self.default_quota_set | set(['id'])
@@ -62,15 +55,14 @@
                          sorted(quota_set.keys()))
         self.assertEqual(quota_set['id'], self.demo_tenant_id)
 
-    @attr(type='gate')
+    @test.attr(type='gate')
     def test_update_all_quota_resources_for_tenant(self):
         # Admin can update all the resource quota limits for a tenant
         resp, default_quota_set = self.client.get_default_quota_set(
             self.demo_tenant_id)
-        new_quota_set = {'injected_file_content_bytes': 20480,
-                         'metadata_items': 256, 'injected_files': 10,
+        new_quota_set = {'metadata_items': 256,
                          'ram': 10240, 'floating_ips': 20, 'fixed_ips': 10,
-                         'key_pairs': 200, 'injected_file_path_bytes': 512,
+                         'key_pairs': 200,
                          'instances': 20, 'security_group_rules': 20,
                          'cores': 2, 'security_groups': 20}
         # Update limits for all quota resources
@@ -83,10 +75,11 @@
         self.addCleanup(self.adm_client.update_quota_set,
                         self.demo_tenant_id, **default_quota_set)
         self.assertEqual(200, resp.status)
+        quota_set.pop('id')
         self.assertEqual(new_quota_set, quota_set)
 
     # TODO(afazekas): merge these test cases
-    @attr(type='gate')
+    @test.attr(type='gate')
     def test_get_updated_quotas(self):
         # Verify that GET shows the updated quota set
         tenant_name = data_utils.rand_name('cpu_quota_tenant_')
@@ -106,7 +99,7 @@
 
     # TODO(afazekas): Add dedicated tenant to the skiped quota tests
     # it can be moved into the setUpClass as well
-    @attr(type='gate')
+    @test.attr(type='gate')
     def test_create_server_when_cpu_quota_is_full(self):
         # Disallow server creation when tenant's vcpu quota is full
         resp, quota_set = self.client.get_quota_set(self.demo_tenant_id)
@@ -121,7 +114,7 @@
                         cores=default_vcpu_quota)
         self.assertRaises(exceptions.OverLimit, self.create_test_server)
 
-    @attr(type='gate')
+    @test.attr(type='gate')
     def test_create_server_when_memory_quota_is_full(self):
         # Disallow server creation when tenant's memory quota is full
         resp, quota_set = self.client.get_quota_set(self.demo_tenant_id)
@@ -136,14 +129,14 @@
                         ram=default_mem_quota)
         self.assertRaises(exceptions.OverLimit, self.create_test_server)
 
-    @attr(type='gate')
+    @test.attr(type='gate')
     def test_update_quota_normal_user(self):
         self.assertRaises(exceptions.Unauthorized,
                           self.client.update_quota_set,
                           self.demo_tenant_id,
                           ram=0)
 
-    @attr(type=['negative', 'gate'])
+    @test.attr(type=['negative', 'gate'])
     def test_create_server_when_instances_quota_is_full(self):
         # Once instances quota limit is reached, disallow server creation
         resp, quota_set = self.client.get_quota_set(self.demo_tenant_id)
@@ -157,66 +150,6 @@
                         instances=default_instances_quota)
         self.assertRaises(exceptions.OverLimit, self.create_test_server)
 
-    @skip_because(bug="1186354",
-                  condition=CONF.service_available.neutron)
-    @attr(type=['negative', 'gate'])
-    def test_security_groups_exceed_limit(self):
-        # Negative test: Creation Security Groups over limit should FAIL
 
-        resp, quota_set = self.client.get_quota_set(self.demo_tenant_id)
-        default_sg_quota = quota_set['security_groups']
-        sg_quota = 0  # Set the quota to zero to conserve resources
-
-        resp, quota_set =\
-            self.adm_client.update_quota_set(self.demo_tenant_id,
-                                             force=True,
-                                             security_groups=sg_quota)
-
-        self.addCleanup(self.adm_client.update_quota_set,
-                        self.demo_tenant_id,
-                        security_groups=default_sg_quota)
-
-        # Check we cannot create anymore
-        self.assertRaises(exceptions.OverLimit,
-                          self.sg_client.create_security_group,
-                          "sg-overlimit", "sg-desc")
-
-    @skip_because(bug="1186354",
-                  condition=CONF.service_available.neutron)
-    @attr(type=['negative', 'gate'])
-    def test_security_groups_rules_exceed_limit(self):
-        # Negative test: Creation of Security Group Rules should FAIL
-        # when we reach limit maxSecurityGroupRules
-
-        resp, quota_set = self.client.get_quota_set(self.demo_tenant_id)
-        default_sg_rules_quota = quota_set['security_group_rules']
-        sg_rules_quota = 0  # Set the quota to zero to conserve resources
-
-        resp, quota_set =\
-            self.adm_client.update_quota_set(
-                self.demo_tenant_id,
-                force=True,
-                security_group_rules=sg_rules_quota)
-
-        self.addCleanup(self.adm_client.update_quota_set,
-                        self.demo_tenant_id,
-                        security_group_rules=default_sg_rules_quota)
-
-        s_name = data_utils.rand_name('securitygroup-')
-        s_description = data_utils.rand_name('description-')
-        resp, securitygroup =\
-            self.sg_client.create_security_group(s_name, s_description)
-        self.addCleanup(self.sg_client.delete_security_group,
-                        securitygroup['id'])
-
-        secgroup_id = securitygroup['id']
-        ip_protocol = 'tcp'
-
-        # Check we cannot create SG rule anymore
-        self.assertRaises(exceptions.OverLimit,
-                          self.sg_client.create_security_group_rule,
-                          secgroup_id, ip_protocol, 1025, 1025)
-
-
-class QuotasAdminTestXML(QuotasAdminTestJSON):
+class QuotasAdminV3TestXML(QuotasAdminV3TestJSON):
     _interface = 'xml'
diff --git a/tempest/api/compute/v3/test_quotas.py b/tempest/api/compute/v3/test_quotas.py
index 475d055..d2f80a5 100644
--- a/tempest/api/compute/v3/test_quotas.py
+++ b/tempest/api/compute/v3/test_quotas.py
@@ -16,29 +16,27 @@
 #    under the License.
 
 from tempest.api.compute import base
-from tempest.test import attr
+from tempest import test
 
 
-class QuotasTestJSON(base.BaseV2ComputeTest):
+class QuotasV3TestJSON(base.BaseV3ComputeTest):
     _interface = 'json'
 
     @classmethod
     def setUpClass(cls):
-        super(QuotasTestJSON, cls).setUpClass()
+        super(QuotasV3TestJSON, cls).setUpClass()
         cls.client = cls.quotas_client
         cls.admin_client = cls._get_identity_admin_client()
         resp, tenants = cls.admin_client.list_tenants()
         cls.tenant_id = [tnt['id'] for tnt in tenants if tnt['name'] ==
                          cls.client.tenant_name][0]
-        cls.default_quota_set = set(('injected_file_content_bytes',
-                                     'metadata_items', 'injected_files',
+        cls.default_quota_set = set(('metadata_items',
                                      'ram', 'floating_ips',
                                      'fixed_ips', 'key_pairs',
-                                     'injected_file_path_bytes',
                                      'instances', 'security_group_rules',
                                      'cores', 'security_groups'))
 
-    @attr(type='smoke')
+    @test.attr(type='smoke')
     def test_get_quotas(self):
         # User can get the quota set for it's tenant
         expected_quota_set = self.default_quota_set | set(['id'])
@@ -48,7 +46,7 @@
                          sorted(quota_set.keys()))
         self.assertEqual(quota_set['id'], self.tenant_id)
 
-    @attr(type='smoke')
+    @test.attr(type='smoke')
     def test_get_default_quotas(self):
         # User can get the default quota set for it's tenant
         expected_quota_set = self.default_quota_set | set(['id'])
@@ -58,7 +56,7 @@
                          sorted(quota_set.keys()))
         self.assertEqual(quota_set['id'], self.tenant_id)
 
-    @attr(type='smoke')
+    @test.attr(type='smoke')
     def test_compare_tenant_quotas_with_default_quotas(self):
         # Tenants are created with the default quota values
         resp, defualt_quota_set = \
@@ -69,5 +67,5 @@
         self.assertEqual(defualt_quota_set, tenant_quota_set)
 
 
-class QuotasTestXML(QuotasTestJSON):
+class QuotasV3TestXML(QuotasV3TestJSON):
     _interface = 'xml'
diff --git a/tempest/clients.py b/tempest/clients.py
index f4548d5..6ff4278 100644
--- a/tempest/clients.py
+++ b/tempest/clients.py
@@ -66,6 +66,8 @@
     InterfacesV3ClientJSON
 from tempest.services.compute.v3.json.keypairs_client import \
     KeyPairsV3ClientJSON
+from tempest.services.compute.v3.json.quotas_client import \
+    QuotasV3ClientJSON
 from tempest.services.compute.v3.json.servers_client import \
     ServersV3ClientJSON
 from tempest.services.compute.v3.json.services_client import \
@@ -87,6 +89,8 @@
 from tempest.services.compute.v3.xml.interfaces_client import \
     InterfacesV3ClientXML
 from tempest.services.compute.v3.xml.keypairs_client import KeyPairsV3ClientXML
+from tempest.services.compute.v3.xml.quotas_client import \
+    QuotasV3ClientXML
 from tempest.services.compute.v3.xml.servers_client import ServersV3ClientXML
 from tempest.services.compute.v3.xml.services_client import \
     ServicesV3ClientXML
@@ -235,6 +239,7 @@
             self.keypairs_v3_client = KeyPairsV3ClientXML(*client_args)
             self.keypairs_client = KeyPairsClientXML(*client_args)
             self.quotas_client = QuotasClientXML(*client_args)
+            self.quotas_v3_client = QuotasV3ClientXML(*client_args)
             self.flavors_client = FlavorsClientXML(*client_args)
             self.flavors_v3_client = FlavorsV3ClientXML(*client_args)
             self.extensions_v3_client = ExtensionsV3ClientXML(*client_args)
@@ -295,6 +300,7 @@
             self.keypairs_v3_client = KeyPairsV3ClientJSON(*client_args)
             self.keypairs_client = KeyPairsClientJSON(*client_args)
             self.quotas_client = QuotasClientJSON(*client_args)
+            self.quotas_v3_client = QuotasV3ClientJSON(*client_args)
             self.flavors_client = FlavorsClientJSON(*client_args)
             self.flavors_v3_client = FlavorsV3ClientJSON(*client_args)
             self.extensions_v3_client = ExtensionsV3ClientJSON(*client_args)
diff --git a/tempest/services/compute/v3/json/quotas_client.py b/tempest/services/compute/v3/json/quotas_client.py
index a910dec..cae2332 100644
--- a/tempest/services/compute/v3/json/quotas_client.py
+++ b/tempest/services/compute/v3/json/quotas_client.py
@@ -20,12 +20,12 @@
 from tempest.common.rest_client import RestClient
 
 
-class QuotasClientJSON(RestClient):
+class QuotasV3ClientJSON(RestClient):
 
     def __init__(self, config, username, password, auth_url, tenant_name=None):
-        super(QuotasClientJSON, self).__init__(config, username, password,
-                                               auth_url, tenant_name)
-        self.service = self.config.compute.catalog_type
+        super(QuotasV3ClientJSON, self).__init__(config, username, password,
+                                                 auth_url, tenant_name)
+        self.service = self.config.compute.catalog_v3_type
 
     def get_quota_set(self, tenant_id):
         """List the quota set for a tenant."""
@@ -44,11 +44,9 @@
         return resp, body['quota_set']
 
     def update_quota_set(self, tenant_id, force=None,
-                         injected_file_content_bytes=None,
                          metadata_items=None, ram=None, floating_ips=None,
                          fixed_ips=None, key_pairs=None, instances=None,
-                         security_group_rules=None, injected_files=None,
-                         cores=None, injected_file_path_bytes=None,
+                         security_group_rules=None, cores=None,
                          security_groups=None):
         """
         Updates the tenant's quota limits for one or more resources
@@ -58,10 +56,6 @@
         if force is not None:
             post_body['force'] = force
 
-        if injected_file_content_bytes is not None:
-            post_body['injected_file_content_bytes'] = \
-                injected_file_content_bytes
-
         if metadata_items is not None:
             post_body['metadata_items'] = metadata_items
 
@@ -83,15 +77,9 @@
         if security_group_rules is not None:
             post_body['security_group_rules'] = security_group_rules
 
-        if injected_files is not None:
-            post_body['injected_files'] = injected_files
-
         if cores is not None:
             post_body['cores'] = cores
 
-        if injected_file_path_bytes is not None:
-            post_body['injected_file_path_bytes'] = injected_file_path_bytes
-
         if security_groups is not None:
             post_body['security_groups'] = security_groups
 
diff --git a/tempest/services/compute/v3/xml/quotas_client.py b/tempest/services/compute/v3/xml/quotas_client.py
index ef5362c..7ef2274 100644
--- a/tempest/services/compute/v3/xml/quotas_client.py
+++ b/tempest/services/compute/v3/xml/quotas_client.py
@@ -21,15 +21,15 @@
 from tempest.services.compute.xml.common import Document
 from tempest.services.compute.xml.common import Element
 from tempest.services.compute.xml.common import xml_to_json
-from tempest.services.compute.xml.common import XMLNS_11
+from tempest.services.compute.xml.common import XMLNS_V3
 
 
-class QuotasClientXML(RestClientXML):
+class QuotasV3ClientXML(RestClientXML):
 
     def __init__(self, config, username, password, auth_url, tenant_name=None):
-        super(QuotasClientXML, self).__init__(config, username, password,
-                                              auth_url, tenant_name)
-        self.service = self.config.compute.catalog_type
+        super(QuotasV3ClientXML, self).__init__(config, username, password,
+                                                auth_url, tenant_name)
+        self.service = self.config.compute.catalog_v3_type
 
     def _format_quota(self, q):
         quota = {}
@@ -65,25 +65,19 @@
         return resp, body
 
     def update_quota_set(self, tenant_id, force=None,
-                         injected_file_content_bytes=None,
                          metadata_items=None, ram=None, floating_ips=None,
                          fixed_ips=None, key_pairs=None, instances=None,
-                         security_group_rules=None, injected_files=None,
-                         cores=None, injected_file_path_bytes=None,
+                         security_group_rules=None, cores=None,
                          security_groups=None):
         """
         Updates the tenant's quota limits for one or more resources
         """
         post_body = Element("quota_set",
-                            xmlns=XMLNS_11)
+                            xmlns=XMLNS_V3)
 
         if force is not None:
             post_body.add_attr('force', force)
 
-        if injected_file_content_bytes is not None:
-            post_body.add_attr('injected_file_content_bytes',
-                               injected_file_content_bytes)
-
         if metadata_items is not None:
             post_body.add_attr('metadata_items', metadata_items)
 
@@ -105,16 +99,9 @@
         if security_group_rules is not None:
             post_body.add_attr('security_group_rules', security_group_rules)
 
-        if injected_files is not None:
-            post_body.add_attr('injected_files', injected_files)
-
         if cores is not None:
             post_body.add_attr('cores', cores)
 
-        if injected_file_path_bytes is not None:
-            post_body.add_attr('injected_file_path_bytes',
-                               injected_file_path_bytes)
-
         if security_groups is not None:
             post_body.add_attr('security_groups', security_groups)