summaryrefslogtreecommitdiffstats
path: root/catalog
diff options
context:
space:
mode:
authordyh <dengyuanhong@chinamobile.com>2019-12-04 16:19:38 +0800
committerdyh <dengyuanhong@chinamobile.com>2019-12-04 16:22:35 +0800
commitf96008008bcbefd4142611c9ecca45899c5bb7d6 (patch)
tree3594854d280b97393595989cd903fd5f2a8bd2d2 /catalog
parent06bfcce3f57176e6b428e43e8e411e245a5fa75e (diff)
update ns on_distribute method
Issue-ID: MODELING-289 Change-Id: Iba353d152b4895a93d0d41ac58afd63f1845c5d4 Signed-off-by: dyh <dengyuanhong@chinamobile.com>
Diffstat (limited to 'catalog')
-rw-r--r--catalog/packages/biz/sdc_ns_package.py18
-rw-r--r--catalog/packages/tests/test_nspackage.py38
-rw-r--r--catalog/pub/msapi/sdc.py2
-rw-r--r--catalog/settings.py9
4 files changed, 39 insertions, 28 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"])
##########################################################################
diff --git a/catalog/pub/msapi/sdc.py b/catalog/pub/msapi/sdc.py
index bb473cc..4b50aab 100644
--- a/catalog/pub/msapi/sdc.py
+++ b/catalog/pub/msapi/sdc.py
@@ -90,6 +90,8 @@ def get_asset(asset_type, uuid):
logger.error("Status code is %s, detail is %s.", ret[2], ret[1])
raise CatalogException("Failed to get asset(%s, %s) from sdc." % (asset_type, uuid))
asset = json.JSONDecoder().decode(ret[1])
+ if len(asset) == 0:
+ raise CatalogException("Failed to get asset(%s, %s) from sdc." % (asset_type, uuid))
if asset.get("distributionStatus", None) != DISTRIBUTED:
raise CatalogException("The asset (%s,%s) is not distributed from sdc." % (asset_type, uuid))
else:
diff --git a/catalog/settings.py b/catalog/settings.py
index df9d5f0..40c7565 100644
--- a/catalog/settings.py
+++ b/catalog/settings.py
@@ -23,6 +23,7 @@ from catalog.pub.config.config import DB_NAME, DB_IP, DB_USER, DB_PASSWD, DB_POR
from catalog.pub.config import config as pub_config
from logging import config as log_config
from onaplogging import monkey
+
monkey.patch_all()
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
@@ -161,11 +162,16 @@ if platform.system() == 'Windows' or 'test' in sys.argv:
'maxBytes': 1024 * 1024 * 50,
'backupCount': 5,
},
+ 'console': {
+ 'level': 'DEBUG',
+ 'class': 'logging.StreamHandler',
+ 'formatter': 'standard'
+ },
},
'loggers': {
'catalog': {
- 'handlers': ['catalog_handler'],
+ 'handlers': ['catalog_handler', 'console'],
'level': 'DEBUG',
'propagate': False
},
@@ -200,5 +206,6 @@ if 'test' in sys.argv:
import mock
from catalog.pub.utils import idutil
+
idutil.get_auto_id = mock.Mock()
idutil.get_auto_id.return_value = 1