Fix health check api 37/84037/3
authorfujinhua <fu.jinhua@zte.com.cn>
Wed, 3 Apr 2019 03:29:42 +0000 (11:29 +0800)
committerfujinhua <fu.jinhua@zte.com.cn>
Wed, 3 Apr 2019 03:44:49 +0000 (11:44 +0800)
Change-Id: I63f9f4e25c6195418516708db3235b3c7a56443c
Issue-ID: VFC-1306
Signed-off-by: fujinhua <fu.jinhua@zte.com.cn>
res/res/resources/health_check_views.py
res/res/resources/tests.py
res/res/resources/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 8d05bf5..7534537 100644 (file)
@@ -11,6 +11,7 @@
 # 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
 from rest_framework import status
@@ -220,3 +221,17 @@ class ResourceTest(TestCase):
         response = self.client.get("/api/vnfres/v1/%s/volumes" % self.nf_inst_id)
         self.assertEqual(self.volumes_data, response.data)
         self.failUnlessEqual(status.HTTP_200_OK, response.status_code)
+
+
+class HealthCheckViewTest(TestCase):
+    def setUp(self):
+        self.client = APIClient()
+
+    def tearDown(self):
+        pass
+
+    def test_health_check(self):
+        response = self.client.get("/api/vnfres/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 d92db1d..41c9d08 100644 (file)
@@ -28,5 +28,5 @@ urlpatterns = [
     url(r'^api/vnfres/v1/(?P<vnfInstanceId>[0-9a-zA-Z\-\_]+)/volumes$', views.getVolumes.as_view(), name='get_volumes'),
 
     # health check
-    url(r'^api/vnfres/v1/healthcheck$', HealthCheckView.as_view()),
+    url(r'^api/vnfres/v1/health_check$', HealthCheckView.as_view()),
 ]