Enable pep8 check 77/74877/1
authorHaibin Huang <haibin.huang@intel.com>
Wed, 19 Dec 2018 07:07:21 +0000 (15:07 +0800)
committerHaibin Huang <haibin.huang@intel.com>
Wed, 19 Dec 2018 07:07:21 +0000 (15:07 +0800)
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>
pike/pike/pub/__init__.py
pike/pike/pub/config/__init__.py
pike/pike/resource/tests/__init__.py
pike/pike/resource/tests/test_capacity.py
pike/pike/resource/views/__init__.py
pike/pike/resource/views/capacity.py
pike/tox.ini

index afa702d..ae1ce9d 100644 (file)
@@ -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.
-
index afa702d..ae1ce9d 100644 (file)
@@ -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.
-
index 741e0af..5a9af6b 100644 (file)
@@ -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.
-
index 23ed327..d6f3ea3 100644 (file)
@@ -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)
-
index 741e0af..5a9af6b 100644 (file)
@@ -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.
-
index 475ccdf..e76c93a 100644 (file)
 # 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)
-
index 9107da3..cd5327a 100644 (file)
@@ -13,7 +13,7 @@
 # limitations under the License.
 
 [tox]
-envlist = py27,cov
+envlist = py27,pep8,cov
 skipsdist = true
 
 [tox:jenkins]