summaryrefslogtreecommitdiffstats
path: root/lcm
diff options
context:
space:
mode:
authorying.yunlong <ying.yunlong@zte.com.cn>2017-02-10 13:05:01 +0800
committerying.yunlong <ying.yunlong@zte.com.cn>2017-02-10 13:05:01 +0800
commitbb5baf14502eddbf4b61d6e29626609602919e3c (patch)
tree3787d3a3312511ee17e1239606e138a425eb8c8f /lcm
parent283dad75adf7f1c9470a8b324ee7697380e08562 (diff)
VNF config SBI
Change-Id: Ifd3f4afea67b97c5365e72b2566e923fff86b9bf Issue-Id: GVNFM-21 Signed-off-by: ying.yunlong <ying.yunlong@zte.com.cn>
Diffstat (limited to 'lcm')
-rw-r--r--lcm/lcm/nf/vnfs/tests/test_vnf_create.py36
-rw-r--r--lcm/lcm/nf/vnfs/vnf_create/create_vnf_identifier.py7
-rw-r--r--lcm/lcm/nf/vnfs/vnf_create/inst_vnf.py18
-rw-r--r--lcm/lcm/pub/database/models.py14
4 files changed, 67 insertions, 8 deletions
diff --git a/lcm/lcm/nf/vnfs/tests/test_vnf_create.py b/lcm/lcm/nf/vnfs/tests/test_vnf_create.py
index 293b6536..185c8292 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.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
+from lcm.pub.database.models import NfInstModel, JobStatusModel, NfvoRegInfoModel
from lcm.pub.utils import restcall
from lcm.pub.utils.jobutil import JobUtil
@@ -129,6 +129,40 @@ 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, "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_success(self, mock_call_req):
+ NfvoRegInfoModel.objects.create(nfvoid='nfvo111', vnfminstid='vnfm111', apiurl='http://10.74.44.11',
+ nfvouser='root', nfvopassword='root123')
+ 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, 100, "Instantiate Vnf success.")
+
vnfd_model_dict = {
'local_storages': [],
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 bb7f80a7..b427e66b 100644
--- a/lcm/lcm/nf/vnfs/vnf_create/create_vnf_identifier.py
+++ b/lcm/lcm/nf/vnfs/vnf_create/create_vnf_identifier.py
@@ -17,15 +17,12 @@ import uuid
from lcm.pub.database.models import NfInstModel
from lcm.pub.exceptions import NFLCMException
-from lcm.pub.utils.restcall import req_by_msb
+from lcm.pub.msapi.nfvolcm import vnfd_rawdata_get
from lcm.pub.utils.timeutil import now_time
from lcm.pub.utils.values import ignore_case_get
logger = logging.getLogger(__name__)
-# Query vnfd_rawdata by vnfdid
-def vnfd_rawdata_get(vnfdid):
- ret = req_by_msb("openoapi/nslcm/v1/vnfpackage/%s" % vnfdid, "GET")
- return ret
+
class CreateVnf:
def __init__(self, data):
diff --git a/lcm/lcm/nf/vnfs/vnf_create/inst_vnf.py b/lcm/lcm/nf/vnfs/vnf_create/inst_vnf.py
index 0182ef5e..0bfeda85 100644
--- a/lcm/lcm/nf/vnfs/vnf_create/inst_vnf.py
+++ b/lcm/lcm/nf/vnfs/vnf_create/inst_vnf.py
@@ -16,7 +16,7 @@ import logging
import traceback
from threading import Thread
-from lcm.pub.database.models import NfInstModel, JobStatusModel
+from lcm.pub.database.models import NfInstModel, JobStatusModel, NfvoRegInfoModel
from lcm.pub.exceptions import NFLCMException
from lcm.pub.msapi.nfvolcm import vnfd_rawdata_get
from lcm.pub.utils.jobutil import JobUtil
@@ -74,6 +74,9 @@ class InstVnf(Thread):
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, 2, 'GET_NFVO_CONNECTION_INFO')
+ self.load_global_config()
+
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)
@@ -136,4 +139,15 @@ class InstVnf(Thread):
except Exception as e:
logger.error('Nf instancing exception process exception=%s' % e.message)
logger.error(traceback.format_exc())
- return {'result': '255', 'msg': 'Nf instancing exception process exception', 'context': {}} \ No newline at end of file
+ return {'result': '255', 'msg': 'Nf instancing exception process exception', 'context': {}}
+
+ def load_global_config(self):
+ logger.info("[NF instantiation]get nfvo connection info start")
+ reg_info = NfvoRegInfoModel.objects.filter(vnfminstid='vnfm111').first()
+ if reg_info:
+ self.nfvo_reg_info = reg_info.nfvoid
+ logger.info("[NF instantiation] Registered nfvo id is [%s]"%self.nfvo_reg_info)
+ else:
+ JobUtil.add_job_status(self.job_id, 255, "Nfvo was not registered")
+ raise NFLCMException("Nfvo was not registered")
+ logger.info("[NF instantiation]get nfvo connection info end") \ No newline at end of file
diff --git a/lcm/lcm/pub/database/models.py b/lcm/lcm/pub/database/models.py
index 1fdf21f3..d4348406 100644
--- a/lcm/lcm/pub/database/models.py
+++ b/lcm/lcm/pub/database/models.py
@@ -98,3 +98,17 @@ class JobStatusModel(models.Model):
def toJSON(self):
import json
return json.dumps(dict([(attr, getattr(self, attr)) for attr in [f.name for f in self._meta.fields]]))
+
+class NfvoRegInfoModel(models.Model):
+ class Meta:
+ db_table = 'NFVOREGINFO'
+
+ nfvoid = models.CharField(max_length=255, primary_key=True, db_column='NFVOID')
+ vnfminstid = models.CharField(max_length=255, db_column='VNFMINSTID')
+ apiurl = models.CharField(max_length=255, db_column='URL')
+ nfvouser = models.CharField(max_length=255, db_column='USERNAME', null=True)
+ nfvopassword = models.CharField(max_length=255, db_column='PASSWD', null=True)
+ authtype = models.IntegerField(db_column='AUTHTYPE', default=2)
+ clientcert = models.CharField(max_length=255, db_column='CLIENTCERT', null=True)
+ servercert = models.CharField(max_length=255, db_column='SERVERCERT', null=True)
+ regtime = models.CharField(max_length=255, db_column='REGTIME')