diff options
author | Jenkins <jenkins@review.openstack.org> | 2015-10-15 11:05:27 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2015-10-15 11:05:27 +0000 |
commit | 9adac247f7b38c8820236dc74d4d09e8a386c0f9 (patch) | |
tree | 8d441eca6dbf40176db7cc8cd1eda5079bd81bf6 | |
parent | 320cdfb5cbf213578efe64ff4a94c49f66aaf6b4 (diff) | |
parent | cffba39bd468d388f39c60258bbac297e93c6c9a (diff) | |
download | tempest-lib-9adac247f7b38c8820236dc74d4d09e8a386c0f9.tar.gz |
Merge "Migrated quota_classes_client.py from tempest"
3 files changed, 147 insertions, 0 deletions
diff --git a/tempest_lib/api_schema/response/compute/v2_1/quota_classes.py b/tempest_lib/api_schema/response/compute/v2_1/quota_classes.py new file mode 100644 index 0000000..5667c11 --- /dev/null +++ b/tempest_lib/api_schema/response/compute/v2_1/quota_classes.py @@ -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'] diff --git a/tempest_lib/services/compute/quota_classes_client.py b/tempest_lib/services/compute/quota_classes_client.py new file mode 100644 index 0000000..c0cb8f4 --- /dev/null +++ b/tempest_lib/services/compute/quota_classes_client.py @@ -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) diff --git a/tempest_lib/tests/services/compute/test_quota_classes_client.py b/tempest_lib/tests/services/compute/test_quota_classes_client.py new file mode 100644 index 0000000..309e026 --- /dev/null +++ b/tempest_lib/tests/services/compute/test_quota_classes_client.py @@ -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") |