summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHaibin Huang <haibin.huang@intel.com>2018-12-19 15:07:21 +0800
committerHaibin Huang <haibin.huang@intel.com>2018-12-19 15:07:21 +0800
commitd76c9be3e8d91675630d8b7772051030e992bf3e (patch)
tree76e41a3126b2c885b5252c788fe8d9c4328e9618
parent9b20c42c81cf3b1d586d04953fc95824898c4b2c (diff)
Enable pep8 check
This patch is fixing the pep8 issues under the pub and resource folder for pike release and also enable pep8 check Change-Id: I1afea756108e7bb0d79ac3f5317209fd8964f863 Issue-ID: MULTICLOUD-428 Signed-off-by: Haibin Huang <haibin.huang@intel.com>
-rw-r--r--pike/pike/pub/__init__.py1
-rw-r--r--pike/pike/pub/config/__init__.py1
-rw-r--r--pike/pike/resource/tests/__init__.py1
-rw-r--r--pike/pike/resource/tests/test_capacity.py74
-rw-r--r--pike/pike/resource/views/__init__.py1
-rw-r--r--pike/pike/resource/views/capacity.py25
-rw-r--r--pike/tox.ini2
7 files changed, 49 insertions, 56 deletions
diff --git a/pike/pike/pub/__init__.py b/pike/pike/pub/__init__.py
index afa702d3..ae1ce9db 100644
--- a/pike/pike/pub/__init__.py
+++ b/pike/pike/pub/__init__.py
@@ -11,4 +11,3 @@
# 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.
-
diff --git a/pike/pike/pub/config/__init__.py b/pike/pike/pub/config/__init__.py
index afa702d3..ae1ce9db 100644
--- a/pike/pike/pub/config/__init__.py
+++ b/pike/pike/pub/config/__init__.py
@@ -11,4 +11,3 @@
# 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.
-
diff --git a/pike/pike/resource/tests/__init__.py b/pike/pike/resource/tests/__init__.py
index 741e0afb..5a9af6b8 100644
--- a/pike/pike/resource/tests/__init__.py
+++ b/pike/pike/resource/tests/__init__.py
@@ -11,4 +11,3 @@
# 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.
-
diff --git a/pike/pike/resource/tests/test_capacity.py b/pike/pike/resource/tests/test_capacity.py
index 23ed3275..d6f3ea32 100644
--- a/pike/pike/resource/tests/test_capacity.py
+++ b/pike/pike/resource/tests/test_capacity.py
@@ -17,30 +17,29 @@ import json
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 = {
@@ -75,31 +74,31 @@ MOCK_GET_HYPER_STATATICS_RESPONSE_OUTOFVCPU = {
}
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 = {
@@ -114,6 +113,7 @@ TEST_REQ_FAILED_SOURCE = {
"Storage": "200"
}
+
class TestCapacity(test_base.TestRequest):
def setUp(self):
super(TestCapacity, self).setUp()
@@ -251,6 +251,9 @@ class TestCapacity(test_base.TestRequest):
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):
@@ -272,4 +275,3 @@ class TestCapacity(test_base.TestRequest):
self.assertEquals(status.HTTP_200_OK, response.status_code)
self.assertEqual({"result": False}, response.data)
-
diff --git a/pike/pike/resource/views/__init__.py b/pike/pike/resource/views/__init__.py
index 741e0afb..5a9af6b8 100644
--- a/pike/pike/resource/views/__init__.py
+++ b/pike/pike/resource/views/__init__.py
@@ -11,4 +11,3 @@
# 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.
-
diff --git a/pike/pike/resource/views/capacity.py b/pike/pike/resource/views/capacity.py
index 475ccdf7..e76c93a3 100644
--- a/pike/pike/resource/views/capacity.py
+++ b/pike/pike/resource/views/capacity.py
@@ -13,12 +13,8 @@
# 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
@@ -42,30 +38,29 @@ class CapacityCheck(APIView):
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)
@@ -82,12 +77,12 @@ class CapacityCheck(APIView):
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)
@@ -123,7 +118,7 @@ class CapacityCheck(APIView):
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()
@@ -134,6 +129,7 @@ class CapacityCheck(APIView):
return Response(data={'result': hasEnoughResource, 'error': str(e)},
status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+
class APIv1CapacityCheck(CapacityCheck):
def __init__(self):
@@ -146,4 +142,3 @@ class APIv1CapacityCheck(CapacityCheck):
vimid = extsys.encode_vim_id(cloud_owner, cloud_region_id)
return super(APIv1CapacityCheck, self).post(request, vimid)
-
diff --git a/pike/tox.ini b/pike/tox.ini
index 9107da32..cd5327a3 100644
--- a/pike/tox.ini
+++ b/pike/tox.ini
@@ -13,7 +13,7 @@
# limitations under the License.
[tox]
-envlist = py27,cov
+envlist = py27,pep8,cov
skipsdist = true
[tox:jenkins]