Merge "SOL instantiate NS test via independant json file"
authorFu Jinhua <fu.jinhua@zte.com.cn>
Wed, 24 Apr 2019 08:21:29 +0000 (08:21 +0000)
committerGerrit Code Review <gerrit@onap.org>
Wed, 24 Apr 2019 08:21:29 +0000 (08:21 +0000)
docker/docker-env-conf.sh [changed mode: 0644->0755]
lcm/ns/biz/ns_get.py
lcm/ns/biz/ns_heal.py
lcm/ns/biz/query_subscription.py
lcm/ns/tests/test_query_subscriptions.py
lcm/settings.py
run.sh

old mode 100644 (file)
new mode 100755 (executable)
index 1839bf0..697d7c4 100644 (file)
@@ -17,8 +17,12 @@ import logging
 
 from lcm.ns.const import NS_INSTANCE_BASE_URI
 from lcm.ns.enum import OWNER_TYPE
-from lcm.pub.utils import restcall
-from lcm.pub.database.models import NSInstModel, NfInstModel, VLInstModel, CPInstModel, VNFFGInstModel
+from lcm.pub.database.models import NSInstModel
+from lcm.pub.database.models import NfInstModel
+from lcm.pub.database.models import VLInstModel
+from lcm.pub.database.models import CPInstModel
+from lcm.pub.database.models import VNFFGInstModel
+from lcm.pub.database.models import PNFInstModel
 
 logger = logging.getLogger(__name__)
 
@@ -167,9 +171,5 @@ class GetNSInfoService(object):
 
     @staticmethod
     def get_pnf_infos(ns_instance_id):
-        uri = "api/nslcm/v1/pnfs?nsInstanceId=%s" % ns_instance_id
-        ret = restcall.req_by_msb(uri, "GET")
-        if ret[0] == 0:
-            return json.loads(ret[1])
-        else:
-            return []
+        pnfs = PNFInstModel.objects.filter(nsInstances__contains=ns_instance_id)
+        return [pnf.__dict__ for pnf in pnfs]
index 20db772..096561e 100644 (file)
@@ -63,20 +63,22 @@ class NSHealService(threading.Thread):
     def get_and_check_params(self):
         ns_info = NSInstModel.objects.filter(id=self.ns_instance_id)
         if not ns_info:
-            logger.error('NS [id=%s] does not exist' % self.ns_instance_id)
-            raise NSLCMException(
-                'NS [id=%s] does not exist' % self.ns_instance_id)
+            errmsg = 'NS [id=%s] does not exist' % self.ns_instance_id
+            logger.error(errmsg)
+            raise NSLCMException(errmsg)
+
         self.heal_ns_data = ignore_case_get(self.request_data, 'healNsData')
         self.heal_vnf_data = ignore_case_get(self.request_data, 'healVnfData')
+
         if self.heal_ns_data and self.heal_vnf_data:
-            logger.error('healNsData and healVnfData can not exist together')
-            raise NSLCMException(
-                'healNsData and healVnfData can not exist together')
+            errmsg = 'healNsData and healVnfData can not exist together'
+            logger.error(errmsg)
+            raise NSLCMException(errmsg)
+
         if not self.heal_ns_data and not self.heal_vnf_data:
-            logger.error(
-                'healNsData and healVnfData parameters does not exist or value is incorrect.')
-            raise NSLCMException(
-                'healNsData and healVnfData parameters does not exist or value is incorrect.')
+            errmsg = 'healNsData and healVnfData parameters does not exist or value is incorrect.'
+            logger.error(errmsg)
+            raise NSLCMException(errmsg)
 
     def do_heal(self):
         if self.heal_vnf_data:
@@ -86,8 +88,9 @@ class NSHealService(threading.Thread):
                 logger.info('nf[%s] heal handle end' % vnf_heal_params.get('vnfInstanceId'))
                 self.update_job(90, desc='nf[%s] heal handle end' % vnf_heal_params.get('vnfInstanceId'))
             else:
-                logger.error('nf heal failed')
-                raise NSLCMException('nf heal failed')
+                errmsg = 'nf heal failed'
+                logger.error(errmsg)
+                raise NSLCMException(errmsg)
         else:
             ns_heal_params = self.prepare_ns_heal_params(self.heal_ns_data)
             for ns_heal_param in ns_heal_params:
@@ -96,8 +99,9 @@ class NSHealService(threading.Thread):
                     logger.info('nf[%s] heal handle end' % ns_heal_param.get('vnfInstanceId'))
                     self.update_job(90, desc='nf[%s] heal handle end' % ns_heal_param.get('vnfInstanceId'))
                 else:
-                    logger.error('nf heal failed')
-                    raise NSLCMException('nf heal failed')
+                    errmsg = 'nf heal failed'
+                    logger.error(errmsg)
+                    raise NSLCMException(errmsg)
 
     def do_vnf_or_ns_heal(self, heal_param, progress):
         instance_id = heal_param.get('vnfInstanceId')
@@ -111,8 +115,9 @@ class NSHealService(threading.Thread):
     def prepare_ns_heal_params(self, ns_data):
         degree_healing = ignore_case_get(ns_data, 'degreeHealing')
         if not degree_healing:
-            logger.error('degreeHealing does not exist.')
-            raise NSLCMException('degreeHealing does not exist.')
+            errmsg = 'degreeHealing does not exist.'
+            logger.error(errmsg)
+            raise NSLCMException(errmsg)
         ns_instance_id = self.ns_instance_id
         cause = 'vm is down'
         # action = ignore_case_get(ns_data, 'actionsHealing')
@@ -149,17 +154,16 @@ class NSHealService(threading.Thread):
                     result_arr.append(result)
             return result_arr
         else:
-            logger.error(
-                'The degree of healing dose not exist or value is incorrect.')
-            raise NSLCMException(
-                'The degree of healing dose not exist or value is incorrect.')
+            errmsg = 'The degree of healing dose not exist or value is incorrect.'
+            logger.error(errmsg)
+            raise NSLCMException(errmsg)
 
     def prepare_vnf_heal_params(self, vnf_data):
         vnf_instance_id = ignore_case_get(vnf_data, 'vnfInstanceId')
         if not vnf_instance_id:
-            logger.error('vnfinstanceid does not exist or value is incorrect.')
-            raise NSLCMException(
-                'vnfinstanceid does not exist or value is incorrect.')
+            errmsg = 'vnfinstanceid does not exist or value is incorrect.'
+            logger.error(errmsg)
+            raise NSLCMException(errmsg)
         cause = ignore_case_get(vnf_data, 'cause')
         additional_params = ignore_case_get(vnf_data, 'additionalParams')
         action = ignore_case_get(additional_params, 'action')
index 4b36aa7..237c87a 100644 (file)
@@ -17,7 +17,6 @@ import json
 import logging
 
 from lcm.pub.database.models import SubscriptionModel
-from lcm.pub.exceptions import NSLCMException
 
 logger = logging.getLogger(__name__)
 ROOT_FILTERS = {
@@ -55,8 +54,6 @@ class QuerySubscription:
             subscriptions = SubscriptionModel.objects.filter(**query_data)
         else:
             subscriptions = SubscriptionModel.objects.all()
-        if not subscriptions.exists():
-            raise NSLCMException('Subscriptions do not exist')
         return [self.fill_resp_data(subscription) for subscription in subscriptions]
 
     def fill_resp_data(self, subscription):
index 04759ee..c797a07 100644 (file)
@@ -115,7 +115,8 @@ class TestQuerySubscriptions(TestCase):
             links=json.dumps(links),
             ns_instance_filter=json.dumps(ns_instance_filter)).save()
         response = self.client.get("/api/nslcm/v1/subscriptions?nsInstanceId=dummy", format='json')
-        self.assertEqual(response.status_code, status.HTTP_500_INTERNAL_SERVER_ERROR)
+        self.assertEqual(response.status_code, status.HTTP_200_OK)
+        self.assertEqual([], response.data)
 
     def test_get_subscriptions_with_invalid_filter(self):
         ns_instance_filter = {
index f20f363..71e609b 100644 (file)
@@ -173,6 +173,7 @@ else:
 if 'test' in sys.argv:
     pub_config.REG_TO_MSB_WHEN_START = False
     pub_config.DEPLOY_WORKFLOW_WHEN_START = False
+    pub_config.REPORT_TO_AAI = False
     DATABASES = {}
     DATABASES['default'] = {
         'ENGINE': 'django.db.backends.sqlite3',
diff --git a/run.sh b/run.sh
index 8053d09..dccfd2e 100755 (executable)
--- a/run.sh
+++ b/run.sh
@@ -21,7 +21,7 @@ fi
 # nohup python manage.py runserver 0.0.0.0:8403 > /dev/null &
 #nohup uwsgi --http :8403 -t 120 --module lcm.wsgi --master --processes 4 &
 
-if [ ${SSL_ENABLED} = "true" ]; then
+if [ "${SSL_ENABLED}" = "true" ]; then
     nohup uwsgi --https :8403,lcm/pub/ssl/cert/foobar.crt,lcm/pub/ssl/cert/foobar.key, HIGH -t 120 --module lcm.wsgi --master --processes 4 &
 else
     nohup uwsgi --http :8403 -t 120 --module lcm.wsgi --master --processes 4 &