summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorying.yunlong <ying.yunlong@zte.com.cn>2017-09-27 14:31:05 +0800
committerying.yunlong <ying.yunlong@zte.com.cn>2017-09-27 14:31:05 +0800
commit841223af12a9db964e9b6d5684b36f71567198b6 (patch)
tree34782acba68e2a10f158ac47481e4f9365b01501
parentf2d0476ad1ecf19b6d9d5428cdfc6c180d10b401 (diff)
Add query ns package from vfc-nfvo-catalog
Change-Id: I1f62e1ec0b88e4fc41343e6ac35f435a4105c003 Issue-ID: VFC-464 Signed-off-by: ying.yunlong <ying.yunlong@zte.com.cn>
-rw-r--r--lcm/ns/ns_create.py5
-rw-r--r--lcm/ns/tests/test_ns_create.py11
-rw-r--r--lcm/pub/msapi/sdc_run_catalog.py8
3 files changed, 18 insertions, 6 deletions
diff --git a/lcm/ns/ns_create.py b/lcm/ns/ns_create.py
index ff501073..058c7712 100644
--- a/lcm/ns/ns_create.py
+++ b/lcm/ns/ns_create.py
@@ -18,6 +18,7 @@ from lcm.pub.config.config import REPORT_TO_AAI
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.msapi.sdc_run_catalog import query_nspackage_by_id
from lcm.pub.utils.timeutil import now_time
logger = logging.getLogger(__name__)
@@ -42,10 +43,10 @@ class CreateNSService(object):
def check_nsd_valid(self):
logger.debug("CreateNSService::check_nsd_valid::nsd_id=%s" % self.nsd_id)
- ns_package_info = NSDModel.objects.filter(nsd_id=self.nsd_id)
+ ns_package_info = query_nspackage_by_id(self.nsd_id)
if not ns_package_info:
raise NSLCMException("nsd(%s) not exists." % self.nsd_id)
- self.ns_package_id = ns_package_info[0].id
+ self.ns_package_id = ns_package_info["csarId"]
logger.debug("CreateNSService::check_nsd_valid::ns_package_id=%s" % self.ns_package_id)
def check_ns_inst_name_exist(self):
diff --git a/lcm/ns/tests/test_ns_create.py b/lcm/ns/tests/test_ns_create.py
index 3847764f..293dfb37 100644
--- a/lcm/ns/tests/test_ns_create.py
+++ b/lcm/ns/tests/test_ns_create.py
@@ -30,16 +30,19 @@ class TestNsInstantiate(TestCase):
self.client = Client()
self.nsd_id = str(uuid.uuid4())
self.ns_package_id = str(uuid.uuid4())
- NSDModel(id=self.ns_package_id, nsd_id=self.nsd_id, name='name').save()
def tearDown(self):
- NSDModel.objects.all().delete()
NSInstModel.objects.all().delete()
@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]
+ nspackage_info = {
+ "csarId": self.ns_package_id,
+ "packageInfo": {}
+ }
+ 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]
data = {
'nsdid': self.nsd_id,
'nsname': 'ns',
diff --git a/lcm/pub/msapi/sdc_run_catalog.py b/lcm/pub/msapi/sdc_run_catalog.py
index 45383c25..6e093d93 100644
--- a/lcm/pub/msapi/sdc_run_catalog.py
+++ b/lcm/pub/msapi/sdc_run_catalog.py
@@ -37,3 +37,11 @@ def parse_vnfd(csar_id, input_parameters=[]):
logger.error("Status code is %s, detail is %s.", ret[2], ret[1])
raise NSLCMException("Failed to parse_vnfd of CSAR(%s) from catalog." % csar_id)
return json.JSONDecoder().decode(ret[1])
+
+
+def query_nspackage_by_id(csar_id):
+ ret = req_by_msb("/api/catalog/v1/nspackages/%s" % csar_id, "GET")
+ if ret[0] != 0:
+ logger.error("Status code is %s, detail is %s.", ret[2], ret[1])
+ raise NSLCMException("Failed to query CSAR(%s) from catalog." % csar_id)
+ return json.JSONDecoder().decode(ret[1])