summaryrefslogtreecommitdiffstats
path: root/lcm
diff options
context:
space:
mode:
authorying.yunlong <ying.yunlong@zte.com.cn>2017-02-23 19:45:11 +0800
committerying.yunlong <ying.yunlong@zte.com.cn>2017-02-23 19:45:11 +0800
commit97f8569b9781e705851f65c51eb7b85242a9037d (patch)
tree14d7fcbdbe3519116af9cd55388c163109fd12da /lcm
parentf74e80669eb2ea45755fd7b111bfa7852c4a03f2 (diff)
Modify code and test case of lcm notify
Change-Id: I5117c53266dbb0c0df994d2a75fe81b62e80dc49 Issue-Id: GVNFM-34 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.py3
-rw-r--r--lcm/lcm/nf/vnfs/vnf_create/inst_vnf.py169
-rw-r--r--lcm/lcm/pub/database/models.py3
-rw-r--r--lcm/lcm/pub/vimapi/adaptor.py3
4 files changed, 111 insertions, 67 deletions
diff --git a/lcm/lcm/nf/vnfs/tests/test_vnf_create.py b/lcm/lcm/nf/vnfs/tests/test_vnf_create.py
index 36f4d2e7..f9b5e30b 100644
--- a/lcm/lcm/nf/vnfs/tests/test_vnf_create.py
+++ b/lcm/lcm/nf/vnfs/tests/test_vnf_create.py
@@ -221,7 +221,8 @@ class TestNFInstantiate(TestCase):
r2 = [0, json.JSONEncoder().encode(vnfd_rawdata), '200'] # get rawdata from catalog by csar_id
r3 = [0, json.JSONEncoder().encode({"vim": {"vimid": 'vimid_1', "accessinfo": {"tenant": 'tenantname_1'}}}),
'200'] # apply_grant_to_nfvo
- mock_call_req.side_effect = [r1, r2, r3]
+ r4 = [0, None, '200']
+ mock_call_req.side_effect = [r1, r2, r3, r4]
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 0727844e..af47768a 100644
--- a/lcm/lcm/nf/vnfs/vnf_create/inst_vnf.py
+++ b/lcm/lcm/nf/vnfs/vnf_create/inst_vnf.py
@@ -90,7 +90,7 @@ class InstVnf(Thread):
self.inst_pre()
self.apply_grant()
self.create_res()
- # 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)
@@ -241,79 +241,105 @@ 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()
+ # reg_info = NfvoRegInfoModel.objects.filter(vnfminstid=self.vnfm_inst_id).first()
# vm_info = VmInstModel.objects.filter(nfinstid=self.nf_inst_id)
- vmlist = []
+ # vmlist = []
# nfs = NfInstModel.objects.filter(nfinstid=self.nf_inst_id)
# nf = nfs[0]
# allocate_data = json.loads(nf.initallocatedata)
# vmlist = json.loads(nf.predefinedvm)
- addition_param = {'vmList': vmlist}
+ # addition_param = {'vmList': vmlist}
affected_vnfc = []
vnfcs = VNFCInstModel.objects.filter(nfinstid=self.nf_inst_id)
for vnfc in vnfcs:
- compute_resource = {}
+ vmResource = {}
if vnfc.vmid:
vm = VmInstModel.objects.filter(vmid=vnfc.vmid)
if vm:
- compute_resource = {'vimId': vm[0].vimid, 'resourceId': vm[0].resouceid,
- 'resourceName': vm[0].vmname, 'tenant': vm[0].tenant}
+ vmResource = {'vimId': vm[0].vimid, 'resourceId': vm[0].resouceid,
+ 'resourceName': vm[0].vmname, 'resourceType': 'vm'}
affected_vnfc.append(
- {'vnfcInstanceId': vnfc.vnfcinstanceid, 'vduId': vnfc.vduid, 'changeType': 'added',
- 'computeResource': compute_resource, 'storageResource': [], 'vduType': vnfc.vdutype})
+ {'vnfcInstanceId': vnfc.vnfcinstanceid,
+ 'vduId': vnfc.vduid,
+ 'changeType': 'added',
+ 'computeResource': vmResource})
affected_vl = []
- vls = VLInstModel.objects.filter(ownerid=self.nf_inst_id)
- for vl in vls:
- network_resource = {}
- subnet_resource = {}
- if vl.relatednetworkid:
- network = NetworkInstModel.objects.filter(networkid=vl.relatednetworkid)
- subnet = SubNetworkInstModel.objects.filter(subnetworkid=vl.relatedsubnetworkid)
- if network:
- network_resource = {'vimId': network[0].vimid, 'resourceId': network[0].resouceid,
- 'resourceName': network[0].name, 'tenant': network[0].tenant}
- if subnet:
- subnet_resource = {'vimId': subnet[0].vimid, 'resourceId': subnet[0].resouceid,
- 'resourceName': subnet[0].name, 'tenant': subnet[0].tenant}
+ networks = NetworkInstModel.objects.filter(instid=self.nf_inst_id)
+ for network in networks:
+ network_resource = {'vimId': network.vimid, 'resourceId': network.resouceid,
+ 'resourceName': network.name, 'resourceType': 'network'}
affected_vl.append(
- {'virtualLinkInstanceId': vl.vlinstanceid, 'virtualLinkDescId': vl.vldid, 'changeType': 'added',
- 'networkResource': network_resource, 'subnetworkResource': subnet_resource, 'tenant': vl.tenant})
+ {'vlInstanceId': network.networkid,
+ 'vldid': network.nodeId,
+ 'changeType': 'added',
+ 'networkResource': network_resource})
+ affected_cp = []
+ ports = PortInstModel.objects.filter(instid=self.nf_inst_id)
+ for port in ports:
+ affected_cp.append(
+ {'vsInstanceId': port.portid,
+ 'cpdid': port.nodeId,
+ 'changeType': 'added',
+ 'storageResource': {'vimId': port.vimid, 'resourceId': port.resouceid,
+ 'resourceName': port.name, 'resourceType': 'port'}})
+ # vls = VLInstModel.objects.filter(ownerid=self.nf_inst_id)
+ # for vl in vls:
+ # network_resource = {}
+ # subnet_resource = {}
+ # if vl.relatednetworkid:
+ # network = NetworkInstModel.objects.filter(networkid=vl.relatednetworkid)
+ # subnet = SubNetworkInstModel.objects.filter(subnetworkid=vl.relatedsubnetworkid)
+ # if network:
+ # network_resource = {'vimId': network[0].vimid, 'resourceId': network[0].resouceid,
+ # 'resourceName': network[0].name, 'tenant': network[0].tenant}
+ # if subnet:
+ # subnet_resource = {'vimId': subnet[0].vimid, 'resourceId': subnet[0].resouceid,
+ # 'resourceName': subnet[0].name, 'tenant': subnet[0].tenant}
+ # affected_vl.append(
+ # {'virtualLinkInstanceId': vl.vlinstanceid, 'virtualLinkDescId': vl.vldid, 'changeType': 'added',
+ # 'networkResource': network_resource, 'subnetworkResource': subnet_resource, 'tenant': vl.tenant})
affected_vs = []
vss = StorageInstModel.objects.filter(instid=self.nf_inst_id)
for vs in vss:
affected_vs.append(
- {'virtualStorageInstanceId': vs.storageid, 'virtualStorageDescId': '', 'changeType': 'added',
+ {'vsInstanceId': vs.storageid,
+ 'vsdId': vs.nodeId,
+ 'changeType': 'added',
'storageResource': {'vimId': vs.vimid, 'resourceId': vs.resouceid,
- 'resourceName': vs.name, 'tenant': vs.tenant}})
- affected_cp = []
- # vnfc cps
- for vnfc in vnfcs:
- cps = CPInstModel.objects.filter(ownerid=vnfc.vnfcinstanceid, ownertype=3)
- for cp in cps:
- port_resource = {}
- if cp.relatedport:
- port = PortInstModel.objects.filter(portid=cp.relatedport)
- if port:
- port_resource = {'vimId': port[0].vimid, 'resourceId': port[0].resouceid,
- 'resourceName': port[0].name, 'tenant': port[0].tenant}
- affected_cp.append(
- {'cPInstanceId': cp.cpinstanceid, 'cpdId': cp.cpdid, 'ownerid': cp.ownerid,
- 'ownertype': cp.ownertype, 'changeType': 'added', 'portResource': port_resource,
- 'virtualLinkInstanceId': cp.vlinstanceid})
- # nf cps
- cps = CPInstModel.objects.filter(ownerid=self.nf_inst_id, ownertype=0)
- logger.info('vnf_inst_id=%s, cps size=%s' % (self.nf_inst_id, cps.count()))
- for cp in cps:
- port_resource = {}
- if cp.relatedport:
- port = PortInstModel.objects.filter(portid=cp.relatedport)
- if port:
- port_resource = {'vimId': port[0].vimid, 'resourceId': port[0].resouceid,
- 'resourceName': port[0].name, 'tenant': port[0].tenant}
- affected_cp.append(
- {'cPInstanceId': cp.cpinstanceid, 'cpdId': cp.cpdid, 'ownerid': cp.ownerid, 'ownertype': cp.ownertype,
- 'changeType': 'added', 'portResource': port_resource,
- 'virtualLinkInstanceId': cp.vlinstanceid})
+ 'resourceName': vs.name, 'resourceType': 'volume'}})
+ # affected_cp = []
+ # # vnfc cps
+ # for vnfc in vnfcs:
+ # cps = CPInstModel.objects.filter(ownerid=vnfc.vnfcinstanceid, ownertype=3)
+ # for cp in cps:
+ # port_resource = {}
+ # if cp.relatedport:
+ # port = PortInstModel.objects.filter(portid=cp.relatedport)
+ # if port:
+ # port_resource = {'vimId': port[0].vimid, 'resourceId': port[0].resouceid,
+ # 'resourceName': port[0].name, 'tenant': port[0].tenant}
+ # affected_cp.append(
+ # {'cPInstanceId': cp.cpinstanceid, 'cpdId': cp.cpdid, 'ownerid': cp.ownerid,
+ # 'ownertype': cp.ownertype, 'changeType': 'added', 'portResource': port_resource,
+ # 'virtualLinkInstanceId': cp.vlinstanceid})
+
+
+ # # nf cps
+ # affected_cp = []
+ # cps = PortInstModel.objects.filter(instid=self.nf_inst_id)
+ # # cps = CPInstModel.objects.filter(ownerid=self.nf_inst_id)
+ # logger.info('vnf_inst_id=%s, cps size=%s' % (self.nf_inst_id, cps.count()))
+ # for cp in cps:
+ # port_resource = {}
+ # if cp.relatedport:
+ # port = PortInstModel.objects.filter(portid=cp.relatedport)
+ # if port:
+ # port_resource = {'vimId': port[0].vimid, 'resourceId': port[0].resouceid,
+ # 'resourceName': port[0].name, 'tenant': port[0].tenant}
+ # affected_cp.append(
+ # {'cPInstanceId': cp.cpinstanceid, 'cpdId': cp.cpdid, 'ownerid': cp.ownerid, 'ownertype': cp.ownertype,
+ # 'changeType': 'added', 'portResource': port_resource,
+ # 'virtualLinkInstanceId': cp.vlinstanceid})
# affectedcapacity = {}
# reserved_total = allocate_data.get('reserved_total', {})
# affectedcapacity['vm'] = str(reserved_total.get('vmnum', 0))
@@ -323,20 +349,21 @@ class InstVnf(Thread):
# affectedcapacity['localStorage'] = str(reserved_total.get('hdsize', 0))
# affectedcapacity['sharedStorage'] = str(reserved_total.get('shdsize', 0))
content_args = {
- # "vnfdmodule": allocate_data,
- "additionalParam": addition_param,
- "nfvoInstanceId": reg_info.nfvoid,
- "vnfmInstanceId": self.vnfm_inst_id,
- "status": 'finished',
+ "status": 'result',
"nfInstanceId": self.nf_inst_id,
"operation": 'instantiate',
- "jobId": '',
- # 'affectedcapacity': affectedcapacity,
- 'affectedService': [],
+ "jobId": self.job_id,
'affectedVnfc': affected_vnfc,
'affectedVirtualLink': affected_vl,
'affectedVirtualStorage': affected_vs,
- 'affectedCp': affected_cp}
+ # "vnfdmodule": allocate_data,
+ # "additionalParam": addition_param,
+ # "nfvoInstanceId": self.nfvo_inst_id,
+ # "vnfmInstanceId": self.vnfm_inst_id,
+ # 'affectedcapacity': affectedcapacity,
+ # 'affectedService': [],
+ 'affectedCp': affected_cp
+ }
logger.info('content_args=%s' % content_args)
# call rest api
resp = notify_lcm_to_nfvo(content_args, self.nf_inst_id)
@@ -382,6 +409,7 @@ class InstVnf(Thread):
size=ignore_case_get(ret, "size"),
insttype=0,
is_predefined=ignore_case_get(ret, "returnCode"),
+ nodeId=ignore_case_get(ret, "nodeId"),
instid=self.nf_inst_id)
elif res_type == adaptor.RES_NETWORK:
logger.info('Create networks!')
@@ -404,6 +432,7 @@ class InstVnf(Thread):
routerExternal=get_boolean(ignore_case_get(ret, "routerExternal")),
insttype = 0,
is_predefined=ignore_case_get(ret, "returnCode"),
+ nodeId=ignore_case_get(ret, "nodeId"),
instid = self.nf_inst_id)
elif res_type == adaptor.RES_SUBNET:
logger.info('Create subnets!')
@@ -427,7 +456,7 @@ class InstVnf(Thread):
hostRoutes=ignore_case_get(ret, "hostRoutes"),
allocationPools=ignore_case_get(ret, "allocationPools"),
insttype=0,
- is_predefined=ret["returnCode"],
+ is_predefined=ignore_case_get(ret, "returnCode"),
instid=self.nf_inst_id)
elif res_type == adaptor.RES_PORT:
logger.info('Create ports!')
@@ -450,6 +479,7 @@ class InstVnf(Thread):
securityGroups=ignore_case_get(ret, "securityGroups"),
insttype=0,
is_predefined=ignore_case_get(ret, "returnCode"),
+ nodeId=ignore_case_get(ret, "nodeId"),
instid=self.nf_inst_id)
elif res_type == adaptor.RES_FLAVOR:
logger.info('Create flavors!')
@@ -480,8 +510,9 @@ class InstVnf(Thread):
# "res_id": ignore_case_get(ret, "res_id")})
# self.inst_resource['vm'].append({"vim_id": "1"}, {"res_id": "2"})
JobUtil.add_job_status(self.job_id, 70, 'Create vms!')
+ vm_id = str(uuid.uuid4())
VmInstModel.objects.create(
- vmid=str(uuid.uuid4()),
+ vmid=vm_id,
vmname=ignore_case_get(ret, "name"),
vimid=ignore_case_get(ret, "vimId"),
resouceid=ignore_case_get(ret, "id"),
@@ -497,6 +528,12 @@ class InstVnf(Thread):
insttype=0,
is_predefined=ignore_case_get(ret, "returnCode"),
instid=self.nf_inst_id)
+ VNFCInstModel.objects.create(
+ vnfcinstanceid=str(uuid.uuid4()),
+ vduid=ignore_case_get(ret, "id"),
+ # vdutype='AAA',
+ nfinstid=self.nf_inst_id,
+ vmid=vm_id)
# def do_rollback(self, args_=None):
# logger.error('error info : %s' % args_)
diff --git a/lcm/lcm/pub/database/models.py b/lcm/lcm/pub/database/models.py
index a15a7df9..3f10d6f2 100644
--- a/lcm/lcm/pub/database/models.py
+++ b/lcm/lcm/pub/database/models.py
@@ -113,6 +113,7 @@ class StorageInstModel(models.Model):
tenant = models.CharField(db_column='TENANT', max_length=50, null=True)
is_predefined = models.IntegerField(db_column='ISPREDEFINED', default=0, null=True)
create_time = models.CharField(db_column='CREATETIME', max_length=200, null=True, blank=True)
+ nodeId = models.CharField(db_column='NODEID', max_length=255, null=True)
class VmInstModel(models.Model):
class Meta:
@@ -190,6 +191,7 @@ class NetworkInstModel(models.Model):
is_shared = models.IntegerField(db_column='ISSHARED', default=0, null=True)
vlantrans = models.IntegerField(db_column='VLANTRANS', null=True)
routerExternal = models.IntegerField(db_column='ROUTEREXTERNAL', default=0, null=True)
+ nodeId = models.CharField(db_column='NODEID', max_length=255, null=True)
class SubNetworkInstModel(models.Model):
class Meta:
@@ -259,6 +261,7 @@ class PortInstModel(models.Model):
create_time = models.CharField(db_column='CREATETIME', max_length=200, null=True, blank=True)
securityGroups = models.CharField(db_column='SECURITYGROUPS', max_length=255)
is_predefined = models.IntegerField(db_column='ISPREDEFINED', default=0, null=True)
+ nodeId = models.CharField(db_column='NODEID', max_length=255, null=True)
class CPInstModel(models.Model):
class Meta:
diff --git a/lcm/lcm/pub/vimapi/adaptor.py b/lcm/lcm/pub/vimapi/adaptor.py
index 4b156708..fed69b1d 100644
--- a/lcm/lcm/pub/vimapi/adaptor.py
+++ b/lcm/lcm/pub/vimapi/adaptor.py
@@ -101,6 +101,7 @@ def create_volume(vim_cache, res_cache, vol, do_notify, res_type):
vim_id, tenant_name = location_info["vimid"], location_info["tenant"]
tenant_id = get_tenant_id(vim_cache, vim_id, tenant_name)
ret = api.create_volume(vim_id, tenant_id, param)
+ ret["nodeId"] = vol["volume_storage_id"]
do_notify(res_type, ret)
vol_id, vol_name, return_code = ret["id"], ret["name"], ret["returnCode"]
set_res_cache(res_cache, res_type, vol["volume_storage_id"], vol_id)
@@ -128,6 +129,7 @@ def create_network(vim_cache, res_cache, network, do_notify, res_type):
vim_id, tenant_name = location_info["vimid"], location_info["tenant"]
tenant_id = get_tenant_id(vim_cache, vim_id, tenant_name)
ret = api.create_network(vim_id, tenant_id, param)
+ ret["nodeId"] = network["vl_id"]
do_notify(res_type, ret)
set_res_cache(res_cache, res_type, network["vl_id"], ret["id"])
@@ -179,6 +181,7 @@ def create_port(vim_cache, res_cache, data, port, do_notify, res_type):
vim_id, tenant_name = location_info["vimid"], location_info["tenant"]
tenant_id = get_tenant_id(vim_cache, vim_id, tenant_name)
ret = api.create_subnet(vim_id, tenant_id, param)
+ ret["nodeId"] = port["cp_id"]
do_notify(res_type, ret)
set_res_cache(res_cache, res_type, port["cp_id"], ret["id"])