carl: add check_status method checking if Carl is up (#88345)
gitea/passerelle/pipeline/head This commit looks good
Details
gitea/passerelle/pipeline/head This commit looks good
Details
This commit is contained in:
parent
a36a0f9e9c
commit
b5ccfb60ff
|
@ -129,6 +129,13 @@ class Carl(BaseResource, HTTPResource):
|
|||
class Meta:
|
||||
verbose_name = _('Carl')
|
||||
|
||||
def check_status(self):
|
||||
url = urllib.parse.urljoin(self.service_url, 'public/status')
|
||||
response = self.requests.get(url)
|
||||
response.raise_for_status()
|
||||
if response.text.strip() != 'status: ok':
|
||||
raise APIError('Carl status check fails')
|
||||
|
||||
@endpoint(
|
||||
name='entity',
|
||||
pattern=r'^(?P<carl_type>[^/]+)$',
|
||||
|
|
|
@ -4,6 +4,7 @@ import urllib
|
|||
import uuid
|
||||
|
||||
import pytest
|
||||
import requests
|
||||
import responses
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from requests.exceptions import ConnectTimeout, ReadTimeout
|
||||
|
@ -11,6 +12,7 @@ from requests.exceptions import ConnectTimeout, ReadTimeout
|
|||
import tests.utils
|
||||
from passerelle.apps.carl.models import Carl
|
||||
from passerelle.base.models import AccessRight, ApiUser
|
||||
from passerelle.utils.jsonresponse import APIError
|
||||
|
||||
APIERROR_CLS = 'passerelle.utils.jsonresponse.APIError'
|
||||
SERVICE_URL = 'http://carl.example.org/'
|
||||
|
@ -104,6 +106,30 @@ def filters_to_params(filters):
|
|||
#
|
||||
|
||||
|
||||
@responses.activate
|
||||
def test_carl_check_status_ok(app, carl_conn):
|
||||
responses.add(responses.GET, f'{SERVICE_URL}public/status', body='status: ok\n')
|
||||
carl_conn.check_status()
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'body,status',
|
||||
[
|
||||
('status: error\n', 200),
|
||||
('status: ok\n', 500),
|
||||
('', 201),
|
||||
(ConnectTimeout('timeout'), 200),
|
||||
(ReadTimeout('timeout'), 200),
|
||||
],
|
||||
)
|
||||
@responses.activate
|
||||
def test_carl_check_status_fail(app, carl_conn, body, status):
|
||||
status_url = f'{SERVICE_URL}public/status'
|
||||
responses.add(responses.GET, status_url, body=body, status=status)
|
||||
with pytest.raises((APIError, requests.RequestException)):
|
||||
carl_conn.check_status()
|
||||
|
||||
|
||||
@responses.activate
|
||||
def test_carl_token_authentication_success(app, carl_token_conn):
|
||||
e_type = 't1'
|
||||
|
|
Loading…
Reference in New Issue