aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoryangyan <yangyanyj@chinamobile.com>2019-04-04 18:26:13 +0800
committerYan Yang <yangyanyj@chinamobile.com>2019-04-04 11:28:18 +0000
commitaa123917b240bb70f0bcb14ece3d4d553539c603 (patch)
tree9b2cd3ba0c8662b2d9dc12c0cb6251f676878f7b
parent8cf5ec4adee3868174f1a7c2735a7fca8992f498 (diff)
fix health check of catalog
Change-Id: I5caf3cc74035a4d27ccebbc90eb7a28834558db2 Issue-ID: VFC-1329 Signed-off-by: yangyan <yangyanyj@chinamobile.com>
-rw-r--r--catalog/packages/tests/test_health_check.py32
-rwxr-xr-xcatalog/packages/urls.py2
-rw-r--r--catalog/packages/views/health_check_views.py11
3 files changed, 42 insertions, 3 deletions
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<subscriptionId>[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"})