From 3b4ff2329a2056e8d85353b037e64049fddbf260 Mon Sep 17 00:00:00 2001 From: biancunkang Date: Thu, 9 Aug 2018 11:47:30 +0800 Subject: CreateVnf and DeleteVnf Modify three files Change-Id: Ib9397d2336a39303e26910dc8948da233fa01cec Issue-ID: VFC-1015 Signed-off-by: biancunkang --- lcm/lcm/nf/biz/create_vnf.py | 6 +++--- lcm/lcm/nf/tests/test_create_vnf.py | 12 +++++++----- lcm/lcm/nf/views/curd_vnf_views.py | 13 ++++++++----- 3 files changed, 18 insertions(+), 13 deletions(-) (limited to 'lcm') diff --git a/lcm/lcm/nf/biz/create_vnf.py b/lcm/lcm/nf/biz/create_vnf.py index cf5435ad..de857b61 100644 --- a/lcm/lcm/nf/biz/create_vnf.py +++ b/lcm/lcm/nf/biz/create_vnf.py @@ -47,15 +47,15 @@ class CreateVnf: def save_db(self): metadata = ignore_case_get(self.vnfd_info, "metadata") - version = ignore_case_get(metadata, "vnfdVersion") - vendor = ignore_case_get(metadata, "vendor") + version = ignore_case_get(metadata, "csarVersion") + provider = ignore_case_get(metadata, "csarProvider") netype = ignore_case_get(metadata, "type") vnfsoftwareversion = ignore_case_get(metadata, "version") NfInstModel.objects.create(nfinstid=self.nf_inst_id, nf_name=self.vnf_instance_mame, package_id=self.csar_id, version=version, - vendor=vendor, + vendor=provider, netype=netype, vnfd_model=self.vnfd_info, status='NOT_INSTANTIATED', diff --git a/lcm/lcm/nf/tests/test_create_vnf.py b/lcm/lcm/nf/tests/test_create_vnf.py index 368b22f7..afeedb31 100644 --- a/lcm/lcm/nf/tests/test_create_vnf.py +++ b/lcm/lcm/nf/tests/test_create_vnf.py @@ -22,6 +22,7 @@ from lcm.nf.const import vnfpackage_info from lcm.pub.database.models import NfInstModel, JobStatusModel from lcm.pub.utils import restcall from lcm.pub.utils.timeutil import now_time +import uuid class TestNFInstantiate(TestCase): @@ -64,15 +65,16 @@ class TestNFInstantiate(TestCase): self.assertEqual({'error': 'VNF is already exist.'}, context) @mock.patch.object(restcall, 'call_req') - def test_create_vnf_identifier(self, mock_call_req): + @mock.patch.object(uuid, 'uuid4') + def test_create_vnf_identifier(self, mock_uuid4, mock_call_req): r2_get_vnfpackage_from_catalog = [0, json.JSONEncoder().encode(vnfpackage_info), '200'] - mock_call_req.side_effect = [r2_get_vnfpackage_from_catalog] + mock_call_req.return_value = r2_get_vnfpackage_from_catalog + mock_uuid4.return_value = "1" data = { "vnfdId": "111", "vnfInstanceName": "vFW_01", "vnfInstanceDescription": "vFW in Nanjing TIC Edge" } response = self.client.post("/api/vnflcm/v1/vnf_instances", data=data, format='json') - self.failUnlessEqual(status.HTTP_201_CREATED, response.status_code) - context = json.loads(response.content) - self.assertTrue(NfInstModel.objects.filter(nfinstid=context['vnfInstanceId']).exists()) + expect_data = {"id": "1", "vnfProvider": "huawei", "vnfdVersion": "1.0", "vnfPkgId": "111"} + self.assertEqual(expect_data, response.data) diff --git a/lcm/lcm/nf/views/curd_vnf_views.py b/lcm/lcm/nf/views/curd_vnf_views.py index 7419e69f..078053a8 100644 --- a/lcm/lcm/nf/views/curd_vnf_views.py +++ b/lcm/lcm/nf/views/curd_vnf_views.py @@ -23,7 +23,7 @@ from rest_framework.views import APIView from lcm.nf.biz.create_vnf import CreateVnf from lcm.nf.biz.query_vnf import QueryVnf -from lcm.nf.serializers.serializers import CreateVnfReqSerializer, CreateVnfRespSerializer +from lcm.nf.serializers.create_vnf_req import CreateVnfReqSerializer from lcm.nf.serializers.vnf_instance import VnfInstanceSerializer from lcm.nf.serializers.vnf_instances import VnfInstancesSerializer from lcm.pub.exceptions import NFLCMException @@ -57,9 +57,9 @@ class CreateVnfAndQueryVnfs(APIView): return Response(data={'error': 'Failed to get Vnfs'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) @swagger_auto_schema( - request_body=CreateVnfReqSerializer(), + request_body=VnfInstanceSerializer(), responses={ - status.HTTP_201_CREATED: CreateVnfRespSerializer(), + status.HTTP_201_CREATED: VnfInstanceSerializer(), status.HTTP_500_INTERNAL_SERVER_ERROR: "Internal error" } ) @@ -70,8 +70,11 @@ class CreateVnfAndQueryVnfs(APIView): if not req_serializer.is_valid(): raise NFLCMException(req_serializer.errors) - nf_inst_id = CreateVnf(req_serializer.data).do_biz().nfinstid - create_vnf_resp_serializer = CreateVnfRespSerializer(data={"vnfInstanceId": nf_inst_id}) + nf_inst = CreateVnf(req_serializer.data).do_biz() + create_vnf_resp_serializer = VnfInstanceSerializer(data={"id": nf_inst.nfinstid, + "vnfProvider": nf_inst.vendor, + "vnfdVersion": nf_inst.version, + "vnfPkgId": nf_inst.package_id}) if not create_vnf_resp_serializer.is_valid(): raise NFLCMException(create_vnf_resp_serializer.errors) return Response(data=create_vnf_resp_serializer.data, status=status.HTTP_201_CREATED) -- cgit 1.2.3-korg