summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorying.yunlong <ying.yunlong@zte.com.cn>2017-09-14 10:18:33 +0800
committerying.yunlong <ying.yunlong@zte.com.cn>2017-09-14 10:21:00 +0800
commite1b19d12336bc3e92d038f97b08d4a9b132bc1e1 (patch)
tree58ab25e238b752fea3e824c11e786378154c66de
parent9adcfb57b0eda21da23b0270c07c59dd11b95238 (diff)
Create ns instance to aai and fix tests
Create ns instance to aai and fix the related unit test Change-Id: Ic6cbf95b8ffa9d382a491bb306ee515341e21473 Issue-ID: VFC-354 Signed-off-by: ying.yunlong <ying.yunlong@zte.com.cn>
-rw-r--r--lcm/ns/ns_create.py36
-rw-r--r--lcm/ns/tests/test_ns_create.py8
-rw-r--r--lcm/pub/msapi/aai.py2
3 files changed, 42 insertions, 4 deletions
diff --git a/lcm/ns/ns_create.py b/lcm/ns/ns_create.py
index 69d7ae5a..9017a09e 100644
--- a/lcm/ns/ns_create.py
+++ b/lcm/ns/ns_create.py
@@ -16,6 +16,7 @@ import uuid
from lcm.pub.database.models import NSDModel, NSInstModel
from lcm.pub.exceptions import NSLCMException
+from lcm.pub.msapi.aai import create_customer_aai
from lcm.pub.utils.timeutil import now_time
logger = logging.getLogger(__name__)
@@ -33,6 +34,7 @@ class CreateNSService(object):
self.check_nsd_valid()
self.check_ns_inst_name_exist()
self.create_ns_inst()
+ self.create_ns_in_aai()
logger.debug("CreateNSService::do_biz::ns_inst_id=%s" % self.ns_inst_id)
return self.ns_inst_id
@@ -53,7 +55,37 @@ class CreateNSService(object):
def create_ns_inst(self):
self.ns_inst_id = str(uuid.uuid4())
logger.debug("CreateNSService::create_ns_inst::ns_inst_id=%s" % self.ns_inst_id)
- NSInstModel(id=self.ns_inst_id, name=self.ns_name, nspackage_id=self.ns_package_id,
- nsd_id=self.nsd_id, description=self.description, status='empty',
+ NSInstModel(id=self.ns_inst_id, name=self.ns_name, nspackage_id=self.ns_package_id,
+ nsd_id=self.nsd_id, description=self.description, status='empty',
lastuptime=now_time()).save()
+ def create_ns_in_aai(self):
+ logger.debug("CreateNSService::create_ns_in_aai::report ns instance[%s] to aai." % self.ns_inst_id)
+ global_customer_id = "global-customer-id-" + self.ns_inst_id
+ data = {
+ "global-customer-id": "global-customer-id-" + self.ns_inst_id,
+ "subscriber-name": "subscriber-name-" + self.ns_inst_id,
+ "subscriber-type": "subscriber-type-" + self.ns_inst_id,
+ "service-subscriptions": {
+ "service-subscription": [
+ {
+ "service-type": "service-type-" + self.ns_inst_id,
+ "service-instances": {
+ "service-instance": [
+ {
+ "service-instance-id": self.ns_inst_id,
+ "service-instance-name": self.ns_name,
+ "service-type": "service-type-" + self.ns_inst_id,
+ "service-role": "service-role-" + self.ns_inst_id
+ }
+ ]
+ }
+ }
+ ]
+ }
+ }
+ resp_data, resp_status = create_customer_aai(global_customer_id, data)
+ if resp_data:
+ logger.debug("Fail to create ns instance[%s] to aai, resp_status: [%s]." % (self.ns_inst_id, resp_status) )
+ else:
+ logger.debug("Success to create ns instance[%s] to aai, resp_status: [%s]." % (self.ns_inst_id, resp_status) )
diff --git a/lcm/ns/tests/test_ns_create.py b/lcm/ns/tests/test_ns_create.py
index a1b836eb..c9e1e080 100644
--- a/lcm/ns/tests/test_ns_create.py
+++ b/lcm/ns/tests/test_ns_create.py
@@ -11,12 +11,15 @@
# 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.pub.database.models import NSInstModel, NSDModel
+from lcm.pub.utils import restcall
class TestNsInstantiate(TestCase):
@@ -30,7 +33,10 @@ class TestNsInstantiate(TestCase):
NSDModel.objects.all().delete()
NSInstModel.objects.all().delete()
- def test_create_ns(self):
+ @mock.patch.object(restcall, 'call_req')
+ def test_create_ns(self, mock_call_req):
+ r1_create_ns_to_aai = [0, json.JSONEncoder().encode({}), '201']
+ mock_call_req.side_effect = [r1_create_ns_to_aai]
data = {
'nsdid': self.nsd_id,
'nsname': 'ns',
diff --git a/lcm/pub/msapi/aai.py b/lcm/pub/msapi/aai.py
index c22b0380..402a9da8 100644
--- a/lcm/pub/msapi/aai.py
+++ b/lcm/pub/msapi/aai.py
@@ -45,7 +45,7 @@ def create_customer_aai(global_customer_id, data):
if ret[0] != 0:
logger.error("Status code is %s, detail is %s.", ret[2], ret[1])
raise NSLCMException("Customer creation exception in AAI")
- return json.JSONDecoder().decode(ret[1])
+ return json.JSONDecoder().decode(ret[1]), ret[2]
def get_customer_aai(global_customer_id):