Merge "Remove six"

This commit is contained in:
Zuul 2022-11-29 12:49:48 +00:00 committed by Gerrit Code Review
commit ca6c205e87
40 changed files with 157 additions and 199 deletions

View File

@ -12,7 +12,6 @@ Barbican Specific Commandments
- [B310] Check for improper use of logging format arguments.
- [B311] Use assertIsNone(...) instead of assertEqual(None, ...).
- [B312] Use assertTrue(...) rather than assertEqual(True, ...).
- [B314] str() and unicode() cannot be used on an exception. Remove or use six.text_type().
- [B317] `oslo_` should be used instead of `oslo`.
- [B318] Must use a dict comprehension instead of a dict constructor
with a sequence of key-value pairs.

View File

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

View File

@ -12,7 +12,6 @@
import pecan
import six
from barbican import api
from barbican.api import controllers
@ -104,8 +103,8 @@ class SecretACLsController(controllers.ACLMixin):
existing_acls_map = {acl.operation: acl for acl in
self.secret.secret_acls}
for operation in six.moves.filter(lambda x: data.get(x),
validators.ACL_OPERATIONS):
for operation in filter(lambda x: data.get(x),
validators.ACL_OPERATIONS):
project_access = data[operation].get('project-access')
user_ids = data[operation].get('users')
s_acl = None
@ -165,8 +164,8 @@ class SecretACLsController(controllers.ACLMixin):
existing_acls_map = {acl.operation: acl for acl in
self.secret.secret_acls}
for operation in six.moves.filter(lambda x: data.get(x),
validators.ACL_OPERATIONS):
for operation in filter(lambda x: data.get(x),
validators.ACL_OPERATIONS):
project_access = data[operation].get('project-access', True)
user_ids = data[operation].get('users', [])
s_acl = None
@ -270,8 +269,8 @@ class ContainerACLsController(controllers.ACLMixin):
existing_acls_map = {acl.operation: acl for acl in
self.container.container_acls}
for operation in six.moves.filter(lambda x: data.get(x),
validators.ACL_OPERATIONS):
for operation in filter(lambda x: data.get(x),
validators.ACL_OPERATIONS):
project_access = data[operation].get('project-access')
user_ids = data[operation].get('users')
if operation in existing_acls_map: # update if matching acl exists
@ -334,8 +333,8 @@ class ContainerACLsController(controllers.ACLMixin):
existing_acls_map = {acl.operation: acl for acl in
self.container.container_acls}
for operation in six.moves.filter(lambda x: data.get(x),
validators.ACL_OPERATIONS):
for operation in filter(lambda x: data.get(x),
validators.ACL_OPERATIONS):
project_access = data[operation].get('project-access', True)
user_ids = data[operation].get('users', [])
if operation in existing_acls_map: # update if matching acl exists

View File

@ -12,7 +12,7 @@
from oslo_utils import timeutils
import pecan
from six.moves.urllib import parse
from urllib import parse
from barbican import api
from barbican.api import controllers

View File

@ -13,7 +13,7 @@
# under the License.
import pecan
from six.moves.urllib import parse
from urllib import parse
from barbican import api
from barbican.api import controllers

View File

@ -11,7 +11,7 @@
# under the License.
import pecan
from six.moves.urllib import parse
from urllib import parse
from barbican.api import controllers
from barbican.api.controllers import containers

View File

@ -12,7 +12,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import argparse
import six
import sys
from barbican.plugin.crypto import pkcs11
@ -30,7 +29,7 @@ class KeyGenerator(object):
self.add_hmac_args()
self.args = self.parser.parse_args()
if not self.args.passphrase:
password = six.moves.input("Please enter your password: ")
password = input("Please enter your password: ")
self.pkcs11 = pkcs11.PKCS11(
library_path=self.args.library_path,
login_passphrase=self.args.passphrase or password,

View File

@ -14,7 +14,6 @@
import argparse
import base64
import six
import traceback
from oslo_db.sqlalchemy import session
@ -62,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 six.text_type(e):
if 'CKR_SIGNATURE_INVALID' in str(e):
sig_good = False
else:
raise
@ -80,7 +79,7 @@ class KekSignatureMigrator(object):
)
sig_bad = True
except P11CryptoPluginException as e:
if 'CKR_SIGNATURE_INVALID' in six.text_type(e):
if 'CKR_SIGNATURE_INVALID' in str(e):
sig_bad = False
else:
raise

View File

@ -16,6 +16,7 @@
"""
Common utilities for Barbican.
"""
import builtins
import collections
import importlib
import mimetypes
@ -25,8 +26,7 @@ from oslo_log import log
from oslo_utils import uuidutils
import pecan
import re
import six
from six.moves.urllib import parse
from urllib import parse
from barbican.common import config
from barbican import i18n as u
@ -179,7 +179,7 @@ def generate_fullname_for(instance):
module = type(instance).__module__
class_name = type(instance).__name__
if module is None or module == six.moves.builtins.__name__:
if module is None or module == builtins.__name__:
return class_name
return "{module}.{class_name}".format(module=module, class_name=class_name)

View File

@ -22,7 +22,6 @@ from ldap3.core import exceptions as ldap_exceptions
from ldap3.utils.dn import parse_dn
from OpenSSL import crypto
from oslo_utils import timeutils
import six
from barbican.api import controllers
from barbican.common import config
@ -46,7 +45,7 @@ ACL_OPERATIONS = ['read', 'write', 'delete', 'list']
def secret_too_big(data):
if isinstance(data, six.text_type):
if isinstance(data, str):
return len(data.encode('UTF-8')) > CONF.max_allowed_secret_in_bytes
else:
return len(data) > CONF.max_allowed_secret_in_bytes
@ -234,7 +233,7 @@ class NewSecretValidator(ValidatorBase):
def _extract_name(self, json_data):
"""Extracts and returns the name from the JSON data."""
name = json_data.get('name')
if isinstance(name, six.string_types):
if isinstance(name, str):
return name.strip()
return None
@ -346,13 +345,13 @@ class NewSecretMetadataValidator(ValidatorBase):
for key in list(metadata):
# make sure key is a string and url-safe.
if not isinstance(key, six.string_types):
if not isinstance(key, str):
raise exception.InvalidMetadataRequest()
self._check_string_url_safe(key)
# make sure value is a string.
value = metadata[key]
if not isinstance(value, six.string_types):
if not isinstance(value, str):
raise exception.InvalidMetadataRequest()
# If key is not lowercase, then change it

View File

@ -15,7 +15,6 @@
import ast
import re
import six
from hacking import core
import pycodestyle
@ -117,7 +116,7 @@ class CheckLoggingFormatArgs(BaseASTChecker):
if obj_name is None:
return None
return obj_name + '.' + method_name
elif isinstance(node, six.string_types):
elif isinstance(node, str):
return node
else: # could be Subscript, Call or many more
return None

View File

@ -20,7 +20,6 @@ import hashlib
from oslo_serialization import jsonutils as json
from oslo_utils import timeutils
import six
import sqlalchemy as sa
from sqlalchemy.ext import compiler
from sqlalchemy.ext import declarative
@ -195,7 +194,7 @@ class ModelBase(object):
def _iso_to_datetime(self, expiration):
"""Convert ISO formatted string to datetime."""
if isinstance(expiration, six.string_types):
if isinstance(expiration, str):
expiration_iso = timeutils.parse_isotime(expiration.strip())
expiration = timeutils.normalize_time(expiration_iso)

View File

@ -14,7 +14,6 @@
from oslo_serialization import jsonutils as json
from oslo_versionedobjects import fields
import six
# Import field errors from oslo.versionedobjects
KeyTypeError = fields.KeyTypeError
@ -75,7 +74,7 @@ IPV6Network = fields.IPV6Network
class Json(FieldType):
def coerce(self, obj, attr, value):
if isinstance(value, six.string_types):
if isinstance(value, str):
loaded = json.loads(value)
return loaded
return value

View File

@ -15,7 +15,6 @@
import abc
import base64
import six
from castellan.common.objects import key
from castellan.common.objects import opaque_data
@ -126,7 +125,7 @@ class CastellanSecretStore(ss.SecretStoreBase, metaclass=abc.ABCMeta):
return ss.SecretDTO(secret_type, data, ss.KeySpec(), None)
except Exception as e:
LOG.exception("Error retrieving secret {}: {}".format(
secret_ref, six.text_type(e)))
secret_ref, str(e)))
raise ss.SecretGeneralException(e)
def store_secret(self, secret_dto):
@ -142,7 +141,7 @@ class CastellanSecretStore(ss.SecretStoreBase, metaclass=abc.ABCMeta):
return self._meta_dict(secret_id)
except Exception as e:
LOG.exception("Error storing secret: {}".format(
six.text_type(e)))
str(e)))
raise ss.SecretGeneralException(e)
def delete_secret(self, secret_metadata):
@ -156,7 +155,7 @@ class CastellanSecretStore(ss.SecretStoreBase, metaclass=abc.ABCMeta):
secret_ref))
except Exception as e:
LOG.exception("Error deleting secret: {}".format(
six.text_type(e)))
str(e)))
raise ss.SecretGeneralException(e)
def generate_symmetric_key(self, key_spec):
@ -172,7 +171,7 @@ class CastellanSecretStore(ss.SecretStoreBase, metaclass=abc.ABCMeta):
return self._meta_dict(secret_id)
except Exception as e:
LOG.exception("Error generating symmetric key: {}".format(
six.text_type(e)))
str(e)))
raise ss.SecretGeneralException(e)
def generate_asymmetric_key(self, key_spec):
@ -205,7 +204,7 @@ class CastellanSecretStore(ss.SecretStoreBase, metaclass=abc.ABCMeta):
)
except Exception as e:
LOG.exception("Error generating asymmetric key: {}".format(
six.text_type(e)))
str(e)))
raise ss.SecretGeneralException(e)
@abc.abstractmethod

View File

@ -16,7 +16,6 @@ import textwrap
import cffi
from cryptography.hazmat.primitives import padding
import six
from barbican.common import exception
from barbican.common import utils
@ -950,7 +949,7 @@ class PKCS11(object):
def _to_bytes(string):
if isinstance(string, six.binary_type):
if isinstance(string, bytes):
return string
else:
return string.encode('UTF-8')

View File

@ -19,7 +19,6 @@ from cryptography.hazmat.primitives.asymmetric import rsa
from cryptography.hazmat.primitives import serialization
from oslo_config import cfg
from oslo_utils import encodeutils
import six
from barbican.common import config
from barbican.common import utils
@ -67,7 +66,7 @@ class SimpleCryptoPlugin(c.CryptoPluginBase):
# the kek is stored encrypted. Need to decrypt.
encryptor = fernet.Fernet(self.master_kek)
# Note : If plugin_meta type is unicode, encode to byte.
if isinstance(kek_meta_dto.plugin_meta, six.text_type):
if isinstance(kek_meta_dto.plugin_meta, str):
kek_meta_dto.plugin_meta = kek_meta_dto.plugin_meta.encode('utf-8')
return encryptor.decrypt(kek_meta_dto.plugin_meta)
@ -75,7 +74,7 @@ class SimpleCryptoPlugin(c.CryptoPluginBase):
def encrypt(self, encrypt_dto, kek_meta_dto, project_id):
kek = self._get_kek(kek_meta_dto)
unencrypted = encrypt_dto.unencrypted
if not isinstance(unencrypted, six.binary_type):
if not isinstance(unencrypted, bytes):
raise ValueError(
u._(
'Unencrypted data must be a byte type, but was '
@ -174,7 +173,7 @@ class SimpleCryptoPlugin(c.CryptoPluginBase):
passphrase_dto = None
if generate_dto.passphrase:
if isinstance(generate_dto.passphrase, six.text_type):
if isinstance(generate_dto.passphrase, str):
generate_dto.passphrase = generate_dto.passphrase.encode(
'utf-8')

View File

@ -38,7 +38,6 @@ import pki.key as key
import pki.kra
import pki.profile
from requests import exceptions as request_exceptions
import six
from barbican.common import exception
from barbican.common import utils
@ -94,7 +93,7 @@ def _setup_nss_db_services(conf):
return None
if nss_password is None:
raise ValueError(u._("nss_password is required"))
if type(nss_password) is not six.binary_type:
if type(nss_password) is not bytes:
# Password needs to be a bytes object in Python 3
nss_password = nss_password.encode('UTF-8')

View File

@ -17,8 +17,6 @@
Barbican defined mime-types
"""
import six
from barbican.common import utils
@ -65,7 +63,7 @@ CTYPES_TO_ENCODINGS = {'text/plain': None,
def normalize_content_type(mime_type):
"""Normalize the supplied content-type to an internal form."""
stripped = list(six.moves.map(lambda x: x.strip(), mime_type.split(';')))
stripped = list(map(lambda x: x.strip(), mime_type.split(';')))
mime = stripped[0].lower()
if len(stripped) > 1:
# mime type includes charset
@ -74,7 +72,7 @@ def normalize_content_type(mime_type):
# charset is malformed
return mime_type
else:
charset = list(six.moves.map(lambda x: x.strip(),
charset = list(map(lambda x: x.strip(),
charset_type.split('=')))[1]
if charset not in PLAIN_TEXT_CHARSETS:
# unsupported charset

View File

@ -15,7 +15,6 @@ from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import serialization
from OpenSSL import crypto
from oslo_serialization import base64
import six
from barbican import i18n as u # noqa
from barbican.plugin.interface import secret_store as s
@ -56,7 +55,7 @@ def normalize_before_encryption(unencrypted, content_type, content_encoding,
if not content_encoding:
b64payload = base64.encode_as_bytes(unencrypted)
elif content_encoding.lower() == 'base64':
if not isinstance(unencrypted, six.binary_type):
if not isinstance(unencrypted, bytes):
b64payload = unencrypted.encode('utf-8')
else:
b64payload = unencrypted

View File

@ -21,7 +21,6 @@ transport key resource classes.
from unittest import mock
import pecan
from six import moves
import webtest
from barbican.api import app
@ -132,7 +131,7 @@ class WhenGettingTransKeysListUsingTransportKeysResource(FunctionalTest):
self.tkeys = [create_transport_key(
id_ref='id' + str(tkid), **tk_params)
for tkid in moves.range(self.num_keys)]
for tkid in range(self.num_keys)]
self.total = len(self.tkeys)
self.repo = mock.MagicMock()
self.repo.get_by_create_date.return_value = (self.tkeys,

View File

@ -13,7 +13,6 @@
# 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
@ -234,10 +233,10 @@ class WhenTestingQuotaEnforcingFunctions(database_utils.RepositoryTestCase):
quota_enforcer.enforce,
self.project
)
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))
self.assertIn('Quota reached for project', str(exception))
self.assertIn('my_keystone_id', str(exception))
self.assertIn('secrets', str(exception))
self.assertIn(str(0), str(exception))
def test_should_pass_below_limit(self):
test_repo = DummyRepoForTestingQuotaEnforcement(4)
@ -262,10 +261,10 @@ class WhenTestingQuotaEnforcingFunctions(database_utils.RepositoryTestCase):
quota_enforcer.enforce,
self.project
)
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))
self.assertIn('Quota reached for project', str(exception))
self.assertIn('my_keystone_id', str(exception))
self.assertIn('secrets', str(exception))
self.assertIn(str(5), str(exception))
def test_should_raise_above_limit(self):
test_repo = DummyRepoForTestingQuotaEnforcement(6)
@ -280,10 +279,10 @@ class WhenTestingQuotaEnforcingFunctions(database_utils.RepositoryTestCase):
quota_enforcer.enforce,
self.project
)
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))
self.assertIn('Quota reached for project', str(exception))
self.assertIn('my_keystone_id', str(exception))
self.assertIn('secrets', str(exception))
self.assertIn(str(5), str(exception))
if __name__ == '__main__':

View File

@ -12,10 +12,10 @@
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import builtins
from unittest import mock
from oslo_config import cfg
import six
from barbican.common import config
from barbican.common import utils
@ -157,7 +157,7 @@ class WhenTestingGenerateFullClassnameForInstance(test_utils.BaseTestCase):
test_string = "foo"
fullname = utils.generate_fullname_for(test_string)
self.assertEqual(0, fullname.count("."))
self.assertNotIn(six.moves.builtins.__name__, fullname)
self.assertNotIn(builtins.__name__, fullname)
def test_returns_class_name_on_null_module(self):
self.instance.__class__.__module__ = None

View File

@ -14,7 +14,6 @@
# limitations under the License.
import datetime
import six
import unittest
from oslo_serialization import base64
@ -242,7 +241,7 @@ class WhenTestingSecretValidator(utils.BaseTestCase):
self.secret_req,
)
self.assertEqual('bit_length', exception.invalid_property)
self.assertIn('bit_length', six.text_type(exception))
self.assertIn('bit_length', str(exception))
def test_should_raise_non_integer_bit_length(self):
self.secret_req['bit_length'] = "23"
@ -253,7 +252,7 @@ class WhenTestingSecretValidator(utils.BaseTestCase):
self.secret_req,
)
self.assertEqual('bit_length', exception.invalid_property)
self.assertIn('bit_length', six.text_type(exception))
self.assertIn('bit_length', str(exception))
def test_should_raise_bit_length_less_than_min(self):
self.secret_req['bit_length'] = 0
@ -264,7 +263,7 @@ class WhenTestingSecretValidator(utils.BaseTestCase):
self.secret_req,
)
self.assertEqual('bit_length', exception.invalid_property)
self.assertIn('bit_length', six.text_type(exception))
self.assertIn('bit_length', str(exception))
def test_should_raise_bit_length_greater_than_max(self):
self.secret_req['bit_length'] = 32768
@ -275,7 +274,7 @@ class WhenTestingSecretValidator(utils.BaseTestCase):
self.secret_req,
)
self.assertEqual('bit_length', exception.invalid_property)
self.assertIn('bit_length', six.text_type(exception))
self.assertIn('bit_length', str(exception))
def test_should_raise_mode_length_greater_than_max(self):
self.secret_req['mode'] = 'a' * 256
@ -286,7 +285,7 @@ class WhenTestingSecretValidator(utils.BaseTestCase):
self.secret_req,
)
self.assertEqual('mode', exception.invalid_property)
self.assertIn('mode', six.text_type(exception))
self.assertIn('mode', str(exception))
def test_should_raise_mode_is_non_string(self):
self.secret_req['mode'] = 123
@ -297,7 +296,7 @@ class WhenTestingSecretValidator(utils.BaseTestCase):
self.secret_req,
)
self.assertEqual('mode', exception.invalid_property)
self.assertIn('mode', six.text_type(exception))
self.assertIn('mode', str(exception))
def test_validation_should_raise_with_empty_payload(self):
self.secret_req['payload'] = ' '
@ -308,7 +307,7 @@ class WhenTestingSecretValidator(utils.BaseTestCase):
self.secret_req,
)
self.assertEqual('payload', exception.invalid_property)
self.assertIn('payload', six.text_type(exception))
self.assertIn('payload', str(exception))
def test_should_raise_already_expired(self):
self.secret_req['expiration'] = '2004-02-28T19:14:44.180394'
@ -319,7 +318,7 @@ class WhenTestingSecretValidator(utils.BaseTestCase):
self.secret_req,
)
self.assertEqual('expiration', exception.invalid_property)
self.assertIn('expiration', six.text_type(exception))
self.assertIn('expiration', str(exception))
def test_should_raise_expiration_nonsense(self):
self.secret_req['expiration'] = 'nonsense'
@ -330,7 +329,7 @@ class WhenTestingSecretValidator(utils.BaseTestCase):
self.secret_req,
)
self.assertEqual('expiration', exception.invalid_property)
self.assertIn('expiration', six.text_type(exception))
self.assertIn('expiration', str(exception))
def test_should_raise_expiration_is_non_string(self):
self.secret_req['expiration'] = 123
@ -341,7 +340,7 @@ class WhenTestingSecretValidator(utils.BaseTestCase):
self.secret_req,
)
self.assertEqual('expiration', exception.invalid_property)
self.assertIn('expiration', six.text_type(exception))
self.assertIn('expiration', str(exception))
def test_should_raise_expiration_greater_than_max(self):
self.secret_req['expiration'] = 'a' * 256
@ -352,7 +351,7 @@ class WhenTestingSecretValidator(utils.BaseTestCase):
self.secret_req,
)
self.assertEqual('expiration', exception.invalid_property)
self.assertIn('expiration', six.text_type(exception))
self.assertIn('expiration', str(exception))
def test_should_raise_algorithm_is_non_string(self):
self.secret_req['algorithm'] = 123
@ -363,7 +362,7 @@ class WhenTestingSecretValidator(utils.BaseTestCase):
self.secret_req,
)
self.assertEqual('algorithm', exception.invalid_property)
self.assertIn('algorithm', six.text_type(exception))
self.assertIn('algorithm', str(exception))
def test_should_raise_algorithm_greater_than_max(self):
self.secret_req['algorithm'] = 'a' * 256
@ -374,7 +373,7 @@ class WhenTestingSecretValidator(utils.BaseTestCase):
self.secret_req,
)
self.assertEqual('algorithm', exception.invalid_property)
self.assertIn('algorithm', six.text_type(exception))
self.assertIn('algorithm', str(exception))
def test_should_raise_all_nulls(self):
self.secret_req = {'name': None,
@ -416,7 +415,7 @@ class WhenTestingSecretValidator(utils.BaseTestCase):
self.validator.validate(self.secret_req)
except excep.InvalidObject as e:
self.assertIsNotNone(e)
self.assertIsNotNone(six.text_type(e))
self.assertIsNotNone(str(e))
else:
self.fail('No validation exception was raised')
@ -454,7 +453,7 @@ class WhenTestingSecretValidator(utils.BaseTestCase):
self.secret_req,
)
self.assertEqual('payload_content_type', exception.invalid_property)
self.assertIn('payload_content_type', six.text_type(exception))
self.assertIn('payload_content_type', str(exception))
def test_should_raise_with_payload_content_encoding_greater_than_max(self):
self.secret_req['payload_content_encoding'] = 'a' * 256
@ -465,7 +464,7 @@ class WhenTestingSecretValidator(utils.BaseTestCase):
)
self.assertEqual('payload_content_encoding',
exception.invalid_property)
self.assertIn('payload_content_encoding', six.text_type(exception))
self.assertIn('payload_content_encoding', str(exception))
def test_should_raise_with_plain_text_and_encoding(self):
self.secret_req['payload_content_encoding'] = 'base64'
@ -515,7 +514,7 @@ class WhenTestingSecretValidator(utils.BaseTestCase):
def test_validation_should_raise_with_unicode_payload(self):
self.secret_req['payload_content_type'] = 'application/octet-stream'
self.secret_req['payload_content_encoding'] = 'base64'
self.secret_req['payload'] = six.unichr(0x0080)
self.secret_req['payload'] = chr(0x0080)
exception = self.assertRaises(
excep.InvalidObject,
@ -624,7 +623,7 @@ class WhenTestingContainerValidator(utils.BaseTestCase):
self.container_req,
)
self.assertEqual('name', exception.invalid_property)
self.assertIn('name', six.text_type(exception))
self.assertIn('name', str(exception))
def test_should_raise_nonstring_secret_name(self):
self.secret_refs[0]["name"] = 5
@ -668,7 +667,7 @@ class WhenTestingContainerValidator(utils.BaseTestCase):
self.container_req,
)
self.assertIn('type', six.text_type(exception))
self.assertIn('type', str(exception))
def test_should_raise_empty_type(self):
self.container_req['type'] = ''
@ -1258,7 +1257,7 @@ class WhenTestingKeyTypeOrderValidator(utils.BaseTestCase):
self.validator.validate,
self.key_order_req)
self.assertIn("bit_length' is required field for key type order",
six.text_type(exception))
str(exception))
def test_should_raise_with_zero_bit_length_in_order_refs(self):
self.key_order_req['meta']['bit_length'] = 0
@ -1347,7 +1346,7 @@ class WhenTestingAsymmetricTypeOrderValidator(utils.BaseTestCase):
self.asymmetric_order_req)
self.assertIn(
"bit_length' is required field for asymmetric key type order",
six.text_type(exception))
str(exception))
def test_should_raise_with_zero_bit_length_in_asymmetric_order_refs(self):
self.asymmetric_order_req['meta']['bit_length'] = 0
@ -1814,7 +1813,7 @@ class WhenTestingSecretMetadataValidator(utils.BaseTestCase):
self.validator.validate,
self.metadata_req)
self.assertIn("metadata' is a required property",
six.text_type(exception))
str(exception))
def test_should_raise_invalid_key_non_string(self):
self.key1 = 0
@ -1827,7 +1826,7 @@ class WhenTestingSecretMetadataValidator(utils.BaseTestCase):
self.validator.validate,
metadata_req)
self.assertIn("Invalid Metadata. Keys and Values must be Strings.",
six.text_type(exception))
str(exception))
def test_should_raise_invalid_key_non_url_safe_string(self):
self.key1 = "key/01"
@ -1840,7 +1839,7 @@ class WhenTestingSecretMetadataValidator(utils.BaseTestCase):
self.validator.validate,
metadata_req)
self.assertIn("Invalid Key. Key must be URL safe.",
six.text_type(exception))
str(exception))
def test_should_raise_invalid_value_non_string(self):
self.value1 = 0
@ -1853,7 +1852,7 @@ class WhenTestingSecretMetadataValidator(utils.BaseTestCase):
self.validator.validate,
metadata_req)
self.assertIn("Invalid Metadata. Keys and Values must be Strings.",
six.text_type(exception))
str(exception))
@utils.parameterized_test_case
@ -1896,7 +1895,7 @@ class WhenTestingSecretMetadatumValidator(utils.BaseTestCase):
self.metadata_req)
self.assertIn("Provided object does not match schema "
"'SecretMetadatum'",
six.text_type(exception))
str(exception))
def test_should_raise_invalid_key_no_key(self):
del self.metadata_req[self.key2]
@ -1905,7 +1904,7 @@ class WhenTestingSecretMetadatumValidator(utils.BaseTestCase):
self.metadata_req)
self.assertIn("Provided object does not match schema "
"'SecretMetadatum'",
six.text_type(exception))
str(exception))
def test_should_raise_invalid_key_no_value(self):
del self.metadata_req[self.key1]
@ -1914,7 +1913,7 @@ class WhenTestingSecretMetadatumValidator(utils.BaseTestCase):
self.metadata_req)
self.assertIn("Provided object does not match schema "
"'SecretMetadatum'",
six.text_type(exception))
str(exception))
def test_should_raise_invalid_key_non_string(self):
self.value1 = 0
@ -1928,7 +1927,7 @@ class WhenTestingSecretMetadatumValidator(utils.BaseTestCase):
metadata_req)
self.assertIn("Provided object does not match schema "
"'SecretMetadatum'",
six.text_type(exception))
str(exception))
def test_should_raise_invalid_key_non_url_safe_string(self):
self.value1 = "key/01"
@ -1941,7 +1940,7 @@ class WhenTestingSecretMetadatumValidator(utils.BaseTestCase):
self.validator.validate,
metadata_req)
self.assertIn("Invalid Key. Key must be URL safe.",
six.text_type(exception))
str(exception))
def test_should_raise_invalid_value_non_string(self):
self.value2 = 0
@ -1955,7 +1954,7 @@ class WhenTestingSecretMetadatumValidator(utils.BaseTestCase):
metadata_req)
self.assertIn("Provided object does not match schema "
"'SecretMetadatum'",
six.text_type(exception))
str(exception))
def test_should_raise_invalid_extra_sent_key(self):
self.value2 = 0
@ -1970,7 +1969,7 @@ class WhenTestingSecretMetadatumValidator(utils.BaseTestCase):
metadata_req)
self.assertIn("Provided object does not match schema "
"'SecretMetadatum'",
six.text_type(exception))
str(exception))
class WhenTestingSecretConsumerValidator(utils.BaseTestCase):

View File

@ -14,7 +14,6 @@ from unittest import mock
from alembic import script as alembic_script
from oslo_config import cfg
import six
import sqlalchemy
from barbican.common import config
@ -120,7 +119,7 @@ class WhenInvokingExceptionMethods(utils.BaseTestCase):
self.assertEqual(
"No test_entity found with ID 123456",
six.text_type(exception_result))
str(exception_result))
def test_should_raise_for_entity_id_not_found(self):
@ -131,7 +130,7 @@ class WhenInvokingExceptionMethods(utils.BaseTestCase):
self.assertEqual(
"Entity ID 123456 not found",
six.text_type(exception_result))
str(exception_result))
def test_should_raise_for_no_entities_found(self):
@ -142,7 +141,7 @@ class WhenInvokingExceptionMethods(utils.BaseTestCase):
self.assertEqual(
"No entities of type test_entity found",
six.text_type(exception_result))
str(exception_result))
class WhenTestingBaseRepository(database_utils.RepositoryTestCase):
@ -159,7 +158,7 @@ class WhenTestingBaseRepository(database_utils.RepositoryTestCase):
self.assertEqual(
"Must supply non-None Entity.",
six.text_type(exception_result))
str(exception_result))
def test_should_raise_invalid_create_from_entity_with_id(self):
entity = models.ModelBase()
@ -172,7 +171,7 @@ class WhenTestingBaseRepository(database_utils.RepositoryTestCase):
self.assertEqual(
"Must supply Entity with id=None (i.e. new entity).",
six.text_type(exception_result))
str(exception_result))
def test_should_raise_invalid_do_validate_no_status(self):
exception_result = self.assertRaises(
@ -182,7 +181,7 @@ class WhenTestingBaseRepository(database_utils.RepositoryTestCase):
self.assertEqual(
"Entity status is required.",
six.text_type(exception_result))
str(exception_result))
def test_should_raise_invalid_do_validate_bad_status(self):
exception_result = self.assertRaises(
@ -192,7 +191,7 @@ class WhenTestingBaseRepository(database_utils.RepositoryTestCase):
self.assertEqual(
"Invalid status 'BOGUS_STATUS' for Entity.",
six.text_type(exception_result))
str(exception_result))
class WhenTestingWrapDbError(utils.BaseTestCase):
@ -239,7 +238,7 @@ class WhenTestingGetEnginePrivate(utils.BaseTestCase):
self.assertEqual(
'Error configuring registry database with supplied '
'sql_connection. Got error: Abort!',
six.text_type(exception_result))
str(exception_result))
@mock.patch('barbican.model.repositories._create_engine')
def test_should_complete_with_no_alembic_create_default_configs(

View File

@ -9,8 +9,6 @@
# 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
from barbican.model import repositories
@ -89,7 +87,7 @@ class WhenTestingContainerConsumerRepository(utils.RepositoryTestCase):
session=session)
self.assertIn(
"SQL constraint check failed",
six.text_type(exception_result))
str(exception_result))
def test_should_raise_no_result_found_get_container_id(self):
session = self.repo.get_session()

View File

@ -11,8 +11,6 @@
# 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
from barbican.model import repositories
@ -119,7 +117,7 @@ class WhenTestingSecretConsumerRepository(utils.RepositoryTestCase):
exception.ConstraintCheck, self._create_consumer
)
self.assertIn(
"SQL constraint check failed", six.text_type(exception_result)
"SQL constraint check failed", str(exception_result)
)
def test_should_get_count_zero(self):

View File

@ -15,7 +15,6 @@ 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):
@ -171,7 +170,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", six.text_type(ex))
self.assertIn("SQL constraint check failed", str(ex))
class WhenTestingProjectSecretStoreRepo(database_utils.RepositoryTestCase):
@ -315,7 +314,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", six.text_type(ex))
self.assertIn("SQL constraint check failed", str(ex))
def test_get_secret_store_for_project(self):
project1 = self._create_project()

View File

@ -11,8 +11,6 @@
# 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 oslo_utils import uuidutils
from barbican.common import exception
@ -150,7 +148,7 @@ class TestProjectSecretStore(test_ovo_base.OVOTestCase):
self._create_project_secret_store(project1.id, secret_stores2.id)
self.assertFail()
except exception.ConstraintCheck as ex:
self.assertIn("SQL constraint check failed", six.text_type(ex))
self.assertIn("SQL constraint check failed", str(ex))
def test_ovo_get_secret_store_for_project(self):
project1 = self._create_project()

View File

@ -19,7 +19,6 @@ from unittest import mock
from cryptography import fernet
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import serialization
import six
from barbican.model import models
from barbican.plugin.crypto import base as plugin
@ -68,7 +67,7 @@ class WhenTestingSimpleCryptoPlugin(utils.BaseTestCase):
project_kek = fernet.Fernet.generate_key()
encryptor = fernet.Fernet(self.plugin.master_kek)
ENC_project_kek = encryptor.encrypt(project_kek)
UENC_project_kek = six.u(ENC_project_kek)
UENC_project_kek = ENC_project_kek
kek_meta_dto = self._get_mocked_kek_meta_dto()
kek_meta_dto.plugin_meta = UENC_project_kek

View File

@ -13,10 +13,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import builtins
from unittest import mock
import six
from barbican.common import exception as ex
from barbican.model import models
from barbican.plugin.crypto import base as plugin_import
@ -309,7 +308,7 @@ class WhenTestingP11CryptoPlugin(utils.BaseTestCase):
d = '01234567' * 4
mo = mock.mock_open(read_data=d)
with mock.patch(six.moves.builtins.__name__ + '.open',
with mock.patch(builtins.__name__ + '.open',
mo,
create=True):
p11 = self.plugin._create_pkcs11(ffi)

View File

@ -15,19 +15,17 @@
from unittest import mock