Migrated limits_client.py from tempest

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

 * limits_client.py     : Ice3665e91ff34409f6f105303213303d1fca1816
 * limits.py            : Ica929c402a3d042ae751302384e68853eb28b405
 * test_limits_client.py: I3ad6761651cec5e66012d08e6b63322f53286a5c

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: I80c6e148ae30148e591d24675fe068c829a0867a
This commit is contained in:
Ken'ichi Ohmichi 2015-09-28 06:26:59 +00:00
parent 6757c130b9
commit 8978712d35
3 changed files with 200 additions and 0 deletions

View File

@ -0,0 +1,106 @@
# Copyright 2014 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.
get_limit = {
'status_code': [200],
'response_body': {
'type': 'object',
'properties': {
'limits': {
'type': 'object',
'properties': {
'absolute': {
'type': 'object',
'properties': {
'maxTotalRAMSize': {'type': 'integer'},
'totalCoresUsed': {'type': 'integer'},
'maxTotalInstances': {'type': 'integer'},
'maxTotalFloatingIps': {'type': 'integer'},
'totalSecurityGroupsUsed': {'type': 'integer'},
'maxTotalCores': {'type': 'integer'},
'totalFloatingIpsUsed': {'type': 'integer'},
'maxSecurityGroups': {'type': 'integer'},
'maxServerMeta': {'type': 'integer'},
'maxPersonality': {'type': 'integer'},
'maxImageMeta': {'type': 'integer'},
'maxPersonalitySize': {'type': 'integer'},
'maxSecurityGroupRules': {'type': 'integer'},
'maxTotalKeypairs': {'type': 'integer'},
'totalRAMUsed': {'type': 'integer'},
'totalInstancesUsed': {'type': 'integer'},
'maxServerGroupMembers': {'type': 'integer'},
'maxServerGroups': {'type': 'integer'},
'totalServerGroupsUsed': {'type': 'integer'}
},
'additionalProperties': False,
# NOTE(gmann): maxServerGroupMembers, maxServerGroups
# and totalServerGroupsUsed are API extension,
# and some environments return a response without these
# attributes.So they are not 'required'.
'required': ['maxImageMeta',
'maxPersonality',
'maxPersonalitySize',
'maxSecurityGroupRules',
'maxSecurityGroups',
'maxServerMeta',
'maxTotalCores',
'maxTotalFloatingIps',
'maxTotalInstances',
'maxTotalKeypairs',
'maxTotalRAMSize',
'totalCoresUsed',
'totalFloatingIpsUsed',
'totalInstancesUsed',
'totalRAMUsed',
'totalSecurityGroupsUsed']
},
'rate': {
'type': 'array',
'items': {
'type': 'object',
'properties': {
'limit': {
'type': 'array',
'items': {
'type': 'object',
'properties': {
'next-available':
{'type': 'string'},
'remaining':
{'type': 'integer'},
'unit':
{'type': 'string'},
'value':
{'type': 'integer'},
'verb':
{'type': 'string'}
},
'additionalProperties': False,
}
},
'regex': {'type': 'string'},
'uri': {'type': 'string'}
},
'additionalProperties': False,
}
}
},
'additionalProperties': False,
'required': ['absolute', 'rate']
}
},
'additionalProperties': False,
'required': ['limits']
}
}

View File

@ -0,0 +1,28 @@
# Copyright 2012 OpenStack Foundation
# 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 limits as schema
from tempest_lib.common import rest_client
class LimitsClient(rest_client.RestClient):
def show_limits(self):
resp, body = self.get("limits")
body = json.loads(body)
self.validate_response(schema.get_limit, resp, body)
return rest_client.ResponseBody(resp, body)

View File

@ -0,0 +1,66 @@
# 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.
from tempest_lib.services.compute import limits_client
from tempest_lib.tests import fake_auth_provider
from tempest_lib.tests.services.compute import base
class TestLimitsClient(base.BaseComputeServiceTest):
def setUp(self):
super(TestLimitsClient, self).setUp()
fake_auth = fake_auth_provider.FakeAuthProvider()
self.client = limits_client.LimitsClient(
fake_auth, 'compute', 'regionOne')
def _test_show_limits(self, bytes_body=False):
expected = {
"limits": {
"rate": [],
"absolute": {
"maxServerMeta": 128,
"maxPersonality": 5,
"totalServerGroupsUsed": 0,
"maxImageMeta": 128,
"maxPersonalitySize": 10240,
"maxServerGroups": 10,
"maxSecurityGroupRules": 20,
"maxTotalKeypairs": 100,
"totalCoresUsed": 0,
"totalRAMUsed": 0,
"totalInstancesUsed": 0,
"maxSecurityGroups": 10,
"totalFloatingIpsUsed": 0,
"maxTotalCores": 20,
"totalSecurityGroupsUsed": 0,
"maxTotalFloatingIps": 10,
"maxTotalInstances": 10,
"maxTotalRAMSize": 51200,
"maxServerGroupMembers": 10
}
}
}
self.check_service_client_function(
self.client.show_limits,
'tempest_lib.common.rest_client.RestClient.get',
expected,
bytes_body)
def test_show_limits_with_str_body(self):
self._test_show_limits()
def test_show_limits_with_bytes_body(self):
self._test_show_limits(bytes_body=True)