Fix lazy translation UnicodeErrors

upload_utils is concatenating str and Message objects which doesn't work
on python 2, so change the str to a unicode object.

test_quota.py was casting Message objects to str which fails for the
same reason, so rather than cast to str, cast using six.text_type.

See oslo commit 2cfc1a78d8063cf20083cf7df796d730a576551c for history and
details on why the Message object doesn't support __str__ casting.

This is a small part of a larger effort that the oslo team will be
rolling out with graduation and adoption of the oslo-i18n library.

Closes-Bug: #1334774

Change-Id: I9d3f29c661f1afffabbbbb499f48d37ef5a8fcee
This commit is contained in:
Matt Riedemann 2014-06-26 11:59:08 -07:00
parent be6e487aeb
commit 834e1f2150
2 changed files with 11 additions and 9 deletions

View File

@ -162,7 +162,7 @@ def upload_data_to_store(req, image_meta, image_data, store, notifier):
content_type='text/plain')
except exception.Duplicate as e:
msg = "Attempt to upload duplicate image: %s" % e
msg = u"Attempt to upload duplicate image: %s" % e
LOG.debug(msg)
# NOTE(dosaboy): do not delete the image since it is likely that this
# conflict is a result of another concurrent upload that will be
@ -173,7 +173,7 @@ def upload_data_to_store(req, image_meta, image_data, store, notifier):
content_type="text/plain")
except exception.Forbidden as e:
msg = "Forbidden upload attempt: %s" % e
msg = u"Forbidden upload attempt: %s" % e
LOG.debug(msg)
safe_kill(req, image_id)
notifier.error('image.upload', msg)

View File

@ -17,6 +17,8 @@ import mock
from mock import patch
import uuid
import six
from glance.common import exception
from glance.openstack.common import units
import glance.quota
@ -338,7 +340,7 @@ class TestImagePropertyQuotas(test_utils.BaseTestCase):
self.image.extra_properties = {'foo': 'bar', 'foo2': 'bar2'}
exc = self.assertRaises(exception.ImagePropertyLimitExceeded,
self.image_repo_proxy.save, self.image)
self.assertIn("Attempted: 2, Maximum: 1", str(exc))
self.assertIn("Attempted: 2, Maximum: 1", six.text_type(exc))
def test_save_image_unlimited_image_properties(self):
self.config(image_property_quota=-1)
@ -362,7 +364,7 @@ class TestImagePropertyQuotas(test_utils.BaseTestCase):
self.image.extra_properties = {'foo': 'bar', 'foo2': 'bar2'}
exc = self.assertRaises(exception.ImagePropertyLimitExceeded,
self.image_repo_proxy.add, self.image)
self.assertIn("Attempted: 2, Maximum: 1", str(exc))
self.assertIn("Attempted: 2, Maximum: 1", six.text_type(exc))
def test_add_image_unlimited_image_properties(self):
self.config(image_property_quota=-1)
@ -398,7 +400,7 @@ class TestImageTagQuotas(test_utils.BaseTestCase):
exc = self.assertRaises(exception.ImageTagLimitExceeded,
setattr, self.image, 'tags', ['foo', 'bar'])
self.assertIn('Attempted: 2, Maximum: 0', str(exc))
self.assertIn('Attempted: 2, Maximum: 0', six.text_type(exc))
self.assertEqual(len(self.image.tags), 0)
def test_replace_unlimited_image_tags(self):
@ -416,7 +418,7 @@ class TestImageTagQuotas(test_utils.BaseTestCase):
self.image.tags.add('foo')
exc = self.assertRaises(exception.ImageTagLimitExceeded,
self.image.tags.add, 'bar')
self.assertIn('Attempted: 2, Maximum: 1', str(exc))
self.assertIn('Attempted: 2, Maximum: 1', six.text_type(exc))
def test_add_unlimited_image_tags(self):
self.config(image_tag_quota=-1)
@ -446,7 +448,7 @@ class TestQuotaImageTagsProxy(test_utils.BaseTestCase):
proxy = glance.quota.QuotaImageTagsProxy(set([]))
exc = self.assertRaises(exception.ImageTagLimitExceeded,
proxy.add, 'bar')
self.assertIn('Attempted: 1, Maximum: 0', str(exc))
self.assertIn('Attempted: 1, Maximum: 0', six.text_type(exc))
def test_equals(self):
proxy = glance.quota.QuotaImageTagsProxy(set([]))
@ -542,7 +544,7 @@ class TestImageLocationQuotas(test_utils.BaseTestCase):
]
exc = self.assertRaises(exception.ImageLocationLimitExceeded,
setattr, self.image, 'locations', locations)
self.assertIn('Attempted: 3, Maximum: 1', str(exc))
self.assertIn('Attempted: 3, Maximum: 1', six.text_type(exc))
self.assertEqual(len(self.image.locations), 1)
def test_replace_unlimited_image_locations(self):
@ -565,7 +567,7 @@ class TestImageLocationQuotas(test_utils.BaseTestCase):
location2 = {"url": "file:///fake2.img.tar.gz", "metadata": {}}
exc = self.assertRaises(exception.ImageLocationLimitExceeded,
self.image.locations.append, location2)
self.assertIn('Attempted: 2, Maximum: 1', str(exc))
self.assertIn('Attempted: 2, Maximum: 1', six.text_type(exc))
def test_add_unlimited_image_locations(self):
self.config(image_location_quota=-1)