diff options
author | maopeng zhang <zhang.maopeng1@zte.com.cn> | 2019-09-03 09:33:06 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2019-09-03 09:33:06 +0000 |
commit | e1e0c957138779a8a19b72f5595550f35866af88 (patch) | |
tree | 6c5aa4ee9b645bba2d74ab64a275b5b8b613e233 | |
parent | e785b0e792f5b50ff2b3667ef61a1ccf6b018d20 (diff) | |
parent | ae84dc13220419c9793abc11485d6d15a2c7a0a8 (diff) |
Merge "fix bug for failure in deleting subscriptions for vnfm"5.0.2-ONAPelalto
-rw-r--r-- | gvnfmadapter/driver/interfaces/tests.py | 51 | ||||
-rw-r--r-- | gvnfmadapter/driver/interfaces/urls.py | 3 | ||||
-rw-r--r-- | gvnfmadapter/driver/interfaces/views.py | 29 |
3 files changed, 82 insertions, 1 deletions
diff --git a/gvnfmadapter/driver/interfaces/tests.py b/gvnfmadapter/driver/interfaces/tests.py index c92a1f9..be8f9df 100644 --- a/gvnfmadapter/driver/interfaces/tests.py +++ b/gvnfmadapter/driver/interfaces/tests.py @@ -727,6 +727,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 = { "vnfmId": "19ecbb3a-3242-4fa3-9926-8dfb7ddc29ee", diff --git a/gvnfmadapter/driver/interfaces/urls.py b/gvnfmadapter/driver/interfaces/urls.py index 368ea8e..cf6f476 100644 --- a/gvnfmadapter/driver/interfaces/urls.py +++ b/gvnfmadapter/driver/interfaces/urls.py @@ -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()), diff --git a/gvnfmadapter/driver/interfaces/views.py b/gvnfmadapter/driver/interfaces/views.py index db47884..3aec4d9 100644 --- a/gvnfmadapter/driver/interfaces/views.py +++ b/gvnfmadapter/driver/interfaces/views.py @@ -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"), |