diff --git a/HACKING.rst b/HACKING.rst index 3c26e1931..d48265e6e 100644 --- a/HACKING.rst +++ b/HACKING.rst @@ -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. diff --git a/barbican/api/__init__.py b/barbican/api/__init__.py index fdd7b724e..ba8a57c27 100644 --- a/barbican/api/__init__.py +++ b/barbican/api/__init__.py @@ -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 diff --git a/barbican/api/controllers/acls.py b/barbican/api/controllers/acls.py index cf9b0ceb6..e5433c490 100644 --- a/barbican/api/controllers/acls.py +++ b/barbican/api/controllers/acls.py @@ -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 diff --git a/barbican/api/controllers/secrets.py b/barbican/api/controllers/secrets.py index 6a60b6709..8aa1e53ea 100644 --- a/barbican/api/controllers/secrets.py +++ b/barbican/api/controllers/secrets.py @@ -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 diff --git a/barbican/api/controllers/transportkeys.py b/barbican/api/controllers/transportkeys.py index 08a834b5b..0c8cdd1e5 100644 --- a/barbican/api/controllers/transportkeys.py +++ b/barbican/api/controllers/transportkeys.py @@ -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 diff --git a/barbican/api/controllers/versions.py b/barbican/api/controllers/versions.py index 385be5e8a..0ba736757 100644 --- a/barbican/api/controllers/versions.py +++ b/barbican/api/controllers/versions.py @@ -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 diff --git a/barbican/cmd/pkcs11_key_generation.py b/barbican/cmd/pkcs11_key_generation.py index e75100ee1..4c7f48ab9 100644 --- a/barbican/cmd/pkcs11_key_generation.py +++ b/barbican/cmd/pkcs11_key_generation.py @@ -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, diff --git a/barbican/cmd/pkcs11_migrate_kek_signatures.py b/barbican/cmd/pkcs11_migrate_kek_signatures.py index 5cb22339f..40c309b64 100644 --- a/barbican/cmd/pkcs11_migrate_kek_signatures.py +++ b/barbican/cmd/pkcs11_migrate_kek_signatures.py @@ -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 diff --git a/barbican/common/utils.py b/barbican/common/utils.py index 5e23d0cfb..fd63411b2 100644 --- a/barbican/common/utils.py +++ b/barbican/common/utils.py @@ -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) diff --git a/barbican/common/validators.py b/barbican/common/validators.py index 366b4cd18..f7958aef4 100644 --- a/barbican/common/validators.py +++ b/barbican/common/validators.py @@ -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 diff --git a/barbican/hacking/checks.py b/barbican/hacking/checks.py index 8fdaf77a7..33b88f0d5 100644 --- a/barbican/hacking/checks.py +++ b/barbican/hacking/checks.py @@ -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 diff --git a/barbican/model/models.py b/barbican/model/models.py index d0f5a6983..2e79d3365 100644 --- a/barbican/model/models.py +++ b/barbican/model/models.py @@ -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) diff --git a/barbican/objects/fields.py b/barbican/objects/fields.py index 25d5ba138..b7c955b97 100644 --- a/barbican/objects/fields.py +++ b/barbican/objects/fields.py @@ -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 diff --git a/barbican/plugin/castellan_secret_store.py b/barbican/plugin/castellan_secret_store.py index a31e64ad7..ee3283ae4 100644 --- a/barbican/plugin/castellan_secret_store.py +++ b/barbican/plugin/castellan_secret_store.py @@ -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 diff --git a/barbican/plugin/crypto/pkcs11.py b/barbican/plugin/crypto/pkcs11.py index f684842a7..823b54639 100644 --- a/barbican/plugin/crypto/pkcs11.py +++ b/barbican/plugin/crypto/pkcs11.py @@ -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') diff --git a/barbican/plugin/crypto/simple_crypto.py b/barbican/plugin/crypto/simple_crypto.py index b81eddebb..0c06fe076 100644 --- a/barbican/plugin/crypto/simple_crypto.py +++ b/barbican/plugin/crypto/simple_crypto.py @@ -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') diff --git a/barbican/plugin/dogtag.py b/barbican/plugin/dogtag.py index bbf942f58..8d3d5ac2e 100644 --- a/barbican/plugin/dogtag.py +++ b/barbican/plugin/dogtag.py @@ -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') diff --git a/barbican/plugin/util/mime_types.py b/barbican/plugin/util/mime_types.py index ab7c8f060..c6cb686d3 100644 --- a/barbican/plugin/util/mime_types.py +++ b/barbican/plugin/util/mime_types.py @@ -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 diff --git a/barbican/plugin/util/translations.py b/barbican/plugin/util/translations.py index 23994a448..880694e2d 100644 --- a/barbican/plugin/util/translations.py +++ b/barbican/plugin/util/translations.py @@ -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 diff --git a/barbican/tests/api/test_transport_keys_resource.py b/barbican/tests/api/test_transport_keys_resource.py index 6c7aec8b2..c0855af52 100644 --- a/barbican/tests/api/test_transport_keys_resource.py +++ b/barbican/tests/api/test_transport_keys_resource.py @@ -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, diff --git a/barbican/tests/common/test_quota.py b/barbican/tests/common/test_quota.py index 59de62ea2..ca1aaec41 100644 --- a/barbican/tests/common/test_quota.py +++ b/barbican/tests/common/test_quota.py @@ -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__': diff --git a/barbican/tests/common/test_utils.py b/barbican/tests/common/test_utils.py index d3ae0f5d8..00e4cffb0 100644 --- a/barbican/tests/common/test_utils.py +++ b/barbican/tests/common/test_utils.py @@ -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 diff --git a/barbican/tests/common/test_validators.py b/barbican/tests/common/test_validators.py index e94f66f5b..0e78db4fd 100644 --- a/barbican/tests/common/test_validators.py +++ b/barbican/tests/common/test_validators.py @@ -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): diff --git a/barbican/tests/model/repositories/test_repositories.py b/barbican/tests/model/repositories/test_repositories.py index 11c0450a8..79c7cbdc7 100644 --- a/barbican/tests/model/repositories/test_repositories.py +++ b/barbican/tests/model/repositories/test_repositories.py @@ -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( diff --git a/barbican/tests/model/repositories/test_repositories_consumers.py b/barbican/tests/model/repositories/test_repositories_consumers.py index e945daef6..4d10f26c5 100644 --- a/barbican/tests/model/repositories/test_repositories_consumers.py +++ b/barbican/tests/model/repositories/test_repositories_consumers.py @@ -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() diff --git a/barbican/tests/model/repositories/test_repositories_secret_consumers.py b/barbican/tests/model/repositories/test_repositories_secret_consumers.py index 0daea49cf..e108d3d5c 100644 --- a/barbican/tests/model/repositories/test_repositories_secret_consumers.py +++ b/barbican/tests/model/repositories/test_repositories_secret_consumers.py @@ -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): diff --git a/barbican/tests/model/repositories/test_repositories_secret_stores.py b/barbican/tests/model/repositories/test_repositories_secret_stores.py index 7b0ad7dbc..64198ef13 100644 --- a/barbican/tests/model/repositories/test_repositories_secret_stores.py +++ b/barbican/tests/model/repositories/test_repositories_secret_stores.py @@ -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() diff --git a/barbican/tests/objects/test_ovo_project_secret_store.py b/barbican/tests/objects/test_ovo_project_secret_store.py index 4e8bcac2e..68bdc7caf 100644 --- a/barbican/tests/objects/test_ovo_project_secret_store.py +++ b/barbican/tests/objects/test_ovo_project_secret_store.py @@ -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() diff --git a/barbican/tests/plugin/crypto/test_crypto.py b/barbican/tests/plugin/crypto/test_crypto.py index e733b4b1c..bcf7e2891 100644 --- a/barbican/tests/plugin/crypto/test_crypto.py +++ b/barbican/tests/plugin/crypto/test_crypto.py @@ -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 diff --git a/barbican/tests/plugin/crypto/test_p11_crypto.py b/barbican/tests/plugin/crypto/test_p11_crypto.py index e6789c3ac..1890ff2cd 100644 --- a/barbican/tests/plugin/crypto/test_p11_crypto.py +++ b/barbican/tests/plugin/crypto/test_p11_crypto.py @@ -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) diff --git a/barbican/tests/plugin/interface/test_secret_store.py b/barbican/tests/plugin/interface/test_secret_store.py index d1050670a..5a1dfa300 100644 --- a/barbican/tests/plugin/interface/test_secret_store.py +++ b/barbican/tests/plugin/interface/test_secret_store.py @@ -15,19 +15,17 @@ from unittest import mock -import six - from barbican.common import utils as common_utils from barbican.plugin.crypto import base from barbican.plugin.crypto import manager as cm from barbican.plugin.crypto import p11_crypto -from barbican.plugin.interface import secret_store as str +from barbican.plugin.interface import secret_store as ss from barbican.plugin import kmip_secret_store as kss from barbican.plugin import store_crypto from barbican.tests import utils -class TestSecretStore(str.SecretStoreBase): +class TestSecretStore(ss.SecretStoreBase): """Secret store plugin for testing support.""" def __init__(self, supported_alg_list): @@ -59,7 +57,7 @@ class TestSecretStore(str.SecretStoreBase): return key_spec.alg in self.alg_list -class TestSecretStoreWithTransportKey(str.SecretStoreBase): +class TestSecretStoreWithTransportKey(ss.SecretStoreBase): """Secret store plugin for testing support. This plugin will override the relevant methods for key wrapping. @@ -104,19 +102,19 @@ class WhenTestingSecretStorePluginManager(utils.BaseTestCase): def setUp(self): super(WhenTestingSecretStorePluginManager, self).setUp() - self.manager = str.SecretStorePluginManager() + self.manager = ss.SecretStorePluginManager() def test_get_store_supported_plugin_no_plugin_name(self): - plugin = TestSecretStore([str.KeyAlgorithm.AES]) + plugin = TestSecretStore([ss.KeyAlgorithm.AES]) plugin_mock = mock.MagicMock(obj=plugin) self.manager.extensions = [plugin_mock] - keySpec = str.KeySpec(str.KeyAlgorithm.AES, 128) + keySpec = ss.KeySpec(ss.KeyAlgorithm.AES, 128) self.assertEqual(plugin, self.manager.get_plugin_store(keySpec)) def test_get_store_supported_plugin_with_plugin_name(self): - plugin = TestSecretStore([str.KeyAlgorithm.AES]) + plugin = TestSecretStore([ss.KeyAlgorithm.AES]) plugin_mock = mock.MagicMock(obj=plugin) self.manager.extensions = [plugin_mock] @@ -125,33 +123,33 @@ class WhenTestingSecretStorePluginManager(utils.BaseTestCase): self.assertEqual(plugin, plugin_found) def test_get_generate_supported_plugin(self): - plugin = TestSecretStore([str.KeyAlgorithm.AES]) + plugin = TestSecretStore([ss.KeyAlgorithm.AES]) plugin_mock = mock.MagicMock(obj=plugin) self.manager.extensions = [plugin_mock] - keySpec = str.KeySpec(str.KeyAlgorithm.AES, 128) + keySpec = ss.KeySpec(ss.KeyAlgorithm.AES, 128) self.assertEqual(plugin, self.manager.get_plugin_generate(keySpec)) def test_get_store_no_plugin_found(self): self.manager.extensions = [] - keySpec = str.KeySpec(str.KeyAlgorithm.AES, 128) + keySpec = ss.KeySpec(ss.KeyAlgorithm.AES, 128) self.assertRaises( - str.SecretStorePluginsNotConfigured, + ss.SecretStorePluginsNotConfigured, self.manager.get_plugin_store, keySpec, ) def test_get_store_no_plugin_found_by_name(self): - plugin = TestSecretStore([str.KeyAlgorithm.AES]) + plugin = TestSecretStore([ss.KeyAlgorithm.AES]) plugin_mock = mock.MagicMock(obj=plugin) self.manager.extensions = [plugin_mock] - keySpec = str.KeySpec(str.KeyAlgorithm.AES, 128) + keySpec = ss.KeySpec(ss.KeyAlgorithm.AES, 128) plugin_name = 'plugin' exception_result = self.assertRaises( - str.SecretStorePluginNotFound, + ss.SecretStorePluginNotFound, self.manager.get_plugin_store, keySpec, plugin_name=plugin_name @@ -159,13 +157,13 @@ class WhenTestingSecretStorePluginManager(utils.BaseTestCase): self.assertEqual( 'Secret store plugin "{name}" not found.'.format(name=plugin_name), - six.text_type(exception_result)) + str(exception_result)) def test_get_generate_no_plugin_found(self): self.manager.extensions = [] - keySpec = str.KeySpec(str.KeyAlgorithm.AES, 128) + keySpec = ss.KeySpec(ss.KeyAlgorithm.AES, 128) self.assertRaises( - str.SecretStorePluginsNotConfigured, + ss.SecretStorePluginsNotConfigured, self.manager.get_plugin_generate, keySpec, ) @@ -174,9 +172,9 @@ class WhenTestingSecretStorePluginManager(utils.BaseTestCase): plugin = TestSecretStore([]) plugin_mock = mock.MagicMock(obj=plugin) self.manager.extensions = [plugin_mock] - keySpec = str.KeySpec(str.KeyAlgorithm.AES, 128) + keySpec = ss.KeySpec(ss.KeyAlgorithm.AES, 128) self.assertRaises( - str.SecretStoreSupportedPluginNotFound, + ss.SecretStoreSupportedPluginNotFound, self.manager.get_plugin_store, keySpec, ) @@ -185,9 +183,9 @@ class WhenTestingSecretStorePluginManager(utils.BaseTestCase): plugin = TestSecretStore([]) plugin_mock = mock.MagicMock(obj=plugin) self.manager.extensions = [plugin_mock] - keySpec = str.KeySpec(str.KeyAlgorithm.AES, 128) + keySpec = ss.KeySpec(ss.KeyAlgorithm.AES, 128) self.assertRaises( - str.SecretGenerateSupportedPluginNotFound, + ss.SecretGenerateSupportedPluginNotFound, self.manager.get_plugin_generate, keySpec, ) @@ -196,9 +194,9 @@ class WhenTestingSecretStorePluginManager(utils.BaseTestCase): plugin = TestSecretStore([]) plugin_mock = mock.MagicMock(obj=plugin) self.manager.extensions = [plugin_mock] - keySpec = str.KeySpec(str.KeyAlgorithm.AES, 128) + keySpec = ss.KeySpec(ss.KeyAlgorithm.AES, 128) self.assertRaises( - str.SecretStoreSupportedPluginNotFound, + ss.SecretStoreSupportedPluginNotFound, self.manager.get_plugin_store, key_spec=keySpec, transport_key_needed=True, @@ -208,21 +206,21 @@ class WhenTestingSecretStorePluginManager(utils.BaseTestCase): plugin = TestSecretStoreWithTransportKey([]) plugin_mock = mock.MagicMock(obj=plugin) self.manager.extensions = [plugin_mock] - keySpec = str.KeySpec(str.KeyAlgorithm.AES, 128) + keySpec = ss.KeySpec(ss.KeyAlgorithm.AES, 128) self.assertRaises( - str.SecretStoreSupportedPluginNotFound, + ss.SecretStoreSupportedPluginNotFound, self.manager.get_plugin_store, key_spec=keySpec, transport_key_needed=True, ) def test_get_store_plugin_with_no_tkey_and_supports_storage(self): - plugin = TestSecretStore([str.KeyAlgorithm.AES]) + plugin = TestSecretStore([ss.KeyAlgorithm.AES]) plugin_mock = mock.MagicMock(obj=plugin) self.manager.extensions = [plugin_mock] - keySpec = str.KeySpec(str.KeyAlgorithm.AES, 128) + keySpec = ss.KeySpec(ss.KeyAlgorithm.AES, 128) self.assertRaises( - str.SecretStoreSupportedPluginNotFound, + ss.SecretStoreSupportedPluginNotFound, self.manager.get_plugin_store, key_spec=keySpec, transport_key_needed=True, @@ -231,7 +229,7 @@ class WhenTestingSecretStorePluginManager(utils.BaseTestCase): @mock.patch('barbican.common.utils.generate_fullname_for') def test_get_retrieve_plugin_raises_when_not_available( self, generate_full_name_for): - plugin = TestSecretStore([str.KeyAlgorithm.AES]) + plugin = TestSecretStore([ss.KeyAlgorithm.AES]) plugin_mock = mock.MagicMock(obj=plugin) self.manager.extensions = [plugin_mock] @@ -239,19 +237,19 @@ class WhenTestingSecretStorePluginManager(utils.BaseTestCase): plugin_name = 'plugin name searched for' exception_result = self.assertRaises( - str.StorePluginNotAvailableOrMisconfigured, + ss.StorePluginNotAvailableOrMisconfigured, self.manager.get_plugin_retrieve_delete, plugin_name=plugin_name, ) - self.assertIn(plugin_name, six.text_type(exception_result)) + self.assertIn(plugin_name, str(exception_result)) def test_get_store_plugin_with_tkey_and_supports_storage(self): - plugin1 = TestSecretStore([str.KeyAlgorithm.AES]) + plugin1 = TestSecretStore([ss.KeyAlgorithm.AES]) plugin1_mock = mock.MagicMock(obj=plugin1) - plugin2 = TestSecretStoreWithTransportKey([str.KeyAlgorithm.AES]) + plugin2 = TestSecretStoreWithTransportKey([ss.KeyAlgorithm.AES]) plugin2_mock = mock.MagicMock(obj=plugin2) self.manager.extensions = [plugin1_mock, plugin2_mock] - keySpec = str.KeySpec(str.KeyAlgorithm.AES, 128) + keySpec = ss.KeySpec(ss.KeyAlgorithm.AES, 128) self.assertEqual(plugin2, self.manager.get_plugin_store( key_spec=keySpec, @@ -274,7 +272,7 @@ class TestSecretStorePluginManagerMultipleBackend( '_create_pkcs11') as m_pkcs11, \ mock.patch('kmip.pie.client.ProxyKmipClient') as m_kmip: - manager = str.SecretStorePluginManager() + manager = ss.SecretStorePluginManager() # check pkcs11 and kmip plugin instantiation call is invoked m_pkcs11.assert_called_once_with(None) @@ -284,7 +282,7 @@ class TestSecretStorePluginManagerMultipleBackend( username='sample_username', password='sample_password') # check store crypto adapter is matched as its defined first. - keySpec = str.KeySpec(str.KeyAlgorithm.AES, 128) + keySpec = ss.KeySpec(ss.KeyAlgorithm.AES, 128) plugin_found = manager.get_plugin_store(keySpec) self.assertIsInstance(plugin_found, store_crypto.StoreCryptoAdapterPlugin) @@ -311,7 +309,7 @@ class TestSecretStorePluginManagerMultipleBackend( '_create_pkcs11') as m_pkcs11, \ mock.patch('kmip.pie.client.ProxyKmipClient') as m_kmip: - manager = str.SecretStorePluginManager() + manager = ss.SecretStorePluginManager() # check pkcs11 and kmip plugin instantiation call is invoked m_pkcs11.assert_called_once_with(None) @@ -321,6 +319,6 @@ class TestSecretStorePluginManagerMultipleBackend( username='sample_username', password='sample_password') # check kmip store is matched as its global default store. - keySpec = str.KeySpec(str.KeyAlgorithm.AES, 128) + keySpec = ss.KeySpec(ss.KeyAlgorithm.AES, 128) plugin_found = manager.get_plugin_store(keySpec) self.assertIsInstance(plugin_found, kss.KMIPSecretStore) diff --git a/barbican/tests/queue/test_server.py b/barbican/tests/queue/test_server.py index 37b04f636..25c1ed36b 100644 --- a/barbican/tests/queue/test_server.py +++ b/barbican/tests/queue/test_server.py @@ -15,8 +15,6 @@ import datetime from unittest import mock -import six - from barbican.model import models from barbican.model import repositories from barbican.queue import server @@ -412,10 +410,9 @@ class WhenUsingTaskServer(database_utils.RepositoryTestCase): self.assertEqual(models.States.ERROR, order_result.status) self.assertEqual( - six.u( - 'Process TypeOrder failure seen - ' - 'please contact site administrator.'), + ('Process TypeOrder failure seen - ' + 'please contact site administrator.'), order_result.error_reason) self.assertEqual( - six.u('500'), + '500', order_result.error_status_code) diff --git a/barbican/tests/tasks/test_resources.py b/barbican/tests/tasks/test_resources.py index b4168f839..d82242b13 100644 --- a/barbican/tests/tasks/test_resources.py +++ b/barbican/tests/tasks/test_resources.py @@ -16,7 +16,6 @@ from unittest import mock from oslo_utils import timeutils -import six from barbican import i18n as u from barbican.model import models @@ -349,7 +348,7 @@ class WhenUpdatingOrder(BaseOrderTestCase): self.meta ) - self.assertEqual('Abort!', six.text_type(exception)) + self.assertEqual('Abort!', str(exception)) mock_mod_cert.assert_called_once_with(self.order, self.meta) @@ -526,7 +525,7 @@ class WhenCheckingCertificateStatus(BaseOrderTestCase): # Order state should be set to ERROR. self.assertEqual(models.States.ERROR, self.order.status) self.assertEqual( - six.u('Check Certificate Order Status failure seen - ' - 'please contact site administrator.'), + ('Check Certificate Order Status failure seen - ' + 'please contact site administrator.'), self.order.error_reason) self.assertEqual(500, self.order.error_status_code) diff --git a/barbican/tests/test_middleware_auth.py b/barbican/tests/test_middleware_auth.py index 6cdbddc99..9235fa1a1 100644 --- a/barbican/tests/test_middleware_auth.py +++ b/barbican/tests/test_middleware_auth.py @@ -10,7 +10,7 @@ # License for the specific language governing permissions and limitations # under the License. -from six.moves import http_client +from http import client as http_client host = "localhost" diff --git a/barbican/tests/utils.py b/barbican/tests/utils.py index c8e891829..d81d4bb5e 100644 --- a/barbican/tests/utils.py +++ b/barbican/tests/utils.py @@ -26,8 +26,7 @@ from oslo_config import cfg from oslo_utils import uuidutils import oslotest.base as oslotest from oslotest import createfile -import six -from six.moves.urllib import parse +from urllib import parse import webtest from barbican.api import app @@ -374,11 +373,11 @@ def construct_new_test_function(original_func, name, build_params): :return: A new function object """ new_func = types.FunctionType( - six.get_function_code(original_func), - six.get_function_globals(original_func), + original_func.__code__, + original_func.__globals__, name=name, - argdefs=six.get_function_defaults(original_func), - closure=six.get_function_closure(original_func) + argdefs=original_func.__defaults__, + closure=original_func.__closure__ ) for key, val in original_func.__dict__.items(): diff --git a/functionaltests/api/base.py b/functionaltests/api/base.py index f195f27dd..1a67d0e02 100644 --- a/functionaltests/api/base.py +++ b/functionaltests/api/base.py @@ -20,7 +20,6 @@ import os from oslo_utils import uuidutils import oslotest.base as oslotest -import six from testtools import testcase from barbican.tests import utils @@ -88,8 +87,7 @@ class TestCase(oslotest.BaseTestCase): return name -@six.add_metaclass(abc.ABCMeta) -class PagingTestCase(TestCase): +class PagingTestCase(TestCase, metaclass=abc.ABCMeta): def setUp(self): # super(PagingTestCase, self).setUp() diff --git a/functionaltests/api/v1/behaviors/base_behaviors.py b/functionaltests/api/v1/behaviors/base_behaviors.py index 30c8e0c6e..04069bc37 100644 --- a/functionaltests/api/v1/behaviors/base_behaviors.py +++ b/functionaltests/api/v1/behaviors/base_behaviors.py @@ -15,7 +15,6 @@ limitations under the License. """ import logging import os -import six class BaseBehaviors(object): @@ -33,7 +32,7 @@ class BaseBehaviors(object): except ValueError as e: self.LOG.exception(e) self.LOG.error("Error converting response to JSON: %s", - six.text_type(e)) + str(e)) self.LOG.error("Response Content: %s", response.content) return json_data diff --git a/functionaltests/api/v1/functional/test_secrets.py b/functionaltests/api/v1/functional/test_secrets.py index afc2cbe04..e3689c586 100644 --- a/functionaltests/api/v1/functional/test_secrets.py +++ b/functionaltests/api/v1/functional/test_secrets.py @@ -16,7 +16,6 @@ import datetime from oslo_serialization import base64 as oslo_base64 from oslo_serialization import jsonutils as json -import six import sys import testtools import time @@ -884,8 +883,8 @@ class SecretsTestCase(base.TestCase): 'array': [['boom']], 'int': [123], 'none': [None], - 'bad_character': [six.unichr(0x0080)], - 'bad_characters': [six.unichr(0x1111) + six.unichr(0xffff)] + 'bad_character': [chr(0x0080)], + 'bad_characters': [chr(0x1111) + chr(0xffff)] }) @testcase.attr('negative') def test_secret_create_defaults_invalid_payload(self, payload): diff --git a/functionaltests/common/client.py b/functionaltests/common/client.py index 08067fa9d..5ee975061 100644 --- a/functionaltests/common/client.py +++ b/functionaltests/common/client.py @@ -18,9 +18,8 @@ import os from oslo_serialization import base64 import requests -import six -from six.moves import urllib from tempest.lib.common.utils import test_utils +import urllib from functionaltests.common import auth from functionaltests.common import config @@ -94,7 +93,7 @@ class BarbicanClient(object): Throw an encode or decode exception is text can not be presented in ascii. """ - if isinstance(text, six.text_type): + if isinstance(text, str): return text.encode('ascii') else: return text.decode('ascii') diff --git a/requirements.txt b/requirements.txt index 341c5cd25..3d0c0e460 100644 --- a/requirements.txt +++ b/requirements.txt @@ -26,7 +26,6 @@ pecan!=1.0.2,!=1.0.3,!=1.0.4,!=1.2,>=1.0.0 # BSD pyOpenSSL>=17.1.0 # Apache-2.0 ldap3>=1.0.2 # LGPLv3 keystonemiddleware>=9.5.0 # Apache-2.0 -six>=1.10.0 # MIT SQLAlchemy!=1.1.5,!=1.1.6,!=1.1.7,!=1.1.8,>=1.0.10 # MIT stevedore>=1.20.0 # Apache-2.0 WebOb>=1.7.1 # MIT