summaryrefslogtreecommitdiffstats
path: root/lcm
diff options
context:
space:
mode:
authorying.yunlong <ying.yunlong@zte.com.cn>2017-02-22 12:00:05 +0800
committerying.yunlong <ying.yunlong@zte.com.cn>2017-02-22 12:00:05 +0800
commitb6c58ae677f7a0ba3ec8bca99d6a88f4326e2065 (patch)
tree0c5f4bf444c232cff81d5f885c42ec2e69618b49 /lcm
parent33e38547c8345726d995318c46655ec5ffc81184 (diff)
Modify code and test case of vnflcm
Change-Id: I5b7e4ba7912e03553ac1ae662b1d03737422ca67 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/const.py4
-rw-r--r--lcm/lcm/nf/vnfs/tests/test_vnf_create.py211
-rw-r--r--lcm/lcm/nf/vnfs/vnf_create/inst_vnf.py47
-rw-r--r--lcm/lcm/pub/database/models.py24
-rw-r--r--lcm/lcm/pub/utils/values.py6
5 files changed, 211 insertions, 81 deletions
diff --git a/lcm/lcm/nf/vnfs/const.py b/lcm/lcm/nf/vnfs/const.py
index b9c0733b..602792db 100644
--- a/lcm/lcm/nf/vnfs/const.py
+++ b/lcm/lcm/nf/vnfs/const.py
@@ -501,8 +501,8 @@ vnfd_model_dict = {
}
],
"location_info": {
- "vimid": "vimid",
- "tenant": "tenantname"
+ "vimid": "vimid_1",
+ "tenant": "tenantname_1"
},
"cloud_type": "IaaS"
},
diff --git a/lcm/lcm/nf/vnfs/tests/test_vnf_create.py b/lcm/lcm/nf/vnfs/tests/test_vnf_create.py
index 4096ee77..87cfd952 100644
--- a/lcm/lcm/nf/vnfs/tests/test_vnf_create.py
+++ b/lcm/lcm/nf/vnfs/tests/test_vnf_create.py
@@ -138,61 +138,166 @@ class TestNFInstantiate(TestCase):
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, "Nf instancing apply grant exception")
+
+ # @mock.patch.object(restcall, 'call_req')
+ # @mock.patch.object(api, 'call')
+ # def test_instantiate_vnf_when_(self, mock_call, 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 = [0, json.JSONEncoder().encode({'package_id': '222', 'csar_id': '2222'}), '200'] # get csar_id from nslcm by vnfd_id
+ # r2 = [0, json.JSONEncoder().encode(vnfd_rawdata), '200'] # get rawdata from catalog by csar_id
+ # r3 = [0, json.JSONEncoder().encode({"vim":{"vimid": '1', "accessinfo": {"tenant": '2'}}}), '200'] # apply_grant_to_nfvo
+ # mock_call_req.side_effect = [r1, r2, r3]
+ # c1_data = { # get_tenant_id
+ # "tenants": [
+ # {
+ # "id": "1",
+ # "name": "tenantname_1"
+ # }
+ # ]
+ # }
+ # c2_data = { # create_volume
+ # "id": "bc9eebdbbfd356458269340b9ea6fb73",
+ # "name": "volume1",
+ # # "returnCode": 1,
+ # "vimId": "vim_volume_1",
+ # "vimName": "vim_volume_1",
+ # "tenantId": "vim_volume_1",
+ # "volumeType": "123",
+ # "availabilityZone": "availabilityZone",
+ # "status": "avaluable"
+ # }
+ # c3_data = { # get_volume
+ # "status": "available11",
+ # "name": "wangsong",
+ # "attachments": [
+ # {
+ # "device": "/dev/vdc",
+ # "serverId": "3030e666-528e-4954-88f5-cc21dab1262b",
+ # "volumeId": "4bd3e9eb-cd8b-456a-8589-910836a0ab31",
+ # "hostName": None,
+ # "id": "4bd3e9eb-cd8b-456a-8589-910836a0ab31"
+ # }
+ # ],
+ # "createTime": "2015-12-02T06:39:40.000000",
+ # "type": None,
+ # "id": "4bd3e9eb-cd8b-456a-8589-910836a0ab31",
+ # "size": 40
+ # }
+ # mock_call.side_effect = [c1_data, c2_data, c3_data]
+ #
+ # 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, "unexpected exception")
- @mock.patch.object(restcall, 'call_req')
- @mock.patch.object(api, 'call')
- def test_instantiate_vnf_when_(self, mock_call, 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 = [0, json.JSONEncoder().encode({'package_id': '222', 'csar_id': '2222'}), '200'] # get csar_id from nslcm by vnfd_id
- r2 = [0, json.JSONEncoder().encode(vnfd_rawdata), '200'] # get rawdata from catalog by csar_id
- r3 = [0, json.JSONEncoder().encode({"vim":{"vimid": '1', "accessinfo": {"tenant": '2'}}}), '200'] # apply_grant_to_nfvo
- mock_call_req.side_effect = [r1, r2, r3]
- c1_data = { # get_tenant_id
- "tenants": [
- {
- "id": "1",
- "name": "tenantname_1"
- }
- ]
- }
- c2_data = { # create_volume
- "id": "bc9eebdbbfd356458269340b9ea6fb73",
- "name": "volume1",
- # "returnCode": 1,
- "vimId": "vim_volume_1",
- "vimName": "vim_volume_1",
- "tenantId": "vim_volume_1",
- "volumeType": "123",
- "availabilityZone": "availabilityZone",
- "status": "avaluable"
- }
- c3_data = { # get_volume
- "status": "available11",
- "name": "wangsong",
- "attachments": [
- {
- "device": "/dev/vdc",
- "serverId": "3030e666-528e-4954-88f5-cc21dab1262b",
- "volumeId": "4bd3e9eb-cd8b-456a-8589-910836a0ab31",
- "hostName": None,
- "id": "4bd3e9eb-cd8b-456a-8589-910836a0ab31"
- }
- ],
- "createTime": "2015-12-02T06:39:40.000000",
- "type": None,
- "id": "4bd3e9eb-cd8b-456a-8589-910836a0ab31",
- "size": 40
- }
- mock_call.side_effect = [c1_data, c2_data, c3_data]
- 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, "unexpected exception")
+
+
+
+
+ # @mock.patch.object(restcall, 'call_req')
+ # @mock.patch.object(api, 'call')
+ # def test_instantiate_vnf_when_111(self, mock_call, 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 = [0, json.JSONEncoder().encode({'package_id': '222', 'csar_id': '2222'}),
+ # '200'] # get csar_id from nslcm by vnfd_id
+ # r2 = [0, json.JSONEncoder().encode(vnfd_rawdata), '200'] # get rawdata from catalog by csar_id
+ # r3 = [0, json.JSONEncoder().encode({"vim": {"vimid": '1', "accessinfo": {"tenant": '2'}}}),
+ # '200'] # apply_grant_to_nfvo
+ # mock_call_req.side_effect = [r1, r2, r3]
+ # c1_data_get_tenant_id = { # get_tenant_id
+ # "tenants": [
+ # {
+ # "id": "1",
+ # "name": "tenantname_1"
+ # }
+ # ]
+ # }
+ # c2_data_create_volume = {
+ # "id": "4bd3e9eb-cd8b-456a-8589-910836a0ab31",
+ # "name": "volume1",
+ # "returnCode": 1,
+ # "vimId": "vim_volume_1",
+ # "vimName": "vim_volume_1",
+ # "tenantId": "vim_volume_1",
+ # "volumeType": "123",
+ # "availabilityZone": "availabilityZone",
+ # "status": "availuable",
+ # "createTime": "2015-12-02T06:39:40.000000",
+ # "type": None,
+ # "size": 40
+ # }
+ # c3_data_get_volume = { # get_volume
+ # "status": "available",
+ # "name": "wangsong",
+ # "attachments": [
+ # {
+ # "device": "/dev/vdc",
+ # "serverId": "3030e666-528e-4954-88f5-cc21dab1262b",
+ # "volumeId": "4bd3e9eb-cd8b-456a-8589-910836a0ab31",
+ # "hostName": None,
+ # "id": "4bd3e9eb-cd8b-456a-8589-910836a0ab31"
+ # }
+ # ],
+ # "createTime": "2015-12-02T06:39:40.000000",
+ # "type": None,
+ # "id": "4bd3e9eb-cd8b-456a-8589-910836a0ab31",
+ # "size": 40
+ # }
+ # c4_data_create_network = { # create_network
+ # "returnCode": 0,
+ # "vimId": "11111",
+ # "vimName": "11111",
+ # "status": "ACTIVE",
+ # "id": "3c9eebdbbfd345658269340b9ea6fb73",
+ # "name": "net1",
+ # "tenantId": "tenant1",
+ # "networkName": "ommnet",
+ # "shared": True,
+ # "vlanTransparent": True,
+ # "networkType": "vlan",
+ # "segmentationId": 202,
+ # "physicalNetwork": "ctrl",
+ # "routerExternal": False
+ # }
+ # c5_data_create_subnet = {
+ # "returnCode": 0,
+ # "vimId": "11111",
+ # "vimName": "11111",
+ # "status": " ACTIVE",
+ # "id": " d62019d3-bc6e-4319-9c1d-6722fc136a23",
+ # "tenantId": "tenant1",
+ # "networkId": "d32019d3-bc6e-4319-9c1d-6722fc136a22",
+ # "name": "subnet1",
+ # "cidr": "10.43.35.0/24",
+ # "ipVersion": 4,
+ # "enableDhcp": 1,
+ # "gatewayIp": "10.43.35.1",
+ # "dnsNameservers": [],
+ # "allocationPools": [
+ # {
+ # "start": "192.168.199.2",
+ # "end": "192.168.199.254"
+ # }
+ # ],
+ # "hostRoutes": []
+ # }
+ # 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]
+ #
+ # 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, "unexpected exception")
+
diff --git a/lcm/lcm/nf/vnfs/vnf_create/inst_vnf.py b/lcm/lcm/nf/vnfs/vnf_create/inst_vnf.py
index d9f8c8bf..1092b912 100644
--- a/lcm/lcm/nf/vnfs/vnf_create/inst_vnf.py
+++ b/lcm/lcm/nf/vnfs/vnf_create/inst_vnf.py
@@ -14,6 +14,7 @@
import json
import logging
import traceback
+import uuid
from threading import Thread
from lcm.nf.vnfs.const import vnfd_model_dict
@@ -25,7 +26,7 @@ from lcm.pub.msapi.nfvolcm import apply_grant_to_nfvo, notify_lcm_to_nfvo, get_p
from lcm.pub.utils import toscautil
from lcm.pub.utils.jobutil import JobUtil
from lcm.pub.utils.timeutil import now_time
-from lcm.pub.utils.values import ignore_case_get
+from lcm.pub.utils.values import ignore_case_get, get_none, get_boolean
from lcm.pub.vimapi import adaptor
logger = logging.getLogger(__name__)
@@ -98,6 +99,7 @@ class InstVnf(Thread):
# self.rollback(e.message)
except:
self.vnf_inst_failed_handle('unexpected exception')
+ tt= traceback.format_exc()
logger.error(traceback.format_exc())
# self.rollback('unexpected exception')
@@ -370,13 +372,16 @@ class InstVnf(Thread):
# "res_id": ignore_case_get(ret, "res_id")})
JobUtil.add_job_status(self.job_id, 25, 'Create vloumns!')
StorageInstModel.objects.create(
- storageid=ret["id"],
- vimid=ret["vimId"],
- resouceid=ret["id"],
- name=ret["name"],
- tenant=ret["tenantId"],
+ storageid=str(uuid.uuid4()),
+ vimid=ignore_case_get(ret, "vimId"),
+ resouceid=ignore_case_get(ret, "id"),
+ name=ignore_case_get(ret, "name"),
+ tenant=ignore_case_get(ret, "tenantId"),
+ create_time=ignore_case_get(ret, "createTime"),
+ storagetype=get_none(ignore_case_get(ret, "type")),
+ size=ignore_case_get(ret, "size"),
insttype=0,
- is_predefined=ret["returnCode"],
+ is_predefined=ignore_case_get(ret, "returnCode"),
instid=self.nf_inst_id)
elif res_type == adaptor.RES_NETWORK:
logger.info('Create networks!')
@@ -386,13 +391,19 @@ class InstVnf(Thread):
# self.inst_resource['network'].append({"vim_id": "1"}, {"res_id": "2"})
JobUtil.add_job_status(self.job_id, 35, 'Create networks!')
NetworkInstModel.objects.create(
- networkid= ignore_case_get(ret, "id"),
- vimid = ignore_case_get(ret, "vimId"),
- resouceid = ignore_case_get(ret, "id"),
- name = ignore_case_get(ret, "name"),
- tenant = ignore_case_get(ret, "tenatId"),
+ networkid=str(uuid.uuid4()),
+ name=ignore_case_get(ret, "name"),
+ vimid=ignore_case_get(ret, "vimId"),
+ resouceid=ignore_case_get(ret, "id"),
+ tenant=ignore_case_get(ret, "tenantId"),
+ segmentid=str(ignore_case_get(ret, "segmentationId")),
+ network_type=ignore_case_get(ret, "networkType"),
+ physicalNetwork=ignore_case_get(ret, "physicalNetwork"),
+ vlantrans=get_boolean(ignore_case_get(ret, "vlanTransparent")),
+ is_shared=get_boolean(ignore_case_get(ret, "shared")),
+ routerExternal=get_boolean(ignore_case_get(ret, "routerExternal")),
insttype = 0,
- is_predefined = ignore_case_get(ret, "returnCode"),
+ is_predefined=ignore_case_get(ret, "returnCode"),
instid = self.nf_inst_id)
elif res_type == adaptor.RES_SUBNET:
logger.info('Create subnets!')
@@ -402,11 +413,11 @@ class InstVnf(Thread):
# self.inst_resource['subnet'].append({"vim_id": "1"}, {"res_id": "2"})
JobUtil.add_job_status(self.job_id, 40, 'Create subnets!')
SubNetworkInstModel.objects.create(
- subnetworkid=ret["id"],
+ subnetworkid=str(uuid.uuid4()),
vimid=ret["vimId"],
resouceid=ret["id"],
name=ret["name"],
- tenant=ret["tenatId"],
+ tenant=ret["tenantId"],
insttype=0,
is_predefined=ret["returnCode"],
instid=self.nf_inst_id)
@@ -418,7 +429,7 @@ class InstVnf(Thread):
# self.inst_resource['port'].append({"vim_id": "1"}, {"res_id": "2"})
JobUtil.add_job_status(self.job_id, 50, 'Create ports!')
PortInstModel.objects.create(
- portid=ret["id"],
+ portid=str(uuid.uuid4()),
networkid=ret["networkId"],
subnetworkid=ret["subnetId"],
vimid=ret["vimId"],
@@ -436,7 +447,7 @@ class InstVnf(Thread):
# self.inst_resource['flavor'].append({"vim_id": "1"}, {"res_id": "2"})
JobUtil.add_job_status(self.job_id, 60, 'Create flavors!')
FlavourInstModel.objects.create(
- falavourid=ret["id"],
+ falavourid=str(uuid.uuid4()),
name=ret["name"],
vcpu=ret["vcpu"],
memory=ret["memory"],
@@ -453,7 +464,7 @@ class InstVnf(Thread):
# self.inst_resource['vm'].append({"vim_id": "1"}, {"res_id": "2"})
JobUtil.add_job_status(self.job_id, 70, 'Create vms!')
VmInstModel.objects.create(
- vmid=ret["id"],
+ vmid=str(uuid.uuid4()),
vimid=ret["vimId"],
resouceid=ret["id"],
insttype=0,
diff --git a/lcm/lcm/pub/database/models.py b/lcm/lcm/pub/database/models.py
index 2fdc0177..85c58d24 100644
--- a/lcm/lcm/pub/database/models.py
+++ b/lcm/lcm/pub/database/models.py
@@ -104,14 +104,15 @@ class StorageInstModel(models.Model):
name = models.CharField(db_column='NAME', max_length=255, null=True)
storagetype = models.CharField(db_column='STORAGETYPE', max_length=255)
size = models.CharField(db_column='SIZE', max_length=255)
- rdmaenabled = models.IntegerField(db_column='RDMAENABLED', null=True)
- disktype = models.CharField(db_column='DISKTYPE', max_length=255)
- ownerid = models.CharField(db_column='OWNERID', max_length=255, null=True)
- zoneid = models.CharField(db_column='ZONEID', max_length=255, null=True)
- hostid = models.CharField(db_column='HOSTID', max_length=255, null=True)
- operationalstate = models.CharField(db_column='OPERATIONALSTATE', max_length=255, null=True)
+ # rdmaenabled = models.IntegerField(db_column='RDMAENABLED', null=True)
+ # disktype = models.CharField(db_column='DISKTYPE', max_length=255)
+ # ownerid = models.CharField(db_column='OWNERID', max_length=255, null=True)
+ # zoneid = models.CharField(db_column='ZONEID', max_length=255, null=True)
+ # hostid = models.CharField(db_column='HOSTID', max_length=255, null=True)
+ # operationalstate = models.CharField(db_column='OPERATIONALSTATE', max_length=255, null=True)
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)
class VmInstModel(models.Model):
class Meta:
@@ -129,6 +130,7 @@ class VmInstModel(models.Model):
hostid = models.CharField(db_column='HOSTID', max_length=255, null=True)
detailinfo = models.TextField(db_column='DETAILINFO', max_length=8192, 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)
class VNFCInstModel(models.Model):
class Meta:
@@ -152,6 +154,7 @@ class FlavourInstModel(models.Model):
instid = models.CharField(db_column='INSTID', max_length=255)
tenant = models.CharField(db_column='TENANT', max_length=255, null=True)
vmid = models.CharField(db_column='VMID', max_length=255)
+ create_time = models.CharField(db_column='CREATETIME', max_length=200, null=True, blank=True)
class NetworkInstModel(models.Model):
class Meta:
@@ -164,7 +167,6 @@ class NetworkInstModel(models.Model):
instid = models.CharField(db_column='INSTID', max_length=255)
name = models.CharField(db_column='NAME', max_length=255)
tenant = models.CharField(db_column='TENANT', max_length=255, null=True)
- is_shared = models.IntegerField(db_column='ISSHARED', default=0, null=True)
is_predefined = models.IntegerField(db_column='ISPREDEFINED', default=0, null=True)
desc = models.CharField(db_column='DESC', max_length=255, null=True)
vendor = models.CharField(db_column='VENDOR', max_length=255, null=True)
@@ -172,8 +174,12 @@ class NetworkInstModel(models.Model):
mtu = models.IntegerField(db_column='MTU', null=True)
network_type = models.CharField(db_column='NETWORKTYPE', max_length=255, null=True)
segmentid = models.CharField(db_column='SEGMENTID', max_length=255, null=True)
- vlantrans = models.IntegerField(db_column='VLANTRANS', null=True)
networkqos = models.CharField(db_column='NETWORKQOS', max_length=255, null=True)
+ create_time = models.CharField(db_column='CREATETIME', max_length=200, null=True, blank=True)
+ physicalNetwork = models.CharField(db_column='PHYNETWORK', max_length=255, null=True)
+ 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)
class SubNetworkInstModel(models.Model):
@@ -195,6 +201,7 @@ class SubNetworkInstModel(models.Model):
operationalstate = models.CharField(db_column='OPERATIONALSTATE', max_length=255, null=True)
tenant = models.CharField(db_column='TENANT', max_length=255, 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)
class VLInstModel(models.Model):
class Meta:
@@ -237,6 +244,7 @@ class PortInstModel(models.Model):
tenant = models.CharField(db_column='TENANT', max_length=255, null=True)
interfacename = models.CharField(db_column='INTERFACENAME', max_length=255, blank=True, null=True)
vmid = models.CharField(db_column='VMID', max_length=255, blank=True, null=True)
+ create_time = models.CharField(db_column='CREATETIME', max_length=200, null=True, blank=True)
class CPInstModel(models.Model):
class Meta:
diff --git a/lcm/lcm/pub/utils/values.py b/lcm/lcm/pub/utils/values.py
index 4262e1da..19b198ee 100644
--- a/lcm/lcm/pub/utils/values.py
+++ b/lcm/lcm/pub/utils/values.py
@@ -25,3 +25,9 @@ def ignore_case_get(args, key, def_val=""):
def set_opt_val(param, key, val):
if val or val is False:
param[key] = val
+
+def get_none(val, def_val=""):
+ return val if val else def_val
+
+def get_boolean(val, def_val=0):
+ return 1 if val else 0