summaryrefslogtreecommitdiffstats
path: root/res
diff options
context:
space:
mode:
authorfujinhua <fu.jinhua@zte.com.cn>2019-04-03 11:29:42 +0800
committerfujinhua <fu.jinhua@zte.com.cn>2019-04-03 11:44:49 +0800
commit9eaf2a2d6cbe527f8ec5b9469986561116742d35 (patch)
tree46eac32b0e2a0696ec4f951720058f05be09aa07 /res
parentaa512690bb1ca2a0334ba8f2caf7bf178aa127c5 (diff)
Fix health check api
Change-Id: I63f9f4e25c6195418516708db3235b3c7a56443c Issue-ID: VFC-1306 Signed-off-by: fujinhua <fu.jinhua@zte.com.cn>
Diffstat (limited to 'res')
-rw-r--r--res/res/resources/health_check_views.py11
-rw-r--r--res/res/resources/tests.py15
-rw-r--r--res/res/resources/urls.py2
3 files changed, 25 insertions, 3 deletions
diff --git a/res/res/resources/health_check_views.py b/res/res/resources/health_check_views.py
index 9df01f2..cc1a379 100644
--- a/res/res/resources/health_check_views.py
+++ b/res/res/resources/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/res/res/resources/tests.py b/res/res/resources/tests.py
index 8d05bf5..7534537 100644
--- a/res/res/resources/tests.py
+++ b/res/res/resources/tests.py
@@ -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)
diff --git a/res/res/resources/urls.py b/res/res/resources/urls.py
index d92db1d..41c9d08 100644
--- a/res/res/resources/urls.py
+++ b/res/res/resources/urls.py
@@ -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()),
]