summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorying.yunlong <ying.yunlong@zte.com.cn>2017-02-20 15:18:27 +0800
committerying.yunlong <ying.yunlong@zte.com.cn>2017-02-20 15:18:27 +0800
commit665ab553e8c09fa35c46a9fe3e5e773af5df7f43 (patch)
tree11665f765e3948124961138aa8f028615cd3f6d3
parent34806616c3a2ad5a7d627dfdd44e7db0cabff863 (diff)
Modify code of apply_grant
Change-Id: I4f7ff27fc97613d55f127ed6698fdcada3053474 Issue-Id: GVNFM-21 Signed-off-by: ying.yunlong <ying.yunlong@zte.com.cn>
-rw-r--r--lcm/lcm/nf/vnfs/tests/test_vnf_create.py63
-rw-r--r--lcm/lcm/nf/vnfs/vnf_create/create_vnf_identifier.py5
-rw-r--r--lcm/lcm/nf/vnfs/vnf_create/inst_vnf.py60
3 files changed, 46 insertions, 82 deletions
diff --git a/lcm/lcm/nf/vnfs/tests/test_vnf_create.py b/lcm/lcm/nf/vnfs/tests/test_vnf_create.py
index 7070c388..6afe6c13 100644
--- a/lcm/lcm/nf/vnfs/tests/test_vnf_create.py
+++ b/lcm/lcm/nf/vnfs/tests/test_vnf_create.py
@@ -115,53 +115,24 @@ 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_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']
+ r3 = [1, json.JSONEncoder().encode(''), '200']
+ mock_call_req.side_effect = [r1, r2, r3]
+ 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, "Nf instancing apply grant exception")
+
+
- # @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']
- # r2 = [0, json.JSONEncoder().encode(''), '200']
- # mock_call_req.side_effect = [r1, r2]
- # create_data = {
- # "vnfdId": "111",
- # "vnfInstanceName": "vFW_01",
- # "vnfInstanceDescription": " vFW in Nanjing TIC Edge"}
- # self.nf_inst_id = CreateVnf(create_data).do_biz()
- # 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, "Input parameter is not defined in vnfd_info.")
- #
- # @mock.patch.object(restcall, 'call_req')
- # def test_instantiate_vnf_when_get_nfvo_config_failed(self, mock_call_req):
- # r1 = [0, json.JSONEncoder().encode(vnfd_model_dict), '200']
- # r2 = [0, json.JSONEncoder().encode(vnfd_model_dict), '200']
- # mock_call_req.side_effect = [r1, r2]
- # create_data = {
- # "vnfdId": "111",
- # "vnfInstanceName": "vFW_01",
- # "vnfInstanceDescription": " vFW in Nanjing TIC Edge"}
- # self.nf_inst_id = CreateVnf(create_data).do_biz()
- # 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, "Nfvo was not registered")
- #
# @mock.patch.object(restcall, 'call_req')
# def test_instantiate_vnf_when_applay_grant_failed(self, mock_call_req):
# NfvoRegInfoModel.objects.create(nfvoid='nfvo111', vnfminstid='vnfm111', apiurl='http://10.74.44.11',
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 7c16607e..14587375 100644
--- a/lcm/lcm/nf/vnfs/vnf_create/create_vnf_identifier.py
+++ b/lcm/lcm/nf/vnfs/vnf_create/create_vnf_identifier.py
@@ -53,13 +53,12 @@ class CreateVnf:
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")
+ metadata = ignore_case_get(self.vnfd, "metadata")
version = ignore_case_get(metadata, "vnfd_version")
vendor = ignore_case_get(metadata, "vendor")
netype = ignore_case_get(metadata, "vnf_type")
vnfsoftwareversion = ignore_case_get(metadata, "version")
- vnfd_model = vnfd_info
+ vnfd_model = self.vnfd
nf_inst_id = str(uuid.uuid4())
NfInstModel.objects.create(nfinstid=nf_inst_id, nf_name=self.vnf_instance_mame, package_id=self.package_id,
diff --git a/lcm/lcm/nf/vnfs/vnf_create/inst_vnf.py b/lcm/lcm/nf/vnfs/vnf_create/inst_vnf.py
index 0c0edbe1..ef895380 100644
--- a/lcm/lcm/nf/vnfs/vnf_create/inst_vnf.py
+++ b/lcm/lcm/nf/vnfs/vnf_create/inst_vnf.py
@@ -109,56 +109,49 @@ class InstVnf(Thread):
if vnf_insts[0].status != 'NOT_INSTANTIATED':
raise NFLCMException('VNF instantiationState is not NOT_INSTANTIATED.')
+ JobUtil.add_job_status(self.job_id, 5, 'Get packageinfo by vnfd_id')
# get csar_id from nslcm by vnfd_id
self.package_info = get_packageinfo_by_vnfdid(vnf_insts[0].vnfdid)
self.package_id = ignore_case_get(self.package_info, "package_id")
self.csar_id = ignore_case_get(self.package_info, "csar_id")
+ JobUtil.add_job_status(self.job_id, 10, 'Get rawdata from catalog by csar_id')
#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_info = self.vnfd
-
- # checkParameterExist
- for cp in self.data:
- if cp not in self.vnfd_info:
- raise NFLCMException('Input parameter is not defined in vnfd_info.')
- # get nfvo info
- JobUtil.add_job_status(self.job_id, 5, 'Get nfvo connection info')
- self.load_nfvo_config()
+ input_parameters = []
+ for key, val in self.data['additionalParams'].items():
+ input_parameters.append({"key": key, "value": val})
+ raw_data = query_rawdata_from_catalog(self.csar_id, input_parameters)
+ self.vnfd_info = toscautil.convert_vnfd_model(raw_data["rawData"]) # convert to inner json
+ self.vnfd_info = json.JSONDecoder().decode(self.vnfd_info)
+ self.checkParameterExist()
# update NfInstModel
NfInstModel.objects.filter(nfinstid=self.nf_inst_id).\
update(flavour_id=ignore_case_get(self.data, "flavourId"),
- vnf_level=ignore_case_get(self.data, 'instantiationLevelId'),
- input_params=ignore_case_get(self.data, 'additionalParams'),
- extension=ignore_case_get(self.data, ''),
- initallocatedata=self.vnfd_info,
+ input_params=self.data,
+ vnfd_model=self.vnfd_info,
localizationLanguage=ignore_case_get(self.data, 'localizationLanguage'),
lastuptime=now_time())
- JobUtil.add_job_status(self.job_id, 10, 'Nf instancing pre-check finish')
+ JobUtil.add_job_status(self.job_id, 15, 'Nf instancing pre-check finish')
logger.info("Nf instancing pre-check finish")
def apply_grant(self):
logger.info('[NF instantiation] send resource grand request to nfvo start')
# self.check_vm_capacity()
- content_args = {'nfvoInstanceId': self.nfvo_inst_id, 'vnfmInstanceId': self.vnfm_inst_id,
- 'nfInstanceId': self.nf_inst_id, 'nfDescriptorId': '',
- 'lifecycleOperation': 'Instantiate', 'jobId': self.job_id, 'addResource': [],
- 'removeResource': [], 'placementConstraint': [], 'exVimIdList': [], 'additionalParam': {}}
+ content_args = {'vnfInstanceId': self.nf_inst_id, 'vnfDescriptorId': '',
+ 'lifecycleOperation': 'Instantiate', 'jobId': self.job_id,
+ 'addResource': [], 'removeResource': [],
+ 'placementConstraint': [], 'additionalParam': {}}
vdus = ignore_case_get(self.vnfd_info, "vdus")
res_index = 1
for vdu in vdus:
+ location_info = ignore_case_get(ignore_case_get(vdu, "properties"), "location_info")
res_def = {'type': 'VDU',
- 'resourceDefinitionId': str(res_index),
- 'vduId': ignore_case_get(vdu, "vdu_id"),
- 'vimid': '',
- 'tenant': ''}
- if self.vnfd_info['metadata']['cross_dc']:
- res_def['vimid'] = vdu['properties']['location_info']['vimId']
- res_def['tenant'] = vdu['properties']['location_info']['tenant']
+ 'resDefId': str(res_index),
+ 'resDesId': ignore_case_get(vdu, "vdu_id"),
+ 'vimid': ignore_case_get(location_info, "vimId"),
+ 'tenant': ignore_case_get(location_info, "tenant")}
content_args['addResource'].append(res_def)
res_index += 1
logger.info('content_args=%s' % content_args)
@@ -167,10 +160,9 @@ class InstVnf(Thread):
if resp[0] != 0:
raise NFLCMException('Nf instancing apply grant exception')
- # update_resources_table()
- NfInstModel.objects.filter(nfinstid=self.nf_inst_id).update(instantiationState='INSTANTIATED',
- lastuptime=now_time())
- JobUtil.add_job_status(self.job_id, 20, 'Nf instancing apply grant finish')
+ # update resources_table
+ NfInstModel.objects.filter(nfinstid=self.nf_inst_id).update(status='INSTANTIATED', lastuptime=now_time())
+ JobUtil.add_job_status(self.job_id,20, 'Nf instancing apply grant finish')
logger.info("Nf instancing apply grant finish")
def create_res(self):
@@ -475,5 +467,7 @@ class InstVnf(Thread):
def do_notify_delete(self, ret):
logger.error('Deleting [%s] resource' % ret)
- def checkParameterExist(self, input_para, vnfd_info):
+ def checkParameterExist(self):
+ # if ignore_case_get(self.data, "flavourId") not in self.vnfd_info:
+ # raise NFLCMException('Input parameter is not defined in vnfd_info.')
pass