From: yangyan Date: Thu, 4 Apr 2019 10:26:13 +0000 (+0800) Subject: fix health check of catalog X-Git-Tag: 1.3.0~52^2 X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F29%2F84229%2F3;p=vfc%2Fnfvo%2Fcatalog.git fix health check of catalog Change-Id: I5caf3cc74035a4d27ccebbc90eb7a28834558db2 Issue-ID: VFC-1329 Signed-off-by: yangyan --- diff --git a/catalog/packages/tests/test_health_check.py b/catalog/packages/tests/test_health_check.py new file mode 100644 index 00000000..8c06fc99 --- /dev/null +++ b/catalog/packages/tests/test_health_check.py @@ -0,0 +1,32 @@ +# Copyright (c) 2019, CMCC Technologies Co., Ltd. + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import json + +from django.test import TestCase, Client +from rest_framework import status + + +class TestHealthCheck(TestCase): + def setUp(self): + self.client = Client() + + def tearDown(self): + pass + + def test_health_check(self): + response = self.client.get("/api/vnfpkgm/v1/health_check") + self.assertEqual(status.HTTP_200_OK, response.status_code, response.content) + resp_data = json.loads(response.content) + self.assertEqual({"status": "active"}, resp_data) diff --git a/catalog/packages/urls.py b/catalog/packages/urls.py index f653b555..16273813 100755 --- a/catalog/packages/urls.py +++ b/catalog/packages/urls.py @@ -69,5 +69,5 @@ urlpatterns = [ # url(r'^api/vnfpkgm/v1/subscriptions/(?P[0-9a-zA-Z\-\_]+)$', vnfpkg_subscription.as_view(), name='subscription_rd'), # health check - url(r'^api/vnfpkgm/v1/healthcheck$', HealthCheckView.as_view()), + url(r'^api/vnfpkgm/v1/health_check$', HealthCheckView.as_view()), ] diff --git a/catalog/packages/views/health_check_views.py b/catalog/packages/views/health_check_views.py index 9df01f2b..cc1a3796 100644 --- a/catalog/packages/views/health_check_views.py +++ b/catalog/packages/views/health_check_views.py @@ -14,11 +14,18 @@ import logging +from drf_yasg.utils import swagger_auto_schema +from rest_framework import status +from rest_framework.response import Response from rest_framework.views import APIView logger = logging.getLogger(__name__) class HealthCheckView(APIView): - logger.debug("Health check") - pass + @swagger_auto_schema( + responses={ + status.HTTP_200_OK: 'Active'}) + def get(self, request, format=None): + logger.debug("Health check.") + return Response({"status": "active"})