aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormaopeng zhang <zhang.maopeng1@zte.com.cn>2017-09-02 07:42:22 +0000
committerGerrit Code Review <gerrit@onap.org>2017-09-02 07:42:22 +0000
commit3a01f015cfcbb6161c4329444e3999c0c8144b4a (patch)
tree6f87d873bd91fa3ea730ff9ab8a336ae033464d2
parent6ebc2fffe9417b0e81bae7a643b0498ca5341864 (diff)
parentaa2bab667e831b5f63f4086ed5537ca6e4ff5b0d (diff)
Merge "Add tosca parser"
-rw-r--r--catalog/packages/nf_package.py6
-rw-r--r--catalog/packages/ns_package.py10
-rw-r--r--catalog/packages/tests.py34
-rw-r--r--catalog/packages/urls.py4
-rw-r--r--catalog/packages/views.py8
-rw-r--r--catalog/pub/msapi/nfvolcm.py5
-rw-r--r--catalog/swagger/tests.py1
-rw-r--r--catalog/swagger/vfc.catalog.swagger.json101
8 files changed, 141 insertions, 28 deletions
diff --git a/catalog/packages/nf_package.py b/catalog/packages/nf_package.py
index 10fccdab..f2e1df93 100644
--- a/catalog/packages/nf_package.py
+++ b/catalog/packages/nf_package.py
@@ -59,18 +59,18 @@ def nf_get_csar(csar_id):
return ret
def parser_vnfmodel(csar_id,inputs):
- ret = None
+ ret= None
try:
nf_pkg = NfPackageModel.objects.filter(nfpackageid=csar_id)
if nf_pkg:
csar_path=nf_pkg["vnfd_path"]
- ret=toscaparser.parse_vnfd(csar_path,inputs)
+ ret={"model":toscaparser.parse_vnfd(csar_path,inputs)}
except CatalogException as e:
return [1, e.message]
except:
logger.error(traceback.format_exc())
return [1, str(sys.exc_info())]
- return ret
+ return [0,ret]
#####################################################################################
class NfDistributeThread(threading.Thread):
diff --git a/catalog/packages/ns_package.py b/catalog/packages/ns_package.py
index 5c32e4e6..8174b44d 100644
--- a/catalog/packages/ns_package.py
+++ b/catalog/packages/ns_package.py
@@ -84,19 +84,19 @@ def ns_get_csar(csar_id):
return [1, str(sys.exc_info())]
return ret
-def parser_nsmodel(csar_id,inputs):
- ret = None
+def parser_nsdmodel(csar_id,inputs):
+ ret= None
try:
nf_pkg = NSDModel.objects.filter(id=csar_id)
if nf_pkg:
csar_path=nf_pkg["nsd_path"]
- ret=toscaparser.parse_nsd(csar_path,inputs)
+ ret={"model":toscaparser.parse_nsd(csar_path,inputs)}
except CatalogException as e:
return [1, e.message]
except:
logger.error(traceback.format_exc())
return [1, str(sys.exc_info())]
- return ret
+ return [0,ret]
###############################################################################################################
@@ -167,7 +167,7 @@ class NsPackage(object):
"csarId": ns.id,
"nsdId": ns.nsd_id
})
- return [0, csars]
+ return [0,csars]
def get_csar(self, csar_id):
package_info = {}
diff --git a/catalog/packages/tests.py b/catalog/packages/tests.py
index d3ab8c27..d7658081 100644
--- a/catalog/packages/tests.py
+++ b/catalog/packages/tests.py
@@ -37,6 +37,17 @@ class PackageTest(unittest.TestCase):
"csarId": str(self.ns_csarId)
}
+ self.csars= [
+ {
+ "csarId": "1",
+ "nsdId": "1"
+ },
+ {
+ "csarId": "2",
+ "nsdId": "2"
+ }
+ ]
+
self.nfdata = {
"csarId": str(self.nf_csarId)
}
@@ -439,12 +450,14 @@ class PackageTest(unittest.TestCase):
NSDModel.objects.all().delete()
JobStatusModel.objects.all().delete()
+ @mock.patch.object(NsPackage, 'get_csars')
+ def test_nspackages_get(self,mock_get_csars):
+
+ mock_get_csars.return_value = [0,self.csars]
- def test_nspackages_get(self):
response = self.client.get("/api/catalog/v1/nspackages")
- print response
self.assertEqual(status.HTTP_200_OK, response.status_code, response.content)
- self.assertEquals([],response.data)
+ self.assertEquals(self.csars,response.data)
@mock.patch.object(NsPackage,'get_nsd')
def test_ns_distribute_2(self, mock_get_nsd):
@@ -565,15 +578,12 @@ class PackageTest(unittest.TestCase):
self.assertEquals(size, len(vnfdmodels))
-
def test_nf_package_parser(self):
- # reqdata={"csarId":"1"}
- # response = self.client.post("api/catalog/v1/vnfpackages/model",reqdata)
- # self.assertEqual(status.HTTP_202_ACCEPTED, response.status_code, response.content)
- pass
+ reqdata={"csarId":"1"}
+ response = self.client.post("/api/catalog/v1/vnfpackagemodel",reqdata)
+ self.assertEqual(status.HTTP_202_ACCEPTED, response.status_code, response.content)
def test_ns_package_parser(self):
- # reqdata={"csarId":"1"}
- # response = self.client.post("api/catalog/v1/nspackages/model",reqdata)
- # self.assertEqual(status.HTTP_202_ACCEPTED, response.status_code, response.content)
- pass \ No newline at end of file
+ reqdata = {"csarId": "1"}
+ response = self.client.post("/api/catalog/v1/nspackagemodel",reqdata)
+ self.assertEqual(status.HTTP_202_ACCEPTED, response.status_code, response.content) \ No newline at end of file
diff --git a/catalog/packages/urls.py b/catalog/packages/urls.py
index 2768ee3b..f372464e 100644
--- a/catalog/packages/urls.py
+++ b/catalog/packages/urls.py
@@ -20,8 +20,8 @@ urlpatterns = [
url(r'^api/catalog/v1/nspackages/(?P<csarId>[0-9a-zA-Z\-\_]+)$', views.ns_rd_csar, name='nspackage_rd'),
url(r'^api/catalog/v1/vnfpackages$', views.nfpackages_rc, name='nfpackages_rc'),
url(r'^api/catalog/v1/vnfpackages/(?P<csarId>[0-9a-zA-Z\-\_]+)$', views.nf_rd_csar, name='nfpackage_rd'),
- url(r'^api/catalog/v1/nspackages/model', views.ns_model_parser, name='ns_model_parser'),
- url(r'^api/catalog/v1/vnfpackages/model', views.vnf_model_parser, name='vnf_model_parser')
+ url(r'^api/catalog/v1/nspackagemodel$', views.ns_model_parser, name='nsmodelparser_rc'),
+ url(r'^api/catalog/v1/vnfpackagemodel$', views.vnf_model_parser, name='vnfmodelparser_rc'),
]
diff --git a/catalog/packages/views.py b/catalog/packages/views.py
index 248c6a11..d4e44cd3 100644
--- a/catalog/packages/views.py
+++ b/catalog/packages/views.py
@@ -110,8 +110,8 @@ def ns_model_parser(request, *args, **kwargs):
csar_id = ignore_case_get(kwargs, "csarId")
inputs = ignore_case_get(kwargs, "inputs")
if request.method == 'POST':
- ret = ns_package.parser_nsmodel(csar_id,inputs)
- normal_status = status.HTTP_200_OK
+ ret = ns_package.parser_nsdmodel(csar_id,inputs)
+ normal_status = status.HTTP_202_ACCEPTED
logger.info("Leave %s, Return value is %s", fun_name(), str(ret))
if ret[0] != 0:
@@ -123,8 +123,8 @@ def vnf_model_parser(request, *args, **kwargs):
csar_id = ignore_case_get(kwargs, "csarId")
inputs = ignore_case_get(kwargs, "inputs")
if request.method == 'POST':
- ret = nf_package.parser_nfmodel(csar_id,inputs)
- normal_status = status.HTTP_200_OK
+ ret = nf_package.parser_vnfmodel(csar_id,inputs)
+ normal_status = status.HTTP_202_ACCEPTED
logger.info("Leave %s, Return value is %s", fun_name(), str(ret))
if ret[0] != 0:
diff --git a/catalog/pub/msapi/nfvolcm.py b/catalog/pub/msapi/nfvolcm.py
index e25430ec..17cf686d 100644
--- a/catalog/pub/msapi/nfvolcm.py
+++ b/catalog/pub/msapi/nfvolcm.py
@@ -33,6 +33,11 @@ def call_lcm(resource, method, content=''):
method=method,
content=content)
+def get_nsInstances(csarid):
+ nsInstances=call_lcm("/nlcm/v1/ns ","get")
+
+
+
# Mock code because the REST API from nfvolcm to delete ns instance is not implemented
def delete_ns_inst_mock():
return [0,'success']
diff --git a/catalog/swagger/tests.py b/catalog/swagger/tests.py
index 40aaea70..46e3f0db 100644
--- a/catalog/swagger/tests.py
+++ b/catalog/swagger/tests.py
@@ -24,7 +24,6 @@ class SampleViewTest(unittest.TestCase):
def test_sample(self):
response = self.client.get("/api/catalog/v1/swagger.json")
- print response
self.assertEqual(status.HTTP_200_OK, response.status_code, response.content)
# resp_data = json.loads(response.content)
# self.assertEqual({"status": "active"}, resp_data)
diff --git a/catalog/swagger/vfc.catalog.swagger.json b/catalog/swagger/vfc.catalog.swagger.json
index ece4cd4d..5ff983e9 100644
--- a/catalog/swagger/vfc.catalog.swagger.json
+++ b/catalog/swagger/vfc.catalog.swagger.json
@@ -144,6 +144,44 @@
}
}
},
+ "/nspackagemodel": {
+ "post": {
+ "tags": [
+ "model"
+ ],
+ "summary": "ns package model",
+ "description": "ns package model",
+ "operationId": "ms_model_parser",
+ "consumes": [
+ "application/json"
+ ],
+ "produces": [
+ "application/json"
+ ],
+ "parameters": [
+ {
+ "in": "body",
+ "name": "body",
+ "description": "distribute request param",
+ "required": true,
+ "schema": {
+ "$ref": "#/definitions/modelParserRequest"
+ }
+ }
+ ],
+ "responses": {
+ "202": {
+ "description": "",
+ "schema": {
+ "$ref": "#/definitions/modelParserResponse"
+ }
+ },
+ "500": {
+ "description": "internal error"
+ }
+ }
+ }
+ },
"/vnfpackages": {
"get": {
"tags": [
@@ -277,7 +315,45 @@
}
}
}
- }
+ },
+ "/vnfpackagemodel": {
+ "post": {
+ "tags": [
+ "model"
+ ],
+ "summary": "vnf package model",
+ "description": "vnf package model",
+ "operationId": "vnf_model_parser",
+ "consumes": [
+ "application/json"
+ ],
+ "produces": [
+ "application/json"
+ ],
+ "parameters": [
+ {
+ "in": "body",
+ "name": "body",
+ "description": "distribute request param",
+ "required": true,
+ "schema": {
+ "$ref": "#/definitions/modelParserRequest"
+ }
+ }
+ ],
+ "responses": {
+ "202": {
+ "description": "",
+ "schema": {
+ "$ref": "#/definitions/modelParserResponse"
+ }
+ },
+ "500": {
+ "description": "internal error"
+ }
+ }
+ }
+ }
},
"definitions": {
"NsPkgDistributeRequest": {
@@ -505,6 +581,29 @@
"description": "image file path in the csar or image url in external repository"
}
}
+ },
+ "modelParserRequest":{
+ "type": "object",
+ "properties": {
+ "csarId": {
+ "type": "string",
+ "description": "csar Package Id"
+ },
+ "inputs": {
+ "type": "string",
+ "description": "csar package inputs"
+ }
+ }
+ },
+ "modelParserResponse":{
+ "type": "object",
+ "properties": {
+ "model": {
+ "type": "string",
+ "description": "model json data"
+ }
+ }
}
+
}
} \ No newline at end of file