From: Bharath Thiruveedula Date: Tue, 10 Jul 2018 09:01:49 +0000 (+0530) Subject: Restrict the download if not DISTRIBUTED X-Git-Tag: 1.2.0~147 X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=98bbf0dae2c94636a1b590c9c3de17a0b542506f;p=vfc%2Fnfvo%2Fcatalog.git Restrict the download if not DISTRIBUTED 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 --- diff --git a/catalog/packages/tests/test_ns.py b/catalog/packages/tests/test_ns.py index 020216a1..5857b5da 100644 --- a/catalog/packages/tests/test_ns.py +++ b/catalog/packages/tests/test_ns.py @@ -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): diff --git a/catalog/pub/msapi/sdc.py b/catalog/pub/msapi/sdc.py index 147eedd5..3db70c96 100644 --- a/catalog/pub/msapi/sdc.py +++ b/catalog/pub/msapi/sdc.py @@ -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))