1 # Copyright 2018 ZTE Corporation.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
20 from rest_framework.test import APIClient
21 from django.test import TestCase
22 from rest_framework import status
23 from catalog.pub.config.config import CATALOG_ROOT_PATH
24 from catalog.packages.biz.vnf_package import VnfPkgUploadThread
25 from catalog.pub.database.models import VnfPackageModel
36 class TestVnfPackage(TestCase):
38 self.client = APIClient()
47 "unit_size": 1000000000
49 "type_of_storage": "volume",
50 "rdma_enabled": False,
53 "volume_storage_id": "vNAT_Storage_6wdgwzedlb6sq18uzrr41sof7",
61 "vNAT_Storage_6wdgwzedlb6sq18uzrr41sof7"
68 "configurable_properties": {
70 "additional_vnfc_configurable_properties": {
77 "description": "the virtual machine of vNat",
88 "artifact_name": "vNatVNFImage",
89 "type": "tosca.artifacts.nfv.SwImage",
91 "operating_system": "linux",
92 "sw_image": "/swimages/vRouterVNF_ControlPlane.qcow2",
93 "name": "vNatVNFImage",
94 "container_format": "bare",
96 "disk_format": "qcow2",
97 "supported_virtualisation_environments": [
105 "file": "/swimages/vRouterVNF_ControlPlane.qcow2"
109 "flavor_extra_specs": {
110 "hw:cpu_sockets": "2",
111 "sw:ovs_dpdk": "true",
112 "hw:cpu_threads": "2",
113 "hw:numa_mem.1": "3072",
114 "hw:numa_mem.0": "1024",
115 "hw:numa_nodes": "2",
116 "hw:numa_cpus.0": "0,1",
117 "hw:numa_cpus.1": "2,3,4,5",
119 "hw:cpu_threads_policy": "isolate"
121 "cpu_frequency": "2.4 GHz",
125 "local_storages": [],
126 "image_file": "vNatVNFImage",
133 "operating_system": "linux",
134 "sw_image": "/swimages/vRouterVNF_ControlPlane.qcow2",
135 "name": "vNatVNFImage",
136 "container_format": "bare",
138 "disk_format": "qcow2",
139 "supported_virtualisation_environments": [
147 "image_file_id": "vNatVNFImage",
152 "local_storages": [],
156 "key_name": "sriov_plane",
157 "cp_id": "SRIOV_Port"
165 "vl_id": "sriov_link",
166 "route_external": False,
172 "connectivity_type": {
173 "layer_protocol": "ipv4",
174 "flow_pattern": "flat"
176 "description": "sriov_link",
185 "vl_id": "sriov_link",
186 "vdu_id": "vdu_vNat",
188 "cp_id": "SRIOV_Port",
192 "address_type": "ip_address",
194 "ip_address_type": "ipv4",
195 "floating_ip_activated": False,
196 "number_of_ip_address": 1,
197 "ip_address_assignment": True
201 "description": "sriov port",
202 "layer_protocol": "ipv4",
203 "virtual_network_interface_requirements": [
208 "support_mandatory": False,
210 "description": "sriov"
216 "support_mandatory": False,
218 "description": "normal"
222 "bitrate_requirement": 10
227 "vnfSoftwareVersion": "1.0.0",
228 "vnfProductName": "zte",
229 "localizationLanguage": [
233 "vnfProvider": "zte",
235 "defaultLocalizationLanguage": "english",
236 "vnfdId": "zte-hss-1.0",
238 "vnfProductInfoDescription": "hss",
239 "vnfdVersion": "1.0.0",
240 "vnfProductInfoName": "hss"
247 def test_upload_vnf_pkg(self):
248 data = {'file': open(os.path.join(CATALOG_ROOT_PATH, "empty.txt"), "rb")}
249 VnfPackageModel.objects.create(
251 onboardingState="CREATED"
253 response = self.client.put("/api/vnfpkgm/v1/vnf_packages/222/package_content", data=data)
254 self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)
256 @mock.patch.object(urllib2, 'urlopen')
257 def test_upload_nf_pkg_from_uri(self, mock_urlopen):
258 vnf_pkg = VnfPackageModel.objects.create(
260 onboardingState="CREATED"
262 req_data = {"addressInformation": "https://127.0.0.1:1234/sdc/v1/hss.csar"}
263 mock_urlopen.return_value = MockReq()
264 vnf_pkg_id = vnf_pkg.vnfPackageId
265 VnfPkgUploadThread(req_data, vnf_pkg_id).run()
267 def test_create_vnf_pkg(self):
269 "userDefinedData": {"a": "A"}
271 response = self.client.post("/api/vnfpkgm/v1/vnf_packages", data=req_data, format="json")
272 resp_data = json.loads(response.content)
274 "id": resp_data.get("id"),
275 "onboardingState": "CREATED",
276 "operationalState": "DISABLED",
277 "usageState": "NOT_IN_USE",
278 "userDefinedData": {"a": "A"},
279 "_links": None # TODO
281 self.assertEqual(expect_resp_data, resp_data)
282 self.assertEqual(response.status_code, status.HTTP_201_CREATED)