use HTTPStatus instead of direct code

Python introduced http.HTTPStatus since version 3.5,
and Wallaby has targeted a minimum version of python 3.6.

Change-Id: I45f732f0f59b8fae831bb6c07f4fdd98cdd7409a
This commit is contained in:
sue
2021-03-25 15:49:10 +08:00
committed by Dantali0n
parent 546b730c9b
commit c28756c48b
25 changed files with 215 additions and 177 deletions

View File

@@ -18,6 +18,7 @@
from urllib import parse as urlparse
from http import HTTPStatus
from oslo_config import cfg
from oslo_log import log
@@ -138,11 +139,11 @@ class GrafanaHelper(base.DataSourceBase):
resp = requests.get(self._base_url + str(project_id) + '/query',
params=params, headers=self._headers)
if resp.status_code == 200:
if resp.status_code == HTTPStatus.OK:
return resp
elif resp.status_code == 400:
elif resp.status_code == HTTPStatus.BAD_REQUEST:
LOG.error("Query for metric is invalid")
elif resp.status_code == 401:
elif resp.status_code == HTTPStatus.UNAUTHORIZED:
LOG.error("Authorization token is invalid")
raise exception.DataSourceNotAvailable(self.NAME)