From: ying.yunlong Date: Wed, 22 Feb 2017 09:28:08 +0000 (+0800) Subject: Modify code and test case of vnflcm and adaptor X-Git-Tag: release/mercury~52 X-Git-Url: https://gerrit.onap.org/r/gitweb?p=vfc%2Fgvnfm%2Fvnflcm.git;a=commitdiff_plain;h=19fce59efa91c1e37b64098ce6e99b2c90eb8f05 Modify code and test case of vnflcm and adaptor Change-Id: I2e4b644a4469add9c18f184e0d66c4988e88c992 Issue-Id: GVNFM-21 Signed-off-by: ying.yunlong --- diff --git a/lcm/lcm/nf/vnfs/const.py b/lcm/lcm/nf/vnfs/const.py index 602792db..d73ec3d6 100644 --- a/lcm/lcm/nf/vnfs/const.py +++ b/lcm/lcm/nf/vnfs/const.py @@ -545,8 +545,8 @@ vnfd_model_dict = { "is_virtual": False, "function": "control" }, - "vl_id": "vlid1", - "vdu_id": "vdu_id1" + "vl_id": "vldId1", + "vdu_id": u'vdu_omm.001' } ], 'local_storages': [ diff --git a/lcm/lcm/nf/vnfs/tests/test_vnf_create.py b/lcm/lcm/nf/vnfs/tests/test_vnf_create.py index 87cfd952..c2ac445c 100644 --- a/lcm/lcm/nf/vnfs/tests/test_vnf_create.py +++ b/lcm/lcm/nf/vnfs/tests/test_vnf_create.py @@ -85,6 +85,11 @@ class TestNFInstantiate(TestCase): self.nf_inst_id = str(uuid.uuid4()) self.job_id = JobUtil.create_job('NF', 'CREATE', self.nf_inst_id) JobUtil.add_job_status(self.job_id, 0, "INST_VNF_READY") + jobs = JobStatusModel.objects.filter( + jobid=self.job_id, + progress=0, + descp="INST_VNF_READY") + self.assertEqual(1, len(jobs)) 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, "VNF nf_inst_id is not exist.") @@ -138,165 +143,188 @@ 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 = { + "returnCode": 0, + "vimId": "11111", + "vimName": "11111", + "status": "ACTIVE", + "id": "3c9eebdbbfd345658269340b9ea6fb73", + "name": "net1", + "tenantId": "tenant1", + "networkName": "ommnet", + "shared": 1, + "vlanTransparent": 1, + "networkType": "vlan", + "segmentationId": 202, + "physicalNetwork": "ctrl", + "routerExternal": 0 + } + 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") + + + @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": 'vimid_1', "accessinfo": {"tenant": 'tenantname_1'}}}), + '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", + "networkName": "networkName", + "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": [] + } + c6_data_create_port = { + "returnCode": 0, + "vimId": "11111", + "vimName": "11111", + "status": " ACTIVE", + "id": " 872019d3-bc6e-4319-9c1d-6722fc136afg", + "tenantId": "tenant1", + "name": "subnet1", + "networkId": "d32019d3-bc6e-4319-9c1d-6722fc136a22", + "networkName": "networkName", + "subnetId": "d62019d3-bc6e-4319-9c1d-6722fc136a23", + "subnetName": "subnet1", + "macAddress": "212.12.61.23", + "ip": "10.43.38.11", + "vnicType": "normal", + "securityGroups": "" + } + 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] + + 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 1092b912..6bc996fb 100644 --- a/lcm/lcm/nf/vnfs/vnf_create/inst_vnf.py +++ b/lcm/lcm/nf/vnfs/vnf_create/inst_vnf.py @@ -414,10 +414,18 @@ class InstVnf(Thread): JobUtil.add_job_status(self.job_id, 40, 'Create subnets!') SubNetworkInstModel.objects.create( subnetworkid=str(uuid.uuid4()), - vimid=ret["vimId"], - resouceid=ret["id"], - name=ret["name"], - tenant=ret["tenantId"], + name=ignore_case_get(ret, "name"), + vimid=ignore_case_get(ret, "vimId"), + resouceid=ignore_case_get(ret, "id"), + tenant=ignore_case_get(ret, "tenantId"), + networkid=ignore_case_get(ret, "networkId"), + cidr=ignore_case_get(ret, "cidr"), + ipversion=ignore_case_get(ret, "ipversion"), + isdhcpenabled=ignore_case_get(ret, "enableDhcp"), + gatewayip=ignore_case_get(ret, "gatewayIp"), + dnsNameservers=ignore_case_get(ret, "dnsNameservers"), + hostRoutes=ignore_case_get(ret, "hostRoutes"), + allocationPools=ignore_case_get(ret, "allocationPools"), insttype=0, is_predefined=ret["returnCode"], instid=self.nf_inst_id) diff --git a/lcm/lcm/pub/database/models.py b/lcm/lcm/pub/database/models.py index 85c58d24..a765e24f 100644 --- a/lcm/lcm/pub/database/models.py +++ b/lcm/lcm/pub/database/models.py @@ -181,7 +181,6 @@ class NetworkInstModel(models.Model): vlantrans = models.IntegerField(db_column='VLANTRANS', null=True) routerExternal = models.IntegerField(db_column='ROUTEREXTERNAL', default=0, null=True) - class SubNetworkInstModel(models.Model): class Meta: db_table = 'SUBNETWORKINST' @@ -202,6 +201,9 @@ class SubNetworkInstModel(models.Model): 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) + dnsNameservers = models.TextField(db_column='DNSNAMESERVERS', max_length=1024) + hostRoutes = models.TextField(db_column='HOSTROUTES', max_length=1024) + allocationPools = models.TextField(db_column='ALLOCATIONPOOLS', max_length=1024) class VLInstModel(models.Model): class Meta: diff --git a/lcm/lcm/pub/vimapi/adaptor.py b/lcm/lcm/pub/vimapi/adaptor.py index e1d7537b..593d779d 100644 --- a/lcm/lcm/pub/vimapi/adaptor.py +++ b/lcm/lcm/pub/vimapi/adaptor.py @@ -70,7 +70,7 @@ def create_vim_res(data, do_notify): for subnet in ignore_case_get(data, "vls"): create_subnet(vim_cache, res_cache, subnet, do_notify, RES_SUBNET) for port in ignore_case_get(data, "cps"): - create_port(vim_cache, res_cache, port, do_notify, RES_PORT) + create_port(vim_cache, res_cache, data, port, do_notify, RES_PORT) for flavor in ignore_case_get(data, "vdus"): create_flavor(vim_cache, res_cache, data, flavor, do_notify, RES_FLAVOR) for vm in ignore_case_get(data, "vdus"): @@ -155,8 +155,16 @@ def create_subnet(vim_cache, res_cache, subnet, do_notify, res_type): do_notify(res_type, ret) set_res_cache(res_cache, res_type, subnet["vl_id"], ret["id"]) -def create_port(vim_cache, res_cache, port, do_notify, res_type): - location_info = port["properties"]["location_info"] +def create_port(vim_cache, res_cache, data, port, do_notify, res_type): + location_info = None + port_ref_vdu_id = ignore_case_get(port, "vdu_id") + for vdu in ignore_case_get(data, "vdus"): + if vdu["vdu_id"] == port_ref_vdu_id: + location_info = vdu["properties"]["location_info"] + break + if not location_info: + err_msg = "vdu_id(%s) for cp(%s) is not defined" + raise VimException(err_msg % (port_ref_vdu_id, port["cp_id"]), ERR_CODE) network_id = get_res_id(res_cache, RES_NETWORK, port["vl_id"]) subnet_id = get_res_id(res_cache, RES_SUBNET, port["vl_id"]) param = {