summaryrefslogtreecommitdiffstats
path: root/lcm
diff options
context:
space:
mode:
authorying.yunlong <ying.yunlong@zte.com.cn>2017-02-14 11:31:37 +0800
committerying.yunlong <ying.yunlong@zte.com.cn>2017-02-14 11:31:37 +0800
commit90c1fa5d05f8aefae0fd0f114b479216ba6d8490 (patch)
treeef05b10e495eb5dc82bc6f9707e691e699225093 /lcm
parent4172b7cc2de363393808514b979c46cae3d0c642 (diff)
change lcm notify code and test case
Change-Id: Id4640d0dd7a22542fb1c259b4976ed149d875c7a Issue-Id: GVNFM-12 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.py79
-rw-r--r--lcm/lcm/nf/vnfs/vnf_create/inst_vnf.py28
2 files changed, 55 insertions, 52 deletions
diff --git a/lcm/lcm/nf/vnfs/tests/test_vnf_create.py b/lcm/lcm/nf/vnfs/tests/test_vnf_create.py
index cb524c59..2fe03ba5 100644
--- a/lcm/lcm/nf/vnfs/tests/test_vnf_create.py
+++ b/lcm/lcm/nf/vnfs/tests/test_vnf_create.py
@@ -20,7 +20,8 @@ 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, NfvoRegInfoModel
+from lcm.pub.database.models import NfInstModel, JobStatusModel, NfvoRegInfoModel, VmInstModel, NetworkInstModel, \
+ SubNetworkInstModel, PortInstModel
from lcm.pub.utils import restcall
from lcm.pub.utils.jobutil import JobUtil
@@ -28,23 +29,23 @@ from lcm.pub.utils.jobutil import JobUtil
class TestNsInstantiate(TestCase):
def setUp(self):
self.client = Client()
- # VmInstModel.objects.create(vmid="1", vimid="1", resouceid="11", insttype=0, instid="1", vmname="test_01",
- # operationalstate=1)
- # VmInstModel.objects.create(vmid="2", vimid="2", resouceid="22", insttype=0, instid="2", vmname="test_02",
- # operationalstate=1)
- # NetworkInstModel.objects.create(networkid='1', vimid='1', resouceid='1', name='pnet_network',
- # tenant='admin', insttype=0, instid='1')
- # SubNetworkInstModel.objects.create(subnetworkid='1', vimid='1', resouceid='1', networkid='1',
- # name='sub_pnet',tenant='admin', insttype=0, instid='1')
- # PortInstModel.objects.create(portid='1', networkid='1', subnetworkid='1', vimid='1', resouceid='1',
- # name='aaa_pnet_cp', tenant='admin', insttype=0, instid='1')
+ VmInstModel.objects.create(vmid="1", vimid="1", resouceid="11", insttype=0, instid="1", vmname="test_01",
+ operationalstate=1)
+ VmInstModel.objects.create(vmid="2", vimid="2", resouceid="22", insttype=0, instid="2", vmname="test_02",
+ operationalstate=1)
+ NetworkInstModel.objects.create(networkid='1', vimid='1', resouceid='1', name='pnet_network',
+ tenant='admin', insttype=0, instid='1')
+ SubNetworkInstModel.objects.create(subnetworkid='1', vimid='1', resouceid='1', networkid='1',
+ name='sub_pnet',tenant='admin', insttype=0, instid='1')
+ PortInstModel.objects.create(portid='1', networkid='1', subnetworkid='1', vimid='1', resouceid='1',
+ name='aaa_pnet_cp', tenant='admin', insttype=0, instid='1')
def tearDown(self):
pass
- # VmInstModel.objects.all().delete()
- # NetworkInstModel.objects.all().delete()
- # SubNetworkInstModel.objects.all().delete()
- # PortInstModel.objects.all().delete()
+ VmInstModel.objects.all().delete()
+ NetworkInstModel.objects.all().delete()
+ SubNetworkInstModel.objects.all().delete()
+ PortInstModel.objects.all().delete()
def assert_job_result(self, job_id, job_progress, job_detail):
jobs = JobStatusModel.objects.filter(
@@ -135,31 +136,9 @@ 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, "Nf instancing apply grant exception")
- @mock.patch.object(restcall, '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]
- # 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, 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):
+ # 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']
@@ -177,7 +156,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('None'), '200']
+ mock_call_req.side_effect = [r1, r2, r3, r4]
+ # 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.")
inst_req_data = {
"flavourId": "flavour_1",
diff --git a/lcm/lcm/nf/vnfs/vnf_create/inst_vnf.py b/lcm/lcm/nf/vnfs/vnf_create/inst_vnf.py
index a23ced9a..2384ee2b 100644
--- a/lcm/lcm/nf/vnfs/vnf_create/inst_vnf.py
+++ b/lcm/lcm/nf/vnfs/vnf_create/inst_vnf.py
@@ -87,7 +87,7 @@ class InstVnf(Thread):
self.create_res()
# self.check_res_status()
# self.wait_inst_finish(args)
- # self.lcm_notify()
+ self.lcm_notify()
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)
@@ -163,7 +163,7 @@ class InstVnf(Thread):
def create_res(self):
logger.info("[NF instantiation] create resource start")
- adaptor.create_vim_res(self.vnfd_info, self.do_notify, self.do_rollback)
+ adaptor.create_vim_res('', self.do_notify, self.do_rollback)
JobUtil.add_job_status(self.job_id, 70, '[NF instantiation] create resource finish')
logger.info("[NF instantiation] create resource finish")
@@ -236,10 +236,12 @@ class InstVnf(Thread):
def lcm_notify(self):
logger.info('[NF instantiation] send notify request to nfvo start')
reg_info = NfvoRegInfoModel.objects.filter(vnfminstid=self.vnfm_inst_id).first()
+ # vm_info = VmInstModel.objects.filter(nfinstid=self.nf_inst_id)
+ vmlist = []
nfs = NfInstModel.objects.filter(nfinstid=self.nf_inst_id)
nf = nfs[0]
- allocate_data = json.loads(nf.initallocatedata)
- vmlist = json.loads(nf.predefinedvm)
+ # allocate_data = json.loads(nf.initallocatedata)
+ # vmlist = json.loads(nf.predefinedvm)
addition_param = {'vmList': vmlist}
affected_vnfc = []
vnfcs = VNFCInstModel.objects.filter(nfinstid=self.nf_inst_id)
@@ -307,15 +309,15 @@ class InstVnf(Thread):
'changeType': 'added', 'portResource': port_resource,
'virtualLinkInstanceId': cp.vlinstanceid})
affectedcapacity = {}
- reserved_total = allocate_data.get('reserved_total', {})
- affectedcapacity['vm'] = str(reserved_total.get('vmnum', 0))
- affectedcapacity['vcpu'] = str(reserved_total.get('vcpunum', 0))
- affectedcapacity['vMemory'] = str(reserved_total.get('memorysize', 0))
- affectedcapacity['port'] = str(reserved_total.get('portnum', 0))
- affectedcapacity['localStorage'] = str(reserved_total.get('hdsize', 0))
- affectedcapacity['sharedStorage'] = str(reserved_total.get('shdsize', 0))
+ # reserved_total = allocate_data.get('reserved_total', {})
+ # affectedcapacity['vm'] = str(reserved_total.get('vmnum', 0))
+ # affectedcapacity['vcpu'] = str(reserved_total.get('vcpunum', 0))
+ # affectedcapacity['vMemory'] = str(reserved_total.get('memorysize', 0))
+ # affectedcapacity['port'] = str(reserved_total.get('portnum', 0))
+ # affectedcapacity['localStorage'] = str(reserved_total.get('hdsize', 0))
+ # affectedcapacity['sharedStorage'] = str(reserved_total.get('shdsize', 0))
content_args = {
- "vnfdmodule": allocate_data,
+ # "vnfdmodule": allocate_data,
"additionalParam": addition_param,
"nfvoInstanceId": reg_info.nfvoid,
"vnfmInstanceId": self.vnfm_inst_id,
@@ -323,7 +325,7 @@ class InstVnf(Thread):
"nfInstanceId": self.nf_inst_id,
"operation": 'instantiate',
"jobId": '',
- 'affectedcapacity': affectedcapacity,
+ # 'affectedcapacity': affectedcapacity,
'affectedService': [],
'affectedVnfc': affected_vnfc,
'affectedVirtualLink': affected_vl,