aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormaopengzhang <zhang.maopeng1@zte.com.cn>2019-03-26 17:41:00 +0800
committermaopengzhang <zhang.maopeng1@zte.com.cn>2019-03-26 18:37:34 +0800
commit112c6623a3a5bd422446f99cd0615bf220bc65ec (patch)
treed06d100a4c3555856c9e793e95e4b3558123a99f
parentf329c36b11390cf8f6718bc366e67e07bb4b787b (diff)
add NS create test usecase
add NS create test usecase Change-Id: Ie7d13d9a01637f7a2258d75d7952d828f0be594f Issue-ID: VFC-1211 Signed-off-by: maopengzhang <zhang.maopeng1@zte.com.cn>
-rw-r--r--lcm/ns/biz/ns_create.py2
-rw-r--r--lcm/ns/biz/ns_get.py52
-rw-r--r--lcm/ns/tests/test_sol_ns_instances_api.py62
-rw-r--r--lcm/ns/views/sol/ns_instances_views.py3
4 files changed, 98 insertions, 21 deletions
diff --git a/lcm/ns/biz/ns_create.py b/lcm/ns/biz/ns_create.py
index 6bcc5a05..5fba81bc 100644
--- a/lcm/ns/biz/ns_create.py
+++ b/lcm/ns/biz/ns_create.py
@@ -72,7 +72,7 @@ class CreateNSService(object):
nsd_id=self.nsd_id,
nsd_invariant_id=self.nsd_invariant_id,
description=self.description,
- status='empty',
+ status='NOT_INSTANTIATED', # 'empty',
lastuptime=now_time(),
global_customer_id=self.global_customer_id,
service_type=self.service_type).save()
diff --git a/lcm/ns/biz/ns_get.py b/lcm/ns/biz/ns_get.py
index 0d1f77c8..0804b490 100644
--- a/lcm/ns/biz/ns_get.py
+++ b/lcm/ns/biz/ns_get.py
@@ -37,32 +37,46 @@ class GetNSInfoService(object):
def get_single_ns_info(self, ns_inst, is_sol=False):
if is_sol:
- return {
- 'id': ns_inst.id,
- 'nsInstanceName': ns_inst.name,
- 'nsInstanceDescription': ns_inst.description,
- 'nsdId': ns_inst.nsd_id,
- 'nsdInvariantId': ns_inst.nsd_invariant_id,
- 'nsdInfoId': ns_inst.nspackage_id,
- 'flavourId': ns_inst.flavour_id,
- 'nsState': ns_inst.status,
+ nsInstance = {}
+ nsInstance['id'] = ns_inst.id
+ if ns_inst.name:
+ nsInstance['nsInstanceName'] = ns_inst.name
+ if ns_inst.description:
+ nsInstance['nsInstanceDescription'] = ns_inst.description
+ if ns_inst.nsd_id:
+ nsInstance['nsdId'] = ns_inst.nsd_id
+ if ns_inst.nsd_invariant_id:
+ nsInstance['nsdInvariantId'] = ns_inst.nsd_invariant_id
+ if ns_inst.nspackage_id:
+ nsInstance['nsdInfoId'] = ns_inst.nspackage_id
+ if ns_inst.flavour_id:
+ nsInstance['flavourId'] = ns_inst.flavour_id
+ if ns_inst.status:
+ nsInstance['nsState'] = ns_inst.status
# todo 'nsScaleStatus':{}
# todo 'additionalAffinityOrAntiAffinityRule':{}
- 'vnfInstance': self.get_vnf_infos(ns_inst.id, is_sol),
+ logger.debug(" test ")
+ vnf_instance_list = self.get_vnf_infos(ns_inst.id, is_sol)
+ if vnf_instance_list:
+ nsInstance['vnfInstance'] = vnf_instance_list
# todo 'pnfInfo': self.get_pnf_infos(ns_inst.id,is_sol),
- 'virtualLinkInfo': self.get_vl_infos(ns_inst.id, is_sol),
+ vl_list = self.get_vl_infos(ns_inst.id, is_sol)
+ if vl_list:
+ nsInstance['virtualLinkInfo'] = vl_list
# todo 'vnffgInfo': self.get_vnffg_infos(ns_inst.id, ns_inst.nsd_model),
# todo 'sapInfo':{},
# todo nestedNsInstanceId
- '_links': {
- 'self': {'href': NS_INSTANCE_BASE_URI % ns_inst.id},
- 'instantiate': {'href': NS_INSTANCE_BASE_URI + '/instantiate' % ns_inst.id},
- 'terminate': {'href': NS_INSTANCE_BASE_URI + '/terminate' % ns_inst.id},
- 'update': {'href': NS_INSTANCE_BASE_URI + '/update' % ns_inst.id},
- 'scale': {'href': NS_INSTANCE_BASE_URI + '/scale' % ns_inst.id},
- 'heal': {'href': NS_INSTANCE_BASE_URI + '/heal' % ns_inst.id}
- }
+ logger.debug(" test ")
+ nsInstance['_links'] = {
+ 'self': {'href': NS_INSTANCE_BASE_URI % ns_inst.id},
+ 'instantiate': {'href': NS_INSTANCE_BASE_URI % ns_inst.id + '/instantiate'},
+ 'terminate': {'href': NS_INSTANCE_BASE_URI % ns_inst.id + '/terminate'},
+ 'update': {'href': NS_INSTANCE_BASE_URI % ns_inst.id + '/update'},
+ 'scale': {'href': NS_INSTANCE_BASE_URI % ns_inst.id + '/scale'},
+ 'heal': {'href': NS_INSTANCE_BASE_URI % ns_inst.id + '/heal'}
}
+ logger.debug(" test ")
+ return nsInstance
return {
'nsInstanceId': ns_inst.id,
'nsName': ns_inst.name,
diff --git a/lcm/ns/tests/test_sol_ns_instances_api.py b/lcm/ns/tests/test_sol_ns_instances_api.py
new file mode 100644
index 00000000..77e9e1cb
--- /dev/null
+++ b/lcm/ns/tests/test_sol_ns_instances_api.py
@@ -0,0 +1,62 @@
+# Copyright 2019 ZTE Corporation.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# 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 rest_framework.test import APIClient
+from lcm.pub.database.models import NSInstModel
+from lcm.pub.utils import restcall
+
+
+class TestNsInstanceApi(TestCase):
+ def setUp(self):
+ self.client = Client()
+ self.apiClient = APIClient()
+ self.format = 'json'
+ self.ns_instances_url = '/api/nslcm/v1/ns_instances'
+ self.nsd_id = str(uuid.uuid4())
+ self.ns_package_id = str(uuid.uuid4())
+
+ def tearDown(self):
+ NSInstModel.objects.all().delete()
+
+ @mock.patch.object(restcall, 'call_req')
+ def test_create_ns(self, mock_call_req):
+ nspackage_info = {
+ "csarId": self.ns_package_id,
+ "packageInfo": {
+ "nsPackageId": self.ns_package_id,
+ "nsdId": self.nsd_id
+ }
+ }
+ r1_query_nspackage_from_catalog = [0, json.JSONEncoder().encode(nspackage_info), '201']
+ r2_create_ns_to_aai = [0, json.JSONEncoder().encode({}), '201']
+ mock_call_req.side_effect = [r1_query_nspackage_from_catalog, r2_create_ns_to_aai]
+
+ header = {
+ 'HTTP_GLOBALCUSTOMERID': 'global-customer-id-test1',
+ 'HTTP_SERVICETYPE': 'service-type-test1'
+ }
+
+ data = {
+ "nsdId": self.nsd_id,
+ "nsName": "ns",
+ "nsDescription": "description"
+ }
+ response = self.apiClient.post(self.ns_instances_url, data=data, format=self.format, **header)
+
+ self.failUnlessEqual(status.HTTP_201_CREATED, response.status_code)
diff --git a/lcm/ns/views/sol/ns_instances_views.py b/lcm/ns/views/sol/ns_instances_views.py
index 1af7cf78..dbbdbb53 100644
--- a/lcm/ns/views/sol/ns_instances_views.py
+++ b/lcm/ns/views/sol/ns_instances_views.py
@@ -79,7 +79,7 @@ class NSInstancesView(APIView):
return Response(data={'nsInstanceId': "test"}, status=status.HTTP_201_CREATED)
csar_id = ignore_case_get(request.data, 'nsdId')
ns_name = ignore_case_get(request.data, 'nsName')
- description = ignore_case_get(request.data, 'description')
+ description = ignore_case_get(request.data, 'nsDescription')
context = {
"globalCustomerId": globalCustomerId,
"serviceType": serviceType
@@ -88,6 +88,7 @@ class NSInstancesView(APIView):
logger.debug("CreateNSView::post::ret={'nsInstanceId':%s}", ns_inst_id)
ns_filter = {"ns_inst_id": ns_inst_id}
nsInstance = GetNSInfoService(ns_filter).get_ns_info(is_sol=True)[0]
+ logger.debug("nsInstance: %s" % nsInstance)
resp_serializer = NsInstanceSerializer(data=nsInstance)
if not resp_serializer.is_valid():
raise NSLCMException(resp_serializer.errors)