Import HTTPStatus instead of http_client
python introduced http.HTTPStatus since version 3.5, and the OpenStack Victoria has targeted a minimum version of python 3.6[1], cyborg also does that. To keep update with the latest version we introduce HTTPStatus to replace http_client in cyborg code. [1]https://governance.openstack.org/tc/reference/runtimes/victoria.html
This commit is contained in:
parent
9fa4e71c1f
commit
acac833908
|
@ -15,7 +15,7 @@
|
|||
"""Accelerator base exception handling. """
|
||||
|
||||
import collections
|
||||
from http import client as http_client
|
||||
from http import HTTPStatus
|
||||
from oslo_log import log as logging
|
||||
from oslo_serialization import jsonutils
|
||||
|
||||
|
@ -82,7 +82,7 @@ class AcceleratorException(Exception):
|
|||
str(exc).
|
||||
"""
|
||||
_msg_fmt = _("An unknown exception occurred.")
|
||||
code = http_client.INTERNAL_SERVER_ERROR
|
||||
code = HTTPStatus.INTERNAL_SERVER_ERROR
|
||||
headers = {}
|
||||
safe = False
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from http import client as http_client
|
||||
from http import HTTPStatus
|
||||
import pecan
|
||||
import wsme
|
||||
from wsme import types as wtypes
|
||||
|
@ -105,7 +105,7 @@ class ARQsController(base.CyborgController):
|
|||
|
||||
@authorize_wsgi.authorize_wsgi("cyborg:arq", "create", False)
|
||||
@expose.expose(ARQCollection, body=types.jsontype,
|
||||
status_code=http_client.CREATED)
|
||||
status_code=HTTPStatus.CREATED)
|
||||
def post(self, req):
|
||||
"""Create one or more ARQs for a single device profile.
|
||||
Request body:
|
||||
|
@ -197,7 +197,7 @@ class ARQsController(base.CyborgController):
|
|||
'resolved', instance)
|
||||
return wsme.api.Response(
|
||||
None,
|
||||
status_code=http_client.LOCKED)
|
||||
status_code=HTTPStatus.LOCKED)
|
||||
elif bind_state:
|
||||
arqs = [arq for arq in arqs
|
||||
if arq['state'] in valid_bind_states]
|
||||
|
@ -208,7 +208,7 @@ class ARQsController(base.CyborgController):
|
|||
|
||||
@authorize_wsgi.authorize_wsgi("cyborg:arq", "delete", False)
|
||||
@expose.expose(None, wtypes.text, wtypes.text,
|
||||
status_code=http_client.NO_CONTENT)
|
||||
status_code=HTTPStatus.NO_CONTENT)
|
||||
def delete(self, arqs=None, instance=None):
|
||||
"""Delete one or more ARQS.
|
||||
|
||||
|
@ -296,7 +296,7 @@ class ARQsController(base.CyborgController):
|
|||
|
||||
@authorize_wsgi.authorize_wsgi("cyborg:arq", "update", False)
|
||||
@expose.expose(None, body=types.jsontype,
|
||||
status_code=http_client.ACCEPTED)
|
||||
status_code=HTTPStatus.ACCEPTED)
|
||||
def patch(self, patch_list):
|
||||
"""Bind/Unbind one or more ARQs.
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
# under the License.
|
||||
|
||||
import copy
|
||||
from http import client as http_client
|
||||
from http import HTTPStatus
|
||||
import pecan
|
||||
import re
|
||||
import wsme
|
||||
|
@ -115,7 +115,7 @@ class DeviceProfilesController(base.CyborgController,
|
|||
|
||||
@authorize_wsgi.authorize_wsgi("cyborg:device_profile", "create", False)
|
||||
@expose.expose(DeviceProfile, body=types.jsontype,
|
||||
status_code=http_client.CREATED)
|
||||
status_code=HTTPStatus.CREATED)
|
||||
def post(self, req_devprof_list):
|
||||
"""Create one or more device_profiles.
|
||||
|
||||
|
@ -257,7 +257,7 @@ class DeviceProfilesController(base.CyborgController,
|
|||
return DeviceProfile.convert_with_links(ret)
|
||||
|
||||
@authorize_wsgi.authorize_wsgi("cyborg:device_profile", "delete")
|
||||
@expose.expose(None, wtypes.text, status_code=http_client.NO_CONTENT)
|
||||
@expose.expose(None, wtypes.text, status_code=HTTPStatus.NO_CONTENT)
|
||||
def delete(self, value):
|
||||
"""Delete one or more device_profiles.
|
||||
|
||||
|
|
|
@ -141,7 +141,7 @@ def authorize_wsgi(api_name, act=None, need_target=True):
|
|||
@authorize_wsgi.authorize_wsgi("cyborg:accelerator",
|
||||
"create", False)
|
||||
@wsme_pecan.wsexpose(Accelerator, body=types.jsontype,
|
||||
status_code=http_client.CREATED)
|
||||
status_code=HTTPStatus.CREATED)
|
||||
def post(self, values):
|
||||
...
|
||||
"""
|
||||
|
|
|
@ -19,7 +19,7 @@ SHOULD include dedicated exception logging.
|
|||
|
||||
"""
|
||||
|
||||
from http import client as http_client
|
||||
from http import HTTPStatus
|
||||
from oslo_log import log
|
||||
|
||||
from cyborg.common.i18n import _
|
||||
|
@ -40,7 +40,7 @@ class CyborgException(Exception):
|
|||
str(exc).
|
||||
"""
|
||||
_msg_fmt = _("An unknown exception occurred.")
|
||||
code = http_client.INTERNAL_SERVER_ERROR
|
||||
code = HTTPStatus.INTERNAL_SERVER_ERROR
|
||||
headers = {}
|
||||
safe = False
|
||||
|
||||
|
@ -84,7 +84,7 @@ class CyborgException(Exception):
|
|||
|
||||
class Forbidden(CyborgException):
|
||||
_msg_fmt = _("Forbidden")
|
||||
code = http_client.FORBIDDEN
|
||||
code = HTTPStatus.FORBIDDEN
|
||||
|
||||
|
||||
# TODO(Sundar): Eliminate this after ARQBadState is merged.
|
||||
|
@ -145,7 +145,7 @@ class InUse(CyborgException):
|
|||
|
||||
class Invalid(CyborgException):
|
||||
_msg_fmt = _("Invalid parameters.")
|
||||
code = http_client.BAD_REQUEST
|
||||
code = HTTPStatus.BAD_REQUEST
|
||||
|
||||
|
||||
class InvalidIdentity(Invalid):
|
||||
|
@ -187,7 +187,7 @@ class PatchError(Invalid):
|
|||
|
||||
class NotAuthorized(CyborgException):
|
||||
_msg_fmt = _("Not authorized.")
|
||||
code = http_client.UNAUTHORIZED
|
||||
code = HTTPStatus.UNAUTHORIZED
|
||||
|
||||
|
||||
class HTTPForbidden(Forbidden):
|
||||
|
@ -196,12 +196,12 @@ class HTTPForbidden(Forbidden):
|
|||
|
||||
class NotFound(CyborgException):
|
||||
_msg_fmt = _("Resource could not be found.")
|
||||
code = http_client.NOT_FOUND
|
||||
code = HTTPStatus.NOT_FOUND
|
||||
|
||||
|
||||
class ServiceUnavailable(CyborgException):
|
||||
_msg_fmt = _("Service is unavailable at this time.")
|
||||
code = http_client.SERVICE_UNAVAILABLE
|
||||
code = HTTPStatus.SERVICE_UNAVAILABLE
|
||||
|
||||
|
||||
class ServiceNotFound(NotFound):
|
||||
|
@ -219,7 +219,7 @@ class InvalidDeployType(CyborgException):
|
|||
|
||||
class Conflict(CyborgException):
|
||||
_msg_fmt = _('Conflict.')
|
||||
code = http_client.CONFLICT
|
||||
code = HTTPStatus.CONFLICT
|
||||
|
||||
|
||||
class DuplicateDeviceName(Conflict):
|
||||
|
@ -410,7 +410,7 @@ class ResourceNotFound(NotFound):
|
|||
|
||||
class NotAcceptable(CyborgException):
|
||||
_msg_fmt = _("Request not acceptable.")
|
||||
code = http_client.NOT_ACCEPTABLE
|
||||
code = HTTPStatus.NOT_ACCEPTABLE
|
||||
|
||||
|
||||
class FPGAProgramError(CyborgException):
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from http import client as http_client
|
||||
from http import HTTPStatus
|
||||
import unittest
|
||||
from unittest import mock
|
||||
|
||||
|
@ -182,7 +182,7 @@ class TestARQsController(v2_test.APITestV2):
|
|||
url = '%s?instance=%s&bind_state=resolved' % (
|
||||
self.ARQ_URL, instance_uuid)
|
||||
response = self.get_json(url, headers=self.headers, expect_errors=True)
|
||||
self.assertEqual(http_client.LOCKED, response.status_int)
|
||||
self.assertEqual(HTTPStatus.LOCKED, response.status_int)
|
||||
|
||||
@mock.patch('cyborg.objects.DeviceProfile.get_by_name')
|
||||
@mock.patch('cyborg.conductor.rpcapi.ConductorAPI.arq_create')
|
||||
|
@ -195,7 +195,7 @@ class TestARQsController(v2_test.APITestV2):
|
|||
data = jsonutils.loads(response.__dict__['controller_output'])
|
||||
out_arqs = data['arqs']
|
||||
|
||||
self.assertEqual(http_client.CREATED, response.status_int)
|
||||
self.assertEqual(HTTPStatus.CREATED, response.status_int)
|
||||
self.assertEqual(len(out_arqs), 3)
|
||||
for in_extarq, out_arq in zip(self.fake_extarqs, out_arqs):
|
||||
self._validate_arq(in_extarq.arq, out_arq)
|
||||
|
@ -231,12 +231,12 @@ class TestARQsController(v2_test.APITestV2):
|
|||
mock_by_arq.return_value = None
|
||||
args = '?' + "arqs=" + str(arq['uuid'])
|
||||
response = self.delete(url + args, headers=self.headers)
|
||||
self.assertEqual(http_client.NO_CONTENT, response.status_int)
|
||||
self.assertEqual(HTTPStatus.NO_CONTENT, response.status_int)
|
||||
|
||||
mock_by_inst.return_value = None
|
||||
args = '?' + "instance=" + instance
|
||||
response = self.delete(url + args, headers=self.headers)
|
||||
self.assertEqual(http_client.NO_CONTENT, response.status_int)
|
||||
self.assertEqual(HTTPStatus.NO_CONTENT, response.status_int)
|
||||
|
||||
@unittest.skip("Need more code to implement _get_resource in rbac")
|
||||
def test_delete_with_non_default(self):
|
||||
|
@ -308,7 +308,7 @@ class TestARQsController(v2_test.APITestV2):
|
|||
response = self.patch_json(self.ARQ_URL, params=patch_list,
|
||||
headers=self.headers,
|
||||
expect_errors=True)
|
||||
self.assertEqual(http_client.NOT_ACCEPTABLE, response.status_code)
|
||||
self.assertEqual(HTTPStatus.NOT_ACCEPTABLE, response.status_code)
|
||||
self.assertTrue(response.json['error_message'])
|
||||
|
||||
# TODO(all): Add exception test cases for apply_patch.
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from http import client as http_client
|
||||
from http import HTTPStatus
|
||||
from unittest import mock
|
||||
import webtest
|
||||
|
||||
|
@ -79,7 +79,7 @@ class TestDeviceProfileController(v2_test.APITestV2):
|
|||
response = self.post_json(self.DP_URL, dp, headers=self.headers)
|
||||
out_dp = jsonutils.loads(response.controller_output)
|
||||
|
||||
self.assertEqual(http_client.CREATED, response.status_int)
|
||||
self.assertEqual(HTTPStatus.CREATED, response.status_int)
|
||||
self._validate_dp(dp[0], out_dp)
|
||||
|
||||
def test_create_with_unsupported_trait(self):
|
||||
|
@ -181,8 +181,8 @@ class TestDeviceProfileController(v2_test.APITestV2):
|
|||
# Delete by UUID
|
||||
url = self.DP_URL + "/5d2c0797-c3cd-4f4b-b0d0-2cc5e99ef66e"
|
||||
response = self.delete(url, headers=self.headers)
|
||||
self.assertEqual(http_client.NO_CONTENT, response.status_int)
|
||||
self.assertEqual(HTTPStatus.NO_CONTENT, response.status_int)
|
||||
# Delete by name
|
||||
url = self.DP_URL + "/mydp"
|
||||
response = self.delete(url, headers=self.headers)
|
||||
self.assertEqual(http_client.NO_CONTENT, response.status_int)
|
||||
self.assertEqual(HTTPStatus.NO_CONTENT, response.status_int)
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from http import client as http_client
|
||||
from http import HTTPStatus
|
||||
from oslo_serialization import jsonutils
|
||||
from unittest import mock
|
||||
|
||||
|
@ -59,7 +59,7 @@ class TestFPGAProgramController(v2_test.APITestV2):
|
|||
response = self.patch_json('/deployables/%s/program' % dep_uuid,
|
||||
[{'path': '/bitstream_id', 'value': body,
|
||||
'op': 'replace'}], headers=self.headers)
|
||||
self.assertEqual(http_client.OK, response.status_code)
|
||||
self.assertEqual(HTTPStatus.OK, response.status_code)
|
||||
data = response.json_body
|
||||
self.assertEqual(dep_uuid, data['uuid'])
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from http import client as http_client
|
||||
from http import HTTPStatus
|
||||
from oslo_log import log as logging
|
||||
from oslo_serialization import jsonutils
|
||||
from unittest import mock
|
||||
|
@ -97,7 +97,7 @@ class DeviceProfilePolicyTest(base.BasePolicyTest):
|
|||
response = self.post_json(DP_URL, dp, headers=headers)
|
||||
out_dp = jsonutils.loads(response.controller_output)
|
||||
|
||||
self.assertEqual(http_client.CREATED, response.status_int)
|
||||
self.assertEqual(HTTPStatus.CREATED, response.status_int)
|
||||
self._validate_dp(dp[0], out_dp)
|
||||
|
||||
def test_create_device_profile_forbidden(self):
|
||||
|
@ -121,11 +121,11 @@ class DeviceProfilePolicyTest(base.BasePolicyTest):
|
|||
# Delete by UUID
|
||||
url = DP_URL + "/5d2c0797-c3cd-4f4b-b0d0-2cc5e99ef66e"
|
||||
response = self.delete(url, headers=headers)
|
||||
self.assertEqual(http_client.NO_CONTENT, response.status_int)
|
||||
self.assertEqual(HTTPStatus.NO_CONTENT, response.status_int)
|
||||
# Delete by name
|
||||
url = DP_URL + "/mydp"
|
||||
response = self.delete(url, headers=headers)
|
||||
self.assertEqual(http_client.NO_CONTENT, response.status_int)
|
||||
self.assertEqual(HTTPStatus.NO_CONTENT, response.status_int)
|
||||
|
||||
def test_delete_device_profile_forbidden(self):
|
||||
dp = self.fake_dp_objs[0]
|
||||
|
|
Loading…
Reference in New Issue