summaryrefslogtreecommitdiffstats
path: root/lcm
diff options
context:
space:
mode:
authorying.yunlong <ying.yunlong@zte.com.cn>2017-02-13 21:46:17 +0800
committerying.yunlong <ying.yunlong@zte.com.cn>2017-02-13 21:46:17 +0800
commit93ec155596e9433d8c414af6995f86ed5967b9f8 (patch)
treec8c300dee9b1f36197f4a8a20d5d67dfaefc4471 /lcm
parent9f79fa5c4d8a373d141399e63b247c0ba122cb14 (diff)
call vim adapter create res
Change-Id: I666fcde51f92e6694c9121d18f235346a8abde3d Issue-Id: GVNFM-30 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.py33
-rw-r--r--lcm/lcm/nf/vnfs/vnf_create/inst_vnf.py74
2 files changed, 70 insertions, 37 deletions
diff --git a/lcm/lcm/nf/vnfs/tests/test_vnf_create.py b/lcm/lcm/nf/vnfs/tests/test_vnf_create.py
index 68a77812..9a1d3ef6 100644
--- a/lcm/lcm/nf/vnfs/tests/test_vnf_create.py
+++ b/lcm/lcm/nf/vnfs/tests/test_vnf_create.py
@@ -24,6 +24,7 @@ from lcm.nf.vnfs.vnf_create.inst_vnf import InstVnf
from lcm.pub.database.models import NfInstModel, JobStatusModel, NfvoRegInfoModel, VmInstModel, NetworkInstModel, \
SubNetworkInstModel, PortInstModel
from lcm.pub.utils import restcall
+from lcm.pub.vimapi import adaptor
from lcm.pub.utils.jobutil import JobUtil
inst_req_data = {
@@ -180,14 +181,16 @@ class TestNsInstantiate(TestCase):
self.assert_job_result(self.job_id, 255, "Nf instancing apply grant exception")
@mock.patch.object(restcall, 'call_req')
- def test_instantiate_vnf_success(self, mock_call_req):
+ # @mock.patch.object(adaptor, 'create_vim_res')
+ def test_instantiate_vnf_when_create_res_failed(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']
r3 = [0, json.JSONEncoder().encode('Nf instancing apply grant'), '200']
- r4 = [0, json.JSONEncoder().encode('Nf instancing apply resource'), '200']
- mock_call_req.side_effect = [r1, r2, r3, r4]
+ # r4 = [0, json.JSONEncoder().encode('Nf instancing apply resource'), '200']
+ mock_call_req.side_effect = [r1, r2, r3]
+ # mock_create_vim_res.re.return_value = None
create_data = {
"vnfdId": "111",
"vnfInstanceName": "vFW_01",
@@ -197,7 +200,29 @@ 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, "Create resource failed")
+
+ # @mock.patch.object(restcall, 'call_req')
+ # # @mock.patch.object(adaptor, 'create_vim_res')
+ # 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']
+ # r3 = [0, json.JSONEncoder().encode('Nf instancing apply grant'), '200']
+ # # r4 = [0, json.JSONEncoder().encode('Nf instancing apply resource'), '200']
+ # mock_call_req.side_effect = [r1, r2, r3]
+ # # mock_create_vim_res.re.return_value = None
+ # 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 = {
diff --git a/lcm/lcm/nf/vnfs/vnf_create/inst_vnf.py b/lcm/lcm/nf/vnfs/vnf_create/inst_vnf.py
index c2da9cc2..f5c88eef 100644
--- a/lcm/lcm/nf/vnfs/vnf_create/inst_vnf.py
+++ b/lcm/lcm/nf/vnfs/vnf_create/inst_vnf.py
@@ -19,7 +19,7 @@ from threading import Thread
from lcm.pub.database.models import NfInstModel, JobStatusModel, NfvoRegInfoModel, VmInstModel, VNFCInstModel, \
NetworkInstModel, SubNetworkInstModel, VLInstModel, PortInstModel, CPInstModel, StorageInstModel, FlavourInstModel
from lcm.pub.exceptions import NFLCMException
-from lcm.pub.msapi.nfvolcm import vnfd_rawdata_get, apply_grant_to_nfvo, apply_res_to_nfvo
+from lcm.pub.msapi.nfvolcm import vnfd_rawdata_get, apply_grant_to_nfvo
from lcm.pub.utils.jobutil import JobUtil
from lcm.pub.utils.timeutil import now_time
from lcm.pub.utils.values import ignore_case_get
@@ -95,7 +95,7 @@ class InstVnf(Thread):
self.vnf_inst_failed_handle(e.message)
# self.rollback(e.message)
except:
- # self.vnf_inst_failed_handle('unexpected exception')
+ self.vnf_inst_failed_handle('unexpected exception')
logger.error(traceback.format_exc())
# self.rollback('unexpected exception')
@@ -163,21 +163,23 @@ class InstVnf(Thread):
def create_res(self):
logger.info("[NF instantiation] create resource start")
- volumns = ignore_case_get(self.data, "volumn_storages")
- #create_vim_res(data, do_notify, do_rollback)
- #create_volumns(volumns)
- JobUtil.add_job_status(self.job_id, 35, 'Nf instancing create resource(volumn_storages) finish')
-
- vls = ignore_case_get(self.data, "vls")
- # create_networks(vls)
- JobUtil.add_job_status(self.job_id, 55, 'Nf instancing create resource(networks) finish')
- vdus = ignore_case_get(self.data, "vdus")
- # create_vdus(vdus)
- JobUtil.add_job_status(self.job_id, 75, 'Nf instancing create resource(vms) finish')
+ adaptor.create_vim_res(self.vnfd_info, self.do_notify, self.do_rollback)
- JobUtil.add_job_status(self.job_id, 20, 'Nf instancing apply grant finish')
- logger.info("[NF instantiation] create resource end")
+ # volumns = ignore_case_get(self.data, "volumn_storages")
+ #create_volumns(volumns)
+ # JobUtil.add_job_status(self.job_id, 35, 'Nf instancing create resource(volumn_storages) finish')
+ #
+ # vls = ignore_case_get(self.data, "vls")
+ # # create_networks(vls)
+ # JobUtil.add_job_status(self.job_id, 55, 'Nf instancing create resource(networks) finish')
+ #
+ # vdus = ignore_case_get(self.data, "vdus")
+ # # create_vdus(vdus)
+ # JobUtil.add_job_status(self.job_id, 75, 'Nf instancing create resource(vms) finish')
+
+ JobUtil.add_job_status(self.job_id, 70, '[NF instantiation] create resource finish')
+ logger.info("[NF instantiation] create resource finish")
def check_res_status(self):
logger.info("[NF instantiation] confirm all vms are active start")
@@ -280,15 +282,13 @@ class InstVnf(Thread):
JobUtil.add_job_status(self.job_id, 255, error_msg)
# JobUtil.add_job_status(self.job_id, 255, 'VNF instantiation failed, detail message: %s' % error_msg, 0)
- def do_notify(res_type, progress, ret):
+ def do_notify(self, res_type, progress, ret):
# logger.info('add job, progress=%s, msgid=%s, args=%s' % (progress, msgid, args_))
progress = 20 + int(progress/2) #20-70
if res_type == adaptor.RES_VOLUME:
logger.info('Create vloumns!')
-
- # if ret['rescode'] == 0:#new create
- # self.inst_resource['volumn'].append({"vim_id": "1"}, {"res_id": "2"})
- self.inst_resource['volumn'].append({"vim_id": "1"}, {"res_id": "2"})
+ if ret["returnCode"] == adaptor.RES_NEW:#new create
+ self.inst_resource['volumn'].append({"vim_id": ret["vim_id"]}, {"res_id": ret["res_id"]})
JobUtil.add_job_status(self.job_id, progress, 'Create vloumns!')
StorageInstModel.objects.create(
storageid='1',
@@ -300,8 +300,9 @@ class InstVnf(Thread):
instid=self.nf_inst_id)
elif res_type == adaptor.RES_NETWORK:
logger.info('Create networks!')
- # self.inst_resource['network'] = ret
- self.inst_resource['network'].append({"vim_id": "1"}, {"res_id": "2"})
+ if ret["returnCode"] == adaptor.RES_NEW:
+ self.inst_resource['network'].append({"vim_id": ret["vim_id"]}, {"res_id": ret["res_id"]})
+ # self.inst_resource['network'].append({"vim_id": "1"}, {"res_id": "2"})
JobUtil.add_job_status(self.job_id, progress, 'Create networks!')
NetworkInstModel.objects.create(
networkid='1',
@@ -313,8 +314,9 @@ class InstVnf(Thread):
instid=self.nf_inst_id)
elif res_type == adaptor.RES_SUBNET:
logger.info('Create subnets!')
- # self.inst_resource['subnet'] = ret
- self.inst_resource['subnet'].append({"vim_id": "1"}, {"res_id": "2"})
+ if ret["returnCode"] == adaptor.RES_NEW:
+ self.inst_resource['subnet'].append({"vim_id": ret["vim_id"]}, {"res_id": ret["res_id"]})
+ # self.inst_resource['subnet'].append({"vim_id": "1"}, {"res_id": "2"})
JobUtil.add_job_status(self.job_id, progress, 'Create subnets!')
SubNetworkInstModel.objects.create(
subnetworkid='1',
@@ -327,8 +329,9 @@ class InstVnf(Thread):
instid=self.nf_inst_id)
elif res_type == adaptor.RES_PORT:
logger.info('Create ports!')
- # self.inst_resource['port'] = ret
- self.inst_resource['port'].append({"vim_id": "1"}, {"res_id": "2"})
+ if ret["returnCode"] == adaptor.RES_NEW:
+ self.inst_resource['port'].append({"vim_id": ret["vim_id"]}, {"res_id": ret["res_id"]})
+ # self.inst_resource['port'].append({"vim_id": "1"}, {"res_id": "2"})
JobUtil.add_job_status(self.job_id, progress, 'Create ports!')
PortInstModel.objects.create(
portid='1',
@@ -342,8 +345,9 @@ class InstVnf(Thread):
instid=self.nf_inst_id)
elif res_type == adaptor.RES_FLAVOR:
logger.info('Create flavors!')
- # self.inst_resource['flavor'] = ret
- self.inst_resource['flavor'].append({"vim_id": "1"}, {"res_id": "2"})
+ if ret["returnCode"] == adaptor.RES_NEW:
+ self.inst_resource['flavor'].append({"vim_id": ret["vim_id"]}, {"res_id": ret["res_id"]})
+ # self.inst_resource['flavor'].append({"vim_id": "1"}, {"res_id": "2"})
JobUtil.add_job_status(self.job_id, progress, 'Create flavors!')
FlavourInstModel.objects.create(
falavourid='1',
@@ -353,7 +357,9 @@ class InstVnf(Thread):
instid=self.nf_inst_id)
elif res_type == adaptor.RES_VM:
logger.info('Create vms!')
- self.inst_resource['vm'].append({"vim_id": "1"}, {"res_id": "2"})
+ if ret["returnCode"] == adaptor.RES_NEW:
+ self.inst_resource['vm'].append({"vim_id": ret["vim_id"]}, {"res_id": ret["res_id"]})
+ # self.inst_resource['vm'].append({"vim_id": "1"}, {"res_id": "2"})
JobUtil.add_job_status(self.job_id, progress, 'Create vms!')
VmInstModel.objects.create(
vmid="1",
@@ -363,10 +369,11 @@ class InstVnf(Thread):
instid=self.nf_inst_id,
vmname="test_01",
operationalstate=1)
- def do_rollback(self, progress, msgid, args_=None):
- # logger.info('add job, progress=%s, msgid=%s, args=%s' % (progress, msgid, args_))
- # adaptor.delete_vim_res(self.inst_resource, self.do_notify_delete)
+ def do_rollback(self, args_=None):
+ logger.error('error info : %s'%(args_))
+
+ adaptor.delete_vim_res(self.inst_resource, self.do_notify_delete)
StorageInstModel.objects.filter(instid=self.nf_inst_id).delete()
NetworkInstModel.objects.filter(instid=self.nf_inst_id).delete()
@@ -374,7 +381,8 @@ class InstVnf(Thread):
PortInstModel.objects.filter(instid=self.nf_inst_id).delete()
FlavourInstModel.objects.filter(instid=self.nf_inst_id).delete()
VmInstModel.objects.filter(instid=self.nf_inst_id).delete()
- JobUtil.add_job_status(self.job_id, 255, 'Create resource failed')
+
+ raise NFLCMException("Create resource failed")
def do_notify_delete(ret):
logger.error('Delete [%s] resource'%ret)