From: ying.yunlong Date: Mon, 20 Feb 2017 06:11:58 +0000 (+0800) Subject: Modify code of query_rawdata_from_catalog X-Git-Tag: release/mercury~69 X-Git-Url: https://gerrit.onap.org/r/gitweb?p=vfc%2Fgvnfm%2Fvnflcm.git;a=commitdiff_plain;h=34806616c3a2ad5a7d627dfdd44e7db0cabff863 Modify code of query_rawdata_from_catalog Change-Id: I5f2556a24419e0b943111daa0c6df8971807536c Issue-Id: GVNFM-34 Signed-off-by: ying.yunlong --- diff --git a/lcm/lcm/nf/vnfs/tests/test_vnf_create.py b/lcm/lcm/nf/vnfs/tests/test_vnf_create.py index 9243b3ea..7070c388 100644 --- a/lcm/lcm/nf/vnfs/tests/test_vnf_create.py +++ b/lcm/lcm/nf/vnfs/tests/test_vnf_create.py @@ -61,7 +61,7 @@ class TestNFInstantiate(TestCase): @mock.patch.object(restcall, 'call_req') def test_create_vnf_identifier(self, mock_call_req): r1 = [0, json.JSONEncoder().encode({'package_id':'222', 'csar_id':'2222'}), '200'] # get csar_id from nslcm by vnfd_id - r2 = [0, json.JSONEncoder().encode(vnfd_model_dict), '200'] + r2 = [0, json.JSONEncoder().encode(vnfd_raw_data), '200'] mock_call_req.side_effect = [r1, r2] data = { "vnfdId": "111", @@ -88,7 +88,7 @@ class TestNFInstantiate(TestCase): @mock.patch.object(restcall, 'call_req') def test_instantiate_vnf_when_get_package_info_by_vnfdid_failed(self, mock_call_req): - NfInstModel.objects.create(nfinstid='1111', nf_name='vFW_01', package_id='todo', + NfInstModel.objects.create(nfinstid='1111', nf_name='vFW_01', package_id='222', version='', vendor='', netype='', vnfd_model='', status='NOT_INSTANTIATED', nf_desc='vFW in Nanjing TIC Edge', vnfdid='111', create_time=now_time()) r1 = [1, json.JSONEncoder().encode({'package_id':'222', 'csar_id':'2222'}), '200'] # get csar_id from nslcm by vnfd_id @@ -102,11 +102,11 @@ class TestNFInstantiate(TestCase): @mock.patch.object(restcall, 'call_req') def test_instantiate_vnf_when_get_rawdata_by_csarid_failed(self, mock_call_req): - NfInstModel.objects.create(nfinstid='1111', nf_name='vFW_01', package_id='todo', + NfInstModel.objects.create(nfinstid='1111', nf_name='vFW_01', package_id='222', version='', vendor='', netype='', vnfd_model='', status='NOT_INSTANTIATED', nf_desc='vFW in Nanjing TIC Edge', vnfdid='111', create_time=now_time()) r1 = [0, json.JSONEncoder().encode({'package_id':'222', 'csar_id':'2222'}), '200'] # get csar_id from nslcm by vnfd_id - r2 = [1, json.JSONEncoder().encode(''), '200'] + r2 = [1, json.JSONEncoder().encode(vnfd_raw_data), '200'] mock_call_req.side_effect = [r1, r2] self.nf_inst_id = '1111' self.job_id = JobUtil.create_job('NF', 'CREATE', self.nf_inst_id) @@ -115,6 +115,21 @@ class TestNFInstantiate(TestCase): InstVnf(data, nf_inst_id=self.nf_inst_id, job_id=self.job_id).run() self.assert_job_result(self.job_id, 255, "Failed to query rawdata of CSAR(2222) from catalog.") + # @mock.patch.object(restcall, 'call_req') + # def test_instantiate_vnf_when_get_rawdata_by_csarid_failed(self, mock_call_req): + # NfInstModel.objects.create(nfinstid='1111', nf_name='vFW_01', package_id='222', + # version='', vendor='', netype='', vnfd_model='', status='NOT_INSTANTIATED', + # nf_desc='vFW in Nanjing TIC Edge', vnfdid='111', create_time=now_time()) + # r1 = [0, json.JSONEncoder().encode({'package_id': '222', 'csar_id': '2222'}), '200'] # get csar_id from nslcm by vnfd_id + # r2 = [0, json.JSONEncoder().encode(vnfd_raw_data), '200'] + # mock_call_req.side_effect = [r1, r2] + # self.nf_inst_id = '1111' + # self.job_id = JobUtil.create_job('NF', 'CREATE', self.nf_inst_id) + # 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, 255, "Failed to query rawdata of CSAR(2222) from catalog.") + # @mock.patch.object(restcall, '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'] @@ -574,3 +589,115 @@ vnfd_model_dict = { "localizationLanguage": "en_US", "additionalParams": {} } + +vnfd_raw_data = { + "rawData": { + "instance": { + "metadata": { + "is_shared": False, + "plugin_info": "vbrasplugin_1.0", + "vendor": "zte", + "request_reclassification": False, + "name": "vbras", + "version": 1, + "vnf_type": "vbras", + "cross_dc": False, + "vnfd_version": "1.0.0", + "id": "zte_vbras_1.0", + "nsh_aware": True + }, + "nodes": [ + { + "id": "aaa_dnet_cp_0xu2j5sbigxc8h1ega3if0ld1", + "type_name": "tosca.nodes.nfv.ext.zte.CP", + "template_name": "aaa_dnet_cp", + "properties": { + "bandwidth": { + "type_name": "integer", + "value": 0 + }, + "direction": { + "type_name": "string", + "value": "bidirectional" + }, + "vnic_type": { + "type_name": "string", + "value": "normal" + }, + "sfc_encapsulation": { + "type_name": "string", + "value": "mac" + }, + "order": { + "type_name": "integer", + "value": 2 + } + }, + "relationships": [ + { + "name": "guest_os", + "source_requirement_index": 0, + "target_node_id": "AAA_image_d8aseebr120nbm7bo1ohkj194", + "target_capability_name": "feature" + } + ] + }, + { + "id": "LB_Image_oj5l2ay8l2g6vcq6fsswzduha", + "type_name": "tosca.nodes.nfv.ext.ImageFile", + "template_name": "LB_Image", + "properties": { + "disk_format": { + "type_name": "string", + "value": "qcow2" + }, + "file_url": { + "type_name": "string", + "value": "/SoftwareImages/image-lb" + }, + "name": { + "type_name": "string", + "value": "image-lb" + } + } + } + ] + }, + "model": { + "metadata": { + "is_shared": False, + "plugin_info": "vbrasplugin_1.0", + "vendor": "zte", + "request_reclassification": False, + "name": "vbras", + "version": 1, + "vnf_type": "vbras", + "cross_dc": False, + "vnfd_version": "1.0.0", + "id": "zte_vbras_1.0", + "nsh_aware": True + }, + "node_templates": [ + { + "name": "aaa_dnet_cp", + "type_name": "tosca.nodes.nfv.ext.zte.CP", + "default_instances": 1, + "min_instances": 0, + "properties": { + "bandwidth": { + "type_name": "integer", + "value": 0 + } + }, + "requirement_templates": [ + { + "name": "virtualbinding", + "target_node_template_name": "AAA", + "target_capability_name": "virtualbinding" + } + ] + } + ] + } + } +} diff --git a/lcm/lcm/nf/vnfs/vnf_create/create_vnf_identifier.py b/lcm/lcm/nf/vnfs/vnf_create/create_vnf_identifier.py index 88738216..7c16607e 100644 --- a/lcm/lcm/nf/vnfs/vnf_create/create_vnf_identifier.py +++ b/lcm/lcm/nf/vnfs/vnf_create/create_vnf_identifier.py @@ -50,8 +50,8 @@ class CreateVnf: # get rawdata from catalog by csar_id raw_data = query_rawdata_from_catalog(self.csar_id, self.data) - # self.vnfd = toscautil.convert_vnfd_model(raw_data["rawData"]) # convert to inner json - # self.vnfd = json.JSONDecoder().decode(self.vnfd) + self.vnfd = toscautil.convert_vnfd_model(raw_data["rawData"]) # convert to inner json + self.vnfd = json.JSONDecoder().decode(self.vnfd) vnfd_info = raw_data metadata = ignore_case_get(vnfd_info, "metadata") diff --git a/lcm/lcm/nf/vnfs/vnf_create/inst_vnf.py b/lcm/lcm/nf/vnfs/vnf_create/inst_vnf.py index 6e51f64a..0c0edbe1 100644 --- a/lcm/lcm/nf/vnfs/vnf_create/inst_vnf.py +++ b/lcm/lcm/nf/vnfs/vnf_create/inst_vnf.py @@ -118,11 +118,8 @@ class InstVnf(Thread): raw_data = query_rawdata_from_catalog(self.csar_id, self.data) self.vnfd = toscautil.convert_vnfd_model(raw_data["rawData"]) # convert to inner json self.vnfd = json.JSONDecoder().decode(self.vnfd) + self.vnfd_info = self.vnfd - ret = vnfd_rawdata_get(vnf_insts[0].vnfdid, self.data) - if ret[0] != 0: - raise NFLCMException("Get vnfd_raw_data failed.") - self.vnfd_info = json.JSONDecoder().decode(ret[1]) # checkParameterExist for cp in self.data: if cp not in self.vnfd_info: @@ -477,3 +474,6 @@ class InstVnf(Thread): def do_notify_delete(self, ret): logger.error('Deleting [%s] resource' % ret) + + def checkParameterExist(self, input_para, vnfd_info): + pass