summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorying.yunlong <ying.yunlong@zte.com.cn>2018-01-06 14:34:16 +0800
committeryunlong ying <ying.yunlong@zte.com.cn>2018-01-08 00:52:50 +0000
commit42ea82f3195cd3da69693b56b04c486d086a0484 (patch)
tree26ef5e3d6ae7909e554f48ddec23f0ebe4edf7fb
parentd3cd0dee53f71e779e1565b5566981ca76872bb5 (diff)
Modify vfc-vnflcm instantiation code
Change-Id: I0ac3ba903141c6abbeb5161b7bac9b12c3eaecc9 Issue-ID: VFC-630 Signed-off-by: ying.yunlong <ying.yunlong@zte.com.cn>
-rw-r--r--lcm/lcm/nf/vnfs/const.py86
-rw-r--r--lcm/lcm/nf/vnfs/tests/test_vnf_create.py92
-rw-r--r--lcm/lcm/nf/vnfs/vnf_create/inst_vnf.py53
-rw-r--r--lcm/lcm/pub/msapi/catalog.py106
4 files changed, 121 insertions, 216 deletions
diff --git a/lcm/lcm/nf/vnfs/const.py b/lcm/lcm/nf/vnfs/const.py
index bf4343ad..6412e746 100644
--- a/lcm/lcm/nf/vnfs/const.py
+++ b/lcm/lcm/nf/vnfs/const.py
@@ -837,3 +837,89 @@ c10_data_get_vm = {
"tenantId": "tenant1",
"status": "ACTIVE"
}
+
+vnfpackage_info = {
+ "volume_storages": [],
+ "inputs": {
+ "pe1_id": {
+ "type": "string",
+ "description": "pe1_idofunderlayvpn"
+ },
+ "pe2_id": {
+ "type": "string",
+ "description": "pe2_idofunderlayvpn"
+ },
+ "serviceType": {
+ "type": "string",
+ "description": "serviceTypeofunderlayvpn"
+ },
+ "description": {
+ "type": "string",
+ "description": "descriptionofunderlayvpn"
+ },
+ "ac2_route": {
+ "type": "string",
+ "description": "ac2_routeofunderlayvpn"
+ },
+ "ac1_route": {
+ "type": "string",
+ "description": "ac1_routeofunderlayvpn"
+ },
+ "ac1_svlan": {
+ "type": "integer",
+ "description": "ac1_svlanofunderlayvpn"
+ },
+ "ac2_ip": {
+ "type": "string",
+ "description": "ac2_ipofunderlayvpn"
+ },
+ "ac1_ip": {
+ "type": "string",
+ "description": "ac1_ipofunderlayvpn"
+ },
+ "ac2_port": {
+ "type": "string",
+ "description": "ac2_portofunderlayvpn"
+ },
+ "topology": {
+ "type": "string",
+ "description": "topologyofunderlayvpn"
+ },
+ "technology": {
+ "type": "string",
+ "description": "technologyofunderlayvpn"
+ },
+ "ac1_port": {
+ "type": "string",
+ "description": "ac1_portofunderlayvpn"
+ },
+ "ac2_svlan": {
+ "type": "integer",
+ "description": "ac2_svlanofunderlayvpn"
+ },
+ "name": {
+ "type": "string",
+ "description": "Nameofunderlayervpn"
+ }
+ },
+ "vdus": [],
+ "image_files": [],
+ "routers": [],
+ "local_storages": [],
+ "vnf_exposed": {
+ "external_cps": [],
+ "forward_cps": []
+ },
+ "vls": [],
+ "cps": [],
+ "metadata": {
+ "designer": "sdno",
+ "name": "underlayervpn",
+ "csarVersion": "1.0",
+ "csarType": "SSAR",
+ "csarProvider": "huawei",
+ "version": "1.0",
+ "type": "SSAR",
+ "id": "ns_underlayervpn_1_0"
+ }
+}
diff --git a/lcm/lcm/nf/vnfs/tests/test_vnf_create.py b/lcm/lcm/nf/vnfs/tests/test_vnf_create.py
index 537171e3..7804e109 100644
--- a/lcm/lcm/nf/vnfs/tests/test_vnf_create.py
+++ b/lcm/lcm/nf/vnfs/tests/test_vnf_create.py
@@ -21,7 +21,7 @@ from rest_framework import status
from lcm.nf.vnfs.const import vnfd_rawdata, c1_data_get_tenant_id, c4_data_create_network, c2_data_create_volume, \
c5_data_create_subnet, c3_data_get_volume, c6_data_create_port, c7_data_create_flavor, c8_data_list_image, \
- c9_data_create_vm, c10_data_get_vm, inst_req_data
+ c9_data_create_vm, c10_data_get_vm, inst_req_data, vnfpackage_info
from lcm.nf.vnfs.vnf_create.inst_vnf import InstVnf
from lcm.pub.database.models import NfInstModel, JobStatusModel
from lcm.pub.utils import restcall
@@ -87,37 +87,6 @@ class TestNFInstantiate(TestCase):
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_when_get_package_info_by_vnfdid_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_get_csarid_by_vnfdid = [1, json.JSONEncoder().encode(
- {
- 'csars': [
- {
- 'package_id': '222',
- 'csarId': '2222',
- 'vnfdId': '111'
- }
- ]
- }), '200']
- mock_call_req.side_effect = [r1_get_csarid_by_vnfdid]
- 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 package_info of vnfdid(111) from nslcm.")
-
- @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',
@@ -130,24 +99,14 @@ class TestNFInstantiate(TestCase):
nf_desc='vFW in Nanjing TIC Edge',
vnfdid='111',
create_time=now_time())
- r1_get_csarid_by_vnfdid = [0, json.JSONEncoder().encode(
- {
- 'csars': [
- {
- 'package_id': '222',
- 'csarId': '2222',
- 'vnfdId': '111'
- }
- ]
- }), '200']
- r2_get_rawdata_from_catalog = [1, json.JSONEncoder().encode(vnfd_rawdata), '200']
- mock_call_req.side_effect = [r1_get_csarid_by_vnfdid, r2_get_rawdata_from_catalog]
+ r1_get_vnfpackage_by_vnfdid = [1, json.JSONEncoder().encode(vnfpackage_info), '200']
+ mock_call_req.side_effect = [r1_get_vnfpackage_by_vnfdid]
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.")
+ self.assert_job_result(self.job_id, 255, "Failed to query vnf CSAR(111) from catalog.")
@mock.patch.object(restcall, 'call_req')
def test_instantiate_vnf_when_applay_grant_failed(self, mock_call_req):
@@ -162,17 +121,7 @@ class TestNFInstantiate(TestCase):
nf_desc='vFW in Nanjing TIC Edge',
vnfdid='111',
create_time=now_time())
- r1_get_csarid_by_vnfdid = [0, json.JSONEncoder().encode(
- {
- 'csars': [
- {
- 'package_id': '222',
- 'csarId': '2222',
- 'vnfdId': '111'
- }
- ]
- }), '200']
- r2_get_rawdata_from_catalog = [0, json.JSONEncoder().encode(vnfd_rawdata), '200']
+ r1_get_vnfpackage_by_vnfdid = [0, json.JSONEncoder().encode(vnfpackage_info), '200']
r3_apply_grant_result = [1, json.JSONEncoder().encode(
{
"vim": {
@@ -182,7 +131,7 @@ class TestNFInstantiate(TestCase):
}
}
}), '200']
- mock_call_req.side_effect = [r1_get_csarid_by_vnfdid, r2_get_rawdata_from_catalog, r3_apply_grant_result]
+ mock_call_req.side_effect = [r1_get_vnfpackage_by_vnfdid, r3_apply_grant_result]
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")
@@ -204,17 +153,7 @@ class TestNFInstantiate(TestCase):
nf_desc='vFW in Nanjing TIC Edge',
vnfdid='111',
create_time=now_time())
- r1_get_csarid_by_vnfdid = [0, json.JSONEncoder().encode(
- {
- 'csars': [
- {
- 'package_id': '222',
- 'csarId': '2222',
- 'vnfdId': '111'
- }
- ]
- }), '200']
- r2_get_rawdata_from_catalog = [0, json.JSONEncoder().encode(vnfd_rawdata), '200']
+ r1_get_vnfpackage_by_vnfdid = [0, json.JSONEncoder().encode(vnfpackage_info), '200']
r3_apply_grant_result = [0, json.JSONEncoder().encode(
{
"vim": {
@@ -224,7 +163,7 @@ class TestNFInstantiate(TestCase):
}
}
}), '200']
- mock_call_req.side_effect = [r1_get_csarid_by_vnfdid, r2_get_rawdata_from_catalog, r3_apply_grant_result]
+ mock_call_req.side_effect = [r1_get_vnfpackage_by_vnfdid, r3_apply_grant_result]
mock_call.side_effect = [c1_data_get_tenant_id, c2_data_create_volume, c3_data_get_volume]
self.nf_inst_id = '1111'
self.job_id = JobUtil.create_job('NF', 'CREATE', self.nf_inst_id)
@@ -247,17 +186,7 @@ class TestNFInstantiate(TestCase):
nf_desc='vFW in Nanjing TIC Edge',
vnfdid='111',
create_time=now_time())
- r1_get_csarid_by_vnfdid = [0, json.JSONEncoder().encode(
- {
- 'csars': [
- {
- 'package_id': '222',
- 'csarId': '2222',
- 'vnfdId': '111'
- }
- ]
- }), '200']
- r2_get_rawdata_from_catalog = [0, json.JSONEncoder().encode(vnfd_rawdata), '200']
+ r1_get_vnfpackage_by_vnfdid = [0, json.JSONEncoder().encode(vnfpackage_info), '200']
r3_apply_grant_result = [0, json.JSONEncoder().encode(
{
"vim": {
@@ -268,8 +197,7 @@ class TestNFInstantiate(TestCase):
}
}), '200']
r4_lcm_notify_result = [0, json.JSONEncoder().encode(''), '200']
- mock_call_req.side_effect = [r1_get_csarid_by_vnfdid, r2_get_rawdata_from_catalog,
- r3_apply_grant_result, r4_lcm_notify_result]
+ mock_call_req.side_effect = [r1_get_vnfpackage_by_vnfdid, r3_apply_grant_result, r4_lcm_notify_result]
mock_call.side_effect = [c1_data_get_tenant_id, c2_data_create_volume, c3_data_get_volume,
c4_data_create_network, c5_data_create_subnet, c6_data_create_port,
c7_data_create_flavor, c8_data_list_image, c9_data_create_vm, c10_data_get_vm]
diff --git a/lcm/lcm/nf/vnfs/vnf_create/inst_vnf.py b/lcm/lcm/nf/vnfs/vnf_create/inst_vnf.py
index 9b6babb2..a1f66391 100644
--- a/lcm/lcm/nf/vnfs/vnf_create/inst_vnf.py
+++ b/lcm/lcm/nf/vnfs/vnf_create/inst_vnf.py
@@ -21,9 +21,8 @@ from threading import Thread
from lcm.pub.database.models import NfInstModel, VmInstModel, NetworkInstModel, \
SubNetworkInstModel, PortInstModel, StorageInstModel, FlavourInstModel, VNFCInstModel, NfvoRegInfoModel
from lcm.pub.exceptions import NFLCMException
-from lcm.pub.msapi.catalog import query_rawdata_from_catalog
-from lcm.pub.msapi.gvnfmdriver import apply_grant_to_nfvo, notify_lcm_to_nfvo, get_packageinfo_by_vnfdid
-from lcm.pub.utils import toscautil
+from lcm.pub.msapi.gvnfmdriver import apply_grant_to_nfvo, notify_lcm_to_nfvo
+from lcm.pub.msapi.sdc_run_catalog import query_vnfpackage_by_id
from lcm.pub.utils.jobutil import JobUtil
from lcm.pub.utils.timeutil import now_time
from lcm.pub.utils.values import ignore_case_get, get_none, get_boolean, get_integer
@@ -43,7 +42,6 @@ class InstVnf(Thread):
self.nfvo_inst_id = ''
self.vnfm_inst_id = ''
self.package_id = ''
- # self.csar_id = ''
self.vnfd_info = []
def run(self):
@@ -69,13 +67,7 @@ class InstVnf(Thread):
JobUtil.add_job_status(self.job_id, 5, 'Get packageinfo by vnfd_id')
self.vnfd_id = vnf_insts[0].vnfdid
- package_info = get_packageinfo_by_vnfdid(self.vnfd_id)
- for val in ignore_case_get(package_info, "csars"):
- if self.vnfd_id == ignore_case_get(val, "vnfdId"):
- self.package_id = ignore_case_get(val, "csarId")
- break
-
- JobUtil.add_job_status(self.job_id, 10, 'Get rawdata from catalog by csar_id')
+ JobUtil.add_job_status(self.job_id, 10, 'Get vnf package info from catalog by csar_id')
input_parameters = []
inputs = ignore_case_get(self.data['additionalParams'], "inputs")
if inputs:
@@ -83,27 +75,23 @@ class InstVnf(Thread):
inputs = json.loads(inputs)
for key, val in inputs.items():
input_parameters.append({"key": key, "value": val})
- raw_data = query_rawdata_from_catalog(self.package_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.vnfd_info = query_vnfpackage_by_id(self.vnfd_id)
# self.vnfd_info = vnfd_model_dict # just for test
- self.update_cps()
+ self.update_cps()
self.check_parameter_exist()
metadata = ignore_case_get(self.vnfd_info, "metadata")
- version = ignore_case_get(metadata, "vnfd_version")
+ version = ignore_case_get(metadata, "vnfdVersion")
vendor = ignore_case_get(metadata, "vendor")
- netype = ignore_case_get(metadata, "vnf_type")
+ netype = ignore_case_get(metadata, "type")
vnfsoftwareversion = ignore_case_get(metadata, "version")
- vnfd_model = self.vnfd_info
NfInstModel.objects.filter(nfinstid=self.nf_inst_id).\
update(package_id=self.package_id,
flavour_id=ignore_case_get(self.data, "flavourId"),
version=version,
vendor=vendor,
netype=netype,
- vnfd_model=vnfd_model,
+ vnfd_model=self.vnfd_info,
status='NOT_INSTANTIATED',
vnfdid=self.vnfd_id,
localizationLanguage=ignore_case_get(self.data, 'localizationLanguage'),
@@ -121,17 +109,25 @@ class InstVnf(Thread):
def apply_grant(self):
logger.info('[NF instantiation] send resource grand request to nfvo start')
- content_args = {'vnfInstanceId': self.nf_inst_id, 'vnfDescriptorId': '',
- 'lifecycleOperation': 'Instantiate', 'jobId': self.job_id,
- 'addResource': [], 'removeResource': [],
- 'placementConstraint': [], '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:
- res_def = {'type': 'VDU',
- 'resDefId': str(res_index),
- 'resDesId': ignore_case_get(vdu, "vdu_id")}
+ res_def = {
+ 'type': 'VDU',
+ 'resDefId': str(res_index),
+ 'resDesId': ignore_case_get(vdu, "vdu_id")
+ }
content_args['addResource'].append(res_def)
res_index += 1
@@ -230,7 +226,8 @@ class InstVnf(Thread):
'affectedVnfc': affected_vnfc,
'affectedVirtualLink': affected_vl,
'affectedVirtualStorage': affected_vs,
- 'affectedCp': affected_cp}
+ 'affectedCp': affected_cp
+ }
vnfmInfo = NfvoRegInfoModel.objects.filter(nfvoid=self.nf_inst_id)
if len(vnfmInfo) == 0:
diff --git a/lcm/lcm/pub/msapi/catalog.py b/lcm/lcm/pub/msapi/catalog.py
deleted file mode 100644
index 6683370a..00000000
--- a/lcm/lcm/pub/msapi/catalog.py
+++ /dev/null
@@ -1,106 +0,0 @@
-# Copyright 2016 ZTE Corporation.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# 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
-
-from lcm.pub.utils.restcall import req_by_msb
-from lcm.pub.utils.values import ignore_case_get
-from lcm.pub.exceptions import NFLCMException
-
-logger = logging.getLogger(__name__)
-
-STATUS_ONBOARDED, STATUS_NON_ONBOARDED = "onBoarded", "non-onBoarded"
-
-P_STATUS_NORMAL, P_STATUS_ONBOARDING, P_STATUS_ONBOARDFAILED = "normal", "onBoarding", "onBoardFailed"
-P_STATUS_DELETING, P_STATUS_DELETEFAILED = "deleting", "deleteFailed"
-
-
-def query_csar_from_catalog(csar_id, key=''):
- ret = req_by_msb("/api/catalog/v1/csars/%s" % csar_id, "GET")
- if ret[0] != 0:
- logger.error("Status code is %s, detail is %s.", ret[2], ret[1])
- if ret[2] == '404':
- raise NFLCMException("CSAR(%s) does not exist." % csar_id)
- raise NFLCMException("Failed to query CSAR(%s) from catalog." % csar_id)
- csar_info = json.JSONDecoder().decode(ret[1])
- return ignore_case_get(csar_info, key) if key else csar_info
-
-
-def query_rawdata_from_catalog(csar_id, input_parameters=[]):
- req_param = json.JSONEncoder().encode({"csarId": csar_id, "inputParameters": input_parameters})
- ret = req_by_msb("/api/catalog/v1/servicetemplates/queryingrawdata", "POST", req_param)
- if ret[0] != 0:
- logger.error("Status code is %s, detail is %s.", ret[2], ret[1])
- raise NFLCMException("Failed to query rawdata of CSAR(%s) from catalog." % csar_id)
- return json.JSONDecoder().decode(ret[1])
-
-
-def set_csar_state(csar_id, prop, val):
- ret = req_by_msb("/api/catalog/v1/csars/%s?%s=%s" % (csar_id, prop, val), "PUT")
- if ret[0] != 0:
- logger.error("Status code is %s, detail is %s.", ret[2], ret[1])
- return [1, "Failed to set %s to %s of CSAR(%s)." % (prop, val, csar_id)]
- return [0, "Set %s to %s of CSAR(%s) successfully." % (prop, val, csar_id)]
-
-
-def delete_csar_from_catalog(csar_id):
- ret = req_by_msb("/api/catalog/v1/csars/%s" % csar_id, "DELETE")
- if ret[0] != 0 and ret[2] != '404':
- logger.error("Status code is %s, detail is %s.", ret[2], ret[1])
- set_csar_state(csar_id, "processState", P_STATUS_DELETEFAILED)
- return [1, "Failed to delete CSAR(%s) from catalog." % csar_id]
- return [0, "Delete CSAR(%s) successfully." % csar_id]
-
-
-def get_download_url_from_catalog(csar_id, relative_path):
- ret = req_by_msb("/api/catalog/v1/csars/%s/files?relativePath=%s" % (csar_id, relative_path), "GET")
- if ret[0] != 0:
- logger.error("Status code is %s, detail is %s.", ret[2], ret[1])
- raise NFLCMException("Failed to get download url of CSAR(%s)." % csar_id)
- csar_file_info = json.JSONDecoder().decode(ret[1])
- return ignore_case_get(csar_file_info, "downloadUri"), ignore_case_get(csar_file_info, "localPath")
-
-
-def get_process_id(name, srv_template_id):
- ret = req_by_msb('/api/catalog/v1/servicetemplates/%s/operations' % srv_template_id, 'GET')
- if ret[0] != 0:
- raise NFLCMException('Failed to get service[%s,%s] process id' % (name, srv_template_id))
- items = json.JSONDecoder().decode(ret[1])
- for item in items:
- if name in item['name']:
- return item['processId']
- raise NFLCMException('service[%s,%s] process id not exist' % (name, srv_template_id))
-
-
-def get_servicetemplate_id(nsd_id):
- ret = req_by_msb('/api/catalog/v1/servicetemplates', 'GET')
- if ret[0] != 0:
- raise NFLCMException('Failed to get servicetemplates info')
- stpls = json.JSONDecoder().decode(ret[1])
- for stpl in stpls:
- if stpl["id"] == nsd_id:
- return stpl["serviceTemplateId"]
- raise NFLCMException('servicetemplate(%s) does not exist.' % nsd_id)
-
-
-def get_servicetemplate(nsd_id):
- ret = req_by_msb('/api/catalog/v1/servicetemplates', 'GET')
- if ret[0] != 0:
- raise NFLCMException('Failed to get servicetemplates info')
- stpls = json.JSONDecoder().decode(ret[1])
- for stpl in stpls:
- if stpl["id"] == nsd_id:
- return stpl
- return NFLCMException('servicetemplate(%s) does not exist.' % nsd_id)