diff options
author | 2017-02-10 12:51:55 +0800 | |
---|---|---|
committer | 2017-02-10 12:51:55 +0800 | |
commit | 283dad75adf7f1c9470a8b324ee7697380e08562 (patch) | |
tree | 547228f7ae77170c5ea39bfd78c215024a1665c9 | |
parent | e18107b63ac7bde38b47e5451fa2d4667ceb53b7 (diff) |
GET Vnf Description
Change-Id: Ie836dcad38ee2a7825064b4d853b53eceacd0f80
Issue-Id: GVNFM-5
Signed-off-by: ying.yunlong <ying.yunlong@zte.com.cn>
-rw-r--r-- | lcm/lcm/nf/vnfs/tests/test_vnf_create.py | 57 | ||||
-rw-r--r-- | lcm/lcm/nf/vnfs/vnf_create/inst_vnf.py | 54 |
2 files changed, 82 insertions, 29 deletions
diff --git a/lcm/lcm/nf/vnfs/tests/test_vnf_create.py b/lcm/lcm/nf/vnfs/tests/test_vnf_create.py index 5537f191..293b6536 100644 --- a/lcm/lcm/nf/vnfs/tests/test_vnf_create.py +++ b/lcm/lcm/nf/vnfs/tests/test_vnf_create.py @@ -19,7 +19,6 @@ import mock from django.test import TestCase, Client from rest_framework import status -from lcm.nf.vnfs.views import InstantiateVnf from lcm.nf.vnfs.vnf_create.create_vnf_identifier import CreateVnf from lcm.nf.vnfs.vnf_create.inst_vnf import InstVnf from lcm.pub.database.models import NfInstModel, JobStatusModel @@ -114,11 +113,11 @@ class TestNsInstantiate(TestCase): InstVnf(data, nf_inst_id=self.nf_inst_id, job_id=self.job_id).run() self.assert_job_result(self.job_id, 255, "VNF nf_inst_id is not exist.") - @mock.patch.object(restcall, 'call_req') - def test_instantiate_vnf_success(self, mock_call_req): + def test_instantiate_vnf_when_input_para_not_define_in_vnfd(self, mock_call_req): r1 = [0, json.JSONEncoder().encode(vnfd_model_dict), '200'] - mock_call_req.side_effect = [r1] + r2 = [0, json.JSONEncoder().encode(''), '200'] + mock_call_req.side_effect = [r1, r2] create_data = { "vnfdId": "111", "vnfInstanceName": "vFW_01", @@ -128,7 +127,8 @@ class TestNsInstantiate(TestCase): JobUtil.add_job_status(self.job_id, 0, "INST_VNF_READY") data = inst_req_data InstVnf(data, nf_inst_id=self.nf_inst_id, job_id=self.job_id).run() - self.assert_job_result(self.job_id, 100, "Instantiate Vnf success.") + self.assert_job_result(self.job_id, 255, "Input parameter is not defined in vnfd_info.") + vnfd_model_dict = { 'local_storages': [], @@ -401,4 +401,49 @@ vnfd_model_dict = { 'vnf_type': u'SSS', 'vnfd_version': u'V00000001', 'id': u'sss-vnf-template', - 'name': u'sss-vnf-template'}}
\ No newline at end of file + 'name': u'sss-vnf-template'}, + "flavourId": "flavour_1", + "instantiationLevelId": "instantiationLevel_1", + "extVirtualLinks": [ + { + "vlInstanceId": "1", + "vim": { + "vimInfoId": "1", + "vimId": "1", + "interfaceInfo": { + "vimType": "vim", + "apiVersion": "v2", + "protocolType": "http" + }, + "accessInfo": { + "tenant": "tenant_vCPE", + "username": "vCPE", + "password": "vCPE_321" + }, + "interfaceEndpoint": "http://10.43.21.105:80/" + }, + "resourceId": "1246", + "extCps": [ + { + "cpdId": "11", + "addresses": [ + { + "addressType": "MAC", + "l2AddressData": "00:f3:43:20:a2:a3" + }, + { + "addressType": "IP", + "l3AddressData": { + "iPAddressType": "IPv4", + "iPAddress": "192.168.104.2" + } + } + ], + "numDynamicAddresses": 0 + } + ] + } + ], + "localizationLanguage": "en_US", + "additionalParams": {} +}
\ No newline at end of file diff --git a/lcm/lcm/nf/vnfs/vnf_create/inst_vnf.py b/lcm/lcm/nf/vnfs/vnf_create/inst_vnf.py index cf67fad8..0182ef5e 100644 --- a/lcm/lcm/nf/vnfs/vnf_create/inst_vnf.py +++ b/lcm/lcm/nf/vnfs/vnf_create/inst_vnf.py @@ -11,15 +11,14 @@ # 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. - +import json import logging import traceback from threading import Thread -import time - from lcm.pub.database.models import NfInstModel, JobStatusModel from lcm.pub.exceptions import NFLCMException +from lcm.pub.msapi.nfvolcm import vnfd_rawdata_get from lcm.pub.utils.jobutil import JobUtil logger = logging.getLogger(__name__) @@ -49,26 +48,35 @@ class InstVnf(Thread): self.inst_exception('unexpected exception') def inst_pre(self, args): - try: - logger.info('inst_pre, args=%s' % args) - is_exist = NfInstModel.objects.filter(nfinstid=self.nf_inst_id).exists() - logger.debug("check_ns_inst_name_exist::is_exist=%s" % is_exist) - if not is_exist: - JobUtil.add_job_status(self.job_id, 255, "VNF nf_inst_id is not exist.") - raise NFLCMException('VNF nf_inst_id is not exist.') - - vnf_inst = NfInstModel.objects.get(nfinstid=self.nf_inst_id) - if vnf_inst.instantiationState != 'NOT_INSTANTIATED': - JobUtil.add_job_status(self.job_id, 255, "VNF instantiationState is not NOT_INSTANTIATED.") - raise NFLCMException('VNF instantiationState is not NOT_INSTANTIATED.') - - JobUtil.add_job_status(self.job_id, 100, "Instantiate Vnf success.") - is_exist = JobStatusModel.objects.filter(jobid=self.job_id).exists() - logger.debug("check_ns_inst_name_exist::is_exist=%s" % is_exist) - except Exception as e: - logger.error('Nf instancing preprocess exception=%s' % e.message) - logger.error(traceback.format_exc()) - return {'result': '255', 'msg': 'Nf instancing preprocess exception', 'context': {}} + logger.info('inst_pre, args=%s' % args) + is_exist = NfInstModel.objects.filter(nfinstid=self.nf_inst_id).exists() + logger.debug("check_ns_inst_name_exist::is_exist=%s" % is_exist) + if not is_exist: + logger.error("VNF nf_inst_id is not exist.") + JobUtil.add_job_status(self.job_id, 255, "VNF nf_inst_id is not exist.") + raise NFLCMException('VNF nf_inst_id is not exist.') + + vnf_inst = NfInstModel.objects.get(nfinstid=self.nf_inst_id) + if vnf_inst.instantiationState != 'NOT_INSTANTIATED': + logger.error("VNF instantiationState is not NOT_INSTANTIATED.") + JobUtil.add_job_status(self.job_id, 255, "VNF instantiationState is not NOT_INSTANTIATED.") + raise NFLCMException('VNF instantiationState is not NOT_INSTANTIATED.') + + #get rawdata by vnfd_id + ret = vnfd_rawdata_get(vnf_inst.vnfdid) + if ret[0] != 0: + raise NFLCMException("Get vnfd_raw_data failed.") + dst_plan = json.JSONDecoder().decode(ret[1]) + #checkParameterExist + for cp in self.data: + if cp not in dst_plan: + logger.error("[%s] is not defined in vnfd_info."%cp) + JobUtil.add_job_status(self.job_id, 255, "Input parameter is not defined in vnfd_info.") + raise NFLCMException('Input parameter is not defined in vnfd_info.') + + JobUtil.add_job_status(self.job_id, 100, "Instantiate Vnf success.") + is_exist = JobStatusModel.objects.filter(jobid=self.job_id).exists() + logger.debug("check_ns_inst_name_exist::is_exist=%s" % is_exist) def apply_grant(self, args): try: |