Migrated quota_classes_client.py from tempest

This migrates the above files from tempest. This includes tempest commits:

 * quota_classes_client.py: Idd8afb1bcfc1b0165b1e967a991d4705ff182249
 * test_quota_classes_client.py: I3ad6761651cec5e66012d08e6b63322f53286a5c
 * quota_classes.py: I2378e019353f551a3ac49666edd5ecb561b5b6ed

to see the commit history for these files refer to the above Change-Ids
in the tempest repository.

Partially implements blueprint migrate-service-clients-to-tempest-lib

Change-Id: I48ce2ddf21218eb02f6ae47cb0356c340ced06ae
This commit is contained in:
Tuan Nguyen
2015-10-09 08:31:02 -04:00
parent a23ffbaa5b
commit cffba39bd4
3 changed files with 147 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
# Copyright 2014 IBM Corporation.
# All rights reserved.
#
# 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 copy
from tempest_lib.api_schema.response.compute.v2_1 import quotas
# NOTE(mriedem): os-quota-class-sets responses are the same as os-quota-sets
# except for the key in the response body is quota_class_set instead of
# quota_set, so update this copy of the schema from os-quota-sets.
get_quota_class_set = copy.deepcopy(quotas.get_quota_set)
get_quota_class_set['response_body']['properties']['quota_class_set'] = (
get_quota_class_set['response_body']['properties'].pop('quota_set'))
get_quota_class_set['response_body']['required'] = ['quota_class_set']
update_quota_class_set = copy.deepcopy(quotas.update_quota_set)
update_quota_class_set['response_body']['properties']['quota_class_set'] = (
update_quota_class_set['response_body']['properties'].pop('quota_set'))
update_quota_class_set['response_body']['required'] = ['quota_class_set']

View File

@@ -0,0 +1,45 @@
# Copyright 2012 NTT Data
# All Rights Reserved.
#
# 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.
from oslo_serialization import jsonutils as json
from tempest_lib.api_schema.response.compute.v2_1\
import quota_classes as classes_schema
from tempest_lib.common import rest_client
class QuotaClassesClient(rest_client.RestClient):
def show_quota_class_set(self, quota_class_id):
"""List the quota class set for a quota class."""
url = 'os-quota-class-sets/%s' % quota_class_id
resp, body = self.get(url)
body = json.loads(body)
self.validate_response(classes_schema.get_quota_class_set, resp, body)
return rest_client.ResponseBody(resp, body)
def update_quota_class_set(self, quota_class_id, **kwargs):
"""Updates the quota class's limits for one or more resources."""
post_body = json.dumps({'quota_class_set': kwargs})
resp, body = self.put('os-quota-class-sets/%s' % quota_class_id,
post_body)
body = json.loads(body)
self.validate_response(classes_schema.update_quota_class_set,
resp, body)
return rest_client.ResponseBody(resp, body)

View File

@@ -0,0 +1,71 @@
# Copyright 2015 NEC Corporation. All rights reserved.
#
# 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 copy
from tempest_lib.services.compute import quota_classes_client
from tempest_lib.tests import fake_auth_provider
from tempest_lib.tests.services.compute import base
class TestQuotaClassesClient(base.BaseComputeServiceTest):
FAKE_QUOTA_CLASS_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": u'\u2740(*\xb4\u25e1`*)\u2740',
"instances": 10,
"security_group_rules": 20,
"security_groups": 10,
"injected_files": 5,
"cores": 20,
"fixed_ips": -1,
"injected_file_path_bytes": 255,
}
def setUp(self):
super(TestQuotaClassesClient, self).setUp()
fake_auth = fake_auth_provider.FakeAuthProvider()
self.client = quota_classes_client.QuotaClassesClient(
fake_auth, 'compute', 'regionOne')
def _test_show_quota_class_set(self, bytes_body=False):
fake_body = {'quota_class_set': self.FAKE_QUOTA_CLASS_SET}
self.check_service_client_function(
self.client.show_quota_class_set,
'tempest_lib.common.rest_client.RestClient.get',
fake_body,
bytes_body,
quota_class_id="test")
def test_show_quota_class_set_with_str_body(self):
self._test_show_quota_class_set()
def test_show_quota_class_set_with_bytes_body(self):
self._test_show_quota_class_set(bytes_body=True)
def test_update_quota_class_set(self):
fake_quota_class_set = copy.deepcopy(self.FAKE_QUOTA_CLASS_SET)
fake_quota_class_set.pop("id")
fake_body = {'quota_class_set': fake_quota_class_set}
self.check_service_client_function(
self.client.update_quota_class_set,
'tempest_lib.common.rest_client.RestClient.put',
fake_body,
quota_class_id="test")