From 62a7d22d82ee73a5061af3597763212e0a621eed Mon Sep 17 00:00:00 2001 From: haixin Date: Wed, 7 Oct 2020 15:52:18 +0800 Subject: [PATCH] remove usage of six library in api layer Replace six with Python 3 style code. Change-Id: I091a45c04686ac8d036107618945fea65fb4a2cf --- manila/api/common.py | 9 +++--- manila/api/middleware/fault.py | 3 +- manila/api/openstack/api_version_request.py | 5 ++-- manila/api/openstack/wsgi.py | 30 +++++++++---------- manila/api/v1/limits.py | 2 +- manila/api/v1/security_service.py | 3 +- manila/api/v1/share_manage.py | 16 +++++----- manila/api/v1/share_metadata.py | 3 +- manila/api/v1/share_servers.py | 3 +- manila/api/v1/share_snapshots.py | 3 +- manila/api/v1/share_types_extra_specs.py | 8 ++--- manila/api/v1/share_unmanage.py | 7 +++-- manila/api/v1/shares.py | 21 +++++++------ manila/api/v2/messages.py | 3 +- manila/api/v2/quota_sets.py | 5 ++-- manila/api/v2/share_group_snapshots.py | 12 ++++---- manila/api/v2/share_group_type_specs.py | 6 ++-- manila/api/v2/share_group_types.py | 22 +++++++------- manila/api/v2/share_groups.py | 18 +++++------ .../api/v2/share_instance_export_locations.py | 3 +- manila/api/v2/share_network_subnets.py | 2 +- manila/api/v2/share_networks.py | 3 +- .../api/v2/share_replica_export_locations.py | 3 +- manila/api/v2/share_replicas.py | 20 ++++++------- manila/api/v2/share_servers.py | 13 ++++---- manila/api/v2/share_snapshots.py | 9 +++--- manila/api/v2/share_types.py | 27 ++++++++--------- manila/api/v2/shares.py | 13 ++++---- manila/api/views/versions.py | 3 +- 29 files changed, 138 insertions(+), 137 deletions(-) diff --git a/manila/api/common.py b/manila/api/common.py index 11962e6bf9..6385fa4677 100644 --- a/manila/api/common.py +++ b/manila/api/common.py @@ -16,15 +16,14 @@ import ipaddress import os import re -import six import string +from urllib import parse from operator import xor from oslo_config import cfg from oslo_log import log from oslo_utils import encodeutils from oslo_utils import strutils -from six.moves.urllib import parse import webob from manila.api.openstack import api_version_request as api_version @@ -134,7 +133,7 @@ def _validate_integer(value, name, min_value=None, max_value=None): value = strutils.validate_integer(value, name, min_value, max_value) return value except ValueError as e: - raise webob.exc.HTTPBadRequest(explanation=e) + raise webob.exc.HTTPBadRequest(explanation=str(e)) def _validate_pagination_query(request, max_limit=CONF.osapi_max_limit): @@ -462,7 +461,7 @@ def validate_ip(access_to, enable_ipv6): validator = ipaddress.ip_network else: validator = ipaddress.IPv4Network - validator(six.text_type(access_to)) + validator(str(access_to)) except ValueError as error: err_msg = encodeutils.exception_to_unicode(error) raise webob.exc.HTTPBadRequest(explanation=err_msg) @@ -530,7 +529,7 @@ def validate_public_share_policy(context, api_params, api='create'): api_params['is_public'] = strutils.bool_from_string( api_params['is_public'], strict=True) except ValueError as e: - raise exception.InvalidParameterValue(six.text_type(e)) + raise exception.InvalidParameterValue(str(e)) public_shares_allowed = policy.check_policy( context, 'share', policy_to_check, do_raise=False) diff --git a/manila/api/middleware/fault.py b/manila/api/middleware/fault.py index 540bdc6384..2583a901bf 100644 --- a/manila/api/middleware/fault.py +++ b/manila/api/middleware/fault.py @@ -15,7 +15,6 @@ # under the License. from oslo_log import log -import six import webob.dec import webob.exc @@ -68,7 +67,7 @@ class FaultWrapper(base_wsgi.Middleware): # including those that are safe to expose, see bug 1021373 if safe: outer.explanation = '%s: %s' % (inner.__class__.__name__, - six.text_type(inner)) + inner) return wsgi.Fault(outer) @webob.dec.wsgify(RequestClass=wsgi.Request) diff --git a/manila/api/openstack/api_version_request.py b/manila/api/openstack/api_version_request.py index 86e085665b..8c9f922dc7 100644 --- a/manila/api/openstack/api_version_request.py +++ b/manila/api/openstack/api_version_request.py @@ -15,7 +15,6 @@ # under the License. import re -import six from manila.api.openstack import versioned_method from manila import exception @@ -280,9 +279,9 @@ class APIVersionRequest(utils.ComparableMixin): if not self.experimental and experimental: return False - if isinstance(min_version, six.string_types): + if isinstance(min_version, str): min_version = APIVersionRequest(version_string=min_version) - if isinstance(max_version, six.string_types): + if isinstance(max_version, str): max_version = APIVersionRequest(version_string=max_version) if not (min_version or max_version): diff --git a/manila/api/openstack/wsgi.py b/manila/api/openstack/wsgi.py index c23ea194b8..1c0b4ca0f6 100644 --- a/manila/api/openstack/wsgi.py +++ b/manila/api/openstack/wsgi.py @@ -14,6 +14,7 @@ # under the License. import functools +import http.client as http_client import inspect import math import time @@ -22,8 +23,6 @@ from oslo_log import log from oslo_serialization import jsonutils from oslo_utils import encodeutils from oslo_utils import strutils -import six -from six.moves import http_client import webob import webob.exc @@ -259,7 +258,7 @@ class ActionDispatcher(object): def dispatch(self, *args, **kwargs): """Find and call local method.""" action = kwargs.pop('action', 'default') - action_method = getattr(self, six.text_type(action), self.default) + action_method = getattr(self, str(action), self.default) return action_method(*args, **kwargs) def default(self, data): @@ -303,7 +302,7 @@ class JSONDictSerializer(DictSerializer): """Default JSON request body serialization.""" def default(self, data): - return six.b(jsonutils.dumps(data)) + return jsonutils.dumps(data).encode("utf-8") def serializers(**serializers): @@ -466,8 +465,8 @@ class ResponseObject(object): response = webob.Response() response.status_int = self.code for hdr, value in self._headers.items(): - response.headers[hdr] = six.text_type(value) - response.headers['Content-Type'] = six.text_type(content_type) + response.headers[hdr] = str(value) + response.headers['Content-Type'] = str(content_type) if self.obj is not None: response.body = serializer.serialize(self.obj) @@ -519,14 +518,14 @@ class ResourceExceptionHandler(object): if not ex_value: return True + msg = str(ex_value) if isinstance(ex_value, exception.NotAuthorized): - msg = six.text_type(ex_value) raise Fault(webob.exc.HTTPForbidden(explanation=msg)) elif isinstance(ex_value, exception.VersionNotFoundForAPIMethod): raise elif isinstance(ex_value, exception.Invalid): raise Fault(exception.ConvertedException( - code=ex_value.code, explanation=six.text_type(ex_value))) + code=ex_value.code, explanation=msg)) elif isinstance(ex_value, TypeError): exc_info = (ex_type, ex_value, ex_traceback) LOG.error('Exception handling resource: %s', @@ -745,10 +744,10 @@ class Resource(wsgi.Application): request.set_api_version_request() except exception.InvalidAPIVersionString as e: return Fault(webob.exc.HTTPBadRequest( - explanation=six.text_type(e))) + explanation=e.message)) except exception.InvalidGlobalAPIVersion as e: return Fault(webob.exc.HTTPNotAcceptable( - explanation=six.text_type(e))) + explanation=e.message)) # Identify the action, its arguments, and the requested # content type @@ -786,7 +785,7 @@ class Resource(wsgi.Application): method_name = meth.__qualname__ except AttributeError: method_name = 'Controller: %s Method: %s' % ( - six.text_type(self.controller), meth.__name__) + str(self.controller), meth.__name__) if body: decoded_body = encodeutils.safe_decode(body, errors='ignore') @@ -1021,8 +1020,7 @@ class ControllerMetaclass(type): cls_dict) -@six.add_metaclass(ControllerMetaclass) -class Controller(object): +class Controller(metaclass=ControllerMetaclass): """Default controller.""" _view_builder_class = None @@ -1233,7 +1231,7 @@ class AdminActionsMixin(object): raise webob.exc.HTTPBadRequest(explanation=msg) if update[status_attr] not in self.valid_statuses[status_attr]: expl = (_("Invalid state. Valid states: %s.") % - ", ".join(six.text_type(i) for i in + ", ".join(str(i) for i in self.valid_statuses[status_attr])) raise webob.exc.HTTPBadRequest(explanation=expl) return update @@ -1252,7 +1250,7 @@ class AdminActionsMixin(object): try: self._update(context, id, update) except exception.NotFound as e: - raise webob.exc.HTTPNotFound(six.text_type(e)) + raise webob.exc.HTTPNotFound(e.message) return webob.Response(status_int=http_client.ACCEPTED) @Controller.authorize('force_delete') @@ -1262,7 +1260,7 @@ class AdminActionsMixin(object): try: resource = self._get(context, id) except exception.NotFound as e: - raise webob.exc.HTTPNotFound(six.text_type(e)) + raise webob.exc.HTTPNotFound(e.message) self._delete(context, resource, force=True) return webob.Response(status_int=http_client.ACCEPTED) diff --git a/manila/api/v1/limits.py b/manila/api/v1/limits.py index d0294d2d29..c5ee4030d1 100644 --- a/manila/api/v1/limits.py +++ b/manila/api/v1/limits.py @@ -19,13 +19,13 @@ Module dedicated functions/classes dealing with rate limiting requests. import collections import copy +import http.client as http_client import math import re import time from oslo_serialization import jsonutils from oslo_utils import importutils -from six.moves import http_client import webob.dec import webob.exc diff --git a/manila/api/v1/security_service.py b/manila/api/v1/security_service.py index 8e998d13b8..262c0fd48c 100644 --- a/manila/api/v1/security_service.py +++ b/manila/api/v1/security_service.py @@ -15,8 +15,9 @@ """The security service api.""" +import http.client as http_client + from oslo_log import log -from six.moves import http_client import webob from webob import exc diff --git a/manila/api/v1/share_manage.py b/manila/api/v1/share_manage.py index 9b4fed567f..6a824fffca 100644 --- a/manila/api/v1/share_manage.py +++ b/manila/api/v1/share_manage.py @@ -61,11 +61,11 @@ class ShareManageMixin(object): try: share_ref = self.share_api.manage(context, share, driver_options) except exception.PolicyNotAuthorized as e: - raise exc.HTTPForbidden(explanation=e) + raise exc.HTTPForbidden(explanation=e.msg) except (exception.InvalidShare, exception.InvalidShareServer) as e: - raise exc.HTTPConflict(explanation=e) + raise exc.HTTPConflict(explanation=e.msg) except exception.InvalidInput as e: - raise exc.HTTPBadRequest(explanation=e) + raise exc.HTTPBadRequest(explanation=e.msg) return self._view_builder.detail(req, share_ref) @@ -103,13 +103,13 @@ class ShareManageMixin(object): utils.validate_service_host( context, share_utils.extract_host(data['service_host'])) except exception.ServiceNotFound as e: - raise exc.HTTPNotFound(explanation=e) + raise exc.HTTPNotFound(explanation=e.msg) except exception.PolicyNotAuthorized as e: - raise exc.HTTPForbidden(explanation=e) + raise exc.HTTPForbidden(explanation=e.msg) except exception.AdminRequired as e: - raise exc.HTTPForbidden(explanation=e) + raise exc.HTTPForbidden(explanation=e.msg) except exception.ServiceIsDown as e: - raise exc.HTTPBadRequest(explanation=e) + raise exc.HTTPBadRequest(explanation=e.msg) data['share_type_id'] = self._get_share_type_id( context, data.get('share_type')) @@ -123,7 +123,7 @@ class ShareManageMixin(object): share_type) return stype['id'] except exception.ShareTypeNotFound as e: - raise exc.HTTPNotFound(explanation=e) + raise exc.HTTPNotFound(explanation=e.msg) class ShareManageController(ShareManageMixin, wsgi.Controller): diff --git a/manila/api/v1/share_metadata.py b/manila/api/v1/share_metadata.py index 80dfa0505f..bcb4984ad4 100644 --- a/manila/api/v1/share_metadata.py +++ b/manila/api/v1/share_metadata.py @@ -13,7 +13,8 @@ # License for the specific language governing permissions and limitations # under the License. -from six.moves import http_client +import http.client as http_client + import webob from webob import exc diff --git a/manila/api/v1/share_servers.py b/manila/api/v1/share_servers.py index d9faaa0217..d0523e0e2e 100644 --- a/manila/api/v1/share_servers.py +++ b/manila/api/v1/share_servers.py @@ -13,8 +13,9 @@ # License for the specific language governing permissions and limitations # under the License. +import http.client as http_client + from oslo_log import log -from six.moves import http_client import webob from webob import exc diff --git a/manila/api/v1/share_snapshots.py b/manila/api/v1/share_snapshots.py index ccf45d4bc7..51c385c3b1 100644 --- a/manila/api/v1/share_snapshots.py +++ b/manila/api/v1/share_snapshots.py @@ -15,8 +15,9 @@ """The share snapshots api.""" +import http.client as http_client + from oslo_log import log -from six.moves import http_client import webob from webob import exc diff --git a/manila/api/v1/share_types_extra_specs.py b/manila/api/v1/share_types_extra_specs.py index 46d64522aa..ec3136c8c1 100644 --- a/manila/api/v1/share_types_extra_specs.py +++ b/manila/api/v1/share_types_extra_specs.py @@ -13,8 +13,8 @@ # License for the specific language governing permissions and limitations # under the License. -import six -from six.moves import http_client +import http.client as http_client + import webob from manila.api import common @@ -50,10 +50,10 @@ class ShareTypeExtraSpecsController(wsgi.Controller): try: share_types.get_valid_required_extra_specs(extra_specs) except exception.InvalidExtraSpec as e: - raise webob.exc.HTTPBadRequest(explanation=six.text_type(e)) + raise webob.exc.HTTPBadRequest(explanation=e.message) def is_valid_string(v): - return isinstance(v, six.string_types) and len(v) in range(1, 256) + return isinstance(v, str) and len(v) in range(1, 256) def is_valid_extra_spec(k, v): valid_extra_spec_key = is_valid_string(k) diff --git a/manila/api/v1/share_unmanage.py b/manila/api/v1/share_unmanage.py index d414b256fb..0a6a128afe 100644 --- a/manila/api/v1/share_unmanage.py +++ b/manila/api/v1/share_unmanage.py @@ -12,8 +12,9 @@ # License for the specific language governing permissions and limitations # under the License. +import http.client as http_client + from oslo_log import log -from six.moves import http_client import webob from webob import exc @@ -61,9 +62,9 @@ class ShareUnmanageMixin(object): raise exc.HTTPForbidden(explanation=msg) self.share_api.unmanage(context, share) except exception.NotFound as e: - raise exc.HTTPNotFound(explanation=e) + raise exc.HTTPNotFound(explanation=e.msg) except (exception.InvalidShare, exception.PolicyNotAuthorized) as e: - raise exc.HTTPForbidden(explanation=e) + raise exc.HTTPForbidden(explanation=e.msg) return webob.Response(status_int=http_client.ACCEPTED) diff --git a/manila/api/v1/shares.py b/manila/api/v1/shares.py index ccec9a5f14..a5d78ef2f8 100644 --- a/manila/api/v1/shares.py +++ b/manila/api/v1/shares.py @@ -16,12 +16,11 @@ """The shares api.""" import ast +import http.client as http_client from oslo_log import log from oslo_utils import strutils from oslo_utils import uuidutils -import six -from six.moves import http_client import webob from webob import exc @@ -91,9 +90,9 @@ class ShareMixin(object): except exception.NotFound: raise exc.HTTPNotFound() except exception.InvalidShare as e: - raise exc.HTTPForbidden(explanation=six.text_type(e)) + raise exc.HTTPForbidden(explanation=e.message) except exception.Conflict as e: - raise exc.HTTPConflict(explanation=six.text_type(e)) + raise exc.HTTPConflict(explanation=e.message) return webob.Response(status_int=http_client.ACCEPTED) @@ -270,14 +269,14 @@ class ShareMixin(object): availability_zone_id = db.availability_zone_get( context, availability_zone).id except exception.AvailabilityZoneNotFound as e: - raise exc.HTTPNotFound(explanation=six.text_type(e)) + raise exc.HTTPNotFound(explanation=e.message) share_group_id = share.get('share_group_id') if share_group_id: try: share_group = db.share_group_get(context, share_group_id) except exception.ShareGroupNotFound as e: - raise exc.HTTPNotFound(explanation=six.text_type(e)) + raise exc.HTTPNotFound(explanation=e.message) sg_az_id = share_group['availability_zone_id'] if availability_zone and availability_zone_id != sg_az_id: msg = _("Share cannot have AZ ('%(s_az)s') different than " @@ -496,7 +495,7 @@ class ShareMixin(object): raise exception.NotFound() share = self.share_api.get(context, id) except exception.NotFound as error: - raise webob.exc.HTTPNotFound(explanation=six.text_type(error)) + raise webob.exc.HTTPNotFound(explanation=error.message) self.share_api.deny_access(context, share, access) return webob.Response(status_int=http_client.ACCEPTED) @@ -518,9 +517,9 @@ class ShareMixin(object): try: self.share_api.extend(context, share, size) except (exception.InvalidInput, exception.InvalidShare) as e: - raise webob.exc.HTTPBadRequest(explanation=six.text_type(e)) + raise webob.exc.HTTPBadRequest(explanation=e.message) except exception.ShareSizeExceedsAvailableQuota as e: - raise webob.exc.HTTPForbidden(explanation=six.text_type(e)) + raise webob.exc.HTTPForbidden(explanation=e.message) return webob.Response(status_int=http_client.ACCEPTED) @@ -533,7 +532,7 @@ class ShareMixin(object): try: self.share_api.shrink(context, share, size) except (exception.InvalidInput, exception.InvalidShare) as e: - raise webob.exc.HTTPBadRequest(explanation=six.text_type(e)) + raise webob.exc.HTTPBadRequest(explanation=e.message) return webob.Response(status_int=http_client.ACCEPTED) @@ -541,7 +540,7 @@ class ShareMixin(object): try: share = self.share_api.get(context, id) except exception.NotFound as e: - raise webob.exc.HTTPNotFound(explanation=six.text_type(e)) + raise webob.exc.HTTPNotFound(explanation=e.message) try: size = int(body.get(action, diff --git a/manila/api/v2/messages.py b/manila/api/v2/messages.py index 0073cdb5d1..b217c1b272 100644 --- a/manila/api/v2/messages.py +++ b/manila/api/v2/messages.py @@ -18,8 +18,9 @@ GET /messages/ DELETE /messages/ """ +import http.client as http_client + from oslo_utils import timeutils -from six.moves import http_client import webob from webob import exc diff --git a/manila/api/v2/quota_sets.py b/manila/api/v2/quota_sets.py index c393d554cb..255e27f144 100644 --- a/manila/api/v2/quota_sets.py +++ b/manila/api/v2/quota_sets.py @@ -14,10 +14,11 @@ # License for the specific language governing permissions and limitations # under the License. +import http.client as http_client +from urllib import parse + from oslo_log import log from oslo_utils import strutils -from six.moves import http_client -from six.moves.urllib import parse import webob from manila.api.openstack import api_version_request as api_version diff --git a/manila/api/v2/share_group_snapshots.py b/manila/api/v2/share_group_snapshots.py index d964d65117..518fbd9472 100644 --- a/manila/api/v2/share_group_snapshots.py +++ b/manila/api/v2/share_group_snapshots.py @@ -13,10 +13,10 @@ # License for the specific language governing permissions and limitations # under the License. +import http.client as http_client + from oslo_log import log from oslo_utils import uuidutils -import six -from six.moves import http_client import webob from webob import exc @@ -77,7 +77,7 @@ class ShareGroupSnapshotController(wsgi.Controller, wsgi.AdminActionsMixin): self.share_group_api.delete_share_group_snapshot( context, sg_snapshot) except exception.InvalidShareGroupSnapshot as e: - raise exc.HTTPConflict(explanation=six.text_type(e)) + raise exc.HTTPConflict(explanation=e.message) return webob.Response(status_int=http_client.ACCEPTED) @wsgi.Controller.api_version('2.31', '2.54', experimental=True) @@ -183,7 +183,7 @@ class ShareGroupSnapshotController(wsgi.Controller, wsgi.AdminActionsMixin): raise exc.HTTPBadRequest(explanation=msg) if not uuidutils.is_uuid_like(share_group_id): msg = _("The 'share_group_id' attribute must be a uuid.") - raise exc.HTTPBadRequest(explanation=six.text_type(msg)) + raise exc.HTTPBadRequest(explanation=msg) kwargs = {"share_group_id": share_group_id} if 'name' in share_group_snapshot: @@ -195,9 +195,9 @@ class ShareGroupSnapshotController(wsgi.Controller, wsgi.AdminActionsMixin): new_snapshot = self.share_group_api.create_share_group_snapshot( context, **kwargs) except exception.ShareGroupNotFound as e: - raise exc.HTTPBadRequest(explanation=six.text_type(e)) + raise exc.HTTPBadRequest(explanation=e.message) except exception.InvalidShareGroup as e: - raise exc.HTTPConflict(explanation=six.text_type(e)) + raise exc.HTTPConflict(explanation=e.message) return self._view_builder.detail(req, dict(new_snapshot.items())) diff --git a/manila/api/v2/share_group_type_specs.py b/manila/api/v2/share_group_type_specs.py index e214a7251c..bfb8f07641 100644 --- a/manila/api/v2/share_group_type_specs.py +++ b/manila/api/v2/share_group_type_specs.py @@ -10,9 +10,9 @@ # License for the specific language governing permissions and limitations # under the License. +import http.client as http_client + import copy -import six -from six.moves import http_client import webob from manila.api import common @@ -43,7 +43,7 @@ class ShareGroupTypeSpecsController(wsgi.Controller): def _verify_group_specs(self, group_specs): def is_valid_string(v): - return isinstance(v, six.string_types) and len(v) in range(1, 256) + return isinstance(v, str) and len(v) in range(1, 256) def is_valid_spec(k, v): valid_spec_key = is_valid_string(k) diff --git a/manila/api/v2/share_group_types.py b/manila/api/v2/share_group_types.py index 1c66c46c0e..0b3d26eeb3 100644 --- a/manila/api/v2/share_group_types.py +++ b/manila/api/v2/share_group_types.py @@ -12,10 +12,10 @@ """The group type API controller module.""" +import http.client as http_client + from oslo_utils import strutils from oslo_utils import uuidutils -import six -from six.moves import http_client import webob from webob import exc @@ -67,7 +67,7 @@ class ShareGroupTypesController(wsgi.Controller): msg = _("Share group type with id %s not found.") raise exc.HTTPNotFound(explanation=msg % id) - share_group_type['id'] = six.text_type(share_group_type['id']) + share_group_type['id'] = str(share_group_type['id']) return self._view_builder.show(req, share_group_type) @wsgi.Controller.api_version('2.31', '2.54', experimental=True) @@ -87,7 +87,7 @@ class ShareGroupTypesController(wsgi.Controller): msg = _("Default share group type not found.") raise exc.HTTPNotFound(explanation=msg) - share_group_type['id'] = six.text_type(share_group_type['id']) + share_group_type['id'] = str(share_group_type['id']) return self._view_builder.show(req, share_group_type) @wsgi.Controller.api_version('2.31', '2.54', experimental=True) @@ -124,7 +124,7 @@ class ShareGroupTypesController(wsgi.Controller): if is_public is None: # preserve default value of showing only public types return True - elif six.text_type(is_public).lower() == "all": + elif str(is_public).lower() == "all": return None else: try: @@ -158,7 +158,7 @@ class ShareGroupTypesController(wsgi.Controller): raise webob.exc.HTTPBadRequest(explanation=msg) if specs: for element in list(specs.keys()) + list(specs.values()): - if not isinstance(element, six.string_types): + if not isinstance(element, str): msg = _("Group specs keys and values should be strings.") raise webob.exc.HTTPBadRequest(explanation=msg) try: @@ -167,9 +167,9 @@ class ShareGroupTypesController(wsgi.Controller): share_group_type = share_group_types.get_by_name( context, name) except exception.ShareGroupTypeExists as err: - raise webob.exc.HTTPConflict(explanation=six.text_type(err)) + raise webob.exc.HTTPConflict(explanation=err.message) except exception.ShareTypeDoesNotExist as err: - raise webob.exc.HTTPNotFound(explanation=six.text_type(err)) + raise webob.exc.HTTPNotFound(explanation=err.message) except exception.NotFound: raise webob.exc.HTTPNotFound() return self._view_builder.show(req, share_group_type) @@ -249,7 +249,7 @@ class ShareGroupTypesController(wsgi.Controller): share_group_types.add_share_group_type_access( context, id, project) except exception.ShareGroupTypeAccessExists as err: - raise webob.exc.HTTPConflict(explanation=six.text_type(err)) + raise webob.exc.HTTPConflict(explanation=err.message) return webob.Response(status_int=http_client.ACCEPTED) # pylint: enable=function-redefined @@ -274,7 +274,7 @@ class ShareGroupTypesController(wsgi.Controller): share_group_types.remove_share_group_type_access( context, id, project) except exception.ShareGroupTypeAccessNotFound as err: - raise webob.exc.HTTPNotFound(explanation=six.text_type(err)) + raise webob.exc.HTTPNotFound(explanation=err.message) return webob.Response(status_int=http_client.ACCEPTED) # pylint: enable=function-redefined @@ -298,7 +298,7 @@ class ShareGroupTypesController(wsgi.Controller): "public share group type.") raise webob.exc.HTTPConflict(explanation=msg) except exception.ShareGroupTypeNotFound as err: - raise webob.exc.HTTPNotFound(explanation=six.text_type(err)) + raise webob.exc.HTTPNotFound(explanation=err.message) def create_resource(): diff --git a/manila/api/v2/share_groups.py b/manila/api/v2/share_groups.py index 52b1b22825..5407eb3bdb 100644 --- a/manila/api/v2/share_groups.py +++ b/manila/api/v2/share_groups.py @@ -13,10 +13,10 @@ # License for the specific language governing permissions and limitations # under the License. +import http.client as http_client + from oslo_log import log from oslo_utils import uuidutils -import six -from six.moves import http_client import webob from webob import exc @@ -78,7 +78,7 @@ class ShareGroupController(wsgi.Controller, wsgi.AdminActionsMixin): try: self.share_group_api.delete(context, share_group) except exception.InvalidShareGroup as e: - raise exc.HTTPConflict(explanation=six.text_type(e)) + raise exc.HTTPConflict(explanation=e.message) return webob.Response(status_int=http_client.ACCEPTED) @wsgi.Controller.api_version('2.31', '2.54', experimental=True) @@ -241,7 +241,7 @@ class ShareGroupController(wsgi.Controller, wsgi.AdminActionsMixin): kwargs['availability_zone_id'] = az.id kwargs['availability_zone'] = az.name except exception.AvailabilityZoneNotFound as e: - raise exc.HTTPNotFound(explanation=six.text_type(e)) + raise exc.HTTPNotFound(explanation=e.message) if 'source_share_group_snapshot_id' in share_group: source_share_group_snapshot_id = share_group.get( @@ -249,21 +249,21 @@ class ShareGroupController(wsgi.Controller, wsgi.AdminActionsMixin): if not uuidutils.is_uuid_like(source_share_group_snapshot_id): msg = _("The 'source_share_group_snapshot_id' attribute " "must be a uuid.") - raise exc.HTTPBadRequest(explanation=six.text_type(msg)) + raise exc.HTTPBadRequest(explanation=msg) kwargs['source_share_group_snapshot_id'] = ( source_share_group_snapshot_id) elif 'share_network_id' in share_group: share_network_id = share_group.get('share_network_id') if not uuidutils.is_uuid_like(share_network_id): msg = _("The 'share_network_id' attribute must be a uuid.") - raise exc.HTTPBadRequest(explanation=six.text_type(msg)) + raise exc.HTTPBadRequest(explanation=msg) kwargs['share_network_id'] = share_network_id if 'share_group_type_id' in share_group: share_group_type_id = share_group.get('share_group_type_id') if not uuidutils.is_uuid_like(share_group_type_id): msg = _("The 'share_group_type_id' attribute must be a uuid.") - raise exc.HTTPBadRequest(explanation=six.text_type(msg)) + raise exc.HTTPBadRequest(explanation=msg) kwargs['share_group_type_id'] = share_group_type_id else: # get default def_share_group_type = share_group_types.get_default() @@ -277,10 +277,10 @@ class ShareGroupController(wsgi.Controller, wsgi.AdminActionsMixin): try: new_share_group = self.share_group_api.create(context, **kwargs) except exception.InvalidShareGroupSnapshot as e: - raise exc.HTTPConflict(explanation=six.text_type(e)) + raise exc.HTTPConflict(explanation=e.message) except (exception.ShareGroupSnapshotNotFound, exception.InvalidInput) as e: - raise exc.HTTPBadRequest(explanation=six.text_type(e)) + raise exc.HTTPBadRequest(explanation=e.message) return self._view_builder.detail( req, {k: v for k, v in new_share_group.items()}) diff --git a/manila/api/v2/share_instance_export_locations.py b/manila/api/v2/share_instance_export_locations.py index be9c9c35b4..aa49cdc80a 100644 --- a/manila/api/v2/share_instance_export_locations.py +++ b/manila/api/v2/share_instance_export_locations.py @@ -13,7 +13,6 @@ # License for the specific language governing permissions and limitations # under the License. -import six from webob import exc from manila.api.openstack import wsgi @@ -66,7 +65,7 @@ class ShareInstanceExportLocationController(wsgi.Controller): context, export_location_uuid) return self._view_builder.detail(req, export_location) except exception.ExportLocationNotFound as e: - raise exc.HTTPNotFound(explanation=six.text_type(e)) + raise exc.HTTPNotFound(explanation=e.message) def create_resource(): diff --git a/manila/api/v2/share_network_subnets.py b/manila/api/v2/share_network_subnets.py index 2651800e8c..a703c3c6ca 100644 --- a/manila/api/v2/share_network_subnets.py +++ b/manila/api/v2/share_network_subnets.py @@ -13,11 +13,11 @@ # License for the specific language governing permissions and limitations # under the License. +import http.client as http_client from manila.api import common from oslo_db import exception as db_exception from oslo_log import log -from six.moves import http_client import webob from webob import exc diff --git a/manila/api/v2/share_networks.py b/manila/api/v2/share_networks.py index 3510f35aea..d20a49a6fa 100644 --- a/manila/api/v2/share_networks.py +++ b/manila/api/v2/share_networks.py @@ -16,10 +16,11 @@ """The shares api.""" import copy +import http.client as http_client + from oslo_db import exception as db_exception from oslo_log import log from oslo_utils import timeutils -from six.moves import http_client import webob from webob import exc diff --git a/manila/api/v2/share_replica_export_locations.py b/manila/api/v2/share_replica_export_locations.py index da8eaf66be..3ac01cb22e 100644 --- a/manila/api/v2/share_replica_export_locations.py +++ b/manila/api/v2/share_replica_export_locations.py @@ -12,7 +12,6 @@ # License for the specific language governing permissions and limitations # under the License. -import six from webob import exc from manila.api.openstack import wsgi @@ -86,7 +85,7 @@ class ShareReplicaExportLocationController(wsgi.Controller): return self._view_builder.detail(req, export_location, replica=True) except exception.ExportLocationNotFound as e: - raise exc.HTTPNotFound(explanation=six.text_type(e)) + raise exc.HTTPNotFound(explanation=e.message) def create_resource(): diff --git a/manila/api/v2/share_replicas.py b/manila/api/v2/share_replicas.py index 1a31b21468..4aea91782e 100644 --- a/manila/api/v2/share_replicas.py +++ b/manila/api/v2/share_replicas.py @@ -15,8 +15,8 @@ """The Share Replication API.""" -import six -from six.moves import http_client +import http.client as http_client + import webob from webob import exc @@ -55,7 +55,7 @@ class ShareReplicationController(wsgi.Controller, wsgi.AdminActionsMixin): try: self.share_api.delete_share_replica(context, resource, force=True) except exception.ReplicationException as e: - raise exc.HTTPBadRequest(explanation=six.text_type(e)) + raise exc.HTTPBadRequest(explanation=e.message) @wsgi.Controller.api_version( MIN_SUPPORTED_API_VERSION, PRE_GRADUATION_VERSION, experimental=True) @@ -171,11 +171,11 @@ class ShareReplicationController(wsgi.Controller, wsgi.AdminActionsMixin): context, share_ref, availability_zone=availability_zone, share_network_id=share_network_id) except exception.AvailabilityZoneNotFound as e: - raise exc.HTTPBadRequest(explanation=six.text_type(e)) + raise exc.HTTPBadRequest(explanation=e.message) except exception.ReplicationException as e: - raise exc.HTTPBadRequest(explanation=six.text_type(e)) + raise exc.HTTPBadRequest(explanation=e.message) except exception.ShareBusyException as e: - raise exc.HTTPBadRequest(explanation=six.text_type(e)) + raise exc.HTTPBadRequest(explanation=e.message) return self._view_builder.detail(req, new_replica) @@ -202,7 +202,7 @@ class ShareReplicationController(wsgi.Controller, wsgi.AdminActionsMixin): try: self.share_api.delete_share_replica(context, replica) except exception.ReplicationException as e: - raise exc.HTTPBadRequest(explanation=six.text_type(e)) + raise exc.HTTPBadRequest(explanation=e.message) return webob.Response(status_int=http_client.ACCEPTED) @@ -243,9 +243,9 @@ class ShareReplicationController(wsgi.Controller, wsgi.AdminActionsMixin): try: replica = self.share_api.promote_share_replica(context, replica) except exception.ReplicationException as e: - raise exc.HTTPBadRequest(explanation=six.text_type(e)) + raise exc.HTTPBadRequest(explanation=e.message) except exception.AdminRequired as e: - raise exc.HTTPForbidden(explanation=six.text_type(e)) + raise exc.HTTPForbidden(explanation=e.message) return self._view_builder.detail(req, replica) @@ -327,7 +327,7 @@ class ShareReplicationController(wsgi.Controller, wsgi.AdminActionsMixin): try: self.share_api.update_share_replica(context, replica) except exception.InvalidHost as e: - raise exc.HTTPBadRequest(explanation=six.text_type(e)) + raise exc.HTTPBadRequest(explanation=e.message) def create_resource(): diff --git a/manila/api/v2/share_servers.py b/manila/api/v2/share_servers.py index b20f609423..a042b1353b 100644 --- a/manila/api/v2/share_servers.py +++ b/manila/api/v2/share_servers.py @@ -13,8 +13,9 @@ # License for the specific language governing permissions and limitations # under the License. +import http.client as http_client + from oslo_log import log -from six.moves import http_client import webob from webob import exc @@ -194,19 +195,19 @@ class ShareServerController(share_servers.ShareServerController, utils.validate_service_host( context, share_utils.extract_host(host)) except exception.ServiceNotFound as e: - raise exc.HTTPBadRequest(explanation=e) + raise exc.HTTPBadRequest(explanation=e.msg) except exception.PolicyNotAuthorized as e: - raise exc.HTTPForbidden(explanation=e) + raise exc.HTTPForbidden(explanation=e.msg) except exception.AdminRequired as e: - raise exc.HTTPForbidden(explanation=e) + raise exc.HTTPForbidden(explanation=e.msg) except exception.ServiceIsDown as e: - raise exc.HTTPBadRequest(explanation=e) + raise exc.HTTPBadRequest(explanation=e.msg) try: share_network = db_api.share_network_get( context, share_network_id) except exception.ShareNetworkNotFound as e: - raise exc.HTTPBadRequest(explanation=e) + raise exc.HTTPBadRequest(explanation=e.msg) driver_opts = data.get('driver_options') if driver_opts is not None and not isinstance(driver_opts, dict): diff --git a/manila/api/v2/share_snapshots.py b/manila/api/v2/share_snapshots.py index 37af493e62..5b3292a511 100644 --- a/manila/api/v2/share_snapshots.py +++ b/manila/api/v2/share_snapshots.py @@ -16,8 +16,9 @@ """The share snapshots api.""" +import http.client as http_client + from oslo_log import log -from six.moves import http_client import webob from webob import exc @@ -76,7 +77,7 @@ class ShareSnapshotsController(share_snapshots.ShareSnapshotMixin, self.share_api.unmanage_snapshot(context, snapshot, share['host']) except (exception.ShareSnapshotNotFound, exception.ShareNotFound) as e: - raise exc.HTTPNotFound(explanation=e) + raise exc.HTTPNotFound(explanation=e.msg) return webob.Response(status_int=http_client.ACCEPTED) @@ -128,10 +129,10 @@ class ShareSnapshotsController(share_snapshots.ShareSnapshotMixin, snapshot_ref = self.share_api.manage_snapshot(context, snapshot, driver_options) except (exception.ShareNotFound, exception.ShareSnapshotNotFound) as e: - raise exc.HTTPNotFound(explanation=e) + raise exc.HTTPNotFound(explanation=e.msg) except (exception.InvalidShare, exception.ManageInvalidShareSnapshot) as e: - raise exc.HTTPConflict(explanation=e) + raise exc.HTTPConflict(explanation=e.msg) return self._view_builder.detail(req, snapshot_ref) diff --git a/manila/api/v2/share_types.py b/manila/api/v2/share_types.py index 902357eb3b..7758d464cd 100644 --- a/manila/api/v2/share_types.py +++ b/manila/api/v2/share_types.py @@ -16,12 +16,11 @@ """The share type API controller module..""" import ast +import http.client as http_client from oslo_log import log from oslo_utils import strutils from oslo_utils import uuidutils -import six -from six.moves import http_client import webob from webob import exc @@ -84,7 +83,7 @@ class ShareTypesController(wsgi.Controller): msg = _("Share type not found.") raise exc.HTTPNotFound(explanation=msg) - share_type['id'] = six.text_type(share_type['id']) + share_type['id'] = str(share_type['id']) req.cache_db_share_type(share_type) return self._view_builder.show(req, share_type) @@ -116,7 +115,7 @@ class ShareTypesController(wsgi.Controller): msg = _("Default share type not found") raise exc.HTTPNotFound(explanation=msg) - share_type['id'] = six.text_type(share_type['id']) + share_type['id'] = str(share_type['id']) return self._view_builder.show(req, share_type) def _get_share_types(self, req): @@ -159,7 +158,7 @@ class ShareTypesController(wsgi.Controller): if is_public is None: # preserve default value of showing only public types return True - elif six.text_type(is_public).lower() == "all": + elif str(is_public).lower() == "all": return None else: try: @@ -229,17 +228,17 @@ class ShareTypesController(wsgi.Controller): context, 'share_type.create', share_type) except exception.InvalidExtraSpec as e: - raise webob.exc.HTTPBadRequest(explanation=six.text_type(e)) + raise webob.exc.HTTPBadRequest(explanation=e.message) except exception.ShareTypeExists as err: notifier_err = dict(share_types=share_type, - error_message=six.text_type(err)) + error_message=err.message) self._notify_share_type_error(context, 'share_type.create', notifier_err) - raise webob.exc.HTTPConflict(explanation=six.text_type(err)) + raise webob.exc.HTTPConflict(explanation=err.message) except exception.NotFound as err: notifier_err = dict(share_types=share_type, - error_message=six.text_type(err)) + error_message=err.message) self._notify_share_type_error(context, 'share_type.create', notifier_err) raise webob.exc.HTTPNotFound() @@ -258,13 +257,13 @@ class ShareTypesController(wsgi.Controller): self._notify_share_type_info( context, 'share_type.delete', share_type) except exception.ShareTypeInUse as err: - notifier_err = dict(id=id, error_message=six.text_type(err)) + notifier_err = dict(id=id, error_message=err.message) self._notify_share_type_error(context, 'share_type.delete', notifier_err) msg = 'Target share type is still in use.' raise webob.exc.HTTPBadRequest(explanation=msg) except exception.NotFound as err: - notifier_err = dict(id=id, error_message=six.text_type(err)) + notifier_err = dict(id=id, error_message=err.message) self._notify_share_type_error(context, 'share_type.delete', notifier_err) @@ -380,7 +379,7 @@ class ShareTypesController(wsgi.Controller): try: share_types.add_share_type_access(context, id, project) except exception.ShareTypeAccessExists as err: - raise webob.exc.HTTPConflict(explanation=six.text_type(err)) + raise webob.exc.HTTPConflict(explanation=err.message) return webob.Response(status_int=http_client.ACCEPTED) @@ -396,7 +395,7 @@ class ShareTypesController(wsgi.Controller): try: share_types.remove_share_type_access(context, id, project) except exception.ShareTypeAccessNotFound as err: - raise webob.exc.HTTPNotFound(explanation=six.text_type(err)) + raise webob.exc.HTTPNotFound(explanation=err.message) return webob.Response(status_int=http_client.ACCEPTED) def _verify_if_non_public_share_type(self, context, share_type_id): @@ -409,7 +408,7 @@ class ShareTypesController(wsgi.Controller): raise webob.exc.HTTPConflict(explanation=msg) except exception.ShareTypeNotFound as err: - raise webob.exc.HTTPNotFound(explanation=six.text_type(err)) + raise webob.exc.HTTPNotFound(explanation=err.message) def create_resource(): diff --git a/manila/api/v2/shares.py b/manila/api/v2/shares.py index 0dc9e49275..9baa990659 100644 --- a/manila/api/v2/shares.py +++ b/manila/api/v2/shares.py @@ -13,8 +13,9 @@ # License for the specific language governing permissions and limitations # under the License. +import http.client as http_client + from oslo_log import log -from six.moves import http_client import webob from webob import exc @@ -150,13 +151,13 @@ class ShareController(shares.ShareMixin, self.share_api.revert_to_snapshot(context, share, snapshot) except exception.ShareNotFound as e: - raise exc.HTTPNotFound(explanation=e) + raise exc.HTTPNotFound(explanation=e.msg) except exception.ShareSnapshotNotFound as e: - raise exc.HTTPBadRequest(explanation=e) + raise exc.HTTPBadRequest(explanation=e.msg) except exception.ShareSizeExceedsAvailableQuota as e: - raise exc.HTTPForbidden(explanation=e) + raise exc.HTTPForbidden(explanation=e.msg) except exception.ReplicationException as e: - raise exc.HTTPBadRequest(explanation=e) + raise exc.HTTPBadRequest(explanation=e.msg) return webob.Response(status_int=http_client.ACCEPTED) @@ -285,7 +286,7 @@ class ShareController(shares.ShareMixin, new_share_network=new_share_network, new_share_type=new_share_type) except exception.Conflict as e: - raise exc.HTTPConflict(explanation=e) + raise exc.HTTPConflict(explanation=e.msg) return webob.Response(status_int=return_code) diff --git a/manila/api/views/versions.py b/manila/api/views/versions.py index b2bddcd39c..542632e73b 100644 --- a/manila/api/views/versions.py +++ b/manila/api/views/versions.py @@ -16,8 +16,7 @@ import copy import re - -from six.moves import urllib +import urllib def get_view_builder(req):