From f4e6f12a714080a1e0391d4891d3bcf0eecfbaaf Mon Sep 17 00:00:00 2001 From: David Stanek Date: Wed, 25 Nov 2015 00:23:17 +0000 Subject: [PATCH] Removes py26 support We are removing Python 2.6 support from the Keystone libraries. Change-Id: I1c7a79edd41a73946c9d77bfb8cd2075e2500760 Closes-Bug: 1519449 --- keystoneclient/__init__.py | 6 +++--- keystoneclient/common/cms.py | 8 ++------ keystoneclient/tests/unit/v2_0/test_auth.py | 7 ++----- keystoneclient/tests/unit/v3/test_auth.py | 8 ++------ setup.cfg | 1 - tox.ini | 2 +- 6 files changed, 10 insertions(+), 22 deletions(-) diff --git a/keystoneclient/__init__.py b/keystoneclient/__init__.py index ee848db74..e8ef58ebc 100644 --- a/keystoneclient/__init__.py +++ b/keystoneclient/__init__.py @@ -27,6 +27,7 @@ Identity V2 and V3 clients can also be created directly. See """ +import importlib import sys import pbr.version @@ -67,10 +68,9 @@ class _LazyImporter(object): 'v2_0', 'v3', ] - # __import__ rather than importlib for Python 2.6. if name in lazy_submodules: - __import__('keystoneclient.%s' % name) - return getattr(self, name) + return importlib.import_module('keystoneclient.%s' % name) + # Return module attributes like __all__ etc. return getattr(self._module, name) diff --git a/keystoneclient/common/cms.py b/keystoneclient/common/cms.py index 21cd39432..c1260d3f1 100644 --- a/keystoneclient/common/cms.py +++ b/keystoneclient/common/cms.py @@ -101,7 +101,7 @@ def _process_communicate_handle_oserror(process, data, files): except OSError as e: if e.errno != errno.EPIPE: raise - # OSError with EPIPE only occurs with Python 2.6.x/old 2.7.x + # OSError with EPIPE only occurs with old Python 2.7.x versions # http://bugs.python.org/issue10963 # The quick exit is typically caused by the openssl command not being @@ -191,11 +191,7 @@ def cms_verify(formatted, signing_cert_file_name, ca_file_name, else: raise exceptions.CertificateConfigError(err) elif retcode != OpensslCmsExitStatus.SUCCESS: - # NOTE(dmllr): Python 2.6 compatibility: - # CalledProcessError did not have output keyword argument - e = subprocess.CalledProcessError(retcode, 'openssl') - e.output = err - raise e + raise subprocess.CalledProcessError(retcode, 'openssl', output=err) return output diff --git a/keystoneclient/tests/unit/v2_0/test_auth.py b/keystoneclient/tests/unit/v2_0/test_auth.py index a10fd964b..803fa5cae 100644 --- a/keystoneclient/tests/unit/v2_0/test_auth.py +++ b/keystoneclient/tests/unit/v2_0/test_auth.py @@ -15,6 +15,7 @@ import datetime from oslo_serialization import jsonutils from oslo_utils import timeutils +from testtools import testcase from keystoneclient import exceptions from keystoneclient.tests.unit.v2_0 import utils @@ -91,17 +92,13 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase): self.stub_auth(status_code=401, json=error) - # Workaround for issue with assertRaises on python2.6 - # where with assertRaises(exceptions.Unauthorized): doesn't work - # right - def client_create_wrapper(): + with testcase.ExpectedException(exceptions.Unauthorized): with self.deprecations.expect_deprecations_here(): client.Client(username=self.TEST_USER, password="bad_key", project_id=self.TEST_TENANT_ID, auth_url=self.TEST_URL) - self.assertRaises(exceptions.Unauthorized, client_create_wrapper) self.assertRequestBodyIs(json=self.TEST_REQUEST_BODY) def test_auth_redirect(self): diff --git a/keystoneclient/tests/unit/v3/test_auth.py b/keystoneclient/tests/unit/v3/test_auth.py index 211633be8..177eb3b77 100644 --- a/keystoneclient/tests/unit/v3/test_auth.py +++ b/keystoneclient/tests/unit/v3/test_auth.py @@ -11,6 +11,7 @@ # under the License. from oslo_serialization import jsonutils +from testtools import testcase from keystoneclient import exceptions from keystoneclient.tests.unit.v3 import utils @@ -103,11 +104,7 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase): self.stub_auth(status_code=401, json=error) - # Workaround for issue with assertRaises on python2.6 - # where with assertRaises(exceptions.Unauthorized): doesn't work - # right - def client_create_wrapper(): - # Creating a HTTPClient not using session is deprecated. + with testcase.ExpectedException(exceptions.Unauthorized): with self.deprecations.expect_deprecations_here(): client.Client(user_domain_name=self.TEST_DOMAIN_NAME, username=self.TEST_USER, @@ -115,7 +112,6 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase): project_id=self.TEST_TENANT_ID, auth_url=self.TEST_URL) - self.assertRaises(exceptions.Unauthorized, client_create_wrapper) self.assertRequestBodyIs(json=self.TEST_REQUEST_BODY) def test_auth_redirect(self): diff --git a/setup.cfg b/setup.cfg index bb45837d1..52307d6fa 100644 --- a/setup.cfg +++ b/setup.cfg @@ -15,7 +15,6 @@ classifier = Programming Language :: Python Programming Language :: Python :: 2 Programming Language :: Python :: 2.7 - Programming Language :: Python :: 2.6 Programming Language :: Python :: 3 Programming Language :: Python :: 3.4 diff --git a/tox.ini b/tox.ini index 8e48eb345..e4843de1f 100644 --- a/tox.ini +++ b/tox.ini @@ -1,7 +1,7 @@ [tox] minversion = 1.6 skipsdist = True -envlist = py26,py27,py34,pep8,bandit +envlist = py27,py34,pep8,bandit [testenv] usedevelop = True