_links is not implemented in the response of the Query VNF API 88/101888/4
authorhongyuzhao <zhao.hongyu@zte.com.cn>
Tue, 18 Feb 2020 10:10:21 +0000 (18:10 +0800)
committerhongyuzhao <zhao.hongyu@zte.com.cn>
Wed, 19 Feb 2020 04:31:30 +0000 (12:31 +0800)
Change-Id: Ia5a7de02c05ef75f5dfb0729a25d4d86ffd1ead8
Issue-ID: MODELING-312
Signed-off-by: hongyuzhao <zhao.hongyu@zte.com.cn>
catalog/packages/biz/vnf_package.py
catalog/packages/tests/test_vnf_package.py

index 6dec204..1073879 100644 (file)
@@ -25,7 +25,7 @@ import zipfile
 from catalog.packages import const
 from catalog.packages.biz.common import parse_file_range, read, save
 from catalog.packages.biz.notificationsutil import PkgNotifications
-from catalog.pub.config.config import CATALOG_ROOT_PATH
+from catalog.pub.config.config import CATALOG_ROOT_PATH, MSB_SERVICE_IP, MSB_SERVICE_PORT
 from catalog.pub.database.models import VnfPackageModel, NSPackageModel
 from catalog.pub.exceptions import CatalogException, ResourceNotFoundException
 from catalog.pub.utils import fileutil, toscaparser
@@ -279,6 +279,21 @@ def fill_artifacts_data(vnf_pkg_id):
             } for artifact in artifacts]
 
 
+def fill_links(pkg_id, is_onboarded=False):
+    self_href = "http://%s:%s/api/vnfpkgm/v1/vnf_packages/%s" % (
+        MSB_SERVICE_IP,
+        MSB_SERVICE_PORT,
+        pkg_id)
+    links = {
+        "self": {"href": self_href},
+        "vnfd": {"href": "%s/%s" % (self_href, "vnfd")},
+        "packageContent": {"href": "%s/%s" % (self_href, "package_content")}
+    }
+    if not is_onboarded:
+        links.pop("vnfd")
+    return links
+
+
 def fill_response_data(nf_pkg):
     pkg_info = {}
     pkg_info["id"] = nf_pkg.vnfPackageId
@@ -295,7 +310,7 @@ def fill_response_data(nf_pkg):
     pkg_info["usageState"] = nf_pkg.usageState
     if nf_pkg.userDefinedData:
         pkg_info["userDefinedData"] = json.JSONDecoder().decode(nf_pkg.userDefinedData)
-    pkg_info["_links"] = None  # TODO
+    pkg_info["_links"] = fill_links(nf_pkg.vnfPackageId, True)
     return pkg_info
 
 
index 8deb9ec..0b78cbd 100644 (file)
@@ -150,7 +150,10 @@ class TestVnfPackage(TestCase):
             "operationalState": "DISABLED",
             "usageState": "NOT_IN_USE",
             "userDefinedData": {"a": "A"},
-            "_links": None
+            "_links": {'self': {'href': 'http://127.0.0.1:80/api/vnfpkgm/v1/vnf_packages/222'},
+                       'vnfd': {'href': 'http://127.0.0.1:80/api/vnfpkgm/v1/vnf_packages/222/vnfd'},
+                       'packageContent': {'href': 'http://127.0.0.1:80/api/vnfpkgm/v1/vnf_packages/222/package_content'}
+                       }
         }
         self.assertEqual(response.data, expect_data)
         self.assertEqual(response.status_code, status.HTTP_200_OK)
@@ -201,7 +204,17 @@ class TestVnfPackage(TestCase):
                 "operationalState": "DISABLED",
                 "usageState": "NOT_IN_USE",
                 "userDefinedData": {"a": "A"},
-                "_links": None
+                "_links": {
+                    "self": {
+                        "href": "http://127.0.0.1:80/api/vnfpkgm/v1/vnf_packages/111"
+                    },
+                    "vnfd": {
+                        "href": "http://127.0.0.1:80/api/vnfpkgm/v1/vnf_packages/111/vnfd"
+                    },
+                    "packageContent": {
+                        "href": "http://127.0.0.1:80/api/vnfpkgm/v1/vnf_packages/111/package_content"
+                    }
+                }
             },
             {
                 "id": "222",
@@ -216,7 +229,10 @@ class TestVnfPackage(TestCase):
                 "operationalState": "DISABLED",
                 "usageState": "NOT_IN_USE",
                 "userDefinedData": {"a": "A"},
-                "_links": None
+                "_links": {'self': {'href': 'http://127.0.0.1:80/api/vnfpkgm/v1/vnf_packages/222'},
+                           'vnfd': {'href': 'http://127.0.0.1:80/api/vnfpkgm/v1/vnf_packages/222/vnfd'},
+                           'packageContent': {
+                               'href': 'http://127.0.0.1:80/api/vnfpkgm/v1/vnf_packages/222/package_content'}}
             }
         ]
         self.assertEqual(response.data, expect_data)
@@ -456,6 +472,16 @@ class TestVnfPackage(TestCase):
             "onboardingState": "ONBOARDED",
             "operationalState": "ENABLED",
             "usageState": "NOT_IN_USE",
-            "_links": None
+            "_links": {
+                "self": {
+                    "href": "http://127.0.0.1:80/api/vnfpkgm/v1/vnf_packages/222"
+                },
+                "vnfd": {
+                    "href": "http://127.0.0.1:80/api/vnfpkgm/v1/vnf_packages/222/vnfd"
+                },
+                "packageContent": {
+                    "href": "http://127.0.0.1:80/api/vnfpkgm/v1/vnf_packages/222/package_content"
+                }
+            }
         }
         self.assertEqual(response.data, expact_response_data)