# 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.
-
# 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.
-
# 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 rest_framework import status
-from common.utils import restcall
from newton_base.tests import mock_info
from newton_base.tests import test_base
from newton_base.util import VimDriverUtils
MOCK_GET_TENANT_LIMIT_RESPONSE = {
- "limits" : {
- "rate" : [],
- "absolute" : {
- "maxTotalRAMSize" : 128*1024,
- "totalRAMUsed" : 8*1024,
- "totalCoresUsed" : 4,
- "maxTotalCores" : 20,
- }
- }
+ "limits": {
+ "rate": [],
+ "absolute": {
+ "maxTotalRAMSize": 128 * 1024,
+ "totalRAMUsed": 8 * 1024,
+ "totalCoresUsed": 4,
+ "maxTotalCores": 20,
+ }
+ }
}
MOCK_GET_HYPER_STATATICS_RESPONSE = {
- "hypervisor_statistics" : {
- "vcpus_used" : 4,
- "free_ram_mb" : 120*1024,
- "vcpus" : 10,
- "free_disk_gb" : 300
- }
+ "hypervisor_statistics": {
+ "vcpus_used": 4,
+ "free_ram_mb": 120 * 1024,
+ "vcpus": 10,
+ "free_disk_gb": 300
+ }
}
MOCK_GET_STORAGE_RESPONSE_OOS = {
}
MOCK_GET_HYPER_STATATICS_RESPONSE_OUTOFSTORAGE = {
- "hypervisor_statistics" : {
- "vcpus_used" : 4,
- "free_ram_mb" : 120*1024,
- "vcpus" : 10,
- "free_disk_gb" : 3
- }
+ "hypervisor_statistics": {
+ "vcpus_used": 4,
+ "free_ram_mb": 120 * 1024,
+ "vcpus": 10,
+ "free_disk_gb": 3
+ }
}
MOCK_GET_HYPER_STATATICS_RESPONSE_OUTOFRAM = {
- "hypervisor_statistics" : {
- "vcpus_used" : 4,
- "free_ram_mb" : 1*1024,
- "vcpus" : 10,
- "free_disk_gb" : 300
- }
+ "hypervisor_statistics": {
+ "vcpus_used": 4,
+ "free_ram_mb": 1 * 1024,
+ "vcpus": 10,
+ "free_disk_gb": 300
+ }
}
MOCK_GET_STORAGE_RESPONSE = {
- "limits" : {
- "rate" : [],
- "absolute" : {
- "totalGigabytesUsed" : 200,
- "maxTotalVolumeGigabytes" : 500,
- }
- }
+ "limits": {
+ "rate": [],
+ "absolute": {
+ "totalGigabytesUsed": 200,
+ "maxTotalVolumeGigabytes": 500,
+ }
+ }
}
TEST_REQ_SUCCESS_SOURCE = {
"Storage": "200"
}
+
class TestCapacity(test_base.TestRequest):
def setUp(self):
super(TestCapacity, self).setUp()
content_type='application/json',
HTTP_X_AUTH_TOKEN=mock_info.MOCK_TOKEN_ID)
+ self.assertEquals(status.HTTP_200_OK, response.status_code)
+ self.assertEqual({"result": True}, response.data)
+
@mock.patch.object(VimDriverUtils, 'get_session')
@mock.patch.object(VimDriverUtils, 'get_vim_info')
def test_capacity_check_volume_limits_outofstorage(self, mock_get_vim_info, mock_get_session):
self.assertEquals(status.HTTP_200_OK, response.status_code)
self.assertEqual({"result": False}, response.data)
-
# 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.
-
# limitations under the License.
import logging
-import json
import traceback
-from rest_framework import status
-
-from django.conf import settings
from common.exceptions import VimDriverNewtonException
from newton_base.util import VimDriverUtils
self._logger.debug("CapacityCheck--post::META> %s" % request.META)
hasEnoughResource = False
- try :
+ try:
resource_demand = request.data
tenant_name = None
vim = VimDriverUtils.get_vim_info(vimid)
sess = VimDriverUtils.get_session(vim, tenant_name)
- #get token:
+ # get token:
cloud_owner, regionid = extsys.decode_vim_id(vimid)
interface = 'public'
service = {'service_type': 'compute',
'interface': interface,
'region_name': vim['openstack_region_id']
- if vim.get('openstack_region_id')
- else vim['cloud_region_id']}
-
+ if vim.get('openstack_region_id')
+ else vim['cloud_region_id']}
- #get limit for this tenant
+ # get limit for this tenant
req_resouce = "/limits"
resp = sess.get(req_resouce, endpoint_filter=service)
content = resp.json()
compute_limits = content['limits']['absolute']
- #get total resource of this cloud region
+ # get total resource of this cloud region
try:
req_resouce = "/os-hypervisors/statistics"
self._logger.info("check os-hypervisors statistics> URI:%s" % req_resouce)
conFreeRamMB = int(resource_demand['Memory'])
conFreeDiskGB = int(resource_demand['Storage'])
self._logger.info("Non administator forbidden to access hypervisor statistics data")
- hypervisor_statistics = {'vcpus_used':0, 'vcpus':conVCPUS, 'free_ram_mb':conFreeRamMB, 'free_disk_gb':conFreeDiskGB}
+ hypervisor_statistics = {'vcpus_used': 0, 'vcpus': conVCPUS, 'free_ram_mb': conFreeRamMB, 'free_disk_gb': conFreeDiskGB}
else:
# non forbiden exeption will be redirected
raise e
- #get storage limit for this tenant
+ # get storage limit for this tenant
service['service_type'] = 'volumev2'
req_resouce = "/limits"
resp = sess.get(req_resouce, endpoint_filter=service)
return Response(data={'result': hasEnoughResource}, status=status.HTTP_200_OK)
except VimDriverNewtonException as e:
- return Response(data={'result': hasEnoughResource,'error': e.content}, status=e.status_code)
+ return Response(data={'result': hasEnoughResource, 'error': e.content}, status=e.status_code)
except HttpError as e:
self._logger.error("HttpError: status:%s, response:%s" % (e.http_status, e.response.json()))
resp = e.response.json()
return Response(data={'result': hasEnoughResource, 'error': str(e)},
status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+
class APIv1CapacityCheck(CapacityCheck):
def __init__(self):
vimid = extsys.encode_vim_id(cloud_owner, cloud_region_id)
return super(APIv1CapacityCheck, self).post(request, vimid)
-
# limitations under the License.
[tox]
-envlist = py27,cov
+envlist = py27,pep8,cov
skipsdist = true
[tox:jenkins]