diff options
author | 2019-04-30 15:59:45 +0800 | |
---|---|---|
committer | 2019-04-30 08:25:47 +0000 | |
commit | 52a969dcc2a935930a559b1780d7c95e1cc45d73 (patch) | |
tree | b95f60a4c719a0a24b5343f09fe17cb6fe060666 /genericparser/packages/tests | |
parent | 63c392e9cca3c6654e8383f49e5136fa86d1c72a (diff) |
code refactor for genericparser1.0.0
Change-Id: I68a128944cde015d767576fc4e159d67db2d6b5d
Issue-ID: VFC-1372
Signed-off-by: yangyan <yangyanyj@chinamobile.com>
Diffstat (limited to 'genericparser/packages/tests')
-rw-r--r-- | genericparser/packages/tests/const.py | 139 | ||||
-rw-r--r-- | genericparser/packages/tests/test_ns_descriptor.py | 2 | ||||
-rw-r--r-- | genericparser/packages/tests/test_nsdm_subscription.py | 11 | ||||
-rw-r--r-- | genericparser/packages/tests/test_nspackage.py | 222 | ||||
-rw-r--r-- | genericparser/packages/tests/test_pnf_descriptor.py | 6 | ||||
-rw-r--r-- | genericparser/packages/tests/test_service_descriptor.py | 98 | ||||
-rw-r--r-- | genericparser/packages/tests/test_vnf_package.py | 23 | ||||
-rw-r--r-- | genericparser/packages/tests/test_vnf_pkg_subscription.py | 142 | ||||
-rw-r--r-- | genericparser/packages/tests/test_vnfpackage.py | 292 |
9 files changed, 304 insertions, 631 deletions
diff --git a/genericparser/packages/tests/const.py b/genericparser/packages/tests/const.py index caf60e3..a98ccb6 100644 --- a/genericparser/packages/tests/const.py +++ b/genericparser/packages/tests/const.py @@ -455,3 +455,142 @@ pnfd_data = { "id": "zte-1.0", } } + +sd_data = { + "inputs": { + "sdwanvpnresource_list": [ + { + "sdwanvpn_topology": "", + "required": True, + "type": "string" + } + ] + }, + "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 + } + } + ], + "description": "", + "vnfs": [ + { + "vnf_id": "sdwansiteresource", + "description": "", + "properties": { + "sdwandevice_type": "", + "sdwandevice_class": "PNF", + "multi_stage_design": "false", + "min_instances": "1", + "sdwansite_controlPoint": "", + "id": "cd557883-ac4b-462d-aa01-421b5fa606b1", + "sdwansite_longitude": "", + "sdwansite_latitude": "", + "sdwansite_postcode": "", + "sdwansite_type": "", + "nf_naming": { + "ecomp_generated_naming": True + }, + "sdwansite_emails": "", + "sdwansite_role": "", + "vnfm_info": "", + "sdwansite_address": "", + "sdwansite_description": "", + "availability_zone_max_count": "1", + "sdwansite_name": "" + } + } + ], + "service": { + "type": "org.openecomp.service.EnhanceService", + "properties": { + "descriptor_id": "49ee73f4-1e31-4054-b871-eb9b1c29999b", + "designer": "", + "invariant_id": "5de07996-7ff0-4ec1-b93c-e3a00bb3f207", + "name": "Enhance_Service", + "verison": "" + }, + "metadata": { + "category": "E2E Service", + "serviceType": "", + "description": "Enhance_Service", + "instantiationType": "A-la-carte", + "type": "Service", + "environmentContext": "General_Revenue-Bearing", + "serviceEcompNaming": True, + "UUID": "49ee73f4-1e31-4054-b871-eb9b1c29999b", + "ecompGeneratedNaming": True, + "serviceRole": "", + "invariantUUID": "5de07996-7ff0-4ec1-b93c-e3a00bb3f207", + "namingPolicy": "", + "name": "Enhance_Service" + } + }, + "metadata": { + "category": "E2E Service", + "serviceType": "", + "description": "Enhance_Service", + "instantiationType": "A-la-carte", + "type": "Service", + "environmentContext": "General_Revenue-Bearing", + "serviceEcompNaming": True, + "UUID": "49ee73f4-1e31-4054-b871-eb9b1c29999b", + "ecompGeneratedNaming": True, + "serviceRole": "", + "invariantUUID": "5de07996-7ff0-4ec1-b93c-e3a00bb3f207", + "namingPolicy": "", + "name": "Enhance_Service" + } +} + +vnf_subscription_data = { + "filters": { + "notificationTypes": [ + "VnfPackageOnboardingNotification" + ], + "vnfProductsFromProviders": { + "vnfProvider": "string", + "vnfProducts": { + "vnfProductName": "string", + "versions": { + "vnfSoftwareVersion": "string", + "vnfdVersions": [ + "string" + ] + } + } + }, + "vnfdId": [ + "3fa85f64-5717-4562-b3fc-2c963f66afa6" + ], + "vnfPkgId": [ + "3fa85f64-5717-4562-b3fc-2c963f66afa6" + ], + "operationalState": [ + "ENABLED" + ], + "usageState": [ + "IN_USE" + ] + }, + "callbackUri": "http://www.vnf1.com/notification", + "authentication": { + "authType": [ + "BASIC" + ], + "paramsBasic": { + "userName": "string", + "password": "string" + } + } +} diff --git a/genericparser/packages/tests/test_ns_descriptor.py b/genericparser/packages/tests/test_ns_descriptor.py index 6c4133c..862030a 100644 --- a/genericparser/packages/tests/test_ns_descriptor.py +++ b/genericparser/packages/tests/test_ns_descriptor.py @@ -248,7 +248,7 @@ class TestNsDescriptor(TestCase): response = self.client.get( "/api/nsd/v1/ns_descriptors/23/nsd_content", - RANGE='5-10', + HTTP_RANGE='5-10', format='json' ) partial_file_content = '' diff --git a/genericparser/packages/tests/test_nsdm_subscription.py b/genericparser/packages/tests/test_nsdm_subscription.py index 2d98d7a..99ec92f 100644 --- a/genericparser/packages/tests/test_nsdm_subscription.py +++ b/genericparser/packages/tests/test_nsdm_subscription.py @@ -100,8 +100,7 @@ class TestNsdmSubscription(TestCase): expected_data = { 'status': 500, 'detail': "callbackUri http://callbackuri.com didn't" - " return 204 statuscode.", - 'title': 'Creating Subscription Failed!' + " return 204 statuscode." } response = self.client.post("/api/nsd/v1/subscriptions", data=self.subscription, format='json') @@ -149,7 +148,6 @@ class TestNsdmSubscription(TestCase): 'status': 303, 'detail': 'Already Subscription exists with' ' the same callbackUri and filter', - 'title': 'Creating Subscription Failed!' } response = self.client.post("/api/nsd/v1/subscriptions", data=self.subscription, format='json') @@ -192,7 +190,6 @@ class TestNsdmSubscription(TestCase): expected_data = { 'status': 400, 'detail': 'Auth type should be BASIC', - 'title': 'Creating Subscription Failed!' } response = self.client.post("/api/nsd/v1/subscriptions", data=dummy_subscription, format='json') @@ -218,7 +215,6 @@ class TestNsdmSubscription(TestCase): expected_data = { 'status': 400, 'detail': 'Auth type should be OAUTH2_CLIENT_CREDENTIALS', - 'title': 'Creating Subscription Failed!' } response = self.client.post("/api/nsd/v1/subscriptions", data=dummy_subscription, format='json') @@ -241,7 +237,6 @@ class TestNsdmSubscription(TestCase): expected_data = { 'status': 400, 'detail': 'userName and password needed for BASIC', - 'title': 'Creating Subscription Failed!' } response = self.client.post("/api/nsd/v1/subscriptions", data=dummy_subscription, format='json') @@ -267,7 +262,6 @@ class TestNsdmSubscription(TestCase): 'status': 400, 'detail': 'clientId, clientPassword and tokenEndpoint' ' required for OAUTH2_CLIENT_CREDENTIALS', - 'title': 'Creating Subscription Failed!' } response = self.client.post("/api/nsd/v1/subscriptions", data=dummy_subscription, format='json') @@ -296,7 +290,6 @@ class TestNsdmSubscription(TestCase): 'status': 400, 'detail': 'Notification Filter should contain' ' either nsdId or nsdInfoId', - 'title': 'Creating Subscription Failed!' } response = self.client.post("/api/nsd/v1/subscriptions", data=dummy_subscription, format='json') @@ -325,7 +318,6 @@ class TestNsdmSubscription(TestCase): 'status': 400, 'detail': 'Notification Filter should contain' ' either pnfdId or pnfdInfoIds', - 'title': 'Creating Subscription Failed!' } response = self.client.post("/api/nsd/v1/subscriptions", data=dummy_subscription, format='json') @@ -459,7 +451,6 @@ class TestNsdmSubscription(TestCase): def test_nsdm_get_subscription_failure(self): expected_data = { - "title": "Query Subscription Failed!", "status": 404, "detail": "Subscription(" + self.subscription_id + ") " "doesn't exists" diff --git a/genericparser/packages/tests/test_nspackage.py b/genericparser/packages/tests/test_nspackage.py index 100ebd5..393e0f7 100644 --- a/genericparser/packages/tests/test_nspackage.py +++ b/genericparser/packages/tests/test_nspackage.py @@ -21,6 +21,7 @@ from django.test import Client from genericparser.pub.utils import restcall, toscaparsers from genericparser.pub.database.models import NSPackageModel, VnfPackageModel, PnfPackageModel from genericparser.pub.msapi import sdc +from .const import nsd_data class TestNsPackage(TestCase): @@ -28,226 +29,7 @@ class TestNsPackage(TestCase): self.client = Client() NSPackageModel.objects.filter().delete() VnfPackageModel.objects.filter().delete() - self.nsd_data = {"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": []}], - "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"}, - "ns": { - "properties": { - "descriptor_id": "VCPE_NS", - "version": 1, - "name": "VCPE_NS", - "desginer": "ZTE", - "invariant_id": "vcpe_ns_sff_1"}} - } + self.nsd_data = nsd_data def tearDown(self): pass diff --git a/genericparser/packages/tests/test_pnf_descriptor.py b/genericparser/packages/tests/test_pnf_descriptor.py index 22615f5..fc32bbe 100644 --- a/genericparser/packages/tests/test_pnf_descriptor.py +++ b/genericparser/packages/tests/test_pnf_descriptor.py @@ -17,6 +17,7 @@ import copy import json import mock import os +import shutil from django.test import TestCase from rest_framework import status @@ -24,6 +25,7 @@ from rest_framework.test import APIClient from genericparser.packages.biz.pnf_descriptor import PnfDescriptor from genericparser.packages.const import PKG_STATUS from genericparser.packages.tests.const import pnfd_data +from genericparser.pub.config.config import GENERICPARSER_ROOT_PATH from genericparser.pub.database.models import PnfPackageModel, NSPackageModel from genericparser.pub.utils import toscaparsers @@ -54,7 +56,9 @@ class TestPnfDescriptor(TestCase): } def tearDown(self): - pass + file_path = os.path.join(GENERICPARSER_ROOT_PATH, "22") + if os.path.exists(file_path): + shutil.rmtree(file_path) def test_pnfd_create_normal(self): request_data = {'userDefinedData': self.user_defined_data} diff --git a/genericparser/packages/tests/test_service_descriptor.py b/genericparser/packages/tests/test_service_descriptor.py index 30eafe0..0734577 100644 --- a/genericparser/packages/tests/test_service_descriptor.py +++ b/genericparser/packages/tests/test_service_descriptor.py @@ -22,6 +22,7 @@ from genericparser.packages.const import PKG_STATUS from genericparser.pub.database.models import ServicePackageModel, VnfPackageModel, PnfPackageModel from genericparser.pub.exceptions import PackageNotFoundException from genericparser.pub.utils import toscaparsers +from .const import sd_data logger = logging.getLogger(__name__) @@ -37,102 +38,7 @@ class TestServiceDescription(TestCase): self.data = { 'userDefinedData': self.user_defined_data, } - self.sd_data = { - "inputs": { - "sdwanvpnresource_list": [ - { - "sdwanvpn_topology": "", - "required": True, - "type": "string" - } - ] - }, - "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 - } - } - ], - "description": "", - "vnfs": [ - { - "vnf_id": "sdwansiteresource", - "description": "", - "properties": { - "sdwandevice_type": "", - "sdwandevice_class": "PNF", - "multi_stage_design": "false", - "min_instances": "1", - "sdwansite_controlPoint": "", - "id": "cd557883-ac4b-462d-aa01-421b5fa606b1", - "sdwansite_longitude": "", - "sdwansite_latitude": "", - "sdwansite_postcode": "", - "sdwansite_type": "", - "nf_naming": { - "ecomp_generated_naming": True - }, - "sdwansite_emails": "", - "sdwansite_role": "", - "vnfm_info": "", - "sdwansite_address": "", - "sdwansite_description": "", - "availability_zone_max_count": "1", - "sdwansite_name": "" - } - } - ], - "service": { - "type": "org.openecomp.service.EnhanceService", - "properties": { - "descriptor_id": "49ee73f4-1e31-4054-b871-eb9b1c29999b", - "designer": "", - "invariant_id": "5de07996-7ff0-4ec1-b93c-e3a00bb3f207", - "name": "Enhance_Service", - "verison": "" - }, - "metadata": { - "category": "E2E Service", - "serviceType": "", - "description": "Enhance_Service", - "instantiationType": "A-la-carte", - "type": "Service", - "environmentContext": "General_Revenue-Bearing", - "serviceEcompNaming": True, - "UUID": "49ee73f4-1e31-4054-b871-eb9b1c29999b", - "ecompGeneratedNaming": True, - "serviceRole": "", - "invariantUUID": "5de07996-7ff0-4ec1-b93c-e3a00bb3f207", - "namingPolicy": "", - "name": "Enhance_Service" - } - }, - "metadata": { - "category": "E2E Service", - "serviceType": "", - "description": "Enhance_Service", - "instantiationType": "A-la-carte", - "type": "Service", - "environmentContext": "General_Revenue-Bearing", - "serviceEcompNaming": True, - "UUID": "49ee73f4-1e31-4054-b871-eb9b1c29999b", - "ecompGeneratedNaming": True, - "serviceRole": "", - "invariantUUID": "5de07996-7ff0-4ec1-b93c-e3a00bb3f207", - "namingPolicy": "", - "name": "Enhance_Service" - } - } + self.sd_data = sd_data ServicePackageModel.objects.filter().delete() def tearDown(self): diff --git a/genericparser/packages/tests/test_vnf_package.py b/genericparser/packages/tests/test_vnf_package.py index 22488ba..31c7223 100644 --- a/genericparser/packages/tests/test_vnf_package.py +++ b/genericparser/packages/tests/test_vnf_package.py @@ -16,6 +16,7 @@ import json import os import urllib2 import mock +import shutil from django.test import TestCase from rest_framework import status @@ -42,7 +43,9 @@ class TestVnfPackage(TestCase): self.client = APIClient() def tearDown(self): - pass + file_path = os.path.join(GENERICPARSER_ROOT_PATH, "222") + if os.path.exists(file_path): + shutil.rmtree(file_path) @mock.patch.object(toscaparsers, 'parse_vnfd') def test_upload_vnf_pkg(self, mock_parse_vnfd): @@ -250,7 +253,7 @@ class TestVnfPackage(TestCase): onboardingState="ONBOARDED", localFilePath="vnfPackage.csar" ) - response = self.client.get("/api/vnfpkgm/v1/vnf_packages/222/package_content", RANGE="4-7") + response = self.client.get("/api/vnfpkgm/v1/vnf_packages/222/package_content", HTTP_RANGE="4-7") partial_file_content = '' for data in response.streaming_content: partial_file_content = partial_file_content + data @@ -258,6 +261,22 @@ class TestVnfPackage(TestCase): self.assertEqual('BBB', partial_file_content) os.remove("vnfPackage.csar") + def test_fetch_last_partical_vnf_pkg(self): + with open("vnfPackage.csar", "wb") as fp: + fp.writelines("AAAABBBBCCCCDDDD") + VnfPackageModel.objects.create( + vnfPackageId="222", + onboardingState="ONBOARDED", + localFilePath="vnfPackage.csar" + ) + response = self.client.get("/api/vnfpkgm/v1/vnf_packages/222/package_content", HTTP_RANGE=" 4-") + partial_file_content = '' + for data in response.streaming_content: + partial_file_content = partial_file_content + data + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual('BBBBCCCCDDDD', partial_file_content) + os.remove("vnfPackage.csar") + def test_fetch_vnf_pkg_when_pkg_not_exist(self): response = self.client.get("/api/vnfpkgm/v1/vnf_packages/222/package_content") self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) diff --git a/genericparser/packages/tests/test_vnf_pkg_subscription.py b/genericparser/packages/tests/test_vnf_pkg_subscription.py index 25e8c5d..e35f195 100644 --- a/genericparser/packages/tests/test_vnf_pkg_subscription.py +++ b/genericparser/packages/tests/test_vnf_pkg_subscription.py @@ -14,56 +14,19 @@ import uuid import mock + from rest_framework.test import APIClient from django.test import TestCase + from genericparser.pub.database.models import VnfPkgSubscriptionModel +from .const import vnf_subscription_data class TestNfPackageSubscription(TestCase): def setUp(self): self.client = APIClient() VnfPkgSubscriptionModel.objects.filter().delete() - self.vnf_subscription_data = { - "filters": { - "notificationTypes": [ - "VnfPackageOnboardingNotification" - ], - "vnfProductsFromProviders": { - "vnfProvider": "string", - "vnfProducts": { - "vnfProductName": "string", - "versions": { - "vnfSoftwareVersion": "string", - "vnfdVersions": [ - "string" - ] - } - } - }, - "vnfdId": [ - "3fa85f64-5717-4562-b3fc-2c963f66afa6" - ], - "vnfPkgId": [ - "3fa85f64-5717-4562-b3fc-2c963f66afa6" - ], - "operationalState": [ - "ENABLED" - ], - "usageState": [ - "IN_USE" - ] - }, - "callbackUri": "http://www.vnf1.com/notification", - "authentication": { - "authType": [ - "BASIC" - ], - "paramsBasic": { - "userName": "string", - "password": "string" - } - } - } + self.vnf_subscription_data = vnf_subscription_data def tearDown(self): pass @@ -75,9 +38,16 @@ class TestNfPackageSubscription(TestCase): mock_requests.return_value.status_code = 204 mock_requests.get.status_code = 204 mock_uuid4.return_value = temp_uuid - response = self.client.post("/api/vnfpkgm/v1/subscriptions", data=self.vnf_subscription_data, format='json') + response = self.client.post( + "/api/vnfpkgm/v1/subscriptions", + data=self.vnf_subscription_data, + format='json' + ) self.assertEqual(201, response.status_code) - self.assertEqual(self.vnf_subscription_data["callbackUri"], response.data["callbackUri"]) + self.assertEqual( + self.vnf_subscription_data["callbackUri"], + response.data["callbackUri"] + ) self.assertEqual(temp_uuid, response.data["id"]) @mock.patch("requests.get") @@ -88,15 +58,26 @@ class TestNfPackageSubscription(TestCase): mock_requests.return_value.status_code = 204 mock_requests.get.status_code = 204 mock_uuid4.side_effect = [temp_uuid, temp1_uuid] - response = self.client.post("/api/vnfpkgm/v1/subscriptions", data=self.vnf_subscription_data, format='json') + response = self.client.post( + "/api/vnfpkgm/v1/subscriptions", + data=self.vnf_subscription_data, + format='json' + ) self.assertEqual(201, response.status_code) - self.assertEqual(self.vnf_subscription_data["callbackUri"], response.data["callbackUri"]) + self.assertEqual( + self.vnf_subscription_data["callbackUri"], + response.data["callbackUri"] + ) self.assertEqual(temp_uuid, response.data["id"]) temp_uuid = "00442b18-a5c7-11e8-998c-bf1755941f12" mock_requests.return_value.status_code = 204 mock_requests.get.status_code = 204 mock_uuid4.return_value = temp_uuid - response = self.client.post("/api/vnfpkgm/v1/subscriptions", data=self.vnf_subscription_data, format='json') + response = self.client.post( + "/api/vnfpkgm/v1/subscriptions", + data=self.vnf_subscription_data, + format='json' + ) self.assertEqual(303, response.status_code) @mock.patch("requests.get") @@ -106,10 +87,15 @@ class TestNfPackageSubscription(TestCase): mock_requests.return_value.status_code = 204 mock_requests.get.status_code = 204 mock_uuid4.return_value = temp_uuid - self.client.post("/api/vnfpkgm/v1/subscriptions", - data=self.vnf_subscription_data, format='json') - response = self.client.get("/api/vnfpkgm/v1/subscriptions?usageState=IN_USE", - format='json') + self.client.post( + "/api/vnfpkgm/v1/subscriptions", + data=self.vnf_subscription_data, + format='json' + ) + response = self.client.get( + "/api/vnfpkgm/v1/subscriptions?usageState=IN_USE", + format='json' + ) self.assertEqual(200, response.status_code) self.assertEqual(1, len(response.data)) @@ -120,10 +106,15 @@ class TestNfPackageSubscription(TestCase): mock_requests.return_value.status_code = 204 mock_requests.get.status_code = 204 mock_uuid4.return_value = temp_uuid - self.client.post("/api/vnfpkgm/v1/subscriptions", - data=self.vnf_subscription_data, format='json') - response = self.client.get("/api/vnfpkgm/v1/subscriptions?dummy=dummy", - format='json') + self.client.post( + "/api/vnfpkgm/v1/subscriptions", + data=self.vnf_subscription_data, + format='json' + ) + response = self.client.get( + "/api/vnfpkgm/v1/subscriptions?dummy=dummy", + format='json' + ) self.assertEqual(400, response.status_code) @mock.patch("requests.get") @@ -133,10 +124,15 @@ class TestNfPackageSubscription(TestCase): mock_requests.return_value.status_code = 204 mock_requests.get.status_code = 204 mock_uuid4.return_value = temp_uuid - self.client.post("/api/vnfpkgm/v1/subscriptions", - data=self.vnf_subscription_data, format='json') - response = self.client.get("/api/vnfpkgm/v1/subscriptions/" + temp_uuid, - format='json') + self.client.post( + "/api/vnfpkgm/v1/subscriptions", + data=self.vnf_subscription_data, + format='json' + ) + response = self.client.get( + "/api/vnfpkgm/v1/subscriptions/%s" % temp_uuid, + format='json' + ) self.assertEqual(200, response.status_code) self.assertEqual(temp_uuid, response.data["id"]) @@ -148,10 +144,15 @@ class TestNfPackageSubscription(TestCase): mock_requests.return_value.status_code = 204 mock_requests.get.status_code = 204 mock_uuid4.return_value = temp_uuid - self.client.post("/api/vnfpkgm/v1/subscriptions", - data=self.vnf_subscription_data, format='json') - response = self.client.get("/api/vnfpkgm/v1/subscriptions/" + dummy_uuid, - format='json') + self.client.post( + "/api/vnfpkgm/v1/subscriptions", + data=self.vnf_subscription_data, + format='json' + ) + response = self.client.get( + "/api/vnfpkgm/v1/subscriptions/%s" % dummy_uuid, + format='json' + ) self.assertEqual(404, response.status_code) @mock.patch("requests.get") @@ -162,16 +163,21 @@ class TestNfPackageSubscription(TestCase): mock_requests.return_value.status_code = 204 mock_requests.get.status_code = 204 mock_uuid4.return_value = temp_uuid - self.client.post("/api/vnfpkgm/v1/subscriptions", - data=self.vnf_subscription_data, format='json') - self.client.get("/api/vnfpkgm/v1/subscriptions/" + dummy_uuid, - format='json') - response = self.client.delete("/api/vnfpkgm/v1/subscriptions/" + temp_uuid) + self.client.post( + "/api/vnfpkgm/v1/subscriptions", + data=self.vnf_subscription_data, + format='json' + ) + self.client.get( + "/api/vnfpkgm/v1/subscriptions/%s" % dummy_uuid, + format='json' + ) + response = self.client.delete("/api/vnfpkgm/v1/subscriptions/%s" % temp_uuid) self.assertEqual(204, response.status_code) @mock.patch("requests.get") @mock.patch.object(uuid, 'uuid4') def test_delete_subscription_with_id_not_exists(self, mock_uuid4, mock_requests): dummy_uuid = str(uuid.uuid4()) - response = self.client.delete("/api/vnfpkgm/v1/subscriptions/" + dummy_uuid) + response = self.client.delete("/api/vnfpkgm/v1/subscriptions/%s" % dummy_uuid) self.assertEqual(404, response.status_code) diff --git a/genericparser/packages/tests/test_vnfpackage.py b/genericparser/packages/tests/test_vnfpackage.py index 34b9134..70f7021 100644 --- a/genericparser/packages/tests/test_vnfpackage.py +++ b/genericparser/packages/tests/test_vnfpackage.py @@ -22,6 +22,7 @@ from genericparser.pub.database.models import JobStatusModel, JobModel from genericparser.pub.database.models import VnfPackageModel from genericparser.pub.msapi import sdc from genericparser.pub.utils import restcall, toscaparsers +from .const import vnfd_data class TestNfPackage(TestCase): @@ -30,220 +31,7 @@ class TestNfPackage(TestCase): VnfPackageModel.objects.filter().delete() JobModel.objects.filter().delete() JobStatusModel.objects.filter().delete() - self.vnfd_data = { - "volume_storages": [ - { - "properties": { - "size_of_storage": { - "factor": 10, - "value": 10000000000, - "unit": "GB", - "unit_size": 1000000000 - }, - "type_of_storage": "volume", - "rdma_enabled": False, - "size": "10 GB" - }, - "volume_storage_id": "vNAT_Storage_6wdgwzedlb6sq18uzrr41sof7", - "description": "" - } - ], - "inputs": {}, - "vdus": [ - { - "volume_storages": [ - "vNAT_Storage_6wdgwzedlb6sq18uzrr41sof7" - ], - "description": "", - "dependencies": [], - "vls": [], - "properties": { - "name": "vNat", - "configurable_properties": { - "test": { - "additional_vnfc_configurable_properties": { - "aaa": "1", - "bbb": "2", - "ccc": "3" - } - } - }, - "description": "the virtual machine of vNat", - "nfvi_constraints": [ - "test" - ], - "boot_order": [ - "vNAT_Storage" - ] - }, - "vdu_id": "vdu_vNat", - "artifacts": [ - { - "artifact_name": "vNatVNFImage", - "type": "tosca.artifacts.nfv.SwImage", - "properties": { - "operating_system": "linux", - "sw_image": "/swimages/vRouterVNF_ControlPlane.qcow2", - "name": "vNatVNFImage", - "container_format": "bare", - "min_ram": "1 GB", - "disk_format": "qcow2", - "supported_virtualisation_environments": [ - "test_0" - ], - "version": "1.0", - "checksum": "5000", - "min_disk": "10 GB", - "size": "10 GB" - }, - "file": "/swimages/vRouterVNF_ControlPlane.qcow2" - } - ], - "nfv_compute": { - "flavor_extra_specs": { - "hw:cpu_sockets": "2", - "sw:ovs_dpdk": "true", - "hw:cpu_threads": "2", - "hw:numa_mem.1": "3072", - "hw:numa_mem.0": "1024", - "hw:numa_nodes": "2", - "hw:numa_cpus.0": "0,1", - "hw:numa_cpus.1": "2,3,4,5", - "hw:cpu_cores": "2", - "hw:cpu_threads_policy": "isolate" - }, - "cpu_frequency": "2.4 GHz", - "num_cpus": 2, - "mem_size": "10 GB" - }, - "local_storages": [], - "image_file": "vNatVNFImage", - "cps": [] - } - ], - "image_files": [ - { - "properties": { - "operating_system": "linux", - "sw_image": "/swimages/vRouterVNF_ControlPlane.qcow2", - "name": "vNatVNFImage", - "container_format": "bare", - "min_ram": "1 GB", - "disk_format": "qcow2", - "supported_virtualisation_environments": [ - "test_0" - ], - "version": "1.0", - "checksum": "5000", - "min_disk": "10 GB", - "size": "10 GB" - }, - "image_file_id": "vNatVNFImage", - "description": "" - } - ], - "routers": [], - "local_storages": [], - "vnf_exposed": { - "external_cps": [ - { - "key_name": "sriov_plane", - "cp_id": "SRIOV_Port" - } - ], - "forward_cps": [] - }, - "vls": [ - { - "route_id": "", - "vl_id": "sriov_link", - "route_external": False, - "description": "", - "properties": { - "vl_flavours": { - "vl_id": "aaaa" - }, - "connectivity_type": { - "layer_protocol": "ipv4", - "flow_pattern": "flat" - }, - "description": "sriov_link", - "test_access": [ - "test" - ] - } - } - ], - "cps": [ - { - "vl_id": "sriov_link", - "vdu_id": "vdu_vNat", - "description": "", - "cp_id": "SRIOV_Port", - "properties": { - "address_data": [ - { - "address_type": "ip_address", - "l3_address_data": { - "ip_address_type": "ipv4", - "floating_ip_activated": False, - "number_of_ip_address": 1, - "ip_address_assignment": True - } - } - ], - "description": "sriov port", - "layer_protocol": "ipv4", - "virtual_network_interface_requirements": [ - { - "requirement": { - "SRIOV": "true" - }, - "support_mandatory": False, - "name": "sriov", - "description": "sriov" - }, - { - "requirement": { - "SRIOV": "False" - }, - "support_mandatory": False, - "name": "normal", - "description": "normal" - } - ], - "role": "root", - "bitrate_requirement": 10 - } - } - ], - "metadata": { - "vnfSoftwareVersion": "1.0.0", - "vnfProductName": "zte", - "localizationLanguage": [ - "english", - "chinese" - ], - "vnfProvider": "zte", - "vnfmInfo": "zte", - "defaultLocalizationLanguage": "english", - "vnfdId": "zte-hss-1.0", - "id": "zte-hss-1.0", - "vnfProductInfoDescription": "hss", - "vnfdVersion": "1.0.0", - "vnfProductInfoName": "hss" - }, - "vnf": { - "properties": { - "descriptor_id": "zte-hss-1.0", - "descriptor_verison": "1.0.0", - "software_version": "1.0.0", - "provider": "zte" - }, - "metadata": { - } - } - } + self.vnfd_data = vnfd_data def tearDown(self): pass @@ -257,32 +45,44 @@ class TestNfPackage(TestCase): @mock.patch.object(NfDistributeThread, 'run') def test_nf_pkg_distribute_normal(self, mock_run): - resp = self.client.post("/api/parser/v1/vnfpackages", { - "csarId": "1", - "vimIds": ["1"] - }, format='json') + resp = self.client.post( + "/api/parser/v1/vnfpackages", + { + "csarId": "1", + "vimIds": ["1"] + }, + format='json' + ) self.assertEqual(resp.status_code, status.HTTP_202_ACCEPTED) def test_nf_pkg_distribute_when_csar_already_exist(self): - VnfPackageModel(vnfPackageId="1", vnfdId="vcpe_vfw_zte_1_0").save() - NfDistributeThread(csar_id="1", - vim_ids=["1"], - lab_vim_id="", - job_id="2").run() + VnfPackageModel( + vnfPackageId="1", + vnfdId="vcpe_vfw_zte_1_0" + ).save() + NfDistributeThread( + csar_id="1", + vim_ids=["1"], + lab_vim_id="", + job_id="2" + ).run() self.assert_job_result("2", 255, "NF CSAR(1) already exists.") @mock.patch.object(restcall, 'call_req') @mock.patch.object(sdc, 'download_artifacts') @mock.patch.object(toscaparsers, 'parse_vnfd') def test_nf_pkg_distribute_when_vnfd_already_exist(self, - mock_parse_vnfd, mock_download_artifacts, mock_call_req): + mock_parse_vnfd, + mock_download_artifacts, + mock_call_req): mock_parse_vnfd.return_value = json.JSONEncoder().encode(self.vnfd_data) mock_download_artifacts.return_value = "/home/hss.csar" mock_call_req.return_value = [0, json.JSONEncoder().encode([{ "uuid": "1", "toscaModelURL": "https://127.0.0.1:1234/sdc/v1/hss.csar" }]), '200'] - VnfPackageModel(vnfPackageId="2", vnfdId="zte-hss-1.0").save() + VnfPackageModel(vnfPackageId="2", + vnfdId="zte-hss-1.0").save() NfDistributeThread(csar_id="1", vim_ids=["1"], lab_vim_id="", @@ -319,10 +119,24 @@ class TestNfPackage(TestCase): self.assert_job_result("2", 100, "Delete CSAR(2) successfully.") def test_nf_pkg_get_all(self): - VnfPackageModel(vnfPackageId="3", vnfdId="3", vnfVendor='3', vnfdVersion='3', - vnfSoftwareVersion='', vnfPackageUri='', vnfdModel='').save() - VnfPackageModel(vnfPackageId="4", vnfdId="4", vnfVendor='4', vnfdVersion='4', - vnfSoftwareVersion='', vnfPackageUri='', vnfdModel='').save() + VnfPackageModel( + vnfPackageId="3", + vnfdId="3", + vnfVendor='3', + vnfdVersion='3', + vnfSoftwareVersion='', + vnfPackageUri='', + vnfdModel='' + ).save() + VnfPackageModel( + vnfPackageId="4", + vnfdId="4", + vnfVendor='4', + vnfdVersion='4', + vnfSoftwareVersion='', + vnfPackageUri='', + vnfdModel='' + ).save() resp = self.client.get("/api/parser/v1/vnfpackages") self.assertEqual(resp.status_code, status.HTTP_200_OK) expect_data = [ @@ -358,8 +172,15 @@ class TestNfPackage(TestCase): self.assertEqual(expect_data, resp.data) def test_nf_pkg_get_one(self): - VnfPackageModel(vnfPackageId="4", vnfdId="4", vnfVendor='4', vnfdVersion='4', - vnfSoftwareVersion='', vnfPackageUri='', vnfdModel='').save() + VnfPackageModel( + vnfPackageId="4", + vnfdId="4", + vnfVendor='4', + vnfdVersion='4', + vnfSoftwareVersion='', + vnfPackageUri='', + vnfdModel='' + ).save() resp = self.client.get("/api/parser/v1/vnfpackages/4") self.assertEqual(resp.status_code, status.HTTP_200_OK) @@ -380,8 +201,13 @@ class TestNfPackage(TestCase): self.assertEqual(expect_data, resp.data) def test_nf_pkg_get_one_failed(self): - VnfPackageModel(vnfPackageId="4", vnfdId="4", vnfVendor='4', vnfdVersion='4', - vnfSoftwareVersion='', vnfPackageUri='', vnfdModel='').save() + VnfPackageModel(vnfPackageId="4", + vnfdId="4", + vnfVendor='4', + vnfdVersion='4', + vnfSoftwareVersion='', + vnfPackageUri='', + vnfdModel='').save() resp = self.client.get("/api/parser/v1/vnfpackages/2") self.assertEqual(resp.status_code, status.HTTP_500_INTERNAL_SERVER_ERROR) |