Fix health check api 38/84038/2
authorfujinhua <fu.jinhua@zte.com.cn>
Wed, 3 Apr 2019 03:40:32 +0000 (11:40 +0800)
committerfujinhua <fu.jinhua@zte.com.cn>
Wed, 3 Apr 2019 03:45:38 +0000 (11:45 +0800)
Change-Id: I36e67e4fe27b9ac915e14459d0f29a204e47ee2f
Issue-ID: VFC-1306
Signed-off-by: fujinhua <fu.jinhua@zte.com.cn>
mgr/mgr/vnfreg/health_check_views.py
mgr/mgr/vnfreg/tests.py
mgr/mgr/vnfreg/urls.py

index 9df01f2..cc1a379 100644 (file)
 
 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"})
index 3c197aa..ff0e9d1 100644 (file)
@@ -127,3 +127,17 @@ class VnfRegTest(unittest.TestCase):
         response = self.client.post("/api/vnfmgr/v1/configuration", self.vnfconfig, format='json')
         self.assertEqual(status.HTTP_500_INTERNAL_SERVER_ERROR, response.status_code, response.content)
         self.assertEqual({'error': "Vnf(1) does not exist."}, json.loads(response.content))
+
+
+class HealthCheckViewTest(unittest.TestCase):
+    def setUp(self):
+        self.client = APIClient()
+
+    def tearDown(self):
+        pass
+
+    def test_health_check(self):
+        response = self.client.get("/api/vnfmgr/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)
index 7336cd7..eace301 100644 (file)
@@ -24,5 +24,5 @@ urlpatterns = [
     url(r'^api/vnfmgr/v1/configuration$', views.vnf_config, name='vnf_config'),
 
     # health check
-    url(r'^api/vnfmgr/v1/healthcheck$', HealthCheckView.as_view()),
+    url(r'^api/vnfmgr/v1/health_check$', HealthCheckView.as_view()),
 ]