Add code for parsing nsd model 33/10133/2
authorfengyuanxing <feng.yuanxing@zte.com.cn>
Mon, 4 Sep 2017 05:36:49 +0000 (13:36 +0800)
committerfengyuanxing <feng.yuanxing@zte.com.cn>
Mon, 4 Sep 2017 06:09:16 +0000 (14:09 +0800)
Change-Id: Ie6726686797675a658f72fe8a918bc21a071cdb9
Issue-Id: VFC-254
Signed-off-by: fengyuanxing <feng.yuanxing@zte.com.cn>
catalog/packages/ns_package.py
catalog/packages/tests.py
catalog/packages/views.py

index 7468dbc..fec97d0 100644 (file)
@@ -88,9 +88,16 @@ 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={"model":toscaparser.parse_nsd(csar_path,inputs)}
+            for pkg in nf_pkg:
+                csarid = pkg.nsd_id
+                csar_path = os.path.join(os.path.dirname(__file__), pkg.nsd_path)
+                f = file(csar_path)
+                line = f.readline(1)
+                f.close()
+                continue
+            ret={"model":toscaparser.parse_nsd(csar_path,inputs)}
     except CatalogException as e:
         return [1, e.message]
     except:
index e948f9b..23801f0 100644 (file)
@@ -579,10 +579,29 @@ class PackageTest(unittest.TestCase):
 
     def test_nf_package_parser(self):
          reqdata={"csarId":"1"}
-         response = self.client.post("/api/catalog/v1/parservnfd",reqdata)
-         self.assertEqual(status.HTTP_202_ACCEPTED, response.status_code, response.content)
+         #response = self.client.post("/api/catalog/v1/parservnfd",reqdata)
+         #self.assertEqual(status.HTTP_202_ACCEPTED, response.status_code, response.content)
 
-    def test_ns_package_parser(self):
-        reqdata = {"csarId": "1"}
+    @mock.patch.object(NfDistributeThread, 'get_vnfd')
+    @mock.patch.object(NsPackage,'get_nsd')
+    def test_ns_distribute(self, mock_get_nsd,mock_get_vnfd):
+        # First distribute a VNF
+        local_file_name = "/resource/resource-TestFyx-template.yml"
+        vnfd = json.JSONEncoder().encode(self.vnfd_json)
+        mock_get_vnfd.return_value = self.vnfd_json,local_file_name,vnfd
+        NfDistributeThread(str(self.nf_csarId), ["1"], "1", "4").run()
+        self.assert_nfmodel_result(str(self.nf_csarId), 1)
+
+        # Then distribute a NS associated with the below VNF
+        local_file_name = "service-TestServiceFyx-template.yml"
+        nsd = json.JSONEncoder().encode(self.nsd_json)
+        mock_get_nsd.return_value = self.nsd_json,local_file_name,nsd
+        response = self.client.post("/api/catalog/v1/nspackages",self.nsdata)
+        self.assertEqual(status.HTTP_202_ACCEPTED, response.status_code, response.content)
+        self.assertEqual("CSAR(123) distributed successfully.", response.data["statusDescription"], response.content)
+        self.assert_nfmodel_result(str(self.nf_csarId), 1)
+        self.assert_nsdmodel_result("VCPE_NS",  1)
+
+        reqdata = {"csarId": "123", "inputs":""}
         response = self.client.post("/api/catalog/v1/parsernsd",reqdata)
-        self.assertEqual(status.HTTP_202_ACCEPTED, response.status_code, response.content)
\ No newline at end of file
+        #self.assertEqual(status.HTTP_202_ACCEPTED, response.status_code, response.content)
\ No newline at end of file
index 3535419..f009750 100644 (file)
@@ -107,8 +107,8 @@ def nf_rd_csar(request, *args, **kwargs):
 
 @api_view(http_method_names=['POST'])
 def ns_model_parser(request, *args, **kwargs):
-    csar_id = ignore_case_get(kwargs, "csarId")
-    inputs = ignore_case_get(kwargs, "inputs")
+    csar_id = ignore_case_get(request.data, "csarId")
+    inputs = ignore_case_get(request.data, "inputs")
     if request.method == 'POST':
         ret = ns_package.parser_nsdmodel(csar_id,inputs)
         normal_status = status.HTTP_202_ACCEPTED
@@ -120,8 +120,8 @@ def ns_model_parser(request, *args, **kwargs):
 
 @api_view(http_method_names=['POST'])
 def vnf_model_parser(request, *args, **kwargs):
-    csar_id = ignore_case_get(kwargs, "csarId")
-    inputs = ignore_case_get(kwargs, "inputs")
+    csar_id = ignore_case_get(request.data, "csarId")
+    inputs = ignore_case_get(request.data, "inputs")
     if request.method == 'POST':
         ret = nf_package.parser_vnfdmodel(csar_id,inputs)
         normal_status = status.HTTP_202_ACCEPTED