diff --git a/tempest/api/compute/admin/test_quotas.py b/tempest/api/compute/admin/test_quotas.py index 3416eaeb1c..ef96f9b9d2 100644 --- a/tempest/api/compute/admin/test_quotas.py +++ b/tempest/api/compute/admin/test_quotas.py @@ -59,7 +59,7 @@ class QuotasAdminTestJSON(base.BaseV2ComputeAdminTest): # Admin can get the default resource quota set for a tenant expected_quota_set = self.default_quota_set | set(['id']) quota_set = self.adm_client.show_default_quota_set( - self.demo_tenant_id) + self.demo_tenant_id)['quota_set'] self.assertEqual(quota_set['id'], self.demo_tenant_id) for quota in expected_quota_set: self.assertIn(quota, quota_set.keys()) @@ -68,7 +68,7 @@ class QuotasAdminTestJSON(base.BaseV2ComputeAdminTest): def test_update_all_quota_resources_for_tenant(self): # Admin can update all the resource quota limits for a tenant default_quota_set = self.adm_client.show_default_quota_set( - self.demo_tenant_id) + self.demo_tenant_id)['quota_set'] new_quota_set = {'injected_file_content_bytes': 20480, 'metadata_items': 256, 'injected_files': 10, 'ram': 10240, 'floating_ips': 20, 'fixed_ips': 10, @@ -79,7 +79,7 @@ class QuotasAdminTestJSON(base.BaseV2ComputeAdminTest): quota_set = self.adm_client.update_quota_set( self.demo_tenant_id, force=True, - **new_quota_set) + **new_quota_set)['quota_set'] default_quota_set.pop('id') # NOTE(PhilDay) The following is safe as we're not updating these @@ -107,7 +107,7 @@ class QuotasAdminTestJSON(base.BaseV2ComputeAdminTest): self.addCleanup(identity_client.delete_tenant, tenant_id) self.adm_client.update_quota_set(tenant_id, ram='5120') - quota_set = self.adm_client.show_quota_set(tenant_id) + quota_set = self.adm_client.show_quota_set(tenant_id)['quota_set'] self.assertEqual(5120, quota_set['ram']) # Verify that GET shows the updated quota set of user @@ -126,8 +126,8 @@ class QuotasAdminTestJSON(base.BaseV2ComputeAdminTest): self.adm_client.update_quota_set(tenant_id, user_id=user_id, ram='2048') - quota_set = self.adm_client.show_quota_set(tenant_id, - user_id=user_id) + quota_set = self.adm_client.show_quota_set( + tenant_id, user_id=user_id)['quota_set'] self.assertEqual(2048, quota_set['ram']) @test.idempotent_id('389d04f0-3a41-405f-9317-e5f86e3c44f0') @@ -140,14 +140,15 @@ class QuotasAdminTestJSON(base.BaseV2ComputeAdminTest): description=tenant_desc) tenant_id = tenant['id'] self.addCleanup(identity_client.delete_tenant, tenant_id) - quota_set_default = self.adm_client.show_quota_set(tenant_id) + quota_set_default = (self.adm_client.show_quota_set(tenant_id) + ['quota_set']) ram_default = quota_set_default['ram'] self.adm_client.update_quota_set(tenant_id, ram='5120') self.adm_client.delete_quota_set(tenant_id) - quota_set_new = self.adm_client.show_quota_set(tenant_id) + quota_set_new = self.adm_client.show_quota_set(tenant_id)['quota_set'] self.assertEqual(ram_default, quota_set_new['ram']) @@ -169,7 +170,7 @@ class QuotaClassesAdminTestJSON(base.BaseV2ComputeAdminTest): def _restore_default_quotas(self, original_defaults): LOG.debug("restoring quota class defaults") self.adm_client.update_quota_class_set( - 'default', **original_defaults) + 'default', **original_defaults)['quota_class_set'] # NOTE(sdague): this test is problematic as it changes # global state, and possibly needs to be part of a set of @@ -178,7 +179,8 @@ class QuotaClassesAdminTestJSON(base.BaseV2ComputeAdminTest): @test.idempotent_id('7932ab0f-5136-4075-b201-c0e2338df51a') def test_update_default_quotas(self): LOG.debug("get the current 'default' quota class values") - body = self.adm_client.show_quota_class_set('default') + body = (self.adm_client.show_quota_class_set('default') + ['quota_class_set']) self.assertIn('id', body) self.assertEqual('default', body.pop('id')) # restore the defaults when the test is done @@ -190,8 +192,8 @@ class QuotaClassesAdminTestJSON(base.BaseV2ComputeAdminTest): # to a very small number which causes issues. body[quota] = default + 100 LOG.debug("update limits for the default quota class set") - update_body = self.adm_client.update_quota_class_set('default', - **body) + update_body = self.adm_client.update_quota_class_set( + 'default', **body)['quota_class_set'] LOG.debug("assert that the response has all of the changed values") self.assertThat(update_body.items(), matchers.ContainsAll(body.items())) diff --git a/tempest/api/compute/admin/test_quotas_negative.py b/tempest/api/compute/admin/test_quotas_negative.py index b4fc749a88..1989deb99d 100644 --- a/tempest/api/compute/admin/test_quotas_negative.py +++ b/tempest/api/compute/admin/test_quotas_negative.py @@ -55,13 +55,14 @@ class QuotasAdminNegativeTestJSON(base.BaseV2ComputeAdminTest): @test.idempotent_id('91058876-9947-4807-9f22-f6eb17140d9b') def test_create_server_when_cpu_quota_is_full(self): # Disallow server creation when tenant's vcpu quota is full - quota_set = self.adm_client.show_quota_set(self.demo_tenant_id) + quota_set = (self.adm_client.show_quota_set(self.demo_tenant_id) + ['quota_set']) default_vcpu_quota = quota_set['cores'] vcpu_quota = 0 # Set the quota to zero to conserve resources - quota_set = self.adm_client.update_quota_set(self.demo_tenant_id, - force=True, - cores=vcpu_quota) + self.adm_client.update_quota_set(self.demo_tenant_id, + force=True, + cores=vcpu_quota) self.addCleanup(self.adm_client.update_quota_set, self.demo_tenant_id, cores=default_vcpu_quota) @@ -72,7 +73,8 @@ class QuotasAdminNegativeTestJSON(base.BaseV2ComputeAdminTest): @test.idempotent_id('6fdd7012-584d-4327-a61c-49122e0d5864') def test_create_server_when_memory_quota_is_full(self): # Disallow server creation when tenant's memory quota is full - quota_set = self.adm_client.show_quota_set(self.demo_tenant_id) + quota_set = (self.adm_client.show_quota_set(self.demo_tenant_id) + ['quota_set']) default_mem_quota = quota_set['ram'] mem_quota = 0 # Set the quota to zero to conserve resources @@ -89,7 +91,8 @@ class QuotasAdminNegativeTestJSON(base.BaseV2ComputeAdminTest): @test.idempotent_id('7c6be468-0274-449a-81c3-ac1c32ee0161') def test_create_server_when_instances_quota_is_full(self): # Once instances quota limit is reached, disallow server creation - quota_set = self.adm_client.show_quota_set(self.demo_tenant_id) + quota_set = (self.adm_client.show_quota_set(self.demo_tenant_id) + ['quota_set']) default_instances_quota = quota_set['instances'] instances_quota = 0 # Set quota to zero to disallow server creation @@ -108,17 +111,17 @@ class QuotasAdminNegativeTestJSON(base.BaseV2ComputeAdminTest): def test_security_groups_exceed_limit(self): # Negative test: Creation Security Groups over limit should FAIL - quota_set = self.adm_client.show_quota_set(self.demo_tenant_id) + quota_set = (self.adm_client.show_quota_set(self.demo_tenant_id) + ['quota_set']) default_sg_quota = quota_set['security_groups'] # Set the quota to number of used security groups sg_quota = self.limits_client.show_limits()['absolute'][ 'totalSecurityGroupsUsed'] - quota_set =\ - self.adm_client.update_quota_set(self.demo_tenant_id, - force=True, - security_groups=sg_quota) + 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, @@ -140,15 +143,14 @@ class QuotasAdminNegativeTestJSON(base.BaseV2ComputeAdminTest): # Negative test: Creation of Security Group Rules should FAIL # when we reach limit maxSecurityGroupRules - quota_set = self.adm_client.show_quota_set(self.demo_tenant_id) + quota_set = (self.adm_client.show_quota_set(self.demo_tenant_id) + ['quota_set']) default_sg_rules_quota = quota_set['security_group_rules'] sg_rules_quota = 0 # Set the quota to zero to conserve resources - quota_set =\ - self.adm_client.update_quota_set( - self.demo_tenant_id, - force=True, - security_group_rules=sg_rules_quota) + 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, diff --git a/tempest/api/compute/admin/test_servers_negative.py b/tempest/api/compute/admin/test_servers_negative.py index d65f335989..c2dc94c217 100644 --- a/tempest/api/compute/admin/test_servers_negative.py +++ b/tempest/api/compute/admin/test_servers_negative.py @@ -69,7 +69,8 @@ class ServersAdminNegativeTestJSON(base.BaseV2ComputeAdminTest): self.useFixture(fixtures.LockFixture('compute_quotas')) flavor_name = data_utils.rand_name("flavor") flavor_id = self._get_unused_flavor_id() - quota_set = self.quotas_client.show_default_quota_set(self.tenant_id) + quota_set = (self.quotas_client.show_default_quota_set(self.tenant_id) + ['quota_set']) ram = int(quota_set['ram']) + 1 vcpus = 8 disk = 10 @@ -93,7 +94,8 @@ class ServersAdminNegativeTestJSON(base.BaseV2ComputeAdminTest): flavor_name = data_utils.rand_name("flavor") flavor_id = self._get_unused_flavor_id() ram = 512 - quota_set = self.quotas_client.show_default_quota_set(self.tenant_id) + quota_set = (self.quotas_client.show_default_quota_set(self.tenant_id) + ['quota_set']) vcpus = int(quota_set['cores']) + 1 disk = 10 flavor_ref = self.flavors_client.create_flavor(name=flavor_name, diff --git a/tempest/api/compute/servers/test_server_metadata_negative.py b/tempest/api/compute/servers/test_server_metadata_negative.py index c42ec3d396..5804dbe161 100644 --- a/tempest/api/compute/servers/test_server_metadata_negative.py +++ b/tempest/api/compute/servers/test_server_metadata_negative.py @@ -137,7 +137,7 @@ class ServerMetadataNegativeTestJSON(base.BaseV2ComputeTest): # A 403 Forbidden or 413 Overlimit (old behaviour) exception # will be raised while exceeding metadata items limit for # tenant. - quota_set = self.quotas.show_quota_set(self.tenant_id) + quota_set = self.quotas.show_quota_set(self.tenant_id)['quota_set'] quota_metadata = quota_set['metadata_items'] if quota_metadata == -1: raise self.skipException("No limit for metadata_items") diff --git a/tempest/api/compute/test_quotas.py b/tempest/api/compute/test_quotas.py index 9f37143a90..43f4c97d66 100644 --- a/tempest/api/compute/test_quotas.py +++ b/tempest/api/compute/test_quotas.py @@ -54,14 +54,14 @@ class QuotasTestJSON(base.BaseV2ComputeTest): def test_get_quotas(self): # User can get the quota set for it's tenant expected_quota_set = self.default_quota_set | set(['id']) - quota_set = self.client.show_quota_set(self.tenant_id) + quota_set = self.client.show_quota_set(self.tenant_id)['quota_set'] self.assertEqual(quota_set['id'], self.tenant_id) for quota in expected_quota_set: self.assertIn(quota, quota_set.keys()) # get the quota set using user id quota_set = self.client.show_quota_set(self.tenant_id, - self.user_id) + self.user_id)['quota_set'] self.assertEqual(quota_set['id'], self.tenant_id) for quota in expected_quota_set: self.assertIn(quota, quota_set.keys()) @@ -70,7 +70,8 @@ class QuotasTestJSON(base.BaseV2ComputeTest): 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']) - quota_set = self.client.show_default_quota_set(self.tenant_id) + quota_set = (self.client.show_default_quota_set(self.tenant_id) + ['quota_set']) self.assertEqual(quota_set['id'], self.tenant_id) for quota in expected_quota_set: self.assertIn(quota, quota_set.keys()) @@ -79,6 +80,7 @@ class QuotasTestJSON(base.BaseV2ComputeTest): def test_compare_tenant_quotas_with_default_quotas(self): # Tenants are created with the default quota values defualt_quota_set = \ - self.client.show_default_quota_set(self.tenant_id) - tenant_quota_set = self.client.show_quota_set(self.tenant_id) + self.client.show_default_quota_set(self.tenant_id)['quota_set'] + tenant_quota_set = (self.client.show_quota_set(self.tenant_id) + ['quota_set']) self.assertEqual(defualt_quota_set, tenant_quota_set) diff --git a/tempest/services/compute/json/quota_classes_client.py b/tempest/services/compute/json/quota_classes_client.py index 30d3501805..d55c3f12db 100644 --- a/tempest/services/compute/json/quota_classes_client.py +++ b/tempest/services/compute/json/quota_classes_client.py @@ -29,7 +29,7 @@ class QuotaClassesClient(service_client.ServiceClient): resp, body = self.get(url) body = json.loads(body) self.validate_response(classes_schema.get_quota_class_set, resp, body) - return service_client.ResponseBody(resp, body['quota_class_set']) + return service_client.ResponseBody(resp, body) def update_quota_class_set(self, quota_class_id, **kwargs): """ @@ -43,4 +43,4 @@ class QuotaClassesClient(service_client.ServiceClient): body = json.loads(body) self.validate_response(classes_schema.update_quota_class_set, resp, body) - return service_client.ResponseBody(resp, body['quota_class_set']) + return service_client.ResponseBody(resp, body) diff --git a/tempest/services/compute/json/quotas_client.py b/tempest/services/compute/json/quotas_client.py index 88d05676d7..4a1b909681 100644 --- a/tempest/services/compute/json/quotas_client.py +++ b/tempest/services/compute/json/quotas_client.py @@ -30,7 +30,7 @@ class QuotasClient(service_client.ServiceClient): resp, body = self.get(url) body = json.loads(body) self.validate_response(schema.get_quota_set, resp, body) - return service_client.ResponseBody(resp, body['quota_set']) + return service_client.ResponseBody(resp, body) def show_default_quota_set(self, tenant_id): """List the default quota set for a tenant.""" @@ -39,7 +39,7 @@ class QuotasClient(service_client.ServiceClient): resp, body = self.get(url) body = json.loads(body) self.validate_response(schema.get_quota_set, resp, body) - return service_client.ResponseBody(resp, body['quota_set']) + return service_client.ResponseBody(resp, body) def update_quota_set(self, tenant_id, user_id=None, **kwargs): """ @@ -56,7 +56,7 @@ class QuotasClient(service_client.ServiceClient): body = json.loads(body) self.validate_response(schema.update_quota_set, resp, body) - return service_client.ResponseBody(resp, body['quota_set']) + return service_client.ResponseBody(resp, body) def delete_quota_set(self, tenant_id): """Delete the tenant's quota set.""" diff --git a/tempest/tests/services/compute/test_quota_classes_client.py b/tempest/tests/services/compute/test_quota_classes_client.py index ff9b31031d..bc52511620 100644 --- a/tempest/tests/services/compute/test_quota_classes_client.py +++ b/tempest/tests/services/compute/test_quota_classes_client.py @@ -50,8 +50,8 @@ class TestQuotaClassesClient(base.TestCase): fake_auth, 'compute', 'regionOne') def _test_show_quota_class_set(self, bytes_body=False): - serialized_body = json.dumps({ - "quota_class_set": self.FAKE_QUOTA_CLASS_SET}) + expected = {'quota_class_set': self.FAKE_QUOTA_CLASS_SET} + serialized_body = json.dumps(expected) if bytes_body: serialized_body = serialized_body.encode('utf-8') @@ -60,7 +60,7 @@ class TestQuotaClassesClient(base.TestCase): 'tempest.common.service_client.ServiceClient.get', return_value=mocked_resp)) resp = self.client.show_quota_class_set("test") - self.assertEqual(self.FAKE_QUOTA_CLASS_SET, resp) + self.assertEqual(expected, resp) def test_show_quota_class_set_with_str_body(self): self._test_show_quota_class_set() @@ -71,11 +71,12 @@ class TestQuotaClassesClient(base.TestCase): def test_update_quota_class_set(self): fake_quota_class_set = copy.deepcopy(self.FAKE_QUOTA_CLASS_SET) fake_quota_class_set.pop("id") - serialized_body = json.dumps({"quota_class_set": fake_quota_class_set}) + expected = {'quota_class_set': fake_quota_class_set} + serialized_body = json.dumps(expected) mocked_resp = (httplib2.Response({'status': 200}), serialized_body) self.useFixture(mockpatch.Patch( 'tempest.common.service_client.ServiceClient.put', return_value=mocked_resp)) resp = self.client.update_quota_class_set("test") - self.assertEqual(fake_quota_class_set, resp) + self.assertEqual(expected, resp) diff --git a/tempest/tests/services/compute/test_quotas_client.py b/tempest/tests/services/compute/test_quotas_client.py index a9bd0a1c22..0f72b3d67c 100644 --- a/tempest/tests/services/compute/test_quotas_client.py +++ b/tempest/tests/services/compute/test_quotas_client.py @@ -25,21 +25,24 @@ from tempest.tests import fake_auth_provider class TestQuotasClient(base.TestCase): - FAKE_QUOTA_SET = {"injected_file_content_bytes": 10240, - "metadata_items": 128, - "server_group_members": 10, - "server_groups": 10, - "ram": 51200, - "floating_ips": 10, - "key_pairs": 100, - "id": "8421f7be61064f50b680465c07f334af", - "instances": 10, - "security_group_rules": 20, - "injected_files": 5, - "cores": 20, - "fixed_ips": -1, - "injected_file_path_bytes": 255, - "security_groups": 10} + FAKE_QUOTA_SET = { + "quota_set": { + "injected_file_content_bytes": 10240, + "metadata_items": 128, + "server_group_members": 10, + "server_groups": 10, + "ram": 51200, + "floating_ips": 10, + "key_pairs": 100, + "id": "8421f7be61064f50b680465c07f334af", + "instances": 10, + "security_group_rules": 20, + "injected_files": 5, + "cores": 20, + "fixed_ips": -1, + "injected_file_path_bytes": 255, + "security_groups": 10} + } project_id = "8421f7be61064f50b680465c07f334af" @@ -50,7 +53,7 @@ class TestQuotasClient(base.TestCase): fake_auth, 'compute', 'regionOne') def _test_show_quota_set(self, bytes_body=False): - serialized_body = json.dumps({"quota_set": self.FAKE_QUOTA_SET}) + serialized_body = json.dumps(self.FAKE_QUOTA_SET) if bytes_body: serialized_body = serialized_body.encode('utf-8') @@ -68,7 +71,7 @@ class TestQuotasClient(base.TestCase): self._test_show_quota_set(bytes_body=True) def _test_show_default_quota_set(self, bytes_body=False): - serialized_body = json.dumps({"quota_set": self.FAKE_QUOTA_SET}) + serialized_body = json.dumps(self.FAKE_QUOTA_SET) if bytes_body: serialized_body = serialized_body.encode('utf-8') @@ -87,8 +90,8 @@ class TestQuotasClient(base.TestCase): def test_update_quota_set(self): fake_quota_set = copy.deepcopy(self.FAKE_QUOTA_SET) - fake_quota_set.pop("id") - serialized_body = json.dumps({"quota_set": fake_quota_set}) + fake_quota_set['quota_set'].pop("id") + serialized_body = json.dumps(fake_quota_set) mocked_resp = (httplib2.Response({'status': 200}), serialized_body) self.useFixture(mockpatch.Patch( 'tempest.common.service_client.ServiceClient.put',