diff options
author | ying.yunlong <ying.yunlong@zte.com.cn> | 2018-01-10 09:39:50 +0800 |
---|---|---|
committer | ying.yunlong <ying.yunlong@zte.com.cn> | 2018-01-10 09:39:50 +0800 |
commit | 3a98b5e6be92c1a6073677c662a7b784092569c3 (patch) | |
tree | 3755ea69d94a3a1d63dfe8308c76b75254d3c6fc | |
parent | 7e5de91474b0fb12a4c209fedd16fe4e7fd5cf1f (diff) |
Fix vfc-vnfres pep8 issues
Change-Id: Id0c7477ac25deb91d51d64f0b1e01eb26aae7fd2
Issue-ID: VFC-630
Signed-off-by: ying.yunlong <ying.yunlong@zte.com.cn>
-rw-r--r-- | res/res/resources/tests.py | 109 | ||||
-rw-r--r-- | res/res/resources/views.py | 24 |
2 files changed, 71 insertions, 62 deletions
diff --git a/res/res/resources/tests.py b/res/res/resources/tests.py index c660e10..a6b9ead 100644 --- a/res/res/resources/tests.py +++ b/res/res/resources/tests.py @@ -25,8 +25,8 @@ class ResourceTest(TestCase): self.nf_inst_id = "01" NfInstModel.objects.all().delete() self.test_data = { - "vnfInstanceId": u'1', - "vnfInstanceName": 'VNF1', + "vnfInstanceId": "1", + "vnfInstanceName": "VNF1", "vnfInstanceDescription": None, "onboardedVnfPkgInfoId": None, "vnfdId": None, @@ -64,37 +64,39 @@ class ResourceTest(TestCase): } self.vms_data = { "resp_data": [{ - "vmid": u"vm0", - "vimid": u"vim0", - "resouceid": u"res0", + "vmid": "vm0", + "vimid": "vim0", + "resouceid": "res0", "insttype": 0, - "instid": u"01", - "vmname": u"v1", + "instid": "01", + "vmname": "v1", "operationalstate": None, "tenant": None, "is_predefined": 0, - "security_groups": 'sec0', - "flavor_id": 'flavor0', - "availability_zone": 'ava0', - "server_group": 'server0', - "volume_array": 'volume0', - "metadata": 'meta0', - "nic_array": 'nic0' + "security_groups": "sec0", + "flavor_id": "flavor0", + "availability_zone": "ava0", + "server_group": "server0", + "volume_array": "volume0", + "metadata": "meta0", + "nic_array": "nic0" }] } self.flavors_data = { - "resp_data": [{ - "flavourid": "fla0", - "name": "fname0", - "vcpu": 0, - "memory": 0, - "extraspecs": "ext0", - "instid": "01", - "tenant": None, - "vimid": "vim0", - "resouceid": 'res0', - "create_time": None - }] + "resp_data": [ + { + "extraspecs": "ext0", + "create_time": None, + "name": "fname0", + "vimid": "vim0", + "memory": 0, + "vcpu": 0, + "instid": "01", + "resouceid": "res0", + "flavourid": "fla0", + "tenant": None + } + ] } self.networks_data = { "resp_data": [{ @@ -104,7 +106,6 @@ class ResourceTest(TestCase): "insttype": 0, "instid": "01", "name": "net_name0" - # "tenant": None }] } self.subnets_data = { @@ -148,77 +149,77 @@ class ResourceTest(TestCase): def test_get_vnf(self): vnf_inst_id = "1" - NfInstModel(nfinstid=vnf_inst_id, nf_name='VNF1').save() - StorageInstModel(storageid='s02', vimid='vim01', resouceid='resource01', insttype=1, - instid=vnf_inst_id, storagetype='desc01', size='ten').save() + NfInstModel(nfinstid=vnf_inst_id, nf_name="VNF1").save() + StorageInstModel(storageid="s02", vimid="vim01", resouceid="resource01", insttype=1, + instid=vnf_inst_id, storagetype="desc01", size="ten").save() response = self.client.get("/api/vnfres/v1/vnfs/%s" % vnf_inst_id) self.failUnlessEqual(status.HTTP_200_OK, response.status_code) self.assertEqual(self.test_data, response.data) def test_get_vnfs(self): for i in range(1): - NfInstModel(nfinstid='%s' % i, nf_name='VNF%s' % i).save() - StorageInstModel(storageid='s0%s' % i, vimid='vim0%s' % i, resouceid='resource0%s' % i, - insttype=1, instid='%s' % i, storagetype='desc%s' % i, size='ten').save() + NfInstModel(nfinstid="%s" % i, nf_name="VNF%s" % i).save() + StorageInstModel(storageid="s0%s" % i, vimid="vim0%s" % i, resouceid="resource0%s" % i, + insttype=1, instid="%s" % i, storagetype="desc%s" % i, size="ten").save() response = self.client.get("/api/vnfres/v1/vnfs") self.failUnlessEqual(status.HTTP_200_OK, response.status_code) def test_get_vms(self): - NfInstModel(nfinstid='%s' % '01', nf_name='VFS%s' % '01').save() - nfInst = NfInstModel.objects.get(pk='01') + NfInstModel(nfinstid="%s" % "01", nf_name="VFS%s" % "01").save() + nfInst = NfInstModel.objects.get(pk="01") for i in range(1): - VmInstModel(vmid='vm%s' % i, vimid='vim%s' % i, resouceid='res%s' % i, instid='%s' % nfInst.nfinstid, - insttype=0, vmname='v1', nic_array='nic%s' % i, metadata='meta%s' % i, - volume_array='volume%s' % i, server_group='server%s' % i, availability_zone='ava%s' % i, - flavor_id='flavor%s' % i, security_groups='sec%s' % i).save() + VmInstModel(vmid="vm%s" % i, vimid="vim%s" % i, resouceid="res%s" % i, instid="%s" % nfInst.nfinstid, + insttype=0, vmname="v1", nic_array="nic%s" % i, metadata="meta%s" % i, + volume_array="volume%s" % i, server_group="server%s" % i, availability_zone="ava%s" % i, + flavor_id="flavor%s" % i, security_groups="sec%s" % i).save() response = self.client.get("/api/vnfres/v1/%s/vms" % nfInst.nfinstid) self.failUnlessEqual(status.HTTP_200_OK, response.status_code) self.assertEqual(self.vms_data, response.data) def test_get_flavors(self): - NfInstModel(nfinstid='%s' % '01', nf_name='VFS%s' % '01').save() - nfInst = NfInstModel.objects.get(pk='01') + NfInstModel(nfinstid="%s" % "01", nf_name="VFS%s" % "01").save() + nfInst = NfInstModel.objects.get(pk="01") for i in range(1): - FlavourInstModel(flavourid='fla%s' % i, name='fname%s' % i, vcpu='%d' % i, instid='%s' % nfInst.nfinstid, - memory='%d' % i, extraspecs='ext%s' % i, vimid='vim%s' % i, resouceid='res%s' % i).save() + FlavourInstModel(flavourid="fla%s" % i, name="fname%s" % i, vcpu="%d" % i, instid="%s" % nfInst.nfinstid, + memory="%d" % i, extraspecs="ext%s" % i, vimid="vim%s" % i, resouceid="res%s" % i).save() response = self.client.get("/api/vnfres/v1/%s/flavors" % nfInst.nfinstid) self.failUnlessEqual(status.HTTP_200_OK, response.status_code) self.assertEqual(self.flavors_data, response.data) def test_get_networks(self): for i in range(1): - NetworkInstModel(networkid='net%s' % i, name='net_name%s' % i, vimid='vim%s' % i, - instid='%s' % self.nf_inst_id, resouceid='res%s' % i, insttype='%d' % i).save() + NetworkInstModel(networkid="net%s" % i, name="net_name%s" % i, vimid="vim%s" % i, + instid="%s" % self.nf_inst_id, resouceid="res%s" % i, insttype="%d" % i).save() response = self.client.get("/api/vnfres/v1/%s/networks" % self.nf_inst_id) self.failUnlessEqual(status.HTTP_200_OK, response.status_code) self.assertEqual(self.networks_data, response.data) def test_get_subnets(self): for i in range(1): - SubNetworkInstModel(subnetworkid="sub%s" % i, vimid='vim%s' % i, resouceid='res%s' % i, - networkid='net%s' % i, insttype='%d' % i, instid='%s' % self.nf_inst_id, - name='sub_name%s' % i, cidr="cidr%s" % i).save() + SubNetworkInstModel(subnetworkid="sub%s" % i, vimid="vim%s" % i, resouceid="res%s" % i, + networkid="net%s" % i, insttype="%d" % i, instid="%s" % self.nf_inst_id, + name="sub_name%s" % i, cidr="cidr%s" % i).save() response = self.client.get("/api/vnfres/v1/%s/subnets" % self.nf_inst_id) self.failUnlessEqual(status.HTTP_200_OK, response.status_code) self.assertEqual(self.subnets_data, response.data) def test_get_cps(self): for i in range(1): - CPInstModel(cpinstanceid="cp%s" % i, cpdid='cpd%s' % i, cpinstancename='cpinstname%s' % i, - vlinstanceid='vlinst%s' % i, ownertype='%d' % i, ownerid='%s' % self.nf_inst_id, - relatedtype='%d' % i).save() + CPInstModel(cpinstanceid="cp%s" % i, cpdid="cpd%s" % i, cpinstancename="cpinstname%s" % i, + vlinstanceid="vlinst%s" % i, ownertype="%d" % i, ownerid="%s" % self.nf_inst_id, + relatedtype="%d" % i).save() response = self.client.get("/api/vnfres/v1/%s/cps" % self.nf_inst_id) self.failUnlessEqual(status.HTTP_200_OK, response.status_code) self.assertEqual(self.cps_data, response.data) def test_get_volumes(self): for i in range(1): - StorageInstModel(storageid="st%s" % i, vimid='vim%s' % i, resouceid='res%s' % i, insttype='%d' % i, - instid='%s' % self.nf_inst_id, storagetype='stype%s' % i, size='%s' % i).save() + StorageInstModel(storageid="st%s" % i, vimid="vim%s" % i, resouceid="res%s" % i, insttype="%d" % i, + instid="%s" % self.nf_inst_id, storagetype="stype%s" % i, size="%s" % i).save() response = self.client.get("/api/vnfres/v1/%s/volumes" % self.nf_inst_id) self.assertEqual(self.volumes_data, response.data) self.failUnlessEqual(status.HTTP_200_OK, response.status_code) def test_swagger_ok(self): - resp = self.client.get("/api/vnfres/v1/swagger.json", format='json') + resp = self.client.get("/api/vnfres/v1/swagger.json", format="json") self.assertEqual(resp.status_code, status.HTTP_200_OK, resp.content) diff --git a/res/res/resources/views.py b/res/res/resources/views.py index 7356089..f442931 100644 --- a/res/res/resources/views.py +++ b/res/res/resources/views.py @@ -41,7 +41,8 @@ def get_vnf(request, *args, **kwargs): return Response(data={'error': 'Vnf(%s) does not exist' % vnf_inst_id}, status=status.HTTP_404_NOT_FOUND) resp_data = fill_resp_data(vnf_inst[0]) return Response(data=resp_data, status=status.HTTP_200_OK) - except: + except Exception as e: + logger.error(e.message) logger.error(traceback.format_exc()) return Response(data={'error': 'Failed to get Vnf(%s)' % vnf_inst_id}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) @@ -165,7 +166,8 @@ def get_vnfs(request): for vnf_inst in vnf_insts: arr.append(fill_resp_data(vnf_inst)) return Response(data={'resp_data': arr}, status=status.HTTP_200_OK) - except: + except Exception as e: + logger.error(e.message) logger.error(traceback.format_exc()) return Response(data={'error': 'Failed to get Vnfs'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) @@ -182,7 +184,8 @@ def get_vms(request, *args, **kwargs): for vm in vms: arr.append(fill_vms_data(vm)) return Response(data={'resp_data': arr}, status=status.HTTP_200_OK) - except: + except Exception as e: + logger.error(e.message) logger.error(traceback.format_exc()) return Response(data={'error': 'Failed to get Vms'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) @@ -221,7 +224,8 @@ def get_flavors(request, *args, **kwargs): for flavour in flavours: arr.append(fill_flavours_data(flavour)) return Response(data={'resp_data': arr}, status=status.HTTP_200_OK) - except: + except Exception as e: + logger.error(e.message) logger.error(traceback.format_exc()) return Response(data={'error': 'Failed to get flavours'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) @@ -254,7 +258,8 @@ def get_networks(request, *args, **kwargs): for network in networks: arr.append(fill_networks_data(network)) return Response(data={'resp_data': arr}, status=status.HTTP_200_OK) - except: + except Exception as e: + logger.error(e.message) logger.error(traceback.format_exc()) return Response(data={'error': 'Failed to get networks'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) @@ -283,7 +288,8 @@ def get_subnets(request, *args, **kwargs): for subnet in subnets: arr.append(fill_subnets_data(subnet)) return Response(data={'resp_data': arr}, status=status.HTTP_200_OK) - except: + except Exception as e: + logger.error(e.message) logger.error(traceback.format_exc()) return Response(data={'error': 'Failed to get subnets'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) @@ -314,7 +320,8 @@ def get_cps(request, *args, **kwargs): for cp in cps: arr.append(fill_cps_data(cp)) return Response(data={'resp_data': arr}, status=status.HTTP_200_OK) - except: + except Exception as e: + logger.error(e.message) logger.error(traceback.format_exc()) return Response(data={'error': 'Failed to get cps'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) @@ -344,7 +351,8 @@ def get_volumes(request, *args, **kwargs): for v in volumes: arr.append(fill_volumes_data(v)) return Response(data={'resp_data': arr}, status=status.HTTP_200_OK) - except: + except Exception as e: + logger.error(e.message) logger.error(traceback.format_exc()) return Response(data={'error': 'Failed to get volumes'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) |