Restrict the download if not DISTRIBUTED 57/56057/2
authorBharath Thiruveedula <bharath.thiruveedula@verizon.com>
Tue, 10 Jul 2018 09:01:49 +0000 (14:31 +0530)
committerBharath Thiruveedula <bharath.thiruveedula@verizon.com>
Tue, 10 Jul 2018 09:33:23 +0000 (15:03 +0530)
The patch restricts the download of the artifacts(NSD) if it is
not distributed by operator in SDC.

Issue-ID: VFC-956
Change-Id: Ic4b18ef41c1210ac0f0e690d8e41d1972b1ff04a
Signed-off-by: Bharath Thiruveedula<bharath.thiruveedula@verizon.com>
catalog/packages/tests/test_ns.py
catalog/pub/msapi/sdc.py

index 020216a..5857b5d 100644 (file)
@@ -274,7 +274,8 @@ class TestNsPackage(TestCase):
         mock_download_artifacts.return_value = "/home/vcpe.csar"
         mock_call_req.return_value = [0, json.JSONEncoder().encode([{
             "uuid": "1",
-            "toscaModelURL": "https://127.0.0.1:1234/sdc/v1/vcpe.csar"
+            "toscaModelURL": "https://127.0.0.1:1234/sdc/v1/vcpe.csar",
+            "distributionStatus": "DISTRIBUTED"
         }]), '200']
         NSPackageModel(nsPackageId="2", nsdId="VCPE_NS").save()
         resp = self.client.post(
@@ -294,7 +295,8 @@ class TestNsPackage(TestCase):
         mock_download_artifacts.return_value = "/home/vcpe.csar"
         mock_call_req.return_value = [0, json.JSONEncoder().encode([{
             "uuid": "1",
-            "toscaModelURL": "https://127.0.0.1:1234/sdc/v1/vcpe.csar"
+            "toscaModelURL": "https://127.0.0.1:1234/sdc/v1/vcpe.csar",
+            "distributionStatus": "DISTRIBUTED",
         }]), '200']
         resp = self.client.post(
             "/api/catalog/v1/nspackages", {"csarId": "1"}, format='json')
@@ -313,7 +315,8 @@ class TestNsPackage(TestCase):
         mock_download_artifacts.return_value = "/home/vcpe.csar"
         mock_call_req.return_value = [0, json.JSONEncoder().encode([{
             "uuid": "1",
-            "toscaModelURL": "https://127.0.0.1:1234/sdc/v1/vcpe.csar"
+            "toscaModelURL": "https://127.0.0.1:1234/sdc/v1/vcpe.csar",
+            "distributionStatus": "DISTRIBUTED"
         }]), '200']
         VnfPackageModel(vnfPackageId="1", vnfdId="vcpe_vfw_zte_1_0").save()
         resp = self.client.post(
@@ -324,6 +327,29 @@ class TestNsPackage(TestCase):
             "CSAR(1) distributed successfully.",
             resp.data["statusDescription"])
 
+    @mock.patch.object(sdc, 'get_artifacts')
+    def test_ns_when_not_distributed_by_sdc(self, mock_get_artifacts):
+        mock_get_artifacts.return_value = [{
+            "uuid": "1",
+            "invariantUUID": "63eaec39-ffbe-411c-a838-448f2c73f7eb",
+            "name": "underlayvpn",
+            "version": "2.0",
+            "toscaModelURL": "/sdc/v1/catalog/resources/c94490a0-f7ef-48be-b3f8-8d8662a37236/toscaModel",
+            "category": "Volte",
+            "subCategory": "VolteVNF",
+            "resourceType": "VF",
+            "lifecycleState": "CERTIFIED",
+            "distributionStatus": "DISTRIBUTION_APPROVED",
+            "lastUpdaterUserId": "jh0003"
+        }]
+        resp = self.client.post(
+            "/api/catalog/v1/nspackages", {"csarId": "1"}, format='json')
+        self.assertEqual(resp.status_code, status.HTTP_202_ACCEPTED)
+        self.assertEqual("failed", resp.data["status"])
+        self.assertEqual(
+            "The artifact (services,1) is not distributed from sdc.",
+            resp.data["statusDescription"])
+
     ##########################################################################
 
     def test_ns_pkg_normal_delete(self):
index 147eedd..3db70c9 100644 (file)
@@ -25,6 +25,7 @@ logger = logging.getLogger(__name__)
 
 ASSETTYPE_RESOURCES = "resources"
 ASSETTYPE_SERVICES = "services"
+DISTRIBUTED = "DISTRIBUTED"
 
 
 def call_sdc(resource, method, content=''):
@@ -74,7 +75,11 @@ def get_artifact(asset_type, csar_id):
     artifacts = get_artifacts(asset_type)
     for artifact in artifacts:
         if artifact["uuid"] == csar_id:
-            return artifact
+            if asset_type == ASSETTYPE_SERVICES and \
+                    artifact.get("distributionStatus", None) != DISTRIBUTED:
+                raise CatalogException("The artifact (%s,%s) is not distributed from sdc." % (asset_type, csar_id))
+            else:
+                return artifact
     raise CatalogException("Failed to query artifact(%s,%s) from sdc." % (asset_type, csar_id))