aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--catalog/packages/biz/vnf_package.py24
-rw-r--r--catalog/packages/serializers/vnf_pkg_infos.py2
-rw-r--r--catalog/packages/tests/test_vnf_package.py63
3 files changed, 77 insertions, 12 deletions
diff --git a/catalog/packages/biz/vnf_package.py b/catalog/packages/biz/vnf_package.py
index d251f3ba..2c7c595a 100644
--- a/catalog/packages/biz/vnf_package.py
+++ b/catalog/packages/biz/vnf_package.py
@@ -69,7 +69,7 @@ def query_single(vnf_pkg_id):
nf_pkg = VnfPackageModel.objects.filter(vnfPackageId=vnf_pkg_id)
if not nf_pkg.exists():
raise CatalogException('VNF package(%s) does not exist.' % vnf_pkg_id)
- return fill_response_data(nf_pkg)
+ return fill_response_data(nf_pkg[0])
def delete_vnf_pkg(vnf_pkg_id):
@@ -152,18 +152,20 @@ class VnfPkgUploadThread(threading.Thread):
def fill_response_data(nf_pkg):
pkg_info = {}
- pkg_info["id"] = nf_pkg[0].vnfPackageId
- pkg_info["vnfdId"] = nf_pkg[0].vnfdId
- pkg_info["vnfProductName"] = nf_pkg[0].vnfdProductName
- pkg_info["vnfSoftwareVersion"] = nf_pkg[0].vnfSoftwareVersion
- pkg_info["vnfdVersion"] = nf_pkg[0].vnfdVersion
- pkg_info["checksum"] = json.JSONDecoder().decode(nf_pkg[0].checksum)
+ pkg_info["id"] = nf_pkg.vnfPackageId
+ pkg_info["vnfdId"] = nf_pkg.vnfdId
+ pkg_info["vnfProductName"] = nf_pkg.vnfdProductName
+ pkg_info["vnfSoftwareVersion"] = nf_pkg.vnfSoftwareVersion
+ pkg_info["vnfdVersion"] = nf_pkg.vnfdVersion
+ if nf_pkg.checksum:
+ pkg_info["checksum"] = json.JSONDecoder().decode(nf_pkg.checksum)
pkg_info["softwareImages"] = None # TODO
pkg_info["additionalArtifacts"] = None # TODO
- pkg_info["onboardingState"] = nf_pkg[0].onboardingState
- pkg_info["operationalState"] = nf_pkg[0].operationalState
- pkg_info["usageState"] = nf_pkg[0].usageState
- pkg_info["userDefinedData"] = json.JSONDecoder().decode(nf_pkg[0].userDefinedData)
+ pkg_info["onboardingState"] = nf_pkg.onboardingState
+ pkg_info["operationalState"] = nf_pkg.operationalState
+ pkg_info["usageState"] = nf_pkg.usageState
+ if nf_pkg.userDefinedData:
+ pkg_info["userDefinedData"] = json.JSONDecoder().decode(nf_pkg.userDefinedData)
pkg_info["_links"] = None # TODO
return pkg_info
diff --git a/catalog/packages/serializers/vnf_pkg_infos.py b/catalog/packages/serializers/vnf_pkg_infos.py
index 592ed071..d4cbc655 100644
--- a/catalog/packages/serializers/vnf_pkg_infos.py
+++ b/catalog/packages/serializers/vnf_pkg_infos.py
@@ -16,5 +16,5 @@ from rest_framework import serializers
from vnf_pkg_info import VnfPkgInfoSerializer
-class VnfPkgInfosSerializer(serializers.Serializer):
+class VnfPkgInfosSerializer(serializers.ListSerializer):
child = VnfPkgInfoSerializer()
diff --git a/catalog/packages/tests/test_vnf_package.py b/catalog/packages/tests/test_vnf_package.py
index cf49b89d..9a672ee5 100644
--- a/catalog/packages/tests/test_vnf_package.py
+++ b/catalog/packages/tests/test_vnf_package.py
@@ -328,3 +328,66 @@ class TestVnfPackage(TestCase):
}
self.assertEqual(response.data, expect_data)
self.assertEqual(response.status_code, status.HTTP_200_OK)
+
+ def test_query_multiple_vnf(self):
+ VnfPackageModel.objects.create(
+ vnfPackageId="111",
+ vnfdId="zte-hss-1.0",
+ vnfVendor="zte",
+ vnfdProductName="hss",
+ vnfSoftwareVersion="1.0.0",
+ vnfdVersion="1.0.0",
+ checksum='{"algorithm":"111", "hash": "11"}',
+ onboardingState="CREATED",
+ operationalState="DISABLED",
+ usageState="NOT_IN_USE",
+ userDefinedData='{"a": "A"}'
+ )
+ VnfPackageModel.objects.create(
+ vnfPackageId="222",
+ vnfdId="zte-hss-1.0",
+ vnfVendor="zte",
+ vnfdProductName="hss",
+ vnfSoftwareVersion="1.0.0",
+ vnfdVersion="1.0.0",
+ checksum='{"algorithm":"111", "hash": "11"}',
+ onboardingState="CREATED",
+ operationalState="DISABLED",
+ usageState="NOT_IN_USE",
+ userDefinedData='{"a": "A"}'
+ )
+ response = self.client.get("/api/vnfpkgm/v1/vnf_packages")
+ expect_data = [
+ {
+ "id": "111",
+ "vnfdId": "zte-hss-1.0",
+ "vnfProductName": "hss",
+ "vnfSoftwareVersion": "1.0.0",
+ "vnfdVersion": "1.0.0",
+ "checksum": {"algorithm": "111", "hash": "11"},
+ "softwareImages": None,
+ "additionalArtifacts": None,
+ "onboardingState": "CREATED",
+ "operationalState": "DISABLED",
+ "usageState": "NOT_IN_USE",
+ "userDefinedData": {"a": "A"},
+ "_links": None
+ },
+ {
+ "id": "222",
+ "vnfdId": "zte-hss-1.0",
+ "vnfProductName": "hss",
+ "vnfSoftwareVersion": "1.0.0",
+ "vnfdVersion": "1.0.0",
+ "checksum": {"algorithm": "111", "hash": "11"},
+ "softwareImages": None,
+ "additionalArtifacts": None,
+ "onboardingState": "CREATED",
+ "operationalState": "DISABLED",
+ "usageState": "NOT_IN_USE",
+ "userDefinedData": {"a": "A"},
+ "_links": None
+ }
+ ]
+ self.assertEqual(response.data, expect_data)
+ self.assertEqual(response.status_code, status.HTTP_200_OK)