aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorerlei <zhu.erlei@zte.com.cn>2019-08-12 14:50:59 +0800
committererlei <zhu.erlei@zte.com.cn>2019-08-12 15:09:20 +0800
commit13742ccba4a909e6ee8a184334a13832aeee5fa2 (patch)
tree392e188539f9594175868165de7abf1521065415
parent59b3b9434aa59b7df252a04700d4f6ca44f4a52f (diff)
ADD UT for ns_vls Issue-ID: VFC-1429 Signed-off-by: zhuerlei <zhu.erlei@zte.com.cn>
Change-Id: I4bf8517d40d82dd5e6e1a8f77557c5a8355410eb Signed-off-by: erlei <zhu.erlei@zte.com.cn>
-rw-r--r--lcm/ns_vls/tests/tests.py66
1 files changed, 48 insertions, 18 deletions
diff --git a/lcm/ns_vls/tests/tests.py b/lcm/ns_vls/tests/tests.py
index 07eaf18b..b13e6248 100644
--- a/lcm/ns_vls/tests/tests.py
+++ b/lcm/ns_vls/tests/tests.py
@@ -20,7 +20,7 @@ from django.test import TestCase, Client
from rest_framework import status
from lcm.pub.database.models import VLInstModel, NSInstModel, VNFFGInstModel
-from lcm.pub.nfvi.vim import vimadaptor
+from lcm.pub.nfvi.vim import vimadaptor, const
from lcm.pub.utils import restcall
from lcm.ns_vnfs.tests.tests import vim_info
@@ -31,16 +31,28 @@ class TestVlViews(TestCase):
self.ns_inst_id = str(uuid.uuid4())
self.vnffg_id = str(uuid.uuid4())
self.vl_id_1 = 1
- self.vl_id_2 = 1
- self.vim_id = str(uuid.uuid4())
+ self.vl_id_2 = 2
+ self.vim_id = '{"cloud_owner": "cloud_owner", "cloud_regionid": "cloud_regionid"}'
self.tenant = "tenantname"
- properties = {"network_type": "vlan", "name": "externalMNetworkName", "dhcp_enabled": False,
- "location_info": {"host": True, "vimid": self.vim_id, "region": True, "tenant": self.tenant},
- "end_ip": "190.168.100.100", "gateway_ip": "190.168.100.1", "start_ip": "190.168.100.2",
- "cidr": "190.168.100.0/24", "mtu": 1500, "network_name": "sub_mnet", "ip_version": 4}
+ properties = {"vl_profile": {"networkName": "vl_inst_name", "network_type": "vlan",
+ "segmentationId": "segmentation_id", "physicalNetwork": "physical_network",
+ "mtu": 1500, "vlanTransparent": True, "dhcp_enabled": False,
+ "cidr": "190.168.100.0/24", "ip_version": const.IPV4, "dhcpEnabled": True,
+ "gatewayIp": "190.168.100.1", "dns_nameservers": "dns_nameservers",
+ "host_routes": "host_routes", "start_ip": "190.168.100.2",
+ "end_ip": "190.168.100.100"},
+ "location_info": {"host": True, "vimid": self.vim_id, "region": True, "tenant": self.tenant}}
+ properties2 = {"vl_profile": {"networkName": "vl_inst_name", "network_type": "vlan",
+ "segmentationId": "segmentation_id", "physicalNetwork": "physical_network",
+ "mtu": 1500, "vlanTransparent": True, "dhcp_enabled": False,
+ "cidr": "190.168.100.0/24", "ip_version": const.IPV4, "dhcpEnabled": True,
+ "gatewayIp": "190.168.100.1", "dns_nameservers": "dns_nameservers",
+ "host_routes": "host_routes", "start_ip": "190.168.100.2",
+ "end_ip": "190.168.100.100"},
+ "location_info": {"host": True, "vimid": "", "region": True, "tenant": self.tenant}}
self.context = {
"vls": [{"vl_id": self.vl_id_1, "description": "", "properties": properties, "route_external": False},
- {"vl_id": self.vl_id_2, "description": "", "properties": properties, "route_external": False}],
+ {"vl_id": self.vl_id_2, "description": "", "properties": properties2, "route_external": False}],
"vnffgs": [{"vnffg_id": self.vnffg_id, "description": "",
"properties": {"vendor": "zte", "version": "1.1.2", "number_of_endpoints": 7,
"dependent_virtual_link": [self.vl_id_2, self.vl_id_1],
@@ -57,7 +69,6 @@ class TestVlViews(TestCase):
NSInstModel.objects.all().delete()
VNFFGInstModel.objects.all().delete()
- '''
@mock.patch.object(restcall, "call_req")
@mock.patch.object(vimadaptor.VimAdaptor, "create_network")
def test_create_vl(self, mock_create_network, mock_req_by_rest):
@@ -72,26 +83,46 @@ class TestVlViews(TestCase):
mock_req_by_rest.return_value = [0, json.JSONEncoder().encode(vim_info), '200']
self.create_vl(self.vl_id_1)
- self.create_vl(self.vl_id_2)
vl_from_vl_1 = VLInstModel.objects.filter(vldid=self.vl_id_1, ownerid=self.ns_inst_id)
self.assertEqual(network_id, vl_from_vl_1[0].relatednetworkid)
self.assertEqual(subnetwork_id, vl_from_vl_1[0].relatedsubnetworkid)
self.assertEqual(self.tenant, vl_from_vl_1[0].tenant)
- vl_from_vl_2 = VLInstModel.objects.filter(vldid=self.vl_id_2, ownerid=self.ns_inst_id)
- self.assertEqual(VNFFGInstModel.objects.filter(vnffgdid=self.vnffg_id, nsinstid=self.ns_inst_id)[0].vllist,
- vl_from_vl_2[0].vlinstanceid + "," + vl_from_vl_1[0].vlinstanceid)
- '''
def create_vl(self, vl_id):
req_data = {
"nsInstanceId": self.ns_inst_id,
"context": json.JSONEncoder().encode(self.context),
"vlIndex": vl_id}
- response = self.client.post("/api/nslcm/v1/ns/ns_vls", data=req_data)
+ response = self.client.post("/api/nslcm/v1/ns/vls", data=req_data)
self.assertEqual(status.HTTP_201_CREATED, response.status_code)
self.assertEqual(0, response.data["result"], response.data)
- '''
+ @mock.patch.object(restcall, "call_req")
+ @mock.patch.object(vimadaptor.VimAdaptor, "create_network")
+ def test_create_vl_when_vim_id_in_additional_param(self, mock_create_network, mock_req_by_rest):
+ network_id = str(uuid.uuid4())
+ subnetwork_id = str(uuid.uuid4())
+ mock_create_network.return_value = [0,
+ {"status": "ACTIVE", "id": network_id, "name": "net1",
+ "provider:segmentation_id": 204, "provider:network_type": "vlan",
+ "res_type": 1,
+ "subnet_list": [
+ {"id": subnetwork_id, "name": "subnet1", "res_type": 1}]}]
+ mock_req_by_rest.return_value = [0, json.JSONEncoder().encode(vim_info), '200']
+ vim_id = '{"cloud_owner": "cloud_owner", "cloud_regionid": "cloud_regionid"}'
+ req_data = {
+ "nsInstanceId": self.ns_inst_id,
+ "context": json.JSONEncoder().encode(self.context),
+ "vlIndex": self.vl_id_2,
+ "additionalParamForNs": '{"location": %s}' % vim_id}
+ response = self.client.post("/api/nslcm/v1/ns/vls", data=req_data)
+ self.assertEqual(status.HTTP_201_CREATED, response.status_code)
+ self.assertEqual(0, response.data["result"], response.data)
+ vl_from_vl_2 = VLInstModel.objects.filter(vldid=self.vl_id_2, ownerid=self.ns_inst_id)
+ self.assertEqual(network_id, vl_from_vl_2[0].relatednetworkid)
+ self.assertEqual(subnetwork_id, vl_from_vl_2[0].relatedsubnetworkid)
+ self.assertEqual(self.tenant, vl_from_vl_2[0].tenant)
+
@mock.patch.object(restcall, "call_req")
@mock.patch.object(vimadaptor.VimAdaptor, "create_network")
@mock.patch.object(uuid, "uuid4")
@@ -103,10 +134,9 @@ class TestVlViews(TestCase):
mock_uuid4.return_value = '999'
mock_req_by_rest.return_value = [0, json.JSONEncoder().encode(vim_info), '200']
mock_create_network.return_value = [1, (1)]
- response = self.client.post("/api/nslcm/v1/ns/ns_vls", data=req_data)
+ response = self.client.post("/api/nslcm/v1/ns/vls", data=req_data)
retinfo = {"detail": "vl instantiation failed, detail message: Send post vl request to vim failed."}
self.assertEqual(retinfo["detail"], response.data["detail"])
- '''
class TestVlDetailViews(TestCase):