diff options
Diffstat (limited to 'catalog/packages')
-rw-r--r-- | catalog/packages/biz/sdc_ns_package.py | 18 | ||||
-rw-r--r-- | catalog/packages/tests/test_nspackage.py | 38 |
2 files changed, 29 insertions, 27 deletions
diff --git a/catalog/packages/biz/sdc_ns_package.py b/catalog/packages/biz/sdc_ns_package.py index 4f9d460..553abb0 100644 --- a/catalog/packages/biz/sdc_ns_package.py +++ b/catalog/packages/biz/sdc_ns_package.py @@ -19,7 +19,7 @@ import traceback from catalog.pub.config.config import CATALOG_ROOT_PATH, CATALOG_URL_PATH from catalog.pub.config.config import REG_TO_MSB_REG_PARAM -from catalog.pub.database.models import NSPackageModel +from catalog.pub.database.models import NSPackageModel, VnfPackageModel, PnfPackageModel from catalog.pub.exceptions import CatalogException from catalog.pub.msapi import sdc from catalog.pub.utils import toscaparser @@ -119,10 +119,20 @@ class NsPackage(object): if NSPackageModel.objects.filter(nsPackageId=csar_id): return [1, "NS CSAR(%s) already exists." % csar_id] - artifact = sdc.get_artifact(sdc.ASSETTYPE_SERVICES, csar_id) + ns = sdc.get_asset(sdc.ASSETTYPE_SERVICES, csar_id) + # check if the related resources exist + resources = ns.get('resources', None) + if resources: + for resource in resources: + if not VnfPackageModel.objects.filter(vnfPackageId=resource['resourceUUID']) and \ + not PnfPackageModel.objects.filter(pnfPackageId=resource['resourceUUID']): + logger.error("Resource [%s] is not distributed.", resource['resourceUUID']) + raise CatalogException("Resource (%s) is not distributed." % resource['resourceUUID']) + + # download csar package local_path = os.path.join(CATALOG_ROOT_PATH, csar_id) - csar_name = "%s.csar" % artifact.get("name", csar_id) - local_file_name = sdc.download_artifacts(artifact["toscaModelURL"], local_path, csar_name) + csar_name = "%s.csar" % ns.get("name", csar_id) + local_file_name = sdc.download_artifacts(ns["toscaModelURL"], local_path, csar_name) if local_file_name.endswith(".csar") or local_file_name.endswith(".zip"): artifact_vnf_file = fileutil.unzip_file(local_file_name, local_path, "Artifacts/Deployment/OTHER/ns.csar") if os.path.exists(artifact_vnf_file): diff --git a/catalog/packages/tests/test_nspackage.py b/catalog/packages/tests/test_nspackage.py index 0ca34a2..c282d47 100644 --- a/catalog/packages/tests/test_nspackage.py +++ b/catalog/packages/tests/test_nspackage.py @@ -47,13 +47,13 @@ class TestNsPackage(TestCase): @mock.patch.object(restcall, 'call_req') def test_ns_pkg_distribute_when_csar_not_exist(self, mock_call_req): - mock_call_req.return_value = [0, "[]", '200'] + mock_call_req.return_value = [0, "{}", '200'] 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( - "Failed to query artifact(services,1) from sdc.", + "Failed to get asset(services, 1) from sdc.", resp.data["statusDescription"]) @mock.patch.object(restcall, 'call_req') @@ -63,11 +63,11 @@ class TestNsPackage(TestCase): self, mock_parse_nsd, mock_download_artifacts, mock_call_req): mock_parse_nsd.return_value = json.JSONEncoder().encode(self.nsd_data) mock_download_artifacts.return_value = "/home/vcpe.csar" - mock_call_req.return_value = [0, json.JSONEncoder().encode([{ + mock_call_req.return_value = [0, json.JSONEncoder().encode({ "uuid": "1", "toscaModelURL": "https://127.0.0.1:1234/sdc/v1/vcpe.csar", "distributionStatus": "DISTRIBUTED" - }]), '200'] + }), '200'] NSPackageModel(nsPackageId="2", nsdId="VCPE_NS").save() resp = self.client.post( "/api/catalog/v1/nspackages", {"csarId": "1"}, format='json') @@ -84,11 +84,11 @@ class TestNsPackage(TestCase): self, mock_parse_nsd, mock_download_artifacts, mock_call_req): mock_parse_nsd.return_value = json.JSONEncoder().encode(self.nsd_data) mock_download_artifacts.return_value = "/home/vcpe.csar" - mock_call_req.return_value = [0, json.JSONEncoder().encode([{ + mock_call_req.return_value = [0, json.JSONEncoder().encode({ "uuid": "1", "toscaModelURL": "https://127.0.0.1:1234/sdc/v1/vcpe.csar", "distributionStatus": "DISTRIBUTED", - }]), '200'] + }), '200'] resp = self.client.post( "/api/catalog/v1/nspackages", {"csarId": "1"}, format='json') self.assertEqual(resp.status_code, status.HTTP_202_ACCEPTED) @@ -104,11 +104,11 @@ class TestNsPackage(TestCase): self, mock_parse_nsd, mock_download_artifacts, mock_call_req): mock_parse_nsd.return_value = json.JSONEncoder().encode(self.nsd_data) mock_download_artifacts.return_value = "/home/vcpe.csar" - mock_call_req.return_value = [0, json.JSONEncoder().encode([{ + mock_call_req.return_value = [0, json.JSONEncoder().encode({ "uuid": "1", "toscaModelURL": "https://127.0.0.1:1234/sdc/v1/vcpe.csar", "distributionStatus": "DISTRIBUTED" - }]), '200'] + }), '200'] VnfPackageModel(vnfPackageId="1", vnfdId="vcpe_vfw_zte_1_0").save() PnfPackageModel(pnfPackageId="1", pnfdId="m6000_s").save() resp = self.client.post( @@ -119,27 +119,19 @@ 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 = [{ + @mock.patch.object(restcall, 'call_req') + def test_ns_when_not_distributed_by_sdc(self, mock_call_req): + mock_call_req.return_value = [0, json.JSONEncoder().encode({ "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" - }] + "toscaModelURL": "https://127.0.0.1:1234/sdc/v1/vcpe.csar", + "distributionStatus": "DISTRIBUTION_APPROVED" + }), '200'] 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.", + "The asset (services,1) is not distributed from sdc.", resp.data["statusDescription"]) ########################################################################## |