Update vfc-catalog license head 63/13263/1
authorying.yunlong <ying.yunlong@zte.com.cn>
Tue, 19 Sep 2017 02:16:35 +0000 (10:16 +0800)
committerying.yunlong <ying.yunlong@zte.com.cn>
Tue, 19 Sep 2017 02:16:35 +0000 (10:16 +0800)
Change-Id: If7379fb0e0156034e503059473665f4c93fc2e0b
Issue-ID: VFC-376
Signed-off-by: ying.yunlong <ying.yunlong@zte.com.cn>
20 files changed:
catalog/packages/tests.py
catalog/packages/urls.py
catalog/pub/config/config.py
catalog/pub/database/models.py
catalog/pub/exceptions.py
catalog/pub/msapi/sdc.py
catalog/pub/utils/jobutil.py
catalog/samples/tests.py
catalog/samples/views.py
catalog/swagger/__init__.py
catalog/swagger/tests.py
catalog/swagger/urls.py
catalog/swagger/views.py
catalog/wsgi.py
docker/instance_run.sh
resources/bin/initDB.sh
resources/dbscripts/mysql/vfc-nfvo-catalog-createdb.sql
run.sh
stop.sh
version.properties

index 4084a79..8482eb0 100644 (file)
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import json
+import os
 import unittest
+
 import mock
-import os
-import catalog.pub.utils.restcall
-import json
-from catalog.packages.ns_package import NsPackage
-from catalog.packages.nf_package import NfPackage
-from catalog.packages.nf_package import NfDistributeThread
-from catalog.packages.nf_package import NfPkgDeleteThread
 from django.test import Client
-from catalog.pub.database.models import NSPackageModel, VnfPackageModel, JobStatusModel, JobModel
 from rest_framework import status
+
+from catalog.packages.nf_package import NfDistributeThread
+from catalog.packages.nf_package import NfPkgDeleteThread
+from catalog.packages.ns_package import NsPackage
+from catalog.pub.database.models import NSPackageModel, VnfPackageModel, JobStatusModel
 from catalog.pub.msapi import nfvolcm
 
 
@@ -46,7 +46,7 @@ class PackageTest(unittest.TestCase):
             },
             {
                 "csarId": "2",
-                 "nsdId": "2"
+                "nsdId": "2"
             }
         ]
 
@@ -54,38 +54,205 @@ class PackageTest(unittest.TestCase):
             "csarId": str(self.nf_csarId)
         }
 
-        self.vnfd_json = {
-            "metadata": {
-                "id": "456",
-                "vendor": "zte",
-                "version": "5.16.10",
-                "vnfd_version": "1.1.0",
-                "name": "zte_xgw",
-                "domain_type": "CN",
-                "vnf_type": "XGW",
-                "is_shared": "false",
-                "cross_dc": "false",
-                "vmnumber_overquota_alarm": "false",
-                "description": "",
-                "vnf_extend_type": "driver&script",
-                "plugin_info": "zte_cn_plugin_v6.16.10",
-                "script_info": "script/cn.py",
-                "adjust_vnf_capacity": "true",
-                "custom_properties": "",
-            },
-            "reserved_total": {
-                "vmnum": 10,
-                "vcpunum": 20,
-                "memorysize": 1000,
-                "portnum": 30,
-                "hdsize": 1024,
-                "shdsize": 2048,
-                "isreserve": 0,
-            },
-        }
+    def tearDown(self):
+        VnfPackageModel.objects.all().delete()
+        NSPackageModel.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]
+        response = self.client.get("/api/catalog/v1/nspackages")
+        self.assertEqual(status.HTTP_200_OK, response.status_code, response.content)
+        self.assertEquals(self.csars,response.data)
+
+    @mock.patch.object(NsPackage,'get_nsd')
+    def test_ns_distribute_2(self, mock_get_nsd):
+        local_file_name = "/url/local/filename"
+        nsd = json.JSONEncoder().encode(nsd_json)
+        mock_get_nsd.return_value = 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.assert_nsdmodel_result("VCPE_NS",  0)
+        self.assertEqual("VNF package(456) is not distributed.", response.data["statusDescription"], response.content)
+        NSPackageModel.objects.filter(nsPackageId="VCPE_NS").delete()
+
+    def test_nfpackages_get(self):
+        response = self.client.get("/api/catalog/v1/vnfpackages")
+        self.assertEqual(status.HTTP_200_OK, response.status_code, response.content)
+
+        nsdModel = NSPackageModel.objects.filter(nsdId="VCPE_NS")
+        self.assertEqual(len(nsdModel),0)
+
+
+    @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 = "/url/local/filename"
+        vnfd = json.JSONEncoder().encode(vnfd_json)
+        mock_get_vnfd.return_value = vnfd_json,local_file_name,vnfd
+        NfDistributeThread(str(self.nf_csarId), ["1"], "1", "4").run()
+
+        # Then distribute a NS associated with the below VNF
+        local_file_name = "/url/local/filename"
+        nsd = json.JSONEncoder().encode(nsd_json)
+        mock_get_nsd.return_value = 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_nsdmodel_result("VCPE_NS",  1)
+        VnfPackageModel.objects.filter(vnfdId=str(self.nf_csarId)).delete()
+        NSPackageModel.objects.filter(nsdId="VCPE_NS").delete()
+
+    @mock.patch.object(NfDistributeThread, 'get_vnfd')
+    def test_nf_distribute(self, mock_get_vnfd):
+        local_file_name = "/url/local/filename"
+        vnfd = json.JSONEncoder().encode(vnfd_json)
+        mock_get_vnfd.return_value = vnfd_json,local_file_name,vnfd
+
+        NfDistributeThread("dd", ["1"], "1", "5").run()
+        self.assert_job_result("5", 100, "CSAR(dd) distribute successfully.")
+        VnfPackageModel.objects.filter(vnfPackageId="dd").delete()
+
+    @mock.patch.object(NfDistributeThread, 'get_vnfd')
+    @mock.patch.object(NsPackage,'get_nsd')
+    @mock.patch.object(nfvolcm,'get_nsInstances')
+    def test_ns_package_delete(self, mock_get_nsInstances,mock_get_nsd,mock_get_vnfd):
+
+        # First distribute a VNF
+        local_file_name = "/url/local/filename"
+        vnfd = json.JSONEncoder().encode(vnfd_json)
+        mock_get_vnfd.return_value = 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 = "/url/local/filename"
+        nsd = json.JSONEncoder().encode(nsd_json)
+        mock_get_nsd.return_value = 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)
+
+        # Finally delete ns package
+        mock_get_nsInstances.return_value = []
+        response = self.client.delete("/api/catalog/v1/nspackages/" + str(self.ns_csarId))
+        self.assertEqual(status.HTTP_202_ACCEPTED, response.status_code, response.content)
+        self.assertEqual("Delete CSAR(123) successfully.", response.data["statusDescription"], response.content)
+        self.assert_nsdmodel_result("VCPE_NS",  0)
+
+    @mock.patch.object(NfDistributeThread, 'get_vnfd')
+    @mock.patch.object(NsPackage,'get_nsd')
+    @mock.patch.object(nfvolcm,'get_nsInstances')
+    def test_ns_package_delete_force(self, mock_get_nsInstances,mock_get_nsd,mock_get_vnfd):
+
+        # First distribute a VNF
+        local_file_name = "/url/local/filename"
+        vnfd = json.JSONEncoder().encode(vnfd_json)
+        mock_get_vnfd.return_value = 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 = "/url/local/filename"
+        nsd = json.JSONEncoder().encode(nsd_json)
+        mock_get_nsd.return_value = 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)
+
+        # Finally delete ns package
+        mock_get_nsInstances.return_value = [{"csarid":"1"},{"csarid":"2"}]
+        response = self.client.delete("/api/catalog/v1/nspackages/%sforce"% str(self.ns_csarId))
+        self.assertEqual(status.HTTP_202_ACCEPTED, response.status_code, response.content)
+        self.assertEqual("Delete CSAR(123) successfully.", response.data["statusDescription"], response.content)
+        self.assert_nsdmodel_result("VCPE_NS",  0)
+
+    def test_nf_package_delete_error(self):
+        # Delete it directly
+        self.assert_nfmodel_result("bb",0)
+        NfPkgDeleteThread("bb", "6", False).run()
+        self.assert_job_result("6", 100, "Error! CSAR(bb) does not exist.")
+
+
+    @mock.patch.object(NfDistributeThread, 'get_vnfd')
+    def test_nf_package_delete(self,mock_get_vnfd):
+        # First distribute a VNF
+        local_file_name = "/url/local/filename"
+        vnfd = json.JSONEncoder().encode(vnfd_json)
+        mock_get_vnfd.return_value = vnfd_json,local_file_name,vnfd
+
+        NfDistributeThread("bb", ["1"], "1", "5").run()
+        self.assert_job_result("5", 100, "CSAR(bb) distribute successfully.")
+        self.assert_nfmodel_result("bb",1)
+
+        # Then delete it
+        NfPkgDeleteThread("bb", "6", False).run()
+        self.assert_nfmodel_result("bb",0)
+
+    def assert_job_result(self, job_id, job_progress, job_detail):
+        jobs = JobStatusModel.objects.filter(
+            jobid=job_id,
+            progress=job_progress,
+            descp=job_detail)
+        self.assertEqual(1, len(jobs))
+
+    def assert_nsdmodel_result(self,nsd_id,size):
+        nsdmodels = NSPackageModel.objects.filter(nsdId = nsd_id)
+        self.assertEquals(size, len(nsdmodels))
+
+    def assert_nfmodel_result(self,csar_id,size):
+        vnfdmodels = VnfPackageModel.objects.filter(vnfPackageId = csar_id)
+        self.assertEquals(size, len(vnfdmodels))
+
+    @mock.patch.object(NfDistributeThread, 'get_vnfd')
+    def test_nf_package_parser(self, mock_get_vnfd):
+        # First distribute a VNF
+        template_file_name = "resource-TestFyx-template.yml"
+        local_file_name = os.path.join(os.path.dirname(__file__), template_file_name)
+        vnfd = json.JSONEncoder().encode(vnfd_json)
+        mock_get_vnfd.return_value = vnfd_json,local_file_name,vnfd
+        NfDistributeThread(str(self.nf_csarId), ["1"], "1", "4").run()
+        self.assert_nfmodel_result(str(self.nf_csarId), 1)
+        reqdata={"csarId":"456"}
+        #response = self.client.post("/api/catalog/v1/parservnfd",reqdata)
+        #self.assertEqual(status.HTTP_202_ACCEPTED, response.status_code, response.content)
+
+    @mock.patch.object(NfDistributeThread, 'get_vnfd')
+    @mock.patch.object(NsPackage,'get_nsd')
+    def test_ns_package_parser(self, mock_get_nsd,mock_get_vnfd):
+        # First distribute a VNF
+        template_file_name = "resource-TestFyx-template.yml"
+        local_file_name = os.path.join(os.path.dirname(__file__), template_file_name)
+        vnfd = json.JSONEncoder().encode(vnfd_json)
+        mock_get_vnfd.return_value = 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
+        template_file_name = "service-TestServiceFyx-template.yml"
+        local_file_name = os.path.join(os.path.dirname(__file__), template_file_name)
+        nsd = json.JSONEncoder().encode(nsd_json)
+        mock_get_nsd.return_value = 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)
 
-        self.nsd_json = {
 
+nsd_json = {
     "inputs": {
         "sfc_data_network": {
             "type": "string",
@@ -447,205 +614,33 @@ class PackageTest(unittest.TestCase):
         "description": "vcpe_ns"
     }
 }
-    def tearDown(self):
-        VnfPackageModel.objects.all().delete()
-        NSPackageModel.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]
-        response = self.client.get("/api/catalog/v1/nspackages")
-        self.assertEqual(status.HTTP_200_OK, response.status_code, response.content)
-        self.assertEquals(self.csars,response.data)
-
-    @mock.patch.object(NsPackage,'get_nsd')
-    def test_ns_distribute_2(self, mock_get_nsd):
-        local_file_name = "/url/local/filename"
-        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.assert_nsdmodel_result("VCPE_NS",  0)
-        self.assertEqual("VNF package(456) is not distributed.", response.data["statusDescription"], response.content)
-        NSPackageModel.objects.filter(nsPackageId="VCPE_NS").delete()
-
-    def test_nfpackages_get(self):
-        response = self.client.get("/api/catalog/v1/vnfpackages")
-        self.assertEqual(status.HTTP_200_OK, response.status_code, response.content)
-
-        nsdModel = NSPackageModel.objects.filter(nsdId="VCPE_NS")
-        self.assertEqual(len(nsdModel),0)
-
-
-    @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 = "/url/local/filename"
-        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()
-
-        # Then distribute a NS associated with the below VNF
-        local_file_name = "/url/local/filename"
-        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_nsdmodel_result("VCPE_NS",  1)
-        VnfPackageModel.objects.filter(vnfdId=str(self.nf_csarId)).delete()
-        NSPackageModel.objects.filter(nsdId="VCPE_NS").delete()
-
-    @mock.patch.object(NfDistributeThread, 'get_vnfd')
-    def test_nf_distribute(self, mock_get_vnfd):
-        local_file_name = "/url/local/filename"
-        vnfd = json.JSONEncoder().encode(self.vnfd_json)
-        mock_get_vnfd.return_value = self.vnfd_json,local_file_name,vnfd
-
-        NfDistributeThread("dd", ["1"], "1", "5").run()
-        self.assert_job_result("5", 100, "CSAR(dd) distribute successfully.")
-        VnfPackageModel.objects.filter(vnfPackageId="dd").delete()
-
-    @mock.patch.object(NfDistributeThread, 'get_vnfd')
-    @mock.patch.object(NsPackage,'get_nsd')
-    @mock.patch.object(nfvolcm,'get_nsInstances')
-    def test_ns_package_delete(self, mock_get_nsInstances,mock_get_nsd,mock_get_vnfd):
-
-        # First distribute a VNF
-        local_file_name = "/url/local/filename"
-        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 = "/url/local/filename"
-        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)
-
-        # Finally delete ns package
-        mock_get_nsInstances.return_value = []
-        response = self.client.delete("/api/catalog/v1/nspackages/" + str(self.ns_csarId))
-        self.assertEqual(status.HTTP_202_ACCEPTED, response.status_code, response.content)
-        self.assertEqual("Delete CSAR(123) successfully.", response.data["statusDescription"], response.content)
-        self.assert_nsdmodel_result("VCPE_NS",  0)
-
-    @mock.patch.object(NfDistributeThread, 'get_vnfd')
-    @mock.patch.object(NsPackage,'get_nsd')
-    @mock.patch.object(nfvolcm,'get_nsInstances')
-    def test_ns_package_delete_force(self, mock_get_nsInstances,mock_get_nsd,mock_get_vnfd):
-
-        # First distribute a VNF
-        local_file_name = "/url/local/filename"
-        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 = "/url/local/filename"
-        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)
-
-        # Finally delete ns package
-        mock_get_nsInstances.return_value = [{"csarid":"1"},{"csarid":"2"}]
-        response = self.client.delete("/api/catalog/v1/nspackages/%sforce"% str(self.ns_csarId))
-        self.assertEqual(status.HTTP_202_ACCEPTED, response.status_code, response.content)
-        self.assertEqual("Delete CSAR(123) successfully.", response.data["statusDescription"], response.content)
-        self.assert_nsdmodel_result("VCPE_NS",  0)
-
-    def test_nf_package_delete_error(self):
-        # Delete it directly
-        self.assert_nfmodel_result("bb",0)
-        NfPkgDeleteThread("bb", "6", False).run()
-        self.assert_job_result("6", 100, "Error! CSAR(bb) does not exist.")
-
-
-    @mock.patch.object(NfDistributeThread, 'get_vnfd')
-    def test_nf_package_delete(self,mock_get_vnfd):
-        # First distribute a VNF
-        local_file_name = "/url/local/filename"
-        vnfd = json.JSONEncoder().encode(self.vnfd_json)
-        mock_get_vnfd.return_value = self.vnfd_json,local_file_name,vnfd
 
-        NfDistributeThread("bb", ["1"], "1", "5").run()
-        self.assert_job_result("5", 100, "CSAR(bb) distribute successfully.")
-        self.assert_nfmodel_result("bb",1)
-
-        # Then delete it
-        NfPkgDeleteThread("bb", "6", False).run()
-        self.assert_nfmodel_result("bb",0)
-
-    def assert_job_result(self, job_id, job_progress, job_detail):
-        jobs = JobStatusModel.objects.filter(
-            jobid=job_id,
-            progress=job_progress,
-            descp=job_detail)
-        self.assertEqual(1, len(jobs))
-
-    def assert_nsdmodel_result(self,nsd_id,size):
-        nsdmodels = NSPackageModel.objects.filter(
-            nsdId = nsd_id
-        )
-
-        self.assertEquals(size, len(nsdmodels))
-
-    def assert_nfmodel_result(self,csar_id,size):
-        vnfdmodels = VnfPackageModel.objects.filter(
-            vnfPackageId = csar_id
-        )
-
-        self.assertEquals(size, len(vnfdmodels))
-
-    @mock.patch.object(NfDistributeThread, 'get_vnfd')
-    def test_nf_package_parser(self, mock_get_vnfd):
-        # First distribute a VNF
-        template_file_name = "resource-TestFyx-template.yml"
-        local_file_name = os.path.join(os.path.dirname(__file__), template_file_name)
-        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)
-        reqdata={"csarId":"456"}
-        #response = self.client.post("/api/catalog/v1/parservnfd",reqdata)
-        #self.assertEqual(status.HTTP_202_ACCEPTED, response.status_code, response.content)
-
-    @mock.patch.object(NfDistributeThread, 'get_vnfd')
-    @mock.patch.object(NsPackage,'get_nsd')
-    def test_ns_package_parser(self, mock_get_nsd,mock_get_vnfd):
-        # First distribute a VNF
-        template_file_name = "resource-TestFyx-template.yml"
-        local_file_name = os.path.join(os.path.dirname(__file__), template_file_name)
-        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
-        template_file_name = "service-TestServiceFyx-template.yml"
-        local_file_name = os.path.join(os.path.dirname(__file__), template_file_name)
-        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)
+vnfd_json = {
+    "metadata": {
+        "id": "456",
+        "vendor": "zte",
+        "version": "5.16.10",
+        "vnfd_version": "1.1.0",
+        "name": "zte_xgw",
+        "domain_type": "CN",
+        "vnf_type": "XGW",
+        "is_shared": "false",
+        "cross_dc": "false",
+        "vmnumber_overquota_alarm": "false",
+        "description": "",
+        "vnf_extend_type": "driver&script",
+        "plugin_info": "zte_cn_plugin_v6.16.10",
+        "script_info": "script/cn.py",
+        "adjust_vnf_capacity": "true",
+        "custom_properties": ""
+    },
+    "reserved_total": {
+        "vmnum": 10,
+        "vcpunum": 20,
+        "memorysize": 1000,
+        "portnum": 30,
+        "hdsize": 1024,
+        "shdsize": 2048,
+        "isreserve": 0
+    }
+}
\ No newline at end of file
index 4ddf688..a2b9f9d 100644 (file)
@@ -12,7 +12,8 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-from django.conf.urls import include, url
+from django.conf.urls import url
+
 from catalog.packages import views
 
 urlpatterns = [
index d6acc2b..9a13876 100644 (file)
@@ -11,7 +11,6 @@
 # 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 os
 
 # [MSB]
 MSB_SERVICE_IP = '127.0.0.1'
index 5b73d51..a5747a5 100644 (file)
@@ -11,6 +11,7 @@
 # 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.
+
 from django.db import models
 
 
@@ -33,6 +34,7 @@ class NSPackageModel(models.Model):
     class Meta:
         db_table = 'CATALOG_NSPACKAGE'
 
+
 class VnfPackageModel(models.Model):
     #uuid = models.CharField(db_column='UUID', primary_key=True, max_length=255)
     vnfPackageId = models.CharField(db_column='VNFPACKAGEID', primary_key=True, max_length=50)   #onboardedVnfPkgInfoId
@@ -73,6 +75,7 @@ class SoftwareImageModel(models.Model):
     class Meta:
         db_table = 'CATALOG_SOFTWAREIMAGEMODEL'
 
+
 class JobModel(models.Model):
     jobid = models.CharField(db_column='JOBID', primary_key=True, max_length=255)
     jobtype = models.CharField(db_column='JOBTYPE', max_length=255)
@@ -109,4 +112,3 @@ class JobStatusModel(models.Model):
     def toJSON(self):
         import json
         return json.dumps(dict([(attr, getattr(self, attr)) for attr in [f.name for f in self._meta.fields]]))
-
index c994b46..876cf07 100644 (file)
@@ -12,6 +12,5 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-
 class CatalogException(Exception):
     pass
index e65af4d..2eb8f11 100644 (file)
@@ -25,6 +25,7 @@ logger = logging.getLogger(__name__)
 ASSETTYPE_RESOURCES = "resources" 
 ASSETTYPE_SERVICES = "services"
 
+
 def call_sdc(resource, method, content=''):
     additional_headers = {
         'X-ECOMP-InstanceID': 'VFC',
@@ -55,6 +56,7 @@ sample of return value
     }
 ]
 """
+
 def get_artifacts(asset_type):
     resource = "/sdc/v1/catalog/{assetType}"
     resource = resource.format(assetType=asset_type)
@@ -64,6 +66,7 @@ def get_artifacts(asset_type):
         raise CatalogException("Failed to query artifacts(%s) from sdc." % asset_type)
     return json.JSONDecoder().decode(ret[1])
 
+
 def get_artifact(asset_type, csar_id):
     artifacts = get_artifacts(asset_type)
     for artifact in artifacts:
@@ -71,6 +74,7 @@ def get_artifact(asset_type, csar_id):
             return artifact
     raise CatalogException("Failed to query artifact(%s,%s) from sdc." % (asset_type, csar_id))
 
+
 def delete_artifact(asset_type, asset_id, artifact_id):
     resource = "/sdc/v1/catalog/{assetType}/{uuid}/artifacts/{artifactUUID}"
     resource = resource.format(assetType=asset_type, uuid=asset_id, artifactUUID=artifact_id)
@@ -80,6 +84,7 @@ def delete_artifact(asset_type, asset_id, artifact_id):
         raise CatalogException("Failed to delete artifacts(%s) from sdc." % artifact_id)
     return json.JSONDecoder().decode(ret[1])
 
+
 def download_artifacts(download_url, local_path, file_name):
     additional_headers = {
         'X-ECOMP-InstanceID': 'VFC',
@@ -100,14 +105,3 @@ def download_artifacts(download_url, local_path, file_name):
     local_file.write(ret[1])
     local_file.close()
     return local_file_name
-
-    
-
-    
-
-
-   
-
-
-
-
index c5e8cdf..79f2612 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright 2016-2017 ZTE Corporation.
+# Copyright 2017 ZTE Corporation.
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
index f54c372..9e4c027 100644 (file)
@@ -31,4 +31,3 @@ class SampleViewTest(unittest.TestCase):
         self.assertEqual(status.HTTP_200_OK, response.status_code, response.content)
         resp_data = json.loads(response.content)
         self.assertEqual({"status": "active"}, resp_data)
-
index bc1ebea..b113d06 100644 (file)
 import logging
 import traceback
 
-from rest_framework.views import APIView
-from rest_framework.response import Response
 from rest_framework import status
-from catalog.pub.database import models
-
+from rest_framework.response import Response
+from rest_framework.views import APIView
 
 logger = logging.getLogger(__name__)
 
@@ -32,6 +30,7 @@ class SampleList(APIView):
         logger.debug("get")
         return Response({"status": "active"})
 
+
 class TablesList(APIView):
     def delete(self, request, modelName):
         logger.debug("Start delete model %s", modelName)
@@ -47,7 +46,6 @@ class TablesList(APIView):
                 status=status.HTTP_500_INTERNAL_SERVER_ERROR)
         return Response(data={}, status=status.HTTP_204_NO_CONTENT)
 
-
     def get(self, request, modelName):
         logger.debug("Get model %s", modelName)
         count = 0
@@ -59,7 +57,3 @@ class TablesList(APIView):
             return Response(data={"error": "failed"}, 
                 status=status.HTTP_500_INTERNAL_SERVER_ERROR)
         return Response(data={"count": count}, status=status.HTTP_200_OK)
-
-
-
-
index 49c7b94..c7b6818 100644 (file)
@@ -1,10 +1,13 @@
-# Copyright 2016-2017 ZTE Corporation.
+# Copyright 2017 ZTE Corporation.
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at:
-#       http://www.apache.org/licenses/LICENSE-2.0
+# You may obtain a copy of the License at
+#
+#         http://www.apache.org/licenses/LICENSE-2.0
 #
 # Unless required by applicable law or agreed to in writing, software
 # distributed under the License is distributed on an "AS IS" BASIS,
 # 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.
index 46e3f0d..0664adb 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright 2016-2017 ZTE Corporation.
+# Copyright 2017 ZTE Corporation.
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -10,7 +10,7 @@
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
 import unittest
-import json
+
 from django.test import Client
 from rest_framework import status
 
index b807b88..a7da03d 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright 2016-2017 ZTE Corporation.
+# Copyright 2017 ZTE Corporation.
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -11,6 +11,7 @@
 # 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.
+
 from django.conf.urls import patterns, url
 from rest_framework.urlpatterns import format_suffix_patterns
 
index 3dc4c75..2258a66 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright 2016-2017 ZTE Corporation.
+# Copyright 2017 ZTE Corporation.
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
 # 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 logging
 import os
-import traceback
 
-from rest_framework import status
 from rest_framework.response import Response
 from rest_framework.views import APIView
 
-
 logger = logging.getLogger(__name__)
 
 
 class SwaggerJsonView(APIView):
-
     def get(self, request):
-
         json_file = os.path.join(os.path.dirname(__file__), 'vfc.catalog.swagger.json')
         f = open(json_file)
         json_data = json.JSONDecoder().decode(f.read())
         f.close()
-
         return Response(json_data)
-        
\ No newline at end of file
index 35f6db0..a0b4d5d 100644 (file)
@@ -12,7 +12,6 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-
 import os
 
 from django.core.wsgi import get_wsgi_application
index 3d89477..19d35ea 100755 (executable)
@@ -7,4 +7,4 @@ chmod +x run.sh
 while [ ! -f logs/runtime_catalog.log ]; do
     sleep 1
 done
-tail -F logs/runtime_catalog.log
\ No newline at end of file
+tail -F logs/runtime_catalog.log
index 0971e00..b4fe39e 100644 (file)
@@ -47,4 +47,3 @@ do
 done
 echo "init nfvocatalog database success!"
 exit 0
-
index 5e72e60..5776db4 100644 (file)
@@ -28,4 +28,4 @@ GRANT ALL PRIVILEGES ON mysql.* TO 'nfvocatalog'@'%' IDENTIFIED BY 'nfvocatalog'
 
 GRANT ALL PRIVILEGES ON nfvocatalog.* TO 'nfvocatalog'@'localhost' IDENTIFIED BY 'nfvocatalog' WITH GRANT OPTION;
 GRANT ALL PRIVILEGES ON mysql.* TO 'nfvocatalog'@'localhost' IDENTIFIED BY 'nfvocatalog' WITH GRANT OPTION;
-FLUSH PRIVILEGES; 
\ No newline at end of file
+FLUSH PRIVILEGES;
diff --git a/run.sh b/run.sh
index 4013654..d4c10a5 100644 (file)
--- a/run.sh
+++ b/run.sh
@@ -12,5 +12,6 @@
 # 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.
+
 sip=127.0.0.1
 nohup python manage.py runserver $sip:8806 > /dev/null &
diff --git a/stop.sh b/stop.sh
index 67aceb9..40ed3b6 100644 (file)
--- a/stop.sh
+++ b/stop.sh
@@ -12,5 +12,6 @@
 # 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.
+
 sip=127.0.0.1
 ps auxww | grep "manage.py runserver $sip:8806" | awk '{print $2}' | xargs kill -9
index 7f86aa1..e175101 100644 (file)
@@ -1,3 +1,17 @@
+# Copyright 2017 ZTE Corporation.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#         http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# 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.
+
 # Versioning variables
 # Note that these variables cannot be structured (e.g. : version.release or version.snapshot etc... )
 # because they are used in Jenkins, whose plug-in doesn't support