Merge "Stop using deprecated 'message' attribute in Exception"

This commit is contained in:
Jenkins 2017-09-12 20:41:57 +00:00 committed by Gerrit Code Review
commit 584caafadb
9 changed files with 56 additions and 47 deletions

View File

@ -17,6 +17,7 @@
API handler for Barbican
"""
import pkgutil
import six
from oslo_policy import policy
from oslo_serialization import jsonutils as json
@ -68,7 +69,7 @@ def load_body(req, resp=None, validator=None):
try:
parsed_body = validator.validate(parsed_body)
except exception.BarbicanHTTPException as e:
LOG.exception(e.message)
LOG.exception(six.text_type(e))
pecan.abort(e.status_code, e.client_message)
return parsed_body

View File

@ -14,6 +14,7 @@
import argparse
import base64
import json
import six
import traceback
from oslo_db.sqlalchemy import session
@ -60,7 +61,7 @@ class KekSignatureMigrator(object):
self.pkcs11.verify_hmac(hmac_key, hmac, kek_data, self.session)
sig_good = True
except P11CryptoPluginException as e:
if 'CKR_SIGNATURE_INVALID' in e.message:
if 'CKR_SIGNATURE_INVALID' in six.text_type(e):
sig_good = False
else:
raise
@ -78,7 +79,7 @@ class KekSignatureMigrator(object):
)
sig_bad = True
except P11CryptoPluginException as e:
if 'CKR_SIGNATURE_INVALID' in e.message:
if 'CKR_SIGNATURE_INVALID' in six.text_type(e):
sig_bad = False
else:
raise

View File

@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import six
import unittest
from barbican.common import exception as excep
@ -233,10 +234,10 @@ class WhenTestingQuotaEnforcingFunctions(database_utils.RepositoryTestCase):
quota_enforcer.enforce,
self.project
)
self.assertIn('Quota reached for project', exception.message)
self.assertIn('my_keystone_id', exception.message)
self.assertIn('secrets', exception.message)
self.assertIn(str(0), exception.message)
self.assertIn('Quota reached for project', six.text_type(exception))
self.assertIn('my_keystone_id', six.text_type(exception))
self.assertIn('secrets', six.text_type(exception))
self.assertIn(str(0), six.text_type(exception))
def test_should_pass_below_limit(self):
test_repo = DummyRepoForTestingQuotaEnforcement(4)
@ -261,10 +262,10 @@ class WhenTestingQuotaEnforcingFunctions(database_utils.RepositoryTestCase):
quota_enforcer.enforce,
self.project
)
self.assertIn('Quota reached for project', exception.message)
self.assertIn('my_keystone_id', exception.message)
self.assertIn('secrets', exception.message)
self.assertIn(str(5), exception.message)
self.assertIn('Quota reached for project', six.text_type(exception))
self.assertIn('my_keystone_id', six.text_type(exception))
self.assertIn('secrets', six.text_type(exception))
self.assertIn(str(5), six.text_type(exception))
def test_should_raise_above_limit(self):
test_repo = DummyRepoForTestingQuotaEnforcement(6)
@ -279,10 +280,10 @@ class WhenTestingQuotaEnforcingFunctions(database_utils.RepositoryTestCase):
quota_enforcer.enforce,
self.project
)
self.assertIn('Quota reached for project', exception.message)
self.assertIn('my_keystone_id', exception.message)
self.assertIn('secrets', exception.message)
self.assertIn(str(5), exception.message)
self.assertIn('Quota reached for project', six.text_type(exception))
self.assertIn('my_keystone_id', six.text_type(exception))
self.assertIn('secrets', six.text_type(exception))
self.assertIn(str(5), six.text_type(exception))
if __name__ == '__main__':

View File

@ -242,7 +242,7 @@ class WhenTestingSecretValidator(utils.BaseTestCase):
self.secret_req,
)
self.assertEqual('bit_length', exception.invalid_property)
self.assertIn('bit_length', exception.message)
self.assertIn('bit_length', six.text_type(exception))
def test_should_raise_non_integer_bit_length(self):
self.secret_req['bit_length'] = "23"
@ -253,7 +253,7 @@ class WhenTestingSecretValidator(utils.BaseTestCase):
self.secret_req,
)
self.assertEqual('bit_length', exception.invalid_property)
self.assertIn('bit_length', exception.message)
self.assertIn('bit_length', six.text_type(exception))
def test_should_raise_bit_length_less_than_min(self):
self.secret_req['bit_length'] = 0
@ -264,7 +264,7 @@ class WhenTestingSecretValidator(utils.BaseTestCase):
self.secret_req,
)
self.assertEqual('bit_length', exception.invalid_property)
self.assertIn('bit_length', exception.message)
self.assertIn('bit_length', six.text_type(exception))
def test_should_raise_bit_length_greater_than_max(self):
self.secret_req['bit_length'] = 32768
@ -275,7 +275,7 @@ class WhenTestingSecretValidator(utils.BaseTestCase):
self.secret_req,
)
self.assertEqual('bit_length', exception.invalid_property)
self.assertIn('bit_length', exception.message)
self.assertIn('bit_length', six.text_type(exception))
def test_should_raise_mode_length_greater_than_max(self):
self.secret_req['mode'] = 'a' * 256
@ -286,7 +286,7 @@ class WhenTestingSecretValidator(utils.BaseTestCase):
self.secret_req,
)
self.assertEqual('mode', exception.invalid_property)
self.assertIn('mode', exception.message)
self.assertIn('mode', six.text_type(exception))
def test_should_raise_mode_is_non_string(self):
self.secret_req['mode'] = 123
@ -297,7 +297,7 @@ class WhenTestingSecretValidator(utils.BaseTestCase):
self.secret_req,
)
self.assertEqual('mode', exception.invalid_property)
self.assertIn('mode', exception.message)
self.assertIn('mode', six.text_type(exception))
def test_validation_should_raise_with_empty_payload(self):
self.secret_req['payload'] = ' '
@ -308,7 +308,7 @@ class WhenTestingSecretValidator(utils.BaseTestCase):
self.secret_req,
)
self.assertEqual('payload', exception.invalid_property)
self.assertIn('payload', exception.message)
self.assertIn('payload', six.text_type(exception))
def test_should_raise_already_expired(self):
self.secret_req['expiration'] = '2004-02-28T19:14:44.180394'
@ -319,7 +319,7 @@ class WhenTestingSecretValidator(utils.BaseTestCase):
self.secret_req,
)
self.assertEqual('expiration', exception.invalid_property)
self.assertIn('expiration', exception.message)
self.assertIn('expiration', six.text_type(exception))
def test_should_raise_expiration_nonsense(self):
self.secret_req['expiration'] = 'nonsense'
@ -330,7 +330,7 @@ class WhenTestingSecretValidator(utils.BaseTestCase):
self.secret_req,
)
self.assertEqual('expiration', exception.invalid_property)
self.assertIn('expiration', exception.message)
self.assertIn('expiration', six.text_type(exception))
def test_should_raise_expiration_is_non_string(self):
self.secret_req['expiration'] = 123
@ -341,7 +341,7 @@ class WhenTestingSecretValidator(utils.BaseTestCase):
self.secret_req,
)
self.assertEqual('expiration', exception.invalid_property)
self.assertIn('expiration', exception.message)
self.assertIn('expiration', six.text_type(exception))
def test_should_raise_expiration_greater_than_max(self):
self.secret_req['expiration'] = 'a' * 256
@ -352,7 +352,7 @@ class WhenTestingSecretValidator(utils.BaseTestCase):
self.secret_req,
)
self.assertEqual('expiration', exception.invalid_property)
self.assertIn('expiration', exception.message)
self.assertIn('expiration', six.text_type(exception))
def test_should_raise_algorithm_is_non_string(self):
self.secret_req['algorithm'] = 123
@ -363,7 +363,7 @@ class WhenTestingSecretValidator(utils.BaseTestCase):
self.secret_req,
)
self.assertEqual('algorithm', exception.invalid_property)
self.assertIn('algorithm', exception.message)
self.assertIn('algorithm', six.text_type(exception))
def test_should_raise_algorithm_greater_than_max(self):
self.secret_req['algorithm'] = 'a' * 256
@ -374,7 +374,7 @@ class WhenTestingSecretValidator(utils.BaseTestCase):
self.secret_req,
)
self.assertEqual('algorithm', exception.invalid_property)
self.assertIn('algorithm', exception.message)
self.assertIn('algorithm', six.text_type(exception))
def test_should_raise_all_nulls(self):
self.secret_req = {'name': None,
@ -416,7 +416,7 @@ class WhenTestingSecretValidator(utils.BaseTestCase):
self.validator.validate(self.secret_req)
except excep.InvalidObject as e:
self.assertIsNotNone(e)
self.assertIsNotNone(e.message)
self.assertIsNotNone(six.text_type(e))
else:
self.fail('No validation exception was raised')
@ -454,7 +454,7 @@ class WhenTestingSecretValidator(utils.BaseTestCase):
self.secret_req,
)
self.assertEqual('payload_content_type', exception.invalid_property)
self.assertIn('payload_content_type', exception.message)
self.assertIn('payload_content_type', six.text_type(exception))
def test_should_raise_with_payload_content_encoding_greater_than_max(self):
self.secret_req['payload_content_encoding'] = 'a' * 256
@ -465,7 +465,7 @@ class WhenTestingSecretValidator(utils.BaseTestCase):
)
self.assertEqual('payload_content_encoding',
exception.invalid_property)
self.assertIn('payload_content_encoding', exception.message)
self.assertIn('payload_content_encoding', six.text_type(exception))
def test_should_raise_with_plain_text_and_encoding(self):
self.secret_req['payload_content_encoding'] = 'base64'
@ -624,7 +624,7 @@ class WhenTestingContainerValidator(utils.BaseTestCase):
self.container_req,
)
self.assertEqual('name', exception.invalid_property)
self.assertIn('name', exception.message)
self.assertIn('name', six.text_type(exception))
def test_should_raise_nonstring_secret_name(self):
self.secret_refs[0]["name"] = 5
@ -668,7 +668,7 @@ class WhenTestingContainerValidator(utils.BaseTestCase):
self.container_req,
)
self.assertIn('type', exception.message)
self.assertIn('type', six.text_type(exception))
def test_should_raise_empty_type(self):
self.container_req['type'] = ''

View File

@ -11,6 +11,7 @@
# limitations under the License.
import mock
import six
import sqlalchemy
from alembic import script as alembic_script
@ -120,7 +121,7 @@ class WhenInvokingExceptionMethods(utils.BaseTestCase):
self.assertEqual(
"No test_entity found with ID 123456",
exception_result.message)
six.text_type(exception_result))
def test_should_raise_for_entity_id_not_found(self):
@ -131,7 +132,7 @@ class WhenInvokingExceptionMethods(utils.BaseTestCase):
self.assertEqual(
"Entity ID 123456 not found",
exception_result.message)
six.text_type(exception_result))
def test_should_raise_for_no_entities_found(self):
@ -142,7 +143,7 @@ class WhenInvokingExceptionMethods(utils.BaseTestCase):
self.assertEqual(
"No entities of type test_entity found",
exception_result.message)
six.text_type(exception_result))
class WhenTestingBaseRepository(database_utils.RepositoryTestCase):
@ -159,7 +160,7 @@ class WhenTestingBaseRepository(database_utils.RepositoryTestCase):
self.assertEqual(
"Must supply non-None Entity.",
exception_result.message)
six.text_type(exception_result))
def test_should_raise_invalid_create_from_entity_with_id(self):
entity = models.ModelBase()
@ -172,7 +173,7 @@ class WhenTestingBaseRepository(database_utils.RepositoryTestCase):
self.assertEqual(
"Must supply Entity with id=None (i.e. new entity).",
exception_result.message)
six.text_type(exception_result))
def test_should_raise_invalid_do_validate_no_status(self):
exception_result = self.assertRaises(
@ -182,7 +183,7 @@ class WhenTestingBaseRepository(database_utils.RepositoryTestCase):
self.assertEqual(
"Entity status is required.",
exception_result.message)
six.text_type(exception_result))
def test_should_raise_invalid_do_validate_bad_status(self):
exception_result = self.assertRaises(
@ -192,7 +193,7 @@ class WhenTestingBaseRepository(database_utils.RepositoryTestCase):
self.assertEqual(
"Invalid status 'BOGUS_STATUS' for Entity.",
exception_result.message)
six.text_type(exception_result))
class WhenTestingWrapDbError(utils.BaseTestCase):
@ -239,7 +240,7 @@ class WhenTestingGetEnginePrivate(utils.BaseTestCase):
self.assertEqual(
'Error configuring registry database with supplied '
'sql_connection. Got error: Abort!',
exception_result.message)
six.text_type(exception_result))
@mock.patch('barbican.model.repositories._create_engine')
def test_should_complete_with_no_alembic_create_default_configs(

View File

@ -9,6 +9,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import six
from barbican.common import exception
from barbican.model import models
@ -88,7 +89,7 @@ class WhenTestingContainerConsumerRepository(utils.RepositoryTestCase):
session=session)
self.assertIn(
"SQL constraint check failed",
exception_result.message)
six.text_type(exception_result))
def test_should_raise_no_result_found_get_container_id(self):
session = self.repo.get_session()

View File

@ -15,6 +15,7 @@ from barbican.common import exception
from barbican.model import models
from barbican.model import repositories
from barbican.tests import database_utils
import six
class WhenTestingSecretStoresRepo(database_utils.RepositoryTestCase):
@ -170,7 +171,7 @@ class WhenTestingSecretStoresRepo(database_utils.RepositoryTestCase):
self._create_secret_store(name, store_plugin, crypto_plugin, False)
self.assertFail()
except exception.ConstraintCheck as ex:
self.assertIn("SQL constraint check failed", ex.message)
self.assertIn("SQL constraint check failed", six.text_type(ex))
class WhenTestingProjectSecretStoreRepo(database_utils.RepositoryTestCase):
@ -314,7 +315,7 @@ class WhenTestingProjectSecretStoreRepo(database_utils.RepositoryTestCase):
self._create_project_store(project1.id, s_store2.id)
self.assertFail()
except exception.ConstraintCheck as ex:
self.assertIn("SQL constraint check failed", ex.message)
self.assertIn("SQL constraint check failed", six.text_type(ex))
def test_get_secret_store_for_project(self):
project1 = self._create_project()

View File

@ -14,6 +14,7 @@
# limitations under the License.
import mock
import six
from barbican.common import utils as common_utils
from barbican.plugin.crypto import base
@ -157,7 +158,7 @@ class WhenTestingSecretStorePluginManager(utils.BaseTestCase):
self.assertEqual(
'Secret store plugin "{name}" not found.'.format(name=plugin_name),
exception_result.message)
six.text_type(exception_result))
def test_get_generate_no_plugin_found(self):
self.manager.extensions = []
@ -241,7 +242,7 @@ class WhenTestingSecretStorePluginManager(utils.BaseTestCase):
self.manager.get_plugin_retrieve_delete,
plugin_name=plugin_name,
)
self.assertIn(plugin_name, exception_result.message)
self.assertIn(plugin_name, six.text_type(exception_result))
def test_get_store_plugin_with_tkey_and_supports_storage(self):
plugin1 = TestSecretStore([str.KeyAlgorithm.AES])

View File

@ -15,6 +15,7 @@ limitations under the License.
"""
import logging
import os
import six
class BaseBehaviors(object):
@ -31,7 +32,8 @@ class BaseBehaviors(object):
json_data = response.json()
except ValueError as e:
self.LOG.exception(e)
self.LOG.error("Error converting response to JSON: %s", e.message)
self.LOG.error("Error converting response to JSON: %s",
six.text_type(e))
self.LOG.error("Response Content: %s", response.content)
return json_data