Skip to content

Commit 17ad1ae

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Replace oslo_utils.encodeutils.exception_to_unicode"
2 parents 0989e4d + 0bdc50b commit 17ad1ae

39 files changed

+135
-232
lines changed

glance/api/v2/image_data.py

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
from glance_store import location
2121
from oslo_config import cfg
2222
from oslo_log import log as logging
23-
from oslo_utils import encodeutils
2423
from oslo_utils import excutils
2524
import webob.exc
2625

@@ -67,7 +66,7 @@ def _restore(self, image_repo, image):
6766
except Exception as e:
6867
msg = (_LE("Unable to restore image %(image_id)s: %(e)s") %
6968
{'image_id': image.image_id,
70-
'e': encodeutils.exception_to_unicode(e)})
69+
'e': e})
7170
LOG.exception(msg)
7271

7372
def _unstage(self, image_repo, image, staging_store):
@@ -154,7 +153,7 @@ def upload(self, req, image_id, data, size):
154153
except Exception as e:
155154
LOG.info(_LI("Unable to create trust: %s "
156155
"Use the existing user token."),
157-
encodeutils.exception_to_unicode(e))
156+
e)
158157

159158
image_repo.save(image, from_state='queued')
160159
ks_quota.enforce_image_count_uploading(req.context,
@@ -176,9 +175,9 @@ def upload(self, req, image_id, data, size):
176175
if refresher is not None:
177176
refresher.release_resources()
178177
except Exception as e:
179-
LOG.info(_LI("Unable to delete trust %(trust)s: %(msg)s"),
178+
LOG.info(_LI("Unable to delete trust %(trust)s: %(err)s"),
180179
{"trust": refresher.trust_id,
181-
"msg": encodeutils.exception_to_unicode(e)})
180+
"err": e})
182181

183182
except (glance_store.NotFound,
184183
exception.ImageNotFound,
@@ -213,10 +212,10 @@ def upload(self, req, image_id, data, size):
213212
except ValueError as e:
214213
LOG.debug("Cannot save data for image %(id)s: %(e)s",
215214
{'id': image_id,
216-
'e': encodeutils.exception_to_unicode(e)})
215+
'e': e})
217216
self._restore(image_repo, image)
218217
raise webob.exc.HTTPBadRequest(
219-
explanation=encodeutils.exception_to_unicode(e))
218+
explanation=str(e))
220219

221220
except glance_store.StoreAddDisabled:
222221
msg = _("Error in store configuration. Adding images to store "
@@ -227,8 +226,7 @@ def upload(self, req, image_id, data, size):
227226
content_type='text/plain')
228227

229228
except exception.InvalidImageStatusTransition as e:
230-
msg = encodeutils.exception_to_unicode(e)
231-
LOG.exception(msg)
229+
LOG.exception(str(e))
232230
raise webob.exc.HTTPConflict(explanation=e.msg, request=req)
233231

234232
except exception.Forbidden:
@@ -241,24 +239,21 @@ def upload(self, req, image_id, data, size):
241239
raise webob.exc.HTTPNotFound(explanation=e.msg)
242240

243241
except glance_store.StorageFull as e:
244-
msg = _("Image storage media "
245-
"is full: %s") % encodeutils.exception_to_unicode(e)
242+
msg = _("Image storage media is full: %s") % e
246243
LOG.error(msg)
247244
self._restore(image_repo, image)
248245
raise webob.exc.HTTPRequestEntityTooLarge(explanation=msg,
249246
request=req)
250247

251248
except exception.StorageQuotaFull as e:
252-
msg = _("Image exceeds the storage "
253-
"quota: %s") % encodeutils.exception_to_unicode(e)
249+
msg = _("Image exceeds the storage quota: %s") % e
254250
LOG.error(msg)
255251
self._restore(image_repo, image)
256252
raise webob.exc.HTTPRequestEntityTooLarge(explanation=msg,
257253
request=req)
258254

259255
except exception.ImageSizeLimitExceeded as e:
260-
msg = _("The incoming image is "
261-
"too large: %s") % encodeutils.exception_to_unicode(e)
256+
msg = _("The incoming image is too large: %s") % e
262257
LOG.error(msg)
263258
self._restore(image_repo, image)
264259
raise webob.exc.HTTPRequestEntityTooLarge(explanation=msg,
@@ -277,17 +272,15 @@ def upload(self, req, image_id, data, size):
277272
request=req)
278273

279274
except glance_store.StorageWriteDenied as e:
280-
msg = _("Insufficient permissions on image "
281-
"storage media: %s") % encodeutils.exception_to_unicode(e)
275+
msg = _("Insufficient permissions on image storage media: %s") % e
282276
LOG.error(msg)
283277
self._restore(image_repo, image)
284278
raise webob.exc.HTTPServiceUnavailable(explanation=msg,
285279
request=req)
286280

287281
except cursive_exception.SignatureVerificationError as e:
288282
msg = (_LE("Signature verification failed for image %(id)s: %(e)s")
289-
% {'id': image_id,
290-
'e': encodeutils.exception_to_unicode(e)})
283+
% {'id': image_id, 'e': e})
291284
LOG.error(msg)
292285
self._restore(image_repo, image)
293286
raise webob.exc.HTTPBadRequest(explanation=msg)
@@ -395,24 +388,21 @@ def _build_staging_store():
395388
raise webob.exc.HTTPNotFound(explanation=e.msg)
396389

397390
except glance_store.StorageFull as e:
398-
msg = _("Image storage media "
399-
"is full: %s") % encodeutils.exception_to_unicode(e)
391+
msg = _("Image storage media is full: %s") % e
400392
LOG.error(msg)
401393
self._unstage(image_repo, image, staging_store)
402394
raise webob.exc.HTTPRequestEntityTooLarge(explanation=msg,
403395
request=req)
404396

405397
except exception.StorageQuotaFull as e:
406-
msg = _("Image exceeds the storage "
407-
"quota: %s") % encodeutils.exception_to_unicode(e)
398+
msg = _("Image exceeds the storage quota: %s") % e
408399
LOG.debug(msg)
409400
self._unstage(image_repo, image, staging_store)
410401
raise webob.exc.HTTPRequestEntityTooLarge(explanation=msg,
411402
request=req)
412403

413404
except exception.ImageSizeLimitExceeded as e:
414-
msg = _("The incoming image is "
415-
"too large: %s") % encodeutils.exception_to_unicode(e)
405+
msg = _("The incoming image is too large: %s") % e
416406
LOG.debug(msg)
417407
self._unstage(image_repo, image, staging_store)
418408
raise webob.exc.HTTPRequestEntityTooLarge(explanation=msg,
@@ -426,15 +416,14 @@ def _build_staging_store():
426416

427417
except glance_store.StorageWriteDenied as e:
428418
msg = _("Insufficient permissions on image "
429-
"storage media: %s") % encodeutils.exception_to_unicode(e)
419+
"storage media: %s") % e
430420
LOG.error(msg)
431421
self._unstage(image_repo, image, staging_store)
432422
raise webob.exc.HTTPServiceUnavailable(explanation=msg,
433423
request=req)
434424

435425
except exception.InvalidImageStatusTransition as e:
436-
msg = encodeutils.exception_to_unicode(e)
437-
LOG.debug(msg)
426+
LOG.debug(str(e))
438427
raise webob.exc.HTTPConflict(explanation=e.msg, request=req)
439428

440429
except Exception:

glance/api/v2/image_members.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
from oslo_config import cfg
2121
from oslo_log import log as logging
2222
from oslo_serialization import jsonutils
23-
from oslo_utils import encodeutils
2423
import webob
2524

2625
from glance.api import policy
@@ -179,7 +178,7 @@ def create(self, req, image_id, member_id):
179178
except exception.ImageMemberLimitExceeded as e:
180179
msg = (_("Image member limit exceeded for image %(id)s: %(e)s:")
181180
% {"id": image_id,
182-
"e": encodeutils.exception_to_unicode(e)})
181+
"e": e})
183182
LOG.warning(msg)
184183
raise webob.exc.HTTPRequestEntityTooLarge(explanation=msg)
185184

@@ -228,8 +227,7 @@ def update(self, req, image_id, member_id, status):
228227
LOG.warning(msg)
229228
raise webob.exc.HTTPForbidden(explanation=msg)
230229
except ValueError as e:
231-
msg = (_("Incorrect request: %s")
232-
% encodeutils.exception_to_unicode(e))
230+
msg = (_("Incorrect request: %s") % e)
233231
LOG.warning(msg)
234232
raise webob.exc.HTTPBadRequest(explanation=msg)
235233

glance/api/v2/image_tags.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
import glance_store
1818
from oslo_log import log as logging
19-
from oslo_utils import encodeutils
2019
import webob.exc
2120

2221
from glance.api import policy
@@ -62,14 +61,13 @@ def update(self, req, image_id, tag_value):
6261
LOG.warning(msg)
6362
raise webob.exc.HTTPForbidden(explanation=msg)
6463
except exception.Invalid as e:
65-
msg = (_("Could not update image: %s")
66-
% encodeutils.exception_to_unicode(e))
64+
msg = (_("Could not update image: %s") % e)
6765
LOG.warning(msg)
6866
raise webob.exc.HTTPBadRequest(explanation=msg)
6967
except exception.ImageTagLimitExceeded as e:
7068
msg = (_("Image tag limit exceeded for image %(id)s: %(e)s:")
7169
% {"id": image_id,
72-
"e": encodeutils.exception_to_unicode(e)})
70+
"e": e})
7371
LOG.warning(msg)
7472
raise webob.exc.HTTPRequestEntityTooLarge(explanation=msg)
7573

glance/api/v2/images.py

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
from oslo_config import cfg
2828
from oslo_log import log as logging
2929
from oslo_serialization import jsonutils as json
30-
from oslo_utils import encodeutils
3130
from oslo_utils import timeutils as oslo_timeutils
3231
import requests
3332
import webob.exc
@@ -116,15 +115,15 @@ def create(self, req, image, extra_properties, tags):
116115
LOG.debug("User not permitted to create image")
117116
raise webob.exc.HTTPForbidden(explanation=e.msg)
118117
except exception.LimitExceeded as e:
119-
LOG.warning(encodeutils.exception_to_unicode(e))
118+
LOG.warning(str(e))
120119
raise webob.exc.HTTPRequestEntityTooLarge(
121120
explanation=e.msg, request=req, content_type='text/plain')
122121
except exception.Duplicate as e:
123122
raise webob.exc.HTTPConflict(explanation=e.msg)
124123
except exception.NotAuthenticated as e:
125124
raise webob.exc.HTTPUnauthorized(explanation=e.msg)
126125
except TypeError as e:
127-
LOG.debug(encodeutils.exception_to_unicode(e))
126+
LOG.debug(str(e))
128127
raise webob.exc.HTTPBadRequest(explanation=e)
129128

130129
return image
@@ -505,9 +504,9 @@ def import_image(self, req, image_id, body):
505504
except ValueError as e:
506505
LOG.debug("Cannot import data for image %(id)s: %(e)s",
507506
{'id': image_id,
508-
'e': encodeutils.exception_to_unicode(e)})
507+
'e': e})
509508
raise webob.exc.HTTPBadRequest(
510-
explanation=encodeutils.exception_to_unicode(e))
509+
explanation=str(e))
511510

512511
return image_id
513512

@@ -634,12 +633,12 @@ def update(self, req, image_id, changes):
634633
raise webob.exc.HTTPForbidden(explanation=e.msg)
635634
except exception.StorageQuotaFull as e:
636635
msg = (_("Denying attempt to upload image because it exceeds the"
637-
" quota: %s") % encodeutils.exception_to_unicode(e))
636+
" quota: %s") % e)
638637
LOG.warning(msg)
639638
raise webob.exc.HTTPRequestEntityTooLarge(
640639
explanation=msg, request=req, content_type='text/plain')
641640
except exception.LimitExceeded as e:
642-
LOG.exception(encodeutils.exception_to_unicode(e))
641+
LOG.exception(str(e))
643642
raise webob.exc.HTTPRequestEntityTooLarge(
644643
explanation=e.msg, request=req, content_type='text/plain')
645644
except exception.NotAuthenticated as e:
@@ -806,7 +805,7 @@ def delete_from_store(self, req, store_id, image_id):
806805
raise webob.exc.HTTPConflict(explanation=msg)
807806
except Exception as e:
808807
raise webob.exc.HTTPInternalServerError(
809-
explanation=encodeutils.exception_to_unicode(e))
808+
explanation=str(e))
810809

811810
image_repo.save(image)
812811

@@ -1073,8 +1072,7 @@ def _do_replace_locations(self, image, value):
10731072
except (exception.BadStoreUri, exception.DuplicateLocation) as e:
10741073
raise webob.exc.HTTPBadRequest(explanation=e.msg)
10751074
except ValueError as ve: # update image status failed.
1076-
raise webob.exc.HTTPBadRequest(
1077-
explanation=encodeutils.exception_to_unicode(ve))
1075+
raise webob.exc.HTTPBadRequest(explanation=str(ve))
10781076

10791077
def _do_add_locations(self, image, path_pos, value, context):
10801078
if CONF.show_multiple_locations == False:
@@ -1108,8 +1106,7 @@ def _do_add_locations(self, image, path_pos, value, context):
11081106
except (exception.BadStoreUri, exception.DuplicateLocation) as e:
11091107
raise webob.exc.HTTPBadRequest(explanation=e.msg)
11101108
except ValueError as e: # update image status failed.
1111-
raise webob.exc.HTTPBadRequest(
1112-
explanation=encodeutils.exception_to_unicode(e))
1109+
raise webob.exc.HTTPBadRequest(explanation=str(e))
11131110

11141111
def _do_remove_locations(self, image, path_pos):
11151112
if CONF.show_multiple_locations == False:
@@ -1139,8 +1136,7 @@ def _do_remove_locations(self, image, path_pos):
11391136
# TODO(jokke): Fix this, we should catch what store throws and
11401137
# provide definitely something else than IternalServerError to user.
11411138
except Exception as e:
1142-
raise webob.exc.HTTPInternalServerError(
1143-
explanation=encodeutils.exception_to_unicode(e))
1139+
raise webob.exc.HTTPInternalServerError(explanation=str(e))
11441140

11451141
def add_location(self, req, image_id, body):
11461142
url = body.get('url')
@@ -1225,8 +1221,7 @@ def add_location(self, req, image_id, body):
12251221
except exception.NotAuthenticated as e:
12261222
raise webob.exc.HTTPUnauthorized(explanation=e.msg)
12271223
except ValueError as e:
1228-
raise webob.exc.HTTPBadRequest(
1229-
explanation=encodeutils.exception_to_unicode(e))
1224+
raise webob.exc.HTTPBadRequest(explanation=str(e))
12301225

12311226
return image_id
12321227

glance/api/v2/metadef_namespaces.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
from oslo_config import cfg
2020
from oslo_log import log as logging
2121
from oslo_serialization import jsonutils
22-
from oslo_utils import encodeutils
2322
import webob.exc
2423
from wsme.rest import json
2524

@@ -214,8 +213,7 @@ def create(self, req, namespace):
214213
))
215214
prop_repo.add(new_property_type)
216215
except exception.Invalid as e:
217-
msg = (_("Couldn't create metadata namespace: %s")
218-
% encodeutils.exception_to_unicode(e))
216+
msg = (_("Couldn't create metadata namespace: %s") % e)
219217
raise webob.exc.HTTPBadRequest(explanation=msg)
220218
except exception.Forbidden as e:
221219
self._cleanup_namespace(ns_repo, namespace, namespace_created)
@@ -257,7 +255,7 @@ def _cleanup_namespace(self, namespace_repo, namespace, namespace_created):
257255
msg = (_LE("Failed to delete namespace %(namespace)s."
258256
"Exception: %(exception)s"),
259257
{'namespace': namespace.namespace,
260-
'exception': encodeutils.exception_to_unicode(e)})
258+
'exception': str(e)})
261259
LOG.error(msg)
262260

263261
def show(self, req, namespace, filters=None):
@@ -373,8 +371,7 @@ def update(self, req, user_ns, namespace):
373371
wsme_utils._get_value(user_ns.owner) or req.context.owner)
374372
updated_namespace = namespace_repo.save(ns_obj)
375373
except exception.Invalid as e:
376-
msg = (_("Couldn't update metadata namespace: %s")
377-
% encodeutils.exception_to_unicode(e))
374+
msg = (_("Couldn't update metadata namespace: %s") % e)
378375
raise webob.exc.HTTPBadRequest(explanation=msg)
379376
except exception.Forbidden as e:
380377
LOG.debug("User not permitted to update metadata namespace "

glance/api/v2/metadef_objects.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
from oslo_log import log as logging
1919
from oslo_serialization import jsonutils
20-
from oslo_utils import encodeutils
2120
import webob.exc
2221
from wsme.rest import json
2322

@@ -81,8 +80,7 @@ def create(self, req, metadata_object, namespace):
8180
"'%s' namespace", namespace)
8281
raise webob.exc.HTTPForbidden(explanation=e.msg)
8382
except exception.Invalid as e:
84-
msg = (_("Couldn't create metadata object: %s")
85-
% encodeutils.exception_to_unicode(e))
83+
msg = (_("Couldn't create metadata object: %s") % e)
8684
raise webob.exc.HTTPBadRequest(explanation=msg)
8785
except exception.NotFound as e:
8886
raise webob.exc.HTTPNotFound(explanation=e.msg)
@@ -207,8 +205,7 @@ def update(self, req, metadata_object, namespace, object_name):
207205
metadata_object.properties)
208206
updated_metadata_obj = meta_repo.save(metadef_object)
209207
except exception.Invalid as e:
210-
msg = (_("Couldn't update metadata object: %s")
211-
% encodeutils.exception_to_unicode(e))
208+
msg = (_("Couldn't update metadata object: %s") % e)
212209
raise webob.exc.HTTPBadRequest(explanation=msg)
213210
except exception.Forbidden as e:
214211
LOG.debug("User not permitted to update metadata object '%s' "

0 commit comments

Comments
 (0)