diff options
Diffstat (limited to 'mgr')
-rw-r--r-- | mgr/mgr/vnfreg/health_check_views.py | 11 | ||||
-rw-r--r-- | mgr/mgr/vnfreg/tests.py | 14 | ||||
-rw-r--r-- | mgr/mgr/vnfreg/urls.py | 2 |
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()), ] |