fix bug for failure in deleting subscriptions for vnfm 83/94783/2
authorhongyuzhao <zhao.hongyu@zte.com.cn>
Tue, 3 Sep 2019 05:05:25 +0000 (13:05 +0800)
committerhongyuzhao <zhao.hongyu@zte.com.cn>
Tue, 3 Sep 2019 09:25:39 +0000 (17:25 +0800)
Change-Id: If987eb76acfec269133a2477bded792232feb7c2
Issue-ID: VFC-1508
Signed-off-by: hongyuzhao <zhao.hongyu@zte.com.cn>
gvnfmadapter/driver/interfaces/tests.py
gvnfmadapter/driver/interfaces/urls.py
gvnfmadapter/driver/interfaces/views.py

index c92a1f9..be8f9df 100644 (file)
@@ -726,6 +726,57 @@ class InterfacesTest(TestCase):
         )
         self.assertEqual(status.HTTP_500_INTERNAL_SERVER_ERROR, response.status_code)
 
+    @mock.patch.object(restcall, 'call_req')
+    def test_dissubscribe_successfully(self, mock_call_req):
+        vnfm_info = {
+            "vnfmId": "19ecbb3a-3242-4fa3-9926-8dfb7ddc29ee",
+            "name": "g_vnfm",
+            "type": "gvnfmdriver",
+            "vimId": "",
+            "vendor": "ZTE",
+            "version": "v1.0",
+            "description": "vnfm",
+            "certificateUrl": "",
+            "url": "http://10.74.44.11",
+            "userName": "admin",
+            "password": "admin",
+            "createTime": "2016-07-06 15:33:18"
+        }
+        ret_of_vnfminfo_from_nslcm = [0, json.JSONEncoder().encode(vnfm_info), "200"]
+        ret_from_vnfm = [0, json.JSONEncoder().encode(""), status.HTTP_204_NO_CONTENT]
+        mock_call_req.side_effect = [ret_of_vnfminfo_from_nslcm, ret_from_vnfm]
+        response = self.client.delete(
+            "/api/gvnfmdriver/v1/%s/subscriptions/11" % vnfm_info['vnfmId'],
+            content_type='application/json'
+        )
+        self.assertEqual(status.HTTP_204_NO_CONTENT, response.status_code)
+
+    @mock.patch.object(restcall, 'call_req')
+    def test_dissubscribe_failed(self, mock_call_req):
+        vnfm_info = {
+            "vnfmId": "19ecbb3a-3242-4fa3-9926-8dfb7ddc29ee",
+            "name": "g_vnfm",
+            "type": "gvnfmdriver",
+            "vimId": "",
+            "vendor": "ZTE",
+            "version": "v1.0",
+            "description": "vnfm",
+            "certificateUrl": "",
+            "url": "http://10.74.44.11",
+            "userName": "admin",
+            "password": "admin",
+            "createTime": "2016-07-06 15:33:18"
+        }
+
+        ret_of_vnfminfo_from_nslcm = [0, json.JSONEncoder().encode(vnfm_info), "200"]
+        ret_from_vnfm = [1, None, status.HTTP_404_NOT_FOUND]
+        mock_call_req.side_effect = [ret_of_vnfminfo_from_nslcm, ret_from_vnfm]
+        response = self.client.delete(
+            "/api/gvnfmdriver/v1/%s/subscriptions/11" % vnfm_info['vnfmId'],
+            content_type='application/json'
+        )
+        self.assertEqual(status.HTTP_404_NOT_FOUND, response.status_code)
+
     @mock.patch.object(restcall, 'call_req')
     def test_operate_vnf_404_NotFound(self, mock_call_req):
         vnfm_info = {
index 368ea8e..cf6f476 100644 (file)
@@ -14,7 +14,7 @@
 
 from django.conf.urls import url
 from driver.interfaces.views import VnfInstInfo, VnfTermInfo, VnfQueryInfo, VnfOperInfo
-from driver.interfaces.views import Subscription
+from driver.interfaces.views import Subscription, SubscriptionDetail
 from driver.interfaces.views import VnfPkgsInfo, VnfGrantInfo, VnfNotifyInfo, QuerySingleVnfLcmOpOcc, VnfOperateView, VnfHealView
 from driver.interfaces.views import HealthCheckView
 
@@ -24,6 +24,7 @@ urlpatterns = [
     url(r'^api/(?P<vnfmtype>[0-9a-zA-Z\-\_]+)/v1/(?P<vnfmid>[0-9a-zA-Z\-\_]+)/vnfs/(?P<vnfInstanceId>[0-9a-zA-Z\-\_]+)$', VnfQueryInfo.as_view()),
     url(r'^api/(?P<vnfmtype>[0-9a-zA-Z\-\_]+)/v1/(?P<vnfmid>[0-9a-zA-Z\-\_]+)/jobs/(?P<jobid>[0-9a-zA-Z\-\_]+)$', VnfOperInfo.as_view()),
     url(r'^api/(?P<vnfmtype>[0-9a-zA-Z\-\_]+)/v1/(?P<vnfmid>[0-9a-zA-Z\-\_]+)/subscriptions$', Subscription.as_view()),
+    url(r'^api/(?P<vnfmtype>[0-9a-zA-Z\-\_]+)/v1/(?P<vnfmid>[0-9a-zA-Z\-\_]+)/subscriptions/(?P<subscriptionid>[0-9a-zA-Z_-]+)$', SubscriptionDetail.as_view()),
 
     url(r'^api/(?P<vnfmtype>[0-9a-zA-Z\-\_]+)/v1/vnfpackages$', VnfPkgsInfo.as_view()),
     url(r'^api/(?P<vnfmtype>[0-9a-zA-Z\-\_]+)/v1/resource/grant$', VnfGrantInfo.as_view()),
index db47884..3aec4d9 100644 (file)
@@ -489,6 +489,35 @@ class Subscription(APIView):
             return Response(status=status.HTTP_500_INTERNAL_SERVER_ERROR)
 
 
+class SubscriptionDetail(APIView):
+    @swagger_auto_schema(
+        responses={
+            status.HTTP_204_NO_CONTENT: "Sucess",
+            status.HTTP_404_NOT_FOUND: "Not found",
+            status.HTTP_500_INTERNAL_SERVER_ERROR: "Internal error"
+        }
+    )
+    def delete(self, request, vnfmtype, vnfmid, subscriptionid):
+        try:
+            logger.debug("Subscription--delete begin!")
+            vnfm_info = get_vnfminfo_from_nslcm(vnfmid)
+            logger.debug("[delete_subscription] vnfm_info=[%s]", vnfm_info)
+            ret = call_vnfm("api/vnflcm/v1/subscriptions/%s" % subscriptionid, "DELETE", vnfm_info)
+            logger.debug("[%s] call_req ret=%s", fun_name(), ret)
+            if int(ret[2]) not in [status.HTTP_204_NO_CONTENT, status.HTTP_404_NOT_FOUND]:
+                logger.error("Status code is %s, detail is %s.", ret[2], ret[1])
+                raise GvnfmDriverException('Failed to delete subscribeid=%s.' % subscriptionid)
+            logger.debug("Subscription--delete sucess!")
+            return Response(status=ret[2])
+        except GvnfmDriverException as e:
+            logger.error(e.args[0])
+            return Response(status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+        except Exception as e:
+            logger.error(e.args[0])
+            logger.error(traceback.format_exc())
+            return Response(status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+
+
 def call_vnfm(resource, method, vnfm_info, data=""):
     ret = restcall.call_req(
         base_url=ignorcase_get(vnfm_info, "url"),