aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFu Jinhua <fu.jinhua@zte.com.cn>2019-04-25 02:42:57 +0000
committerGerrit Code Review <gerrit@onap.org>2019-04-25 02:42:57 +0000
commit22631f12c6029a38be6cb3acdc21e6f8f6400f6c (patch)
tree8066fe95d3e02084c8549c0b9a6a3d35dd24d810
parent7da033ea616815244205aa97759ec75bc3326447 (diff)
parent3f6581bc1d4e9c37f71c66a181b6aaa12ab01863 (diff)
Merge "SOL subscription test via independant json file"
-rw-r--r--lcm/ns/tests/__init__.py3
-rw-r--r--lcm/ns/tests/data/subscription_ns_deletion.json12
-rw-r--r--lcm/ns/tests/data/subscription_ns_operation.json19
-rw-r--r--lcm/ns/tests/test_sol_ns_scale_api.py151
-rw-r--r--lcm/ns/tests/test_sol_ns_terminate_api.py42
-rw-r--r--lcm/ns/tests/test_subscribe_notification.py83
6 files changed, 79 insertions, 231 deletions
diff --git a/lcm/ns/tests/__init__.py b/lcm/ns/tests/__init__.py
index 32cabe8b..bf1956af 100644
--- a/lcm/ns/tests/__init__.py
+++ b/lcm/ns/tests/__init__.py
@@ -29,6 +29,7 @@ VNFM_IN_AAI_DICT = fileutil.read_json_file(cur_path + '/data/vnfm_in_aai.json')
JOB_DICT = fileutil.read_json_file(cur_path + '/data/job.json')
INSTANTIATE_NS_WITH_PNF_DICT = fileutil.read_json_file(cur_path + '/data/instantiate_ns_with_pnf.json')
INSTANTIATE_NS_DICT = fileutil.read_json_file(cur_path + '/data/instantiate_ns.json')
+SCALE_DICT = fileutil.read_json_file(cur_path + '/data/scale.json')
SCALING_MAP_DICT = fileutil.read_json_file(cur_path + '/data/scalemapping.json')
SCALE_NS_DICT = fileutil.read_json_file(cur_path + '/data/scale_ns.json')
OCCURRENCE_DICT = fileutil.read_json_file(cur_path + '/data/occurrence.json')
@@ -41,3 +42,5 @@ SOL_INSTANTIATE_NS_DICT = fileutil.read_json_file(cur_path + '/data/sol_instanti
SOL_INSTANTIATE_NS_VCPE_DICT = fileutil.read_json_file(cur_path + '/data/sol_instantiate_ns_vcpe.json')
SOL_INSTANTIATE_NS_WITH_PNF_DICT = fileutil.read_json_file(cur_path + '/data/sol_instantiate_ns_with_pnf.json')
VCPE_NS_MODEL_DICT = fileutil.read_json_file(cur_path + '/data/vcpe_ns_model.json')
+SUBSCRIPTION_NS_OPERATION_DICT = fileutil.read_json_file(cur_path + '/data/subscription_ns_operation.json')
+SUBSCRIPTION_NS_DELETION_DICT = fileutil.read_json_file(cur_path + '/data/subscription_ns_deletion.json')
diff --git a/lcm/ns/tests/data/subscription_ns_deletion.json b/lcm/ns/tests/data/subscription_ns_deletion.json
new file mode 100644
index 00000000..2199447b
--- /dev/null
+++ b/lcm/ns/tests/data/subscription_ns_deletion.json
@@ -0,0 +1,12 @@
+{
+ "callbackUri": "http://aurl.com",
+ "filter": {
+ "notificationTypes": ["NsIdentifierDeletionNotification"],
+ "operationTypes": [
+ "INSTANTIATE"
+ ],
+ "operationStates": [
+ "STARTING"
+ ]
+ }
+}
diff --git a/lcm/ns/tests/data/subscription_ns_operation.json b/lcm/ns/tests/data/subscription_ns_operation.json
new file mode 100644
index 00000000..3c4d9b9e
--- /dev/null
+++ b/lcm/ns/tests/data/subscription_ns_operation.json
@@ -0,0 +1,19 @@
+{
+ "callbackUri": "http://aurl.com",
+ "authentication": {
+ "authType": ["BASIC"],
+ "paramsBasic": {
+ "username": "username",
+ "password": "password"
+ }
+ },
+ "filter": {
+ "notificationTypes": ["NsLcmOperationOccurrenceNotification"],
+ "operationTypes": [
+ "INSTANTIATE"
+ ],
+ "operationStates": [
+ "STARTING"
+ ]
+ }
+}
diff --git a/lcm/ns/tests/test_sol_ns_scale_api.py b/lcm/ns/tests/test_sol_ns_scale_api.py
index ce901e8c..bc71b09f 100644
--- a/lcm/ns/tests/test_sol_ns_scale_api.py
+++ b/lcm/ns/tests/test_sol_ns_scale_api.py
@@ -12,125 +12,39 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-import os
+import json
import uuid
-
import mock
-from django.test import Client
from django.test import TestCase
from rest_framework import status
-
+from rest_framework.test import APIClient
from lcm.ns.biz.ns_manual_scale import NSManualScaleService
from lcm.pub.database.models import NSInstModel, JobModel, NfInstModel
from lcm.pub.exceptions import NSLCMException
from lcm.pub.utils.jobutil import JobUtil, JOB_TYPE
-from lcm.pub.utils import fileutil
-
-SCALING_JSON = {
- "scale_options": [
- {
- "nsd_id": "ns_ims",
- "ns_scale_aspect": "TIC_CORE_IMS",
- "ns_scale_info": [
- {
- "step": "1",
- "scale_list": [
- {
- "vnfd_id": "zte_ims_cscf",
- "vnf_scale_aspect": "mpu",
- "numberOfSteps": "1"
- },
- {
- "vnfd_id": "zte_ims_hss",
- "vnf_scale_aspect": "fpu",
- "numberOfSteps": "3"
- }
- ]
- },
- {
- "step": "2",
- "scale_list": [
- {
- "vnfd_id": "zte_ims_cscf",
- "vnf_scale_aspect": "mpu",
- "numberOfSteps": "2"
- },
- {
- "vnfd_id": "zte_ims_hss",
- "vnf_scale_aspect": "fpu",
- "numberOfSteps": "6"
- }
- ]
- }
- ]
- },
- {
- "nsd_id": "ns_epc",
- "ns_scale_aspect": "TIC_EDGE_EPC",
- "ns_scale_info": [
- {
- "step": "1",
- "scale_list": [
- {
- "vnfd_id": "zte_epc_spgw",
- "vnf_scale_aspect": "gpu",
- "numberOfSteps": "1"
- },
- {
- "vnfd_id": "zte_epc_tas",
- "vnf_scale_aspect": "fpu",
- "numberOfSteps": "2"
- }
- ]
- },
- {
- "step": "2",
- "scale_list": [
- {
- "vnfd_id": "zte_epc_spgw",
- "vnf_scale_aspect": "mpu",
- "numberOfSteps": "2"
- },
- {
- "vnfd_id": "zte_epc_tas",
- "vnf_scale_aspect": "fpu",
- "numberOfSteps": "4"
- }
- ]
- }
- ]
- }
- ]
-}
+from lcm.ns.tests import VNFD_MODEL_DICT, SCALE_NS_DICT
class TestScaleNsApi(TestCase):
def setUp(self):
self.url = "/api/nslcm/v1/ns_instances/%s/scale"
- self.cur_path = os.path.dirname(os.path.abspath(__file__))
self.ns_inst_id = str(uuid.uuid4())
- self.job_id = JobUtil.create_job(
- "NS", JOB_TYPE.MANUAL_SCALE_VNF, self.ns_inst_id)
+ self.job_id = JobUtil.create_job("NS", JOB_TYPE.MANUAL_SCALE_VNF, self.ns_inst_id)
self.package_id = "7"
- self.client = Client()
+ self.client = APIClient()
NSInstModel(
id=self.ns_inst_id,
name="abc",
nspackage_id=self.package_id,
nsd_id="111").save()
- self.init_scaling_map_json()
def tearDown(self):
NSInstModel.objects.filter().delete()
JobModel.objects.filter().delete()
- def init_scaling_map_json(self):
- self.scaling_map_json = fileutil.read_json_file(self.cur_path + '/data/scalemapping.json')
-
def insert_new_ns(self):
ns_inst_id = str(uuid.uuid4())
- job_id = JobUtil.create_job(
- "NS", JOB_TYPE.MANUAL_SCALE_VNF, self.ns_inst_id)
+ job_id = JobUtil.create_job("NS", JOB_TYPE.MANUAL_SCALE_VNF, self.ns_inst_id)
package_id = "23"
NSInstModel(
id=ns_inst_id,
@@ -140,27 +54,12 @@ class TestScaleNsApi(TestCase):
return ns_inst_id, job_id
def insert_new_nf(self):
- # Create a third vnf instance
self.nf_name = "name_1"
self.vnf_id = "1"
self.vnfm_inst_id = "1"
nf_inst_id = "233"
package_id = "nf_zte_hss"
nf_uuid = "ab34-3g5j-de13-ab85-ij93"
- vnf_model = {
- "metadata": {
- "vnfdId": "1",
- "vnfdName": "PGW001",
- "vnfProvider": "zte",
- "vnfdVersion": "V00001",
- "vnfVersion": "V5.10.20",
- "productType": "CN",
- "vnfType": "PGW",
- "description": "PGW VNFD description",
- "isShared": True,
- "vnfExtendType": "driver"
- }
- }
NfInstModel.objects.create(
nfinstid=nf_inst_id,
nf_name=self.nf_name,
@@ -175,22 +74,12 @@ class TestScaleNsApi(TestCase):
status='active',
mnfinstid=nf_uuid,
package_id=package_id,
- vnfd_model=str(vnf_model)
+ vnfd_model=json.dumps(VNFD_MODEL_DICT)
)
@mock.patch.object(NSManualScaleService, 'run')
def test_ns_scale(self, mock_run):
- data = {
- "scaleType": "SCALE_NS",
- "scaleNsData": {
- "scaleNsByStepsData": {
- "aspectId": "1",
- "numberOfSteps": 1,
- "scalingDirection": "0"
- }
- }
- }
- response = self.client.post(self.url % self.ns_inst_id, data=data)
+ response = self.client.post(self.url % self.ns_inst_id, data=SCALE_NS_DICT)
self.failUnlessEqual(status.HTTP_202_ACCEPTED, response.status_code)
self.assertIsNotNone(response['Location'])
response = self.client.get(response['Location'], format='json')
@@ -199,30 +88,14 @@ class TestScaleNsApi(TestCase):
@mock.patch.object(NSManualScaleService, 'start')
def test_ns_manual_scale_empty_data(self, mock_start):
mock_start.side_effect = NSLCMException("NS scale failed.")
- response = self.client.post(
- self.url %
- self.ns_inst_id, data={})
- self.assertEqual(
- response.status_code,
- status.HTTP_400_BAD_REQUEST)
+ response = self.client.post(self.url % self.ns_inst_id, data={}, format='json')
+ self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
@mock.patch.object(NSManualScaleService, 'start')
def test_ns_manual_scale_when_ns_not_exist(self, mock_start):
mock_start.side_effect = NSLCMException("NS scale failed.")
- data = {
- "scaleType": "SCALE_NS",
- "scaleNsData": {
- "scaleNsByStepsData": {
- "aspectId": "1",
- "numberOfSteps": 1,
- "scalingDirection": "0"
- }
- }
- }
- response = self.client.post(self.url % '11', data=data)
- self.assertEqual(
- response.status_code,
- status.HTTP_500_INTERNAL_SERVER_ERROR)
+ response = self.client.post(self.url % '11', data=SCALE_NS_DICT)
+ self.assertEqual(response.status_code, status.HTTP_500_INTERNAL_SERVER_ERROR)
def test_method_not_allowed(self):
response = self.client.put(self.url % '1', data={}, format='json')
diff --git a/lcm/ns/tests/test_sol_ns_terminate_api.py b/lcm/ns/tests/test_sol_ns_terminate_api.py
index 5aec52e9..7380aa68 100644
--- a/lcm/ns/tests/test_sol_ns_terminate_api.py
+++ b/lcm/ns/tests/test_sol_ns_terminate_api.py
@@ -11,21 +11,20 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
+import json
import uuid
-
import mock
from django.test import TestCase, Client
from rest_framework import status
-
from lcm.ns.biz.ns_terminate import TerminateNsService
from lcm.pub.database.models import NfInstModel, NSInstModel
+from lcm.ns.tests import VNFD_MODEL_DICT
class TestTerminateNsApi(TestCase):
def setUp(self):
self.client = Client()
self.url = "/api/nslcm/v1/ns_instances/%s/terminate"
- # self.ns_inst_id = '1'
self.ns_inst_id = str(uuid.uuid4())
self.nf_inst_id = '1'
self.vnffg_id = str(uuid.uuid4())
@@ -33,24 +32,25 @@ class TestTerminateNsApi(TestCase):
self.job_id = str(uuid.uuid4())
self.nf_uuid = '1-1-1'
self.tenant = "tenantname"
- model = {"metadata": {
- "vnfdId": "1",
- "vnfdName": "PGW001",
- "vnfProvider": "zte",
- "vnfdVersion": "V00001",
- "vnfVersion": "V5.10.20",
- "productType": "CN",
- "vnfType": "PGW",
- "description": "PGW VNFD description",
- "isShared": True,
- "vnfExtendType": "driver"
- }}
- NSInstModel(id=self.ns_inst_id, name="ns_name", status='null').save()
- NfInstModel.objects.create(nfinstid=self.nf_inst_id, nf_name='name_1', vnf_id='1',
- vnfm_inst_id='1', ns_inst_id='1-1-1,2-2-2',
- max_cpu='14', max_ram='12296', max_hd='101', max_shd="20", max_net=10,
- status='null', mnfinstid=self.nf_uuid, package_id='pkg1',
- vnfd_model=str(model))
+ NSInstModel(
+ id=self.ns_inst_id,
+ name="ns_name",
+ status='null').save()
+ NfInstModel.objects.create(
+ nfinstid=self.nf_inst_id,
+ nf_name='name_1',
+ vnf_id='1',
+ vnfm_inst_id='1',
+ ns_inst_id='1-1-1,2-2-2',
+ max_cpu='14',
+ max_ram='12296',
+ max_hd='101',
+ max_shd="20",
+ max_net=10,
+ status='null',
+ mnfinstid=self.nf_uuid,
+ package_id='pkg1',
+ vnfd_model=json.dumps(VNFD_MODEL_DICT))
def tearDown(self):
NSInstModel.objects.all().delete()
diff --git a/lcm/ns/tests/test_subscribe_notification.py b/lcm/ns/tests/test_subscribe_notification.py
index 9738bee8..5588766a 100644
--- a/lcm/ns/tests/test_subscribe_notification.py
+++ b/lcm/ns/tests/test_subscribe_notification.py
@@ -12,10 +12,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+import copy
import mock
from django.test import TestCase
from rest_framework.test import APIClient
import uuid
+from lcm.ns.tests import SUBSCRIPTION_NS_DELETION_DICT, SUBSCRIPTION_NS_OPERATION_DICT
class TestSubscription(TestCase):
@@ -44,79 +46,30 @@ class TestSubscription(TestCase):
@mock.patch.object(uuid, 'uuid4')
def test_subscribe_notification(self, mock_uuid4, mock_requests):
temp_uuid = "99442b18-a5c7-11e8-998c-bf1755941f13"
- dummy_subscription = {
- "callbackUri": "http://aurl.com",
- "authentication": {
- "authType": ["BASIC"],
- "paramsBasic": {
- "username": "username",
- "password": "password"
- }
- },
- "filter": {
- "notificationTypes": ["NsLcmOperationOccurrenceNotification"],
- "operationTypes": [
- "INSTANTIATE"
- ],
- "operationStates": [
- "STARTING"
- ],
- }
- }
mock_requests.return_value.status_code = 204
mock_requests.get.return_value.status_code = 204
mock_uuid4.return_value = temp_uuid
- response = self.client.post("/api/nslcm/v1/subscriptions", data=dummy_subscription, format='json')
+ response = self.client.post("/api/nslcm/v1/subscriptions", data=SUBSCRIPTION_NS_OPERATION_DICT, format='json')
self.assertEqual(201, response.status_code)
- self.assertEqual(dummy_subscription["callbackUri"], response.data["callbackUri"])
+ self.assertEqual(SUBSCRIPTION_NS_OPERATION_DICT["callbackUri"], response.data["callbackUri"])
self.assertEqual(temp_uuid, response.data["id"])
@mock.patch("requests.get")
- def test_invalid_auth_subscription(self, mock_requests):
- dummy_subscription = {
- "callbackUri": "http://aurl.com",
- "authentication": {
- "authType": ["OAUTH2_CLIENT_CREDENTIALS"],
- "paramsBasic": {
- "username": "username",
- "password": "password"
- }
- },
- "filter": {
- "notificationTypes": ["NsLcmOperationOccurrenceNotification"],
- "operationTypes": [
- "INSTANTIATE"
- ],
- "operationStates": [
- "STARTING"
- ],
- }
- }
+ def test_subscription_notification_invalide_auth(self, mock_requests):
mock_requests.return_value.status_code = 204
mock_requests.get.return_value.status_code = 204
-
expected_data = {
'status': 500,
'detail': 'Auth type should be BASIC'
}
- response = self.client.post("/api/nslcm/v1/subscriptions", data=dummy_subscription, format='json')
+ subscription = copy.deepcopy(SUBSCRIPTION_NS_OPERATION_DICT)
+ subscription["authentication"]["authType"] = ["OAUTH2_CLIENT_CREDENTIALS"]
+ response = self.client.post("/api/nslcm/v1/subscriptions", data=subscription, format='json')
self.assertEqual(500, response.status_code)
self.assertEqual(expected_data, response.data)
@mock.patch("requests.get")
def test_invalid_notification_type(self, mock_requests):
- dummy_subscription = {
- "callbackUri": "http://aurl.com",
- "filter": {
- "notificationTypes": ["NsIdentifierDeletionNotification"],
- "operationTypes": [
- "INSTANTIATE"
- ],
- "operationStates": [
- "STARTING"
- ],
- }
- }
mock_requests.return_value.status_code = 204
mock_requests.get.return_value.status_code = 204
expected_data = {
@@ -124,7 +77,7 @@ class TestSubscription(TestCase):
'detail': 'If you are setting operationTypes, notificationTypes must be '
'NsLcmOperationOccurrenceNotification'
}
- response = self.client.post("/api/nslcm/v1/subscriptions", data=dummy_subscription, format='json')
+ response = self.client.post("/api/nslcm/v1/subscriptions", data=SUBSCRIPTION_NS_DELETION_DICT, format='json')
self.assertEqual(500, response.status_code)
self.assertEqual(expected_data, response.data)
@@ -132,26 +85,14 @@ class TestSubscription(TestCase):
@mock.patch.object(uuid, 'uuid4')
def test_duplicate_subscription(self, mock_uuid4, mock_requests):
temp_uuid = str(uuid.uuid4())
- dummy_subscription = {
- "callbackUri": "http://aurl.com",
- "filter": {
- "notificationTypes": ["NsLcmOperationOccurrenceNotification"],
- "operationTypes": [
- "INSTANTIATE"
- ],
- "operationStates": [
- "STARTING"
- ]
- }
- }
mock_requests.return_value.status_code = 204
mock_requests.get.return_value.status_code = 204
mock_uuid4.return_value = temp_uuid
- response = self.client.post("/api/nslcm/v1/subscriptions", data=dummy_subscription, format='json')
+ response = self.client.post("/api/nslcm/v1/subscriptions", data=SUBSCRIPTION_NS_OPERATION_DICT, format='json')
self.assertEqual(201, response.status_code)
- self.assertEqual(dummy_subscription["callbackUri"], response.data["callbackUri"])
+ self.assertEqual(SUBSCRIPTION_NS_OPERATION_DICT["callbackUri"], response.data["callbackUri"])
self.assertEqual(temp_uuid, response.data["id"])
- response = self.client.post("/api/nslcm/v1/subscriptions", data=dummy_subscription, format='json')
+ response = self.client.post("/api/nslcm/v1/subscriptions", data=SUBSCRIPTION_NS_OPERATION_DICT, format='json')
self.assertEqual(303, response.status_code)
expected_data = {
'status': 303,