summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfujinhua <fu.jinhua@zte.com.cn>2019-04-03 11:40:32 +0800
committerfujinhua <fu.jinhua@zte.com.cn>2019-04-03 11:45:38 +0800
commitba48b5a16931be84d71c66139f556f99725f145a (patch)
treeee46b9022cbf44acb1f5686d88354efe03ad5d3b
parentd5fc24ed1a4c330027f78ec9378bc269a748ce0f (diff)
Fix health check api
Change-Id: I36e67e4fe27b9ac915e14459d0f29a204e47ee2f Issue-ID: VFC-1306 Signed-off-by: fujinhua <fu.jinhua@zte.com.cn>
-rw-r--r--mgr/mgr/vnfreg/health_check_views.py11
-rw-r--r--mgr/mgr/vnfreg/tests.py14
-rw-r--r--mgr/mgr/vnfreg/urls.py2
3 files changed, 24 insertions, 3 deletions
diff --git a/mgr/mgr/vnfreg/health_check_views.py b/mgr/mgr/vnfreg/health_check_views.py
index 9df01f2..cc1a379 100644
--- a/mgr/mgr/vnfreg/health_check_views.py
+++ b/mgr/mgr/vnfreg/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"})
diff --git a/mgr/mgr/vnfreg/tests.py b/mgr/mgr/vnfreg/tests.py
index 3c197aa..ff0e9d1 100644
--- a/mgr/mgr/vnfreg/tests.py
+++ b/mgr/mgr/vnfreg/tests.py
@@ -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)
diff --git a/mgr/mgr/vnfreg/urls.py b/mgr/mgr/vnfreg/urls.py
index 7336cd7..eace301 100644
--- a/mgr/mgr/vnfreg/urls.py
+++ b/mgr/mgr/vnfreg/urls.py
@@ -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()),
]