Add test code mocking on_distribute data 63/9363/2
authorfengyuanxing <feng.yuanxing@zte.com.cn>
Wed, 30 Aug 2017 09:32:01 +0000 (17:32 +0800)
committerfengyuanxing <feng.yuanxing@zte.com.cn>
Wed, 30 Aug 2017 09:37:24 +0000 (17:37 +0800)
Change-Id: If60c8eed9f1d67f0d65dfcafbf43f8e450296805
Issue-Id: VFC-152
Signed-off-by: fengyuanxing <feng.yuanxing@zte.com.cn>
catalog/packages/tests.py

index 3e68919..15c77bd 100644 (file)
 # limitations under the License.
 
 import unittest
+import mock
+import catalog.pub.utils.restcall
 import json
+from catalog.packages.ns_package import NsPackage
+from catalog.packages import nf_package
 from django.test import Client
+from catalog.pub.database.models import NSDModel, NfPackageModel
 from rest_framework import status
 
 
@@ -34,6 +39,398 @@ class PackageTest(unittest.TestCase):
             "csarId": self.nf_csarId
         }
 
+        self.nsd_json = {
+    "vnffgs": [
+        {
+            "vnffg_id": "vnffg1",
+            "description": "",
+            "members": [
+                "path1",
+                "path2"
+            ],
+            "properties": {
+                "vendor": "zte",
+                "connection_point": [
+                    "m6000_data_in",
+                    "m600_tunnel_cp",
+                    "m6000_data_out"
+                ],
+                "version": "1.0",
+                "constituent_vnfs": [
+                    "VFW",
+                    "VNAT"
+                ],
+                "number_of_endpoints": 3,
+                "dependent_virtual_link": [
+                    "sfc_data_network",
+                    "ext_datanet_net",
+                    "ext_mnet_net"
+                ]
+            }
+        }
+    ],
+    "inputs": {
+        "sfc_data_network": {
+            "type": "string",
+            "value": "sfc_data_network"
+        },
+        "externalDataNetworkName": {
+            "type": "string",
+            "value": "vlan_4004_tunnel_net"
+        },
+        "externalManageNetworkName": {
+            "type": "string",
+            "value": "vlan_4008_mng_net"
+        },
+        "NatIpRange": {
+            "type": "string",
+            "value": "192.167.0.10-192.168.0.20"
+        },
+        "externalPluginManageNetworkName": {
+            "type": "string",
+            "value": "vlan_4007_plugin_net"
+        }
+    },
+    "pnfs": [
+        {
+            "pnf_id": "m6000_s",
+            "cps": [],
+            "description": "",
+            "properties": {
+                "vendor": "zte",
+                "request_reclassification": "false",
+                "pnf_type": "m6000s",
+                "version": "1.0",
+                "management_address": "111111",
+                "id": "m6000_s",
+                "nsh_aware": "false"
+            }
+        }
+    ],
+    "fps": [
+        {
+            "properties": {
+                "symmetric": "false",
+                "policy": {
+                    "type": "ACL",
+                    "criteria": {
+                        "dest_port_range": "1-100",
+                        "ip_protocol": "tcp",
+                        "source_ip_range": [
+                            "119.1.1.1-119.1.1.10"
+                        ],
+                        "dest_ip_range": [
+                            {
+                                "get_input": "NatIpRange"
+                            }
+                        ],
+                        "dscp": 0,
+                        "source_port_range": "1-100"
+                    }
+                }
+            },
+            "forwarder_list": [
+                {
+                    "capability": "",
+                    "type": "cp",
+                    "node_name": "m6000_data_out"
+                },
+                {
+                    "capability": "",
+                    "type": "cp",
+                    "node_name": "m600_tunnel_cp"
+                },
+                {
+                    "capability": "vnat_fw_inout",
+                    "type": "vnf",
+                    "node_name": "VNAT"
+                }
+            ],
+            "description": "",
+            "fp_id": "path2"
+        },
+        {
+            "properties": {
+                "symmetric": "true",
+                "policy": {
+                    "type": "ACL",
+                    "criteria": {
+                        "dest_port_range": "1-100",
+                        "ip_protocol": "tcp",
+                        "source_ip_range": [
+                            "1-100"
+                        ],
+                        "dest_ip_range": [
+                            "1-100"
+                        ],
+                        "dscp": 4,
+                        "source_port_range": "1-100"
+                    }
+                }
+            },
+            "forwarder_list": [
+                {
+                    "capability": "",
+                    "type": "cp",
+                    "node_name": "m6000_data_in"
+                },
+                {
+                    "capability": "",
+                    "type": "cp",
+                    "node_name": "m600_tunnel_cp"
+                },
+                {
+                    "capability": "vfw_fw_inout",
+                    "type": "vnf",
+                    "node_name": "VFW"
+                },
+                {
+                    "capability": "vnat_fw_inout",
+                    "type": "vnf",
+                    "node_name": "VNAT"
+                },
+                {
+                    "capability": "",
+                    "type": "cp",
+                    "node_name": "m600_tunnel_cp"
+                },
+                {
+                    "capability": "",
+                    "type": "cp",
+                    "node_name": "m6000_data_out"
+                }
+            ],
+            "description": "",
+            "fp_id": "path1"
+        }
+    ],
+    "routers": [],
+    "vnfs": [
+        {
+            "vnf_id": "VFW",
+            "description": "",
+            "properties": {
+                "plugin_info": "vbrasplugin_1.0",
+                "vendor": "zte",
+                "is_shared": "false",
+                "adjust_vnf_capacity": "true",
+                "name": "VFW",
+                "vnf_extend_type": "driver",
+                "csarVersion": "v1.0",
+                "csarType": "NFAR",
+                "csarProvider": "ZTE",
+                "version": "1.0",
+                "nsh_aware": "true",
+                "cross_dc": "false",
+                "vnf_type": "VFW",
+                "vmnumber_overquota_alarm": "true",
+                "vnfd_version": "1.0.0",
+                "externalPluginManageNetworkName": "vlan_4007_plugin_net",
+                "id": "vcpe_vfw_zte_1_0",
+                "request_reclassification": "false"
+            },
+            "dependencies": [
+                {
+                    "key_name": "vfw_ctrl_by_manager_cp",
+                    "vl_id": "ext_mnet_net"
+                },
+                {
+                    "key_name": "vfw_data_cp",
+                    "vl_id": "sfc_data_network"
+                }
+            ],
+            "type": "tosca.nodes.nfv.ext.zte.VNF.VFW",
+            "networks": []
+        },
+        {
+            "vnf_id": "VNAT",
+            "description": "",
+            "properties": {
+                "NatIpRange": "192.167.0.10-192.168.0.20",
+                "plugin_info": "vbrasplugin_1.0",
+                "vendor": "zte",
+                "is_shared": "false",
+                "adjust_vnf_capacity": "true",
+                "name": "VNAT",
+                "id": "vcpe_vnat_zte_1",
+                "vnf_extend_type": "driver",
+                "csarVersion": "v1.0",
+                "csarType": "NFAR",
+                "csarProvider": "ZTE",
+                "version": "1.0",
+                "nsh_aware": "true",
+                "cross_dc": "false",
+                "vnf_type": "VNAT",
+                "vmnumber_overquota_alarm": "true",
+                "vnfd_version": "1.0.0",
+                "externalPluginManageNetworkName": "vlan_4007_plugin_net",
+                "request_reclassification": "false"
+            },
+            "dependencies": [
+                {
+                    "key_name": "vnat_ctrl_by_manager_cp",
+                    "vl_id": "ext_mnet_net"
+                },
+                {
+                    "key_name": "vnat_data_cp",
+                    "vl_id": "sfc_data_network"
+                }
+            ],
+            "type": "tosca.nodes.nfv.ext.zte.VNF.VNAT",
+            "networks": []
+        }
+    ],
+    "ns_exposed": {
+        "external_cps": [],
+        "forward_cps": []
+    },
+    "policies": [
+        {
+            "file_url": "policies/abc.drl",
+            "name": "aaa"
+        }
+    ],
+    "vls": [
+        {
+            "route_id": "",
+            "vl_id": "ext_mnet_net",
+            "route_external": "false",
+            "description": "",
+            "properties": {
+                "name": "vlan_4008_mng_net",
+                "mtu": 1500,
+                "location_info": {
+                    "tenant": "admin",
+                    "vimid": 2,
+                    "availability_zone": "nova"
+                },
+                "ip_version": 4,
+                "dhcp_enabled": "true",
+                "network_name": "vlan_4008_mng_net",
+                "network_type": "vlan"
+            }
+        },
+        {
+            "route_id": "",
+            "vl_id": "ext_datanet_net",
+            "route_external": "false",
+            "description": "",
+            "properties": {
+                "name": "vlan_4004_tunnel_net",
+                "mtu": 1500,
+                "location_info": {
+                    "tenant": "admin",
+                    "vimid": 2,
+                    "availability_zone": "nova"
+                },
+                "ip_version": 4,
+                "dhcp_enabled": "true",
+                "network_name": "vlan_4004_tunnel_net",
+                "network_type": "vlan"
+            }
+        },
+        {
+            "route_id": "",
+            "vl_id": "sfc_data_network",
+            "route_external": "false",
+            "description": "",
+            "properties": {
+                "name": "sfc_data_network",
+                "dhcp_enabled": "true",
+                "is_predefined": "false",
+                "location_info": {
+                    "tenant": "admin",
+                    "vimid": 2,
+                    "availability_zone": "nova"
+                },
+                "ip_version": 4,
+                "mtu": 1500,
+                "network_name": "sfc_data_network",
+                "network_type": "vlan"
+            }
+        }
+    ],
+    "cps": [
+        {
+            "pnf_id": "m6000_s",
+            "vl_id": "path2",
+            "description": "",
+            "cp_id": "m6000_data_out",
+            "properties": {
+                "direction": "bidirectional",
+                "vnic_type": "normal",
+                "bandwidth": 0,
+                "mac_address": "11-22-33-22-11-44",
+                "interface_name": "xgei-0/4/1/5",
+                "ip_address": "176.1.1.2",
+                "order": 0,
+                "sfc_encapsulation": "mac"
+            }
+        },
+        {
+            "pnf_id": "m6000_s",
+            "vl_id": "ext_datanet_net",
+            "description": "",
+            "cp_id": "m600_tunnel_cp",
+            "properties": {
+                "direction": "bidirectional",
+                "vnic_type": "normal",
+                "bandwidth": 0,
+                "mac_address": "00-11-00-22-33-00",
+                "interface_name": "gei-0/4/0/13",
+                "ip_address": "191.167.100.5",
+                "order": 0,
+                "sfc_encapsulation": "mac"
+            }
+        },
+        {
+            "pnf_id": "m6000_s",
+            "vl_id": "path2",
+            "description": "",
+            "cp_id": "m6000_data_in",
+            "properties": {
+                "direction": "bidirectional",
+                "vnic_type": "normal",
+                "bandwidth": 0,
+                "mac_address": "11-22-33-22-11-41",
+                "interface_name": "gei-0/4/0/7",
+                "ip_address": "1.1.1.1",
+                "order": 0,
+                "sfc_encapsulation": "mac",
+                "bond": "none"
+            }
+        },
+        {
+            "pnf_id": "m6000_s",
+            "vl_id": "ext_mnet_net",
+            "description": "",
+            "cp_id": "m600_mnt_cp",
+            "properties": {
+                "direction": "bidirectional",
+                "vnic_type": "normal",
+                "bandwidth": 0,
+                "mac_address": "00-11-00-22-33-11",
+                "interface_name": "gei-0/4/0/1",
+                "ip_address": "10.46.244.51",
+                "order": 0,
+                "sfc_encapsulation": "mac",
+                "bond": "none"
+            }
+        }
+    ],
+    "metadata": {
+        "invariant_id": "vcpe_ns_sff_1",
+        "name": "VCPE_NS",
+        "csarVersion": "v1.0",
+        "csarType": "NSAR",
+        "csarProvider": "ZTE",
+        "version": 1,
+        "vendor": "ZTE",
+        "id": "VCPE_NS",
+        "description": "vcpe_ns"
+    }
+}
+
 
     def tearDown(self):
         pass
@@ -42,22 +439,33 @@ class PackageTest(unittest.TestCase):
         response = self.client.get("/api/catalog/v1/nspackages")
         print response
         self.assertEqual(status.HTTP_200_OK, response.status_code, response.content)
+        self.assertEquals([],response.data)
+
+    @mock.patch.object(NsPackage,'get_nsd')
+    def test_ns_distribute(self, mock_get_nsd):
+
+
+        local_file_name = "/url/local/filename"
+        nsd = json.JSONEncoder().encode(self.nsd_json)
+        mock_get_nsd.return_value = self.nsd_json,local_file_name,nsd
+        response = self.client.post("/api/nfvocatalog/v1/nspackages",self.nsdata)
 
-    def test_nspackage_get(self):
-        #response = self.client.get("/api/catalog/v1/nspackages/1")
-        #self.assertEqual(status.HTTP_200_OK, response.status_code, response.content)
-        # to do
-        pass
+
+        self.assertEqual(status.HTTP_202_ACCEPTED, response.status_code, response.content)
+        self.assertIsNotNone(NSDModel.objects.filter(id=self.ns_csarId))
 
     def test_nfpackages_get(self):
         response = self.client.get("/api/catalog/v1/vnfpackages")
         self.assertEqual(status.HTTP_200_OK, response.status_code, response.content)
 
-    def test_nfpackage_get(self):
-        #response = self.client.get("/api/catalog/v1/vnfpackages/1")
-        #self.assertEqual(status.HTTP_200_OK, response.status_code, response.content)
-        # to do
-        pass
+        nsdModel = NSDModel.objects.filter(nsd_id="VCPE_NS")
+        self.assertSequenceEqual(nsdModel,[])
+        #nsd_id = nsdModel.nsd_id
+        #self.assertEqual(self.nsd_json["metadata"]["id"], nsdModel.nsd_id)
+        #self.assertEqual(self.nsd_json["metadata"]["name"], nsdModel.name)
+        #self.assertEqual(self.nsd_json["metadata"]["version"], nsdModel.version)
+        #self.assertEqual(self.nsd_json["metadata"]["description"], nsdModel.description)
+        #self.assertEqual(self.nsd_json["metadata"]["vendor"], nsdModel.vendor)
 
     def test_ns_distribute(self):
         response = self.client.post("/api/catalog/v1/nspackages",self.nsdata)